From c6d35ba732fee5f17f2bde7c2a4389081f7cf348 Mon Sep 17 00:00:00 2001 From: Hugo van Rijswijk Date: Sun, 12 Nov 2023 12:58:35 +0100 Subject: [PATCH] Replace aggregate with dependsOn for single task (#1452) --- build.sbt | 26 +++++++++++-------- docs/contributing.md | 1 - .../model/InitialTestRunCoverageReport.scala | 2 +- .../scala/stryker4s/run/TestRunnerTest.scala | 2 +- .../stryker4s/model/TestInterfaceMapper.scala | 2 +- .../sbt/runner/ProcessTestRunner.scala | 2 +- .../sbt/runner/TestRunnerConnection.scala | 2 +- .../sbt-test/sbt-stryker4s/test-1/build.sbt | 2 +- .../src/test/scala/example/ExampleTest.scala | 12 +++------ .../src/test/scala/example/IgnoreMeTest.scala | 12 +++------ .../src/test/scala/example/TestObj1Spec.scala | 21 +++++++-------- .../src/test/scala/example/TestObj2Spec.scala | 11 +++----- .../src/main/scala/stryker4s/package.scala | 2 +- .../stryker4s/sbt/testrunner/Context.scala | 2 +- .../sbt/testrunner/MessageHandler.scala | 2 +- .../sbt/testrunner/SbtTestRunnerMain.scala | 2 +- .../sbt/testrunner/TestInterfaceMapper.scala | 2 +- .../stryker4s/sbt/testrunner/TestRunner.scala | 2 +- .../protobuf/stryker4s/api/testprocess.proto | 2 +- .../api/testprocess/CoverageReport.scala | 2 +- .../testprocess/TestProcessProperties.scala | 2 +- 21 files changed, 51 insertions(+), 62 deletions(-) diff --git a/build.sbt b/build.sbt index 08cdaa0c0..814b6f3e0 100644 --- a/build.sbt +++ b/build.sbt @@ -1,5 +1,6 @@ import Dependencies.* import Settings.* +import sbt.internal.ProjectMatrix lazy val root = (project withId "stryker4s" in file(".")) .settings( @@ -33,30 +34,26 @@ lazy val root = (project withId "stryker4s" in file(".")) ) lazy val core = (projectMatrix in file("modules") / "core") - .settings(commonSettings, coreSettings) + .settings(commonSettings, coreSettings, publishLocalDependsOn(api, testRunnerApi, testkit)) .dependsOn(api, testRunnerApi, testkit % Test) - .aggregate(api, testRunnerApi, testkit) .jvmPlatform(scalaVersions = versions.crossScalaVersions) lazy val commandRunner = (projectMatrix in file("modules") / "commandRunner") - .settings(commonSettings, commandRunnerSettings) + .settings(commonSettings, commandRunnerSettings, publishLocalDependsOn(core, testkit)) .dependsOn(core, testkit % Test) - .aggregate(core, testkit) .jvmPlatform(scalaVersions = versions.crossScalaVersions) // sbt plugins have to use Scala 2.12 lazy val sbtPlugin = (projectMatrix in file("modules") / "sbt") .enablePlugins(SbtPlugin) .defaultAxes(VirtualAxis.scalaPartialVersion("2.12"), VirtualAxis.jvm) - .settings(commonSettings, sbtPluginSettings) + .settings(commonSettings, sbtPluginSettings, publishLocalDependsOn(core)) .dependsOn(core) - .aggregate(core) .jvmPlatform(scalaVersions = Seq(versions.scala212)) lazy val sbtTestRunner = (projectMatrix in file("modules") / "sbtTestRunner") - .settings(commonSettings, sbtTestRunnerSettings) + .settings(commonSettings, sbtTestRunnerSettings, publishLocalDependsOn(testRunnerApi)) .dependsOn(testRunnerApi) - .aggregate(testRunnerApi) .jvmPlatform(scalaVersions = versions.fullCrossScalaVersions) lazy val testRunnerApi = (projectMatrix in file("modules") / "testRunnerApi") @@ -66,13 +63,20 @@ lazy val testRunnerApi = (projectMatrix in file("modules") / "testRunnerApi") // Pure Java module with interfaces lazy val api = (projectMatrix in file("modules") / "api") .settings(apiSettings) - .jvmPlatform(false) + .jvmPlatform(autoScalaLibrary = false) lazy val testkit = (projectMatrix in file("modules") / "testkit") - .settings(commonSettings, testkitSettings) + .settings(commonSettings, testkitSettings, publishLocalDependsOn(api)) .dependsOn(api) - .aggregate(api) .jvmPlatform(scalaVersions = versions.crossScalaVersions) lazy val writeHooks = taskKey[Unit]("Write git hooks") Global / writeHooks := GitHooks(file("git-hooks"), file(".git/hooks"), streams.value.log) + +def publishLocalDependsOn(matrixes: ProjectMatrix*) = { + val projectRefs = matrixes.flatMap(_.projectRefs) + Seq( + publishLocal := publishLocal.dependsOn(projectRefs.map(_ / publishLocal)*).value, + publishM2 := publishM2.dependsOn(projectRefs.map(_ / publishM2)*).value + ) +} diff --git a/docs/contributing.md b/docs/contributing.md index 28b2b02f6..70ca36531 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -39,7 +39,6 @@ We support mutation testing Stryker4s with Stryker4s! The easiest way is to foll 1. Run `sbt publishPluginLocal` to publish a test snapshot as `0.0.0-TEST-SNAPSHOT` version to your local ivy repository. 2. Add the sbt plugin to `project/plugins.sbt` with `0.0.0-TEST-SNAPSHOT` as the version number. - 1. If the project you are running against is not a 2.13 project, publish `stryker4s-api` and `stryker4s-sbt-testrunner` manually for your appropriate version (.e.g. `sbt "testRunnerApi3/publishLocal; sbtTestRunner3/publishLocal"`) 3. Run stryker4s as described in the readme. ## Learning resources diff --git a/modules/core/src/main/scala/stryker4s/model/InitialTestRunCoverageReport.scala b/modules/core/src/main/scala/stryker4s/model/InitialTestRunCoverageReport.scala index 6150f5daa..75ec7f157 100644 --- a/modules/core/src/main/scala/stryker4s/model/InitialTestRunCoverageReport.scala +++ b/modules/core/src/main/scala/stryker4s/model/InitialTestRunCoverageReport.scala @@ -1,7 +1,7 @@ package stryker4s.model import cats.syntax.option.* -import stryker4s.api.testprocess.CoverageReport +import stryker4s.testrunner.api.testprocess.CoverageReport import scala.concurrent.duration.FiniteDuration diff --git a/modules/core/src/test/scala/stryker4s/run/TestRunnerTest.scala b/modules/core/src/test/scala/stryker4s/run/TestRunnerTest.scala index 36e632e49..c576f5654 100644 --- a/modules/core/src/test/scala/stryker4s/run/TestRunnerTest.scala +++ b/modules/core/src/test/scala/stryker4s/run/TestRunnerTest.scala @@ -4,10 +4,10 @@ import cats.effect.{Deferred, IO, Ref, Resource} import cats.syntax.traverse.* import fansi.Color.* import mutationtesting.{MutantResult, MutantStatus} -import stryker4s.api.testprocess.CoverageReport import stryker4s.config.Config import stryker4s.model.{InitialTestRunCoverageReport, InitialTestRunResult, MutantWithId, NoCoverageInitialTestRun} import stryker4s.scalatest.LogMatchers +import stryker4s.testrunner.api.testprocess.CoverageReport import stryker4s.testutil.stubs.TestRunnerStub import stryker4s.testutil.{Stryker4sIOSuite, TestData} diff --git a/modules/sbt/src/main/scala/stryker4s/model/TestInterfaceMapper.scala b/modules/sbt/src/main/scala/stryker4s/model/TestInterfaceMapper.scala index fb8f5f114..89bbb9654 100644 --- a/modules/sbt/src/main/scala/stryker4s/model/TestInterfaceMapper.scala +++ b/modules/sbt/src/main/scala/stryker4s/model/TestInterfaceMapper.scala @@ -3,7 +3,7 @@ package stryker4s.model import cats.syntax.option.* import sbt.testing.Framework as SbtFramework import sbt.{TestDefinition as SbtTestDefinition, TestFramework as SbtTestFramework, Tests} -import stryker4s.api.testprocess.* +import stryker4s.testrunner.api.testprocess.* trait TestInterfaceMapper { def toApiTestGroups(frameworks: Seq[SbtFramework], sbtTestGroups: Seq[Tests.Group]): Array[TestGroup] = { diff --git a/modules/sbt/src/main/scala/stryker4s/sbt/runner/ProcessTestRunner.scala b/modules/sbt/src/main/scala/stryker4s/sbt/runner/ProcessTestRunner.scala index 6257fc473..34bb96842 100644 --- a/modules/sbt/src/main/scala/stryker4s/sbt/runner/ProcessTestRunner.scala +++ b/modules/sbt/src/main/scala/stryker4s/sbt/runner/ProcessTestRunner.scala @@ -8,13 +8,13 @@ import fs2.io.net.Network import mutationtesting.{MutantResult, MutantStatus} import sbt.Tests import sbt.testing.Framework -import stryker4s.api.testprocess.* import stryker4s.config.Config import stryker4s.extension.DurationExtensions.* import stryker4s.log.Logger import stryker4s.model.* import stryker4s.run.TestRunner import stryker4s.run.process.ProcessResource +import stryker4s.testrunner.api.testprocess.* import java.net.ConnectException import java.util.concurrent.TimeUnit diff --git a/modules/sbt/src/main/scala/stryker4s/sbt/runner/TestRunnerConnection.scala b/modules/sbt/src/main/scala/stryker4s/sbt/runner/TestRunnerConnection.scala index 9cfb80196..e7f975fcf 100644 --- a/modules/sbt/src/main/scala/stryker4s/sbt/runner/TestRunnerConnection.scala +++ b/modules/sbt/src/main/scala/stryker4s/sbt/runner/TestRunnerConnection.scala @@ -6,8 +6,8 @@ import com.google.protobuf.UInt32Value import fs2.Chunk import fs2.io.net.Socket import scodec.bits.BitVector -import stryker4s.api.testprocess.{Request, RequestMessage, Response, ResponseMessage} import stryker4s.log.Logger +import stryker4s.testrunner.api.testprocess.{Request, RequestMessage, Response, ResponseMessage} sealed trait TestRunnerConnection { def sendMessage(request: Request): IO[Response] diff --git a/modules/sbt/src/sbt-test/sbt-stryker4s/test-1/build.sbt b/modules/sbt/src/sbt-test/sbt-stryker4s/test-1/build.sbt index 611e0c58b..5dfc9964b 100644 --- a/modules/sbt/src/sbt-test/sbt-stryker4s/test-1/build.sbt +++ b/modules/sbt/src/sbt-test/sbt-stryker4s/test-1/build.sbt @@ -1,6 +1,6 @@ scalaVersion := "2.12.18" -libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.13" % Test // scala-steward:off +libraryDependencies += "org.scalameta" %% "munit" % "1.0.0-M10" % Test // Reproduce https://github.com/stryker-mutator/stryker4s/issues/726 (Compile / scalaSource) := baseDirectory.value / "src" / "main" / "scala" diff --git a/modules/sbt/src/sbt-test/sbt-stryker4s/test-1/src/test/scala/example/ExampleTest.scala b/modules/sbt/src/sbt-test/sbt-stryker4s/test-1/src/test/scala/example/ExampleTest.scala index b6dbf7e73..ec3e9719a 100644 --- a/modules/sbt/src/sbt-test/sbt-stryker4s/test-1/src/test/scala/example/ExampleTest.scala +++ b/modules/sbt/src/sbt-test/sbt-stryker4s/test-1/src/test/scala/example/ExampleTest.scala @@ -1,12 +1,8 @@ package example -import org.scalatest.matchers.should.Matchers -import org.scalatest.funspec.AnyFunSpec - -class ExampleTest extends AnyFunSpec with Matchers { - describe("Person") { - it("be able to drink with age 18") { - Example.canDrink(18) should be(true) - } +class ExampleTest extends munit.FunSuite { + test("be able to drink with age 18") { + assert(Example.canDrink(18)) } + } diff --git a/modules/sbt/src/sbt-test/sbt-stryker4s/test-1/src/test/scala/example/IgnoreMeTest.scala b/modules/sbt/src/sbt-test/sbt-stryker4s/test-1/src/test/scala/example/IgnoreMeTest.scala index e5da70808..56d87f49d 100644 --- a/modules/sbt/src/sbt-test/sbt-stryker4s/test-1/src/test/scala/example/IgnoreMeTest.scala +++ b/modules/sbt/src/sbt-test/sbt-stryker4s/test-1/src/test/scala/example/IgnoreMeTest.scala @@ -1,12 +1,8 @@ package example -import org.scalatest.matchers.should.Matchers -import org.scalatest.funspec.AnyFunSpec - -class IgnoreMeTest extends AnyFunSpec with Matchers { - describe("Person") { - it("not be able to drink with age 16") { - fail("This test should never be run because of the test-filter") - } +class IgnoreMeTest extends munit.FunSuite { + test("not be able to drink with age 16") { + fail("This test should never be run because of the test-filter") } + } diff --git a/modules/sbt/src/sbt-test/sbt-stryker4s/test-1/src/test/scala/example/TestObj1Spec.scala b/modules/sbt/src/sbt-test/sbt-stryker4s/test-1/src/test/scala/example/TestObj1Spec.scala index b2df64ee2..e0487acc8 100644 --- a/modules/sbt/src/sbt-test/sbt-stryker4s/test-1/src/test/scala/example/TestObj1Spec.scala +++ b/modules/sbt/src/sbt-test/sbt-stryker4s/test-1/src/test/scala/example/TestObj1Spec.scala @@ -1,21 +1,18 @@ package example -import org.scalatest.flatspec.AnyFlatSpec -import org.scalatest.matchers.should.Matchers - -class Spec extends AnyFlatSpec with Matchers { - it should "check for a's in mutatesOkay" in { - TestObj.mutatesOkay(" a ") shouldBe true - TestObj.mutatesOkay(" b ") shouldBe false +class Spec extends munit.FunSuite { + test("check for a's in mutatesOkay") { + assert(TestObj.mutatesOkay(" a ")) + assert(!TestObj.mutatesOkay(" b ")) } - it should "return false if a file does not exists" in { - TestObj.test2("/home/blah/fake") shouldBe false + test("return false if a file does not exists") { + assert(!TestObj.test2("/home/blah/fake")) } - it should "check for b's in alsoMutatesOkay" in { - TestObj.alsoMutatesOkay(" b ") shouldBe true - TestObj.alsoMutatesOkay(" a ") shouldBe false + test("check for b's in alsoMutatesOkay") { + assert(TestObj.alsoMutatesOkay(" b ")) + assert(!TestObj.alsoMutatesOkay(" a ")) } } diff --git a/modules/sbt/src/sbt-test/sbt-stryker4s/test-1/src/test/scala/example/TestObj2Spec.scala b/modules/sbt/src/sbt-test/sbt-stryker4s/test-1/src/test/scala/example/TestObj2Spec.scala index 597857063..c5627a852 100644 --- a/modules/sbt/src/sbt-test/sbt-stryker4s/test-1/src/test/scala/example/TestObj2Spec.scala +++ b/modules/sbt/src/sbt-test/sbt-stryker4s/test-1/src/test/scala/example/TestObj2Spec.scala @@ -1,11 +1,8 @@ package example -import org.scalatest.flatspec.AnyFlatSpec -import org.scalatest.matchers.should.Matchers - -class Spec2 extends AnyFlatSpec with Matchers { - it should "check the string" in { - TestObj2.str("hi") shouldBe false - TestObj2.str("blah") shouldBe true +class Spec2 extends munit.FunSuite { + test("check the string") { + assert(!TestObj2.str("hi")) + assert(TestObj2.str("blah")) } } diff --git a/modules/sbtTestRunner/src/main/scala/stryker4s/package.scala b/modules/sbtTestRunner/src/main/scala/stryker4s/package.scala index 04af06cbd..4b9f975d5 100644 --- a/modules/sbtTestRunner/src/main/scala/stryker4s/package.scala +++ b/modules/sbtTestRunner/src/main/scala/stryker4s/package.scala @@ -1,5 +1,5 @@ -import stryker4s.api.testprocess.CoverageTestNameMap import stryker4s.sbt.testrunner.TestInterfaceMapper +import stryker4s.testrunner.api.testprocess.CoverageTestNameMap import java.util.concurrent.atomic.{AtomicBoolean, AtomicInteger, AtomicReference} import java.util.concurrent.{ConcurrentLinkedQueue, TimeUnit} diff --git a/modules/sbtTestRunner/src/main/scala/stryker4s/sbt/testrunner/Context.scala b/modules/sbtTestRunner/src/main/scala/stryker4s/sbt/testrunner/Context.scala index 6e12c5958..f9dd12536 100644 --- a/modules/sbtTestRunner/src/main/scala/stryker4s/sbt/testrunner/Context.scala +++ b/modules/sbtTestRunner/src/main/scala/stryker4s/sbt/testrunner/Context.scala @@ -1,6 +1,6 @@ package stryker4s.sbt.testrunner -import stryker4s.api.testprocess.TestProcessProperties +import stryker4s.testrunner.api.testprocess.TestProcessProperties object Context { def resolveSocketConfig(): Int = { diff --git a/modules/sbtTestRunner/src/main/scala/stryker4s/sbt/testrunner/MessageHandler.scala b/modules/sbtTestRunner/src/main/scala/stryker4s/sbt/testrunner/MessageHandler.scala index e9f60dc04..43969e6ed 100644 --- a/modules/sbtTestRunner/src/main/scala/stryker4s/sbt/testrunner/MessageHandler.scala +++ b/modules/sbtTestRunner/src/main/scala/stryker4s/sbt/testrunner/MessageHandler.scala @@ -1,8 +1,8 @@ package stryker4s.sbt.testrunner import sbt.testing.Status -import stryker4s.api.testprocess.* import stryker4s.coverage.{collectCoverage, timed} +import stryker4s.testrunner.api.testprocess.* import scala.concurrent.duration.FiniteDuration import scala.util.control.NonFatal diff --git a/modules/sbtTestRunner/src/main/scala/stryker4s/sbt/testrunner/SbtTestRunnerMain.scala b/modules/sbtTestRunner/src/main/scala/stryker4s/sbt/testrunner/SbtTestRunnerMain.scala index 4542943cd..4066d1a1b 100644 --- a/modules/sbtTestRunner/src/main/scala/stryker4s/sbt/testrunner/SbtTestRunnerMain.scala +++ b/modules/sbtTestRunner/src/main/scala/stryker4s/sbt/testrunner/SbtTestRunnerMain.scala @@ -1,7 +1,7 @@ package stryker4s.sbt.testrunner import com.google.protobuf.CodedInputStream -import stryker4s.api.testprocess.RequestMessage +import stryker4s.testrunner.api.testprocess.RequestMessage import java.net.{InetAddress, ServerSocket, Socket} diff --git a/modules/sbtTestRunner/src/main/scala/stryker4s/sbt/testrunner/TestInterfaceMapper.scala b/modules/sbtTestRunner/src/main/scala/stryker4s/sbt/testrunner/TestInterfaceMapper.scala index 9baea8d0f..a07297d2d 100644 --- a/modules/sbtTestRunner/src/main/scala/stryker4s/sbt/testrunner/TestInterfaceMapper.scala +++ b/modules/sbtTestRunner/src/main/scala/stryker4s/sbt/testrunner/TestInterfaceMapper.scala @@ -1,7 +1,7 @@ package stryker4s.sbt.testrunner import sbt.testing.{Status, TaskDef} -import stryker4s.api.testprocess.* +import stryker4s.testrunner.api.testprocess.* /** Maps stryker4s-api test-interface models to sbt-testinterface models */ diff --git a/modules/sbtTestRunner/src/main/scala/stryker4s/sbt/testrunner/TestRunner.scala b/modules/sbtTestRunner/src/main/scala/stryker4s/sbt/testrunner/TestRunner.scala index 6796ba1ff..3755018e9 100644 --- a/modules/sbtTestRunner/src/main/scala/stryker4s/sbt/testrunner/TestRunner.scala +++ b/modules/sbtTestRunner/src/main/scala/stryker4s/sbt/testrunner/TestRunner.scala @@ -1,7 +1,7 @@ package stryker4s.sbt.testrunner import sbt.testing.{Event, EventHandler, Framework, Status, Task} -import stryker4s.api.testprocess.* +import stryker4s.testrunner.api.testprocess.* import java.util.concurrent.atomic.{AtomicInteger, AtomicReference} import java.util.function.UnaryOperator diff --git a/modules/testRunnerApi/src/main/protobuf/stryker4s/api/testprocess.proto b/modules/testRunnerApi/src/main/protobuf/stryker4s/api/testprocess.proto index 922706286..01d732c01 100644 --- a/modules/testRunnerApi/src/main/protobuf/stryker4s/api/testprocess.proto +++ b/modules/testRunnerApi/src/main/protobuf/stryker4s/api/testprocess.proto @@ -1,6 +1,6 @@ syntax = "proto3"; -package stryker4s.api; +package stryker4s.testrunner.api; import "scalapb/scalapb.proto"; option (scalapb.options) = { diff --git a/modules/testRunnerApi/src/main/scala/stryker4s/api/testprocess/CoverageReport.scala b/modules/testRunnerApi/src/main/scala/stryker4s/api/testprocess/CoverageReport.scala index f83a85482..615d615c8 100644 --- a/modules/testRunnerApi/src/main/scala/stryker4s/api/testprocess/CoverageReport.scala +++ b/modules/testRunnerApi/src/main/scala/stryker4s/api/testprocess/CoverageReport.scala @@ -1,4 +1,4 @@ -package stryker4s.api.testprocess +package stryker4s.testrunner.api.testprocess case class CoverageReport(report: Map[Int, Seq[String]]) extends AnyVal diff --git a/modules/testRunnerApi/src/main/scala/stryker4s/api/testprocess/TestProcessProperties.scala b/modules/testRunnerApi/src/main/scala/stryker4s/api/testprocess/TestProcessProperties.scala index 138e09da1..bcc63fc2f 100644 --- a/modules/testRunnerApi/src/main/scala/stryker4s/api/testprocess/TestProcessProperties.scala +++ b/modules/testRunnerApi/src/main/scala/stryker4s/api/testprocess/TestProcessProperties.scala @@ -1,4 +1,4 @@ -package stryker4s.api.testprocess +package stryker4s.testrunner.api.testprocess /** Keys for system properties passed to the testprocess */