From 965edbea1438918ad93d261bb54180504d08c562 Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Wed, 4 May 2022 16:20:58 +0200 Subject: [PATCH] Only compile integration tests once And use a different command than 'test' to run the native flavors of the ITs, like ```text $ ./mill -i integration.test.native $ ./mill -i integration.test.nativeStatic $ ./mill -i integration.test.nativeMostlyStatic ``` The JVM ITs can be run in a few equivalent ways: ```text $ ./mill -i integration.test $ ./mill -i integration.test.test $ ./mill -i integration.test.jvm ``` Note that `./mill __.test` will only run JVM ITs, not native ones. --- .github/workflows/ci.yml | 6 +- INTERNALS.md | 4 +- README.md | 8 +- build.sc | 116 +++++++++--------- .../scala/cli/integration/TestUtil.scala | 4 +- 5 files changed, 68 insertions(+), 70 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2469688ae0..2af05579b8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,7 +46,7 @@ jobs: ./mill -i unitTests ./mill -i bloop-rifle._.test - name: JVM integration tests - run: ./mill -i integration.jvm.test + run: ./mill -i integration.test.jvm native-tests: timeout-minutes: 120 @@ -115,7 +115,7 @@ jobs: if-no-files-found: error retention-days: 2 - name: Native integration tests - run: ./mill -i integration.native-mostly-static.test + run: ./mill -i integration.test.nativeMostlyStatic - name: Docker integration tests run: ./mill integration.docker-slim.test - name: Login to GitHub Container Registry @@ -154,7 +154,7 @@ jobs: if-no-files-found: error retention-days: 2 - name: Native integration tests - run: ./mill -i integration.native-static.test + run: ./mill -i integration.test.nativeStatic - name: Docker integration tests run: ./mill integration.docker.test - name: Login to GitHub Container Registry diff --git a/INTERNALS.md b/INTERNALS.md index d5233cd3fd..069cbfdc37 100644 --- a/INTERNALS.md +++ b/INTERNALS.md @@ -38,12 +38,12 @@ Run unit tests with Run integration tests with a JVM-based `scala-cli` with ```bash -./mill integration.jvm.test +./mill integration.test.jvm ``` Run integration tests with a native-image-based `scala-cli` with ```bash -./mill integration.native.test +./mill integration.test.native ``` ## General workflow in most `scala-cli` commands diff --git a/README.md b/README.md index 81ac351d45..08310563cd 100644 --- a/README.md +++ b/README.md @@ -36,13 +36,13 @@ The Scala CLI sources ship with Mill launchers, so that Mill itself doesn't need #### Run integration tests with the JVM launcher ```bash -./mill integration.jvm.test +./mill integration.test.jvm ``` Filter test suites with ```bash -./mill integration.jvm.test 'scala.cli.integration.RunTestsDefault.*' -./mill integration.jvm.test 'scala.cli.integration.RunTestsDefault.Multiple scripts' +./mill integration.test.jvm 'scala.cli.integration.RunTestsDefault.*' +./mill integration.test.jvm 'scala.cli.integration.RunTestsDefault.Multiple scripts' ``` #### Run integration tests with the native launcher @@ -50,7 +50,7 @@ Filter test suites with (generating the launcher can take several minutes) ```bash -./mill integration.native.test +./mill integration.test.native ``` #### Generate native packages diff --git a/build.sc b/build.sc index 0587611e5a..059ef05c47 100644 --- a/build.sc +++ b/build.sc @@ -94,11 +94,12 @@ object `scala-cli-bsp` extends JavaModule with ScalaCliPublishModule { super.javacOptions() ++ Seq("-target", "8", "-source", "8") } } -object integration extends Module { +object integration extends CliIntegration { + object test extends Tests object docker extends CliIntegrationDocker { object test extends Tests { def sources = T.sources { - super.sources() ++ integration.jvm.sources() + super.sources() ++ integration.sources() } def tmpDirBase = T.persistent { PathRef(T.dest / "working-dir") @@ -127,27 +128,6 @@ object integration extends Module { ) } } - object jvm extends JvmIntegration { - object test extends Tests - } - object native extends NativeIntegration with Bloop.Module { - def skipBloop = true - object test extends Tests with Bloop.Module { - def skipBloop = true - } - } - object `native-static` extends NativeIntegrationStatic with Bloop.Module { - def skipBloop = true - object test extends Tests with Bloop.Module { - def skipBloop = true - } - } - object `native-mostly-static` extends NativeIntegrationMostlyStatic with Bloop.Module { - def skipBloop = true - object test extends Tests with Bloop.Module { - def skipBloop = true - } - } } object packager extends ScalaModule with Bloop.Module { @@ -679,8 +659,6 @@ trait Cli3 extends Cli { trait CliIntegration extends SbtModule with ScalaCliPublishModule with HasTests with ScalaCliScalafixModule { def scalaVersion = sv - def testLauncher: T[PathRef] - def cliKind: T[String] def sv = Scala.scala213 @@ -726,11 +704,9 @@ trait CliIntegration extends SbtModule with ScalaCliPublishModule with HasTests Deps.slf4jNop ) def forkEnv = super.forkEnv() ++ Seq( - "SCALA_CLI" -> testLauncher().path.toString, - "SCALA_CLI_KIND" -> cliKind(), - "SCALA_CLI_TMP" -> tmpDirBase().path.toString, - "CI" -> "1", - "ACTUAL_CI" -> (if (System.getenv("CI") == null) "" else "1") + "SCALA_CLI_TMP" -> tmpDirBase().path.toString, + "CI" -> "1", + "ACTUAL_CI" -> (if (System.getenv("CI") == null) "" else "1") ) private def updateRef(name: String, ref: PathRef): PathRef = { val rawPath = ref.path.toString.replace( @@ -790,15 +766,57 @@ trait CliIntegration extends SbtModule with ScalaCliPublishModule with HasTests } def generatedSources = super.generatedSources() ++ Seq(constantsFile()) - def test(args: String*) = T.command { - val res = super.test(args: _*)() - val dotScalaInRoot = os.pwd / workspaceDirName - assert( - !os.isDir(dotScalaInRoot), - s"Expected $workspaceDirName ($dotScalaInRoot) not to have been created" - ) - res + private final class TestHelper( + launcherTask: T[PathRef], + cliKind: String + ) { + def doTest(args: String*) = + T.command { + val argsTask = T.task { + val launcher = launcherTask().path + val extraArgs = Seq( + s"-Dtest.scala-cli.path=$launcher", + s"-Dtest.scala-cli.kind=$cliKind" + ) + args ++ extraArgs + } + testTask(argsTask, T.task(Seq.empty[String])) + } + def test(args: String*) = + T.command { + val res = doTest(args: _*)() + val dotScalaInRoot = os.pwd / workspaceDirName + assert( + !os.isDir(dotScalaInRoot), + s"Expected $workspaceDirName ($dotScalaInRoot) not to have been created" + ) + res + } } + + def test(args: String*) = + jvm(args: _*) + + def jvm(args: String*) = + new TestHelper( + cli.standaloneLauncher, + "jvm" + ).test(args: _*) + def native(args: String*) = + new TestHelper( + cli.nativeImage, + "native" + ).test(args: _*) + def nativeStatic(args: String*) = + new TestHelper( + cli.nativeImageStatic, + "native-static" + ).test(args: _*) + def nativeMostlyStatic(args: String*) = + new TestHelper( + cli.nativeImageMostlyStatic, + "native-mostly-static" + ).test(args: _*) } } @@ -809,26 +827,6 @@ trait CliIntegrationDocker extends SbtModule with ScalaCliPublishModule with Has ) } -trait NativeIntegration extends CliIntegration { - def testLauncher = cli.nativeImage() - def cliKind = "native" -} - -trait NativeIntegrationStatic extends CliIntegration { - def testLauncher = cli.nativeImageStatic() - def cliKind = "native-static" -} - -trait NativeIntegrationMostlyStatic extends CliIntegration { - def testLauncher = cli.nativeImageMostlyStatic() - def cliKind = "native-mostly-static" -} - -trait JvmIntegration extends CliIntegration { - def testLauncher = cli.standaloneLauncher() - def cliKind = "jvm" -} - class Runner(val crossScalaVersion: String) extends ScalaCliCrossSbtModule with ScalaCliPublishModule with ScalaCliScalafixModule { @@ -1029,7 +1027,7 @@ def defaultNativeImage() = def nativeIntegrationTests() = T.command { - integration.native.test.test()() + integration.test.native()() } def copyDefaultLauncher(directory: String = "artifacts") = diff --git a/modules/integration/src/test/scala/scala/cli/integration/TestUtil.scala b/modules/integration/src/test/scala/scala/cli/integration/TestUtil.scala index b3592556da..f122a3e28e 100644 --- a/modules/integration/src/test/scala/scala/cli/integration/TestUtil.scala +++ b/modules/integration/src/test/scala/scala/cli/integration/TestUtil.scala @@ -10,13 +10,13 @@ import scala.util.Properties object TestUtil { - val cliKind = System.getenv("SCALA_CLI_KIND") + val cliKind = sys.props("test.scala-cli.kind") val isNativeCli = cliKind.startsWith("native") val isCI = Option(System.getenv("ACTUAL_CI")) match { case None => System.getenv("CI") != null case Some(value) => value.nonEmpty } - val cliPath = System.getenv("SCALA_CLI") + val cliPath = sys.props("test.scala-cli.path") val cli = cliCommand(cliPath) def cliCommand(cliPath: String): Seq[String] =