From 06839184facbc3d3d19e9a7fec95575f0ff73d98 Mon Sep 17 00:00:00 2001 From: Tobias Roeser Date: Mon, 11 Apr 2022 23:25:40 +0200 Subject: [PATCH] Added integration tests which run in client-server mode (#1835) Pull request: https://github.com/com-lihaoyi/mill/pull/1835 --- .github/workflows/actions.yml | 6 ++-- build.sc | 4 ++- .../src/forked-server-tests.scala | 8 +++++ integration/forked/src/Tests.scala | 8 ----- integration/forked/src/forked-tests.scala | 8 +++++ .../local/src/DocAnnotationsTests.scala | 3 +- integration/local/src/HygieneTests.scala | 3 +- .../local/src/IntegrationTestSuite.scala | 2 +- integration/local/src/LargeProjectTests.scala | 3 +- .../src/ScriptsInvalidationForeignTests.scala | 3 +- .../local/src/ScriptsInvalidationTests.scala | 3 +- .../local/{Tests.scala => local-tests.scala} | 10 +++---- main/test/src/util/ScriptTestSuite.scala | 30 +++++++++++++++---- 13 files changed, 61 insertions(+), 30 deletions(-) create mode 100644 integration/forked-server/src/forked-server-tests.scala delete mode 100644 integration/forked/src/Tests.scala create mode 100644 integration/forked/src/forked-tests.scala rename integration/local/src/local/{Tests.scala => local-tests.scala} (53%) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 261d49e027e..3e92c338164 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -20,13 +20,11 @@ jobs: # unit and module tests - ./mill -i -k "{main,scalalib,scalajslib,scalanativelib,testrunner,bsp}.__.test" # additional integration tests - - ./mill -i -k "integration.{local,forked}" + - ./mill -i -k "integration.{local,forked,forked-server}" # integrtion tests of thirdparty repos - ./mill -i -k "integration.thirdparty.{local,forked}" # contrib tests - ./mill -i -k "contrib._.test" - # - ./mill -i integration.test "mill.integration.local.JawnTests" - #- ./mill -i integration.test "mill.integration.local.{AcyclicTests,AmmoniteTests}" - ./mill -i docs.antora.githubPages include: # Just some reporting to enable reasoning about library upgrades @@ -91,7 +89,7 @@ jobs: buildcmd: - cmd /C %GITHUB_WORKSPACE%\ci\mill.bat -i -d -k "{__.publishLocal,assembly,__.compile}" - cmd /C %GITHUB_WORKSPACE%\ci\mill.bat -i -d -k "{main,scalalib,scalajslib,bsp}.__.test" - - cmd /C %GITHUB_WORKSPACE%\ci\mill.bat -i -d -k "integration.{local,forked}" + - cmd /C %GITHUB_WORKSPACE%\ci\mill.bat -i -d -k "integration.{local,forked,forked-server}" - cmd /C %GITHUB_WORKSPACE%\ci\mill.bat -i -d -k "integration.thirdparty.{local,forked}" - cmd /C %GITHUB_WORKSPACE%\ci\mill.bat -i -d -k "contrib.__.test" diff --git a/build.sc b/build.sc index 0aa782e52cd..75a94bcf787 100755 --- a/build.sc +++ b/build.sc @@ -906,13 +906,15 @@ object integration extends MillScalaModule { // Integration test of Mill object local extends ITests - object forked extends ITests { + trait Forked extends ITests { override def moduleDeps: Seq[JavaModule] = super.moduleDeps ++ Seq(integration.local) override def forkEnv: Target[Map[String, String]] = super.forkEnv() ++ Map( "MILL_TEST_RELEASE" -> testMill().path.toString() ) } + object forked extends Forked + object `forked-server` extends Forked // Test of various third-party repositories object thirdparty extends Module { diff --git a/integration/forked-server/src/forked-server-tests.scala b/integration/forked-server/src/forked-server-tests.scala new file mode 100644 index 00000000000..ca1a73b5d37 --- /dev/null +++ b/integration/forked-server/src/forked-server-tests.scala @@ -0,0 +1,8 @@ +package mill.integration +package forked.server + +object DocAnnotationsTests extends DocAnnotationsTests(fork = true, clientServer = true) +object HygieneTests extends HygieneTests(fork = true, clientServer = true) +object LargeProjectTests extends LargeProjectTests(fork = true, clientServer = true) +object ScriptsInvalidationTests extends ScriptsInvalidationTests(fork = true, clientServer = true) +object ScriptsInvalidationForeignTests extends ScriptsInvalidationForeignTests(fork = true, clientServer = true) diff --git a/integration/forked/src/Tests.scala b/integration/forked/src/Tests.scala deleted file mode 100644 index 2d997a7555c..00000000000 --- a/integration/forked/src/Tests.scala +++ /dev/null @@ -1,8 +0,0 @@ -package mill.integration -package forked - -object DocAnnotationsTests extends DocAnnotationsTests(fork = true) -object HygieneTests extends HygieneTests(fork = true) -object LargeProjectTests extends LargeProjectTests(fork = true) -object ScriptsInvalidationTests extends ScriptsInvalidationTests(fork = true) -object ScriptsInvalidationForeignTests extends ScriptsInvalidationForeignTests(fork = true) diff --git a/integration/forked/src/forked-tests.scala b/integration/forked/src/forked-tests.scala new file mode 100644 index 00000000000..eb69ff3c562 --- /dev/null +++ b/integration/forked/src/forked-tests.scala @@ -0,0 +1,8 @@ +package mill.integration +package forked + +object DocAnnotationsTests extends DocAnnotationsTests(fork = true, clientServer = false) +object HygieneTests extends HygieneTests(fork = true, clientServer = false) +object LargeProjectTests extends LargeProjectTests(fork = true, clientServer = false) +object ScriptsInvalidationTests extends ScriptsInvalidationTests(fork = true, clientServer = false) +object ScriptsInvalidationForeignTests extends ScriptsInvalidationForeignTests(fork = true, clientServer = false) diff --git a/integration/local/src/DocAnnotationsTests.scala b/integration/local/src/DocAnnotationsTests.scala index 36aa7485ec1..1f654ef29dd 100644 --- a/integration/local/src/DocAnnotationsTests.scala +++ b/integration/local/src/DocAnnotationsTests.scala @@ -3,7 +3,8 @@ package mill.integration import mill.util.ScriptTestSuite import utest._ -class DocAnnotationsTests(fork: Boolean) extends IntegrationTestSuite("docannotations", fork) { +class DocAnnotationsTests(fork: Boolean, clientServer: Boolean) + extends IntegrationTestSuite("docannotations", fork, clientServer) { val tests = Tests { initWorkspace() "test" - { diff --git a/integration/local/src/HygieneTests.scala b/integration/local/src/HygieneTests.scala index 68ac922badd..269eed7238f 100644 --- a/integration/local/src/HygieneTests.scala +++ b/integration/local/src/HygieneTests.scala @@ -3,7 +3,8 @@ package mill.integration import mill.util.ScriptTestSuite import utest._ -class HygieneTests(fork: Boolean) extends IntegrationTestSuite("hygiene", fork) { +class HygieneTests(fork: Boolean, clientServer: Boolean) + extends IntegrationTestSuite("hygiene", fork, clientServer) { val tests = Tests { initWorkspace() diff --git a/integration/local/src/IntegrationTestSuite.scala b/integration/local/src/IntegrationTestSuite.scala index 0572f6f6d60..277a15b409a 100644 --- a/integration/local/src/IntegrationTestSuite.scala +++ b/integration/local/src/IntegrationTestSuite.scala @@ -3,7 +3,7 @@ package mill.integration import mill.util.ScriptTestSuite import utest._ -abstract class IntegrationTestSuite(override val workspaceSlug: String, fork: Boolean) +abstract class IntegrationTestSuite(override val workspaceSlug: String, fork: Boolean, clientServer: Boolean = false) extends ScriptTestSuite(fork) { override def workspacePath: os.Path = diff --git a/integration/local/src/LargeProjectTests.scala b/integration/local/src/LargeProjectTests.scala index 4556d22a1db..7b1ee4a9013 100644 --- a/integration/local/src/LargeProjectTests.scala +++ b/integration/local/src/LargeProjectTests.scala @@ -3,7 +3,8 @@ package mill.integration import mill.util.ScriptTestSuite import utest._ -class LargeProjectTests(fork: Boolean) extends IntegrationTestSuite("large-project", fork) { +class LargeProjectTests(fork: Boolean, clientServer: Boolean) + extends IntegrationTestSuite("large-project", fork, clientServer) { val tests = Tests { initWorkspace() "test" - { diff --git a/integration/local/src/ScriptsInvalidationForeignTests.scala b/integration/local/src/ScriptsInvalidationForeignTests.scala index fe59af3dd79..e7871c590fa 100644 --- a/integration/local/src/ScriptsInvalidationForeignTests.scala +++ b/integration/local/src/ScriptsInvalidationForeignTests.scala @@ -6,7 +6,8 @@ import utest._ import scala.collection.mutable -class ScriptsInvalidationForeignTests(fork: Boolean) extends IntegrationTestSuite("invalidation-foreign", fork) { +class ScriptsInvalidationForeignTests(fork: Boolean, clientServer: Boolean) + extends IntegrationTestSuite("invalidation-foreign", fork, clientServer) { override def buildPath = os.sub / "foreignA" / "build.sc" diff --git a/integration/local/src/ScriptsInvalidationTests.scala b/integration/local/src/ScriptsInvalidationTests.scala index b04230035df..0d808262ca9 100644 --- a/integration/local/src/ScriptsInvalidationTests.scala +++ b/integration/local/src/ScriptsInvalidationTests.scala @@ -5,7 +5,8 @@ import utest._ import scala.collection.mutable -class ScriptsInvalidationTests(fork: Boolean) extends IntegrationTestSuite("invalidation", fork) { +class ScriptsInvalidationTests(fork: Boolean, clientServer: Boolean) + extends IntegrationTestSuite("invalidation", fork, clientServer) { def runTask(task: String) = { val (successful, stdout) = evalStdout(task) diff --git a/integration/local/src/local/Tests.scala b/integration/local/src/local/local-tests.scala similarity index 53% rename from integration/local/src/local/Tests.scala rename to integration/local/src/local/local-tests.scala index 7574bd8b8b0..4e62cd74de0 100644 --- a/integration/local/src/local/Tests.scala +++ b/integration/local/src/local/local-tests.scala @@ -1,8 +1,8 @@ package mill.integration package local -object DocAnnotationsTests extends DocAnnotationsTests(fork = false) -object HygieneTests extends HygieneTests(fork = false) -object LargeProjectTests extends LargeProjectTests(fork = false) -object ScriptsInvalidationTests extends ScriptsInvalidationTests(fork = false) -object ScriptsInvalidationForeignTests extends ScriptsInvalidationForeignTests(fork = false) +object DocAnnotationsTests extends DocAnnotationsTests(fork = false, false) +object HygieneTests extends HygieneTests(fork = false, false) +object LargeProjectTests extends LargeProjectTests(fork = false, false) +object ScriptsInvalidationTests extends ScriptsInvalidationTests(fork = false, false) +object ScriptsInvalidationForeignTests extends ScriptsInvalidationForeignTests(fork = false, false) diff --git a/main/test/src/util/ScriptTestSuite.scala b/main/test/src/util/ScriptTestSuite.scala index 69684591199..ab1ef478bbc 100644 --- a/main/test/src/util/ScriptTestSuite.scala +++ b/main/test/src/util/ScriptTestSuite.scala @@ -9,8 +9,9 @@ import os.Path import utest._ import java.nio.file.NoSuchFileException +import scala.util.control.NonFatal -abstract class ScriptTestSuite(fork: Boolean) extends TestSuite { +abstract class ScriptTestSuite(fork: Boolean, clientServer: Boolean = false) extends TestSuite { def workspaceSlug: String def scriptSourcePath: os.Path def buildPath: os.SubPath = os.sub / "build.sc" @@ -90,18 +91,35 @@ abstract class ScriptTestSuite(fork: Boolean) extends TestSuite { throw new NoSuchFileException(s"Mill binary to use for test not found under: ${millRelease}") } + val extraArgs = if (clientServer) Seq() else Seq("--no-server") + val env = Map("MILL_TEST_SUITE" -> this.getClass().toString()) + try { - os.proc(millReleaseFile, "-i", s).call( - wd, + os.proc(millReleaseFile, extraArgs, s).call( + cwd = wd, stdin = os.Inherit, stdout = stdout, - stderr = os.Inherit + stderr = os.Inherit, + env = env ) + if (clientServer) { + // try to stop the server + try { + os.proc(millReleaseFile, "shutdown").call( + cwd = wd, + stdin = os.Inherit, + stdout = stdout, + stderr = os.Inherit, + env = env + ) + } catch { case NonFatal(_) => } + } true - } catch { case e: Throwable => false } + } catch { case NonFatal(_) => false } } def meta(s: String): String = { - val Seq((List(selector), _)) = mill.define.ParseArgs.apply(Seq(s), SelectMode.Single).getOrElse(???) + val Seq((List(selector), _)) = + mill.define.ParseArgs.apply(Seq(s), SelectMode.Single).getOrElse(???) val segments = selector._2.value.flatMap(_.pathSegments) os.read(wd / "out" / segments.init / s"${segments.last}.json")