diff --git a/contrib/buildinfo/test/src/mill/contrib/buildinfo/BuildInfoTests.scala b/contrib/buildinfo/test/src/mill/contrib/buildinfo/BuildInfoTests.scala index a78497d85c6..7942a14f82e 100644 --- a/contrib/buildinfo/test/src/mill/contrib/buildinfo/BuildInfoTests.scala +++ b/contrib/buildinfo/test/src/mill/contrib/buildinfo/BuildInfoTests.scala @@ -95,48 +95,52 @@ object BuildInfoTests extends TestSuite { eval.outPath / "buildInfoResources.dest" / "foo" / "BuildInfo.buildinfo.properties" def tests: Tests = Tests { - test("notCreateEmptySourcefile") { - val eval = UnitTester(EmptyBuildInfo, testModuleSourcesPath / "scala") + test("notCreateEmptySourcefile") - UnitTester( + EmptyBuildInfo, + testModuleSourcesPath / "scala" + ).scoped { eval => val Right(_) = eval.apply(EmptyBuildInfo.buildInfoSources) assert(!os.exists(buildInfoSourcePath(eval))) } - test("fileGeneration") { - val eval = UnitTester(BuildInfoComment, testModuleSourcesPath / "scala") - val Right(_) = eval.apply(BuildInfoComment.compile) - - // Make sure that the buildinfo Scala file buildinfo is created and buildinfo - // resource file is *not* created when we compile the Scala code - assert(os.exists(buildInfoSourcePath(eval))) - assert(!os.exists(buildInfoResourcePath(eval))) - - val expectedSource = Seq( - """ /** a helpful comment explaining what scalaVersion is all about */ - | val scalaVersion = buildInfoProperties.getProperty("scalaVersion")""".stripMargin, - """ /** - | * a helpful comment explaining what scalaVersion - | * is all about - | */ - | val scalaVersion2 = buildInfoProperties.getProperty("scalaVersion2")""".stripMargin - ) - - val buildInfoCode = os.read(buildInfoSourcePath(eval)).linesIterator.mkString("\n") - for (e <- expectedSource) { - assert(buildInfoCode.contains(e.linesIterator.mkString("\n"))) - } - - // But becomes created once we package the jar for running - val Right(_) = eval.apply(BuildInfoComment.jar) - - val expectedResource = "mill.contrib.buildinfo.BuildInfo for foo." - - assert(os.exists(buildInfoResourcePath(eval))) - val buildInfoResource = os.read(buildInfoResourcePath(eval)) - assert(buildInfoResource.contains(expectedResource)) + test("fileGeneration") - UnitTester(BuildInfoComment, testModuleSourcesPath / "scala").scoped { + eval => + val Right(_) = eval.apply(BuildInfoComment.compile) + + // Make sure that the buildinfo Scala file buildinfo is created and buildinfo + // resource file is *not* created when we compile the Scala code + assert(os.exists(buildInfoSourcePath(eval))) + assert(!os.exists(buildInfoResourcePath(eval))) + + val expectedSource = Seq( + """ /** a helpful comment explaining what scalaVersion is all about */ + | val scalaVersion = buildInfoProperties.getProperty("scalaVersion")""".stripMargin, + """ /** + | * a helpful comment explaining what scalaVersion + | * is all about + | */ + | val scalaVersion2 = buildInfoProperties.getProperty("scalaVersion2")""".stripMargin + ) + + val buildInfoCode = os.read(buildInfoSourcePath(eval)).linesIterator.mkString("\n") + for (e <- expectedSource) { + assert(buildInfoCode.contains(e.linesIterator.mkString("\n"))) + } + + // But becomes created once we package the jar for running + val Right(_) = eval.apply(BuildInfoComment.jar) + + val expectedResource = "mill.contrib.buildinfo.BuildInfo for foo." + + assert(os.exists(buildInfoResourcePath(eval))) + val buildInfoResource = os.read(buildInfoResourcePath(eval)) + assert(buildInfoResource.contains(expectedResource)) } - test("supportCustomSettings") { - val eval = UnitTester(BuildInfoSettings, testModuleSourcesPath / "scala") + test("supportCustomSettings") - UnitTester( + BuildInfoSettings, + testModuleSourcesPath / "scala" + ).scoped { eval => val Right(result) = eval.apply(BuildInfoSettings.buildInfoSources) val path = result.value.head.path @@ -146,14 +150,12 @@ object BuildInfoTests extends TestSuite { assert(found.contains("object bar")) } - test("compile") { - val eval = UnitTester(BuildInfoPlain, testModuleSourcesPath / "scala") + test("compile") - UnitTester(BuildInfoPlain, testModuleSourcesPath / "scala").scoped { eval => val Right(_) = eval.apply(BuildInfoPlain.compile) assert(true) } - test("run") { - val eval = UnitTester(BuildInfoPlain, testModuleSourcesPath / "scala") + test("run") - UnitTester(BuildInfoPlain, testModuleSourcesPath / "scala").scoped { eval => val runResult = eval.outPath / "hello-mill" val Right(_) = eval.apply(BuildInfoPlain.run(T.task(Args(runResult.toString)))) @@ -164,14 +166,13 @@ object BuildInfoTests extends TestSuite { ) } - test("scalajs") { - val eval = UnitTester(BuildInfoScalaJS, testModuleSourcesPath / "scala-simple") - val runResult = eval.outPath / "hello-mill" - assert(eval.apply(BuildInfoScalaJS.fastLinkJS).isRight) + test("scalajs") - UnitTester(BuildInfoScalaJS, testModuleSourcesPath / "scala-simple").scoped { + eval => + val runResult = eval.outPath / "hello-mill" + assert(eval.apply(BuildInfoScalaJS.fastLinkJS).isRight) } - test("static") { - val eval = UnitTester(BuildInfoStatic, testModuleSourcesPath / "scala") + test("static") - UnitTester(BuildInfoStatic, testModuleSourcesPath / "scala").scoped { eval => // When `buildInfoStaticCompiled = true`, make sure we always create the // buildinfo Scala file and never create the resource file val runResult = eval.outPath / "hello-mill" @@ -185,8 +186,7 @@ object BuildInfoTests extends TestSuite { assert(os.read(runResult) == scalaVersionString) } - test("java") { - val eval = UnitTester(BuildInfoJava, testModuleSourcesPath / "java") + test("java") - UnitTester(BuildInfoJava, testModuleSourcesPath / "java").scoped { eval => val runResult = eval.outPath / "hello-mill" val Right(_) = eval.apply(BuildInfoJava.run(T.task(Args(runResult.toString)))) @@ -197,22 +197,24 @@ object BuildInfoTests extends TestSuite { ) } - test("java-static") { - val eval = UnitTester(BuildInfoJavaStatic, testModuleSourcesPath / "java") - val runResult = eval.outPath / "hello-mill" - val generatedSrc = eval.outPath / "buildInfoSources.dest" / "foo" / "BuildInfo.java" - val Right(_) = - eval.apply(BuildInfoJavaStatic.run(T.task(Args(runResult.toString)))) - - assert( - os.exists(runResult), - os.exists(generatedSrc), - os.read(runResult) == "not-provided-for-java-modules" - ) + test("java-static") - UnitTester(BuildInfoJavaStatic, testModuleSourcesPath / "java").scoped { + eval => + val runResult = eval.outPath / "hello-mill" + val generatedSrc = eval.outPath / "buildInfoSources.dest" / "foo" / "BuildInfo.java" + val Right(_) = + eval.apply(BuildInfoJavaStatic.run(T.task(Args(runResult.toString)))) + + assert( + os.exists(runResult), + os.exists(generatedSrc), + os.read(runResult) == "not-provided-for-java-modules" + ) } - test("generatedSources must be a folder") { - val eval = UnitTester(BuildInfoPlain, testModuleSourcesPath / "scala") + test("generatedSources must be a folder") - UnitTester( + BuildInfoPlain, + testModuleSourcesPath / "scala" + ).scoped { eval => val buildInfoGeneratedSourcesFolder = eval.outPath / "buildInfoSources.dest" val Right(result) = eval.apply(BuildInfoPlain.generatedSources) assert( diff --git a/contrib/docker/test/src/mill/contrib/docker/DockerModuleTest.scala b/contrib/docker/test/src/mill/contrib/docker/DockerModuleTest.scala index b4088f50bf3..443c0b625f1 100644 --- a/contrib/docker/test/src/mill/contrib/docker/DockerModuleTest.scala +++ b/contrib/docker/test/src/mill/contrib/docker/DockerModuleTest.scala @@ -89,8 +89,7 @@ object DockerModuleTest extends TestSuite { } test("dockerfile contents") { - test("default options") { - val eval = UnitTester(Docker, null) + test("default options") - UnitTester(Docker, null).scoped { eval => val Right(result) = eval(Docker.dockerDefault.dockerfile) val expected = multineRegex.replaceAllIn( """ @@ -106,8 +105,7 @@ object DockerModuleTest extends TestSuite { assert(dockerfileStringRefined == expected) } - test("all options") { - val eval = UnitTester(Docker, null) + test("all options") - UnitTester(Docker, null).scoped { eval => val Right(result) = eval(Docker.dockerAll.dockerfile) val expected = multineRegex.replaceAllIn( """ @@ -132,8 +130,7 @@ object DockerModuleTest extends TestSuite { assert(dockerfileStringRefined == expected) } - test("extra jvm options") { - val eval = UnitTester(Docker, null) + test("extra jvm options") - UnitTester(Docker, null).scoped { eval => val Right(result) = eval(Docker.dockerJvmOptions.dockerfile) val expected = multineRegex.replaceAllIn( """ diff --git a/contrib/flyway/test/src/mill/contrib/flyway/BuildTest.scala b/contrib/flyway/test/src/mill/contrib/flyway/BuildTest.scala index c2625e3374b..0bb235db9ff 100644 --- a/contrib/flyway/test/src/mill/contrib/flyway/BuildTest.scala +++ b/contrib/flyway/test/src/mill/contrib/flyway/BuildTest.scala @@ -21,14 +21,12 @@ object BuildTest extends TestSuite { } def tests = Tests { - test("clean") { - val eval = UnitTester(Build, null) + test("clean") - UnitTester(Build, null).scoped { eval => val Right(result) = eval(Build.build.flywayClean()) assert(result.evalCount > 0) } - test("migrate") { - val eval = UnitTester(Build, null) + test("migrate") - UnitTester(Build, null).scoped { eval => val Right(result) = eval(Build.build.flywayMigrate()) assert( result.evalCount > 0, @@ -41,8 +39,7 @@ object BuildTest extends TestSuite { ) } - test("info") { - val eval = UnitTester(Build, null) + test("info") - UnitTester(Build, null).scoped { eval => val Right(result) = eval(Build.build.flywayInfo()) assert(result.evalCount > 0) } diff --git a/contrib/gitlab/test/src/mill/contrib/gitlab/GitlabModuleTests.scala b/contrib/gitlab/test/src/mill/contrib/gitlab/GitlabModuleTests.scala index 191873ad9ec..5f0e16d98b2 100644 --- a/contrib/gitlab/test/src/mill/contrib/gitlab/GitlabModuleTests.scala +++ b/contrib/gitlab/test/src/mill/contrib/gitlab/GitlabModuleTests.scala @@ -37,8 +37,10 @@ object GitlabModuleTests extends TestSuite { override def tests: Tests = Tests { - test("GitlabPublishModule produces sane error message") { - val eval = UnitTester(GitlabModule, null) + test("GitlabPublishModule produces sane error message") - UnitTester( + GitlabModule, + null + ).scoped { eval => val e = eval(GitlabModule.gitlabHeaders(Map.empty)) assertMatch(e) { @@ -47,14 +49,14 @@ object GitlabModuleTests extends TestSuite { } } - test("GitlabMavenRepository produces sane error message") { - val eval = UnitTester(GLMvnRepo, null) - val e = eval(GLMvnRepo.mavenRepository) + test("GitlabMavenRepository produces sane error message") - UnitTester(GLMvnRepo, null).scoped { + eval => + val e = eval(GLMvnRepo.mavenRepository) - assertMatch(e) { - case Left(Failure(s, _)) - if s.startsWith("Token lookup for PACKAGE repository") => - } + assertMatch(e) { + case Left(Failure(s, _)) + if s.startsWith("Token lookup for PACKAGE repository") => + } } } diff --git a/contrib/jmh/test/src/mill/contrib/jmh/JmhModuleTest.scala b/contrib/jmh/test/src/mill/contrib/jmh/JmhModuleTest.scala index 04cb157d8de..64520975b98 100644 --- a/contrib/jmh/test/src/mill/contrib/jmh/JmhModuleTest.scala +++ b/contrib/jmh/test/src/mill/contrib/jmh/JmhModuleTest.scala @@ -20,8 +20,7 @@ object JmhModuleTest extends TestSuite { def tests = Tests { test("jmh") { - test("listJmhBenchmarks") { - val eval = UnitTester(jmh, testModuleSourcesPath) + test("listJmhBenchmarks") - UnitTester(jmh, testModuleSourcesPath).scoped { eval => val paths = EvaluatorPaths.resolveDestPaths(eval.outPath, jmh.listJmhBenchmarks()) val outFile = paths.dest / "benchmarks.out" val Right(result) = eval(jmh.listJmhBenchmarks("-o", outFile.toString)) diff --git a/contrib/playlib/test/src/mill/playlib/PlayModuleTests.scala b/contrib/playlib/test/src/mill/playlib/PlayModuleTests.scala index 0daad89b663..413dc5ae87c 100644 --- a/contrib/playlib/test/src/mill/playlib/PlayModuleTests.scala +++ b/contrib/playlib/test/src/mill/playlib/PlayModuleTests.scala @@ -22,107 +22,111 @@ object PlayModuleTests extends TestSuite with PlayTestSuite { test("layout") { test("fromBuild") { matrix.foreach { case (scalaVersion, playVersion) => - val eval = UnitTester(playmulti, resourcePath) - val Right(conf) = eval.apply(playmulti.core(scalaVersion, playVersion).conf) - val Right(app) = eval.apply(playmulti.core(scalaVersion, playVersion).app) - val Right(sources) = eval.apply(playmulti.core(scalaVersion, playVersion).sources) - val Right(resources) = - eval.apply(playmulti.core(scalaVersion, playVersion).resources) - val Right(testSources) = - eval.apply(playmulti.core(scalaVersion, playVersion).test.sources) - val Right(testResources) = - eval.apply(playmulti.core(scalaVersion, playVersion).test.resources) - assert( - conf.value.map(_.path.relativeTo(playmulti.millSourcePath).toString()) == Seq( - "core/conf" - ), - app.value.map(_.path.relativeTo(playmulti.millSourcePath).toString()) == Seq( - "core/app" - ), - sources == app, - resources.value.map(_.path.relativeTo(playmulti.millSourcePath).toString()).contains( - "core/conf" - ), - testSources.value.map(_.path.relativeTo(playmulti.millSourcePath).toString()) == Seq( - "core/test" - ), - testResources.value.map( - _.path.relativeTo(playmulti.millSourcePath).toString() - ) == Seq( - "core/test/resources" + UnitTester(playmulti, resourcePath).scoped { eval => + val Right(conf) = eval.apply(playmulti.core(scalaVersion, playVersion).conf) + val Right(app) = eval.apply(playmulti.core(scalaVersion, playVersion).app) + val Right(sources) = eval.apply(playmulti.core(scalaVersion, playVersion).sources) + val Right(resources) = + eval.apply(playmulti.core(scalaVersion, playVersion).resources) + val Right(testSources) = + eval.apply(playmulti.core(scalaVersion, playVersion).test.sources) + val Right(testResources) = + eval.apply(playmulti.core(scalaVersion, playVersion).test.resources) + assert( + conf.value.map(_.path.relativeTo(playmulti.millSourcePath).toString()) == Seq( + "core/conf" + ), + app.value.map(_.path.relativeTo(playmulti.millSourcePath).toString()) == Seq( + "core/app" + ), + sources == app, + resources.value.map(_.path.relativeTo(playmulti.millSourcePath).toString()).contains( + "core/conf" + ), + testSources.value.map(_.path.relativeTo(playmulti.millSourcePath).toString()) == Seq( + "core/test" + ), + testResources.value.map( + _.path.relativeTo(playmulti.millSourcePath).toString() + ) == Seq( + "core/test/resources" + ) ) - ) + } } } } test("dependencies") { test("fromBuild") { matrix.foreach { case (scalaVersion, playVersion) => - val eval = UnitTester(playmulti, resourcePath) - val Right(result) = - eval.apply(playmulti.core(scalaVersion, playVersion).ivyDeps) - val expectedModules = Seq[String]( - "play", - "play-guice", - "play-server", - "play-logback", - "play-ahc-ws" - ) - val outputModules = result.value.map(_.dep.module.name.value) - assert( - outputModules.forall(expectedModules.contains), - result.evalCount > 0 - ) + UnitTester(playmulti, resourcePath).scoped { eval => + val Right(result) = + eval.apply(playmulti.core(scalaVersion, playVersion).ivyDeps) + val expectedModules = Seq[String]( + "play", + "play-guice", + "play-server", + "play-logback", + "play-ahc-ws" + ) + val outputModules = result.value.map(_.dep.module.name.value) + assert( + outputModules.forall(expectedModules.contains), + result.evalCount > 0 + ) + } } } test("resolvedRunIvyDeps") { matrix.foreach { case (scalaVersion, playVersion) => - val eval = UnitTester(playmulti, resourcePath) - val Right(_) = eval.apply(playmulti.core(scalaVersion, playVersion).resolvedRunIvyDeps) + UnitTester(playmulti, resourcePath).scoped { eval => + val Right(_) = eval.apply(playmulti.core(scalaVersion, playVersion).resolvedRunIvyDeps) + } } } } test("compile") { matrix.foreach { case (scalaVersion, playVersion) => skipUnsupportedVersions(playVersion) { - val eval = UnitTester(playmulti, resourcePath) - val eitherResult = eval.apply(playmulti.core(scalaVersion, playVersion).compile) - val Right(result) = eitherResult - val outputClassFiles = - os.walk(result.value.classes.path).filter(f => os.isFile(f) && f.ext == "class") + UnitTester(playmulti, resourcePath).scoped { eval => + val eitherResult = eval.apply(playmulti.core(scalaVersion, playVersion).compile) + val Right(result) = eitherResult + val outputClassFiles = + os.walk(result.value.classes.path).filter(f => os.isFile(f) && f.ext == "class") - val expectedClassfiles = Seq[os.RelPath]( - os.RelPath("controllers/HomeController.class"), - os.RelPath("controllers/ReverseAssets.class"), - os.RelPath("controllers/ReverseHomeController.class"), - os.RelPath("controllers/routes.class"), - os.RelPath("controllers/routes$javascript.class"), - os.RelPath("controllers/javascript/ReverseHomeController.class"), - os.RelPath("controllers/javascript/ReverseAssets.class"), - if (scalaVersion.startsWith("3.")) os.RelPath("router/Routes$$anon$1.class") - else os.RelPath("router/Routes$$anonfun$routes$1.class"), - os.RelPath("router/Routes.class"), - os.RelPath("router/RoutesPrefix$.class"), - os.RelPath("router/RoutesPrefix.class"), - os.RelPath("views/html/index$.class"), - os.RelPath("views/html/index.class"), - os.RelPath("views/html/main$.class"), - os.RelPath("views/html/main.class") - ).map( - eval.outPath / "core" / scalaVersion / playVersion / "compile.dest" / "classes" / _ - ) - assert( - result.value.classes.path == eval.outPath / "core" / scalaVersion / playVersion / "compile.dest" / "classes", - outputClassFiles.nonEmpty, - outputClassFiles.forall(expectedClassfiles.contains), - outputClassFiles.size == 15, - result.evalCount > 0 - ) + val expectedClassfiles = Seq[os.RelPath]( + os.RelPath("controllers/HomeController.class"), + os.RelPath("controllers/ReverseAssets.class"), + os.RelPath("controllers/ReverseHomeController.class"), + os.RelPath("controllers/routes.class"), + os.RelPath("controllers/routes$javascript.class"), + os.RelPath("controllers/javascript/ReverseHomeController.class"), + os.RelPath("controllers/javascript/ReverseAssets.class"), + if (scalaVersion.startsWith("3.")) os.RelPath("router/Routes$$anon$1.class") + else os.RelPath("router/Routes$$anonfun$routes$1.class"), + os.RelPath("router/Routes.class"), + os.RelPath("router/RoutesPrefix$.class"), + os.RelPath("router/RoutesPrefix.class"), + os.RelPath("views/html/index$.class"), + os.RelPath("views/html/index.class"), + os.RelPath("views/html/main$.class"), + os.RelPath("views/html/main.class") + ).map( + eval.outPath / "core" / scalaVersion / playVersion / "compile.dest" / "classes" / _ + ) + assert( + result.value.classes.path == eval.outPath / "core" / scalaVersion / playVersion / "compile.dest" / "classes", + outputClassFiles.nonEmpty, + outputClassFiles.forall(expectedClassfiles.contains), + outputClassFiles.size == 15, + result.evalCount > 0 + ) - // don't recompile if nothing changed - val Right(result2) = - eval.apply(playmulti.core(scalaVersion, playVersion).compile) - assert(result2.evalCount == 0) + // don't recompile if nothing changed + val Right(result2) = + eval.apply(playmulti.core(scalaVersion, playVersion).compile) + assert(result2.evalCount == 0) + } } } } diff --git a/contrib/playlib/test/src/mill/playlib/PlaySingleApiModuleTests.scala b/contrib/playlib/test/src/mill/playlib/PlaySingleApiModuleTests.scala index d59c88c312a..9162baf084a 100644 --- a/contrib/playlib/test/src/mill/playlib/PlaySingleApiModuleTests.scala +++ b/contrib/playlib/test/src/mill/playlib/PlaySingleApiModuleTests.scala @@ -17,8 +17,7 @@ object PlaySingleApiModuleTests extends TestSuite with PlayTestSuite { def tests: Tests = Tests { test("playVersion") { - test("fromBuild") { - val eval = UnitTester(playsingleapi, resourcePath) + test("fromBuild") - UnitTester(playsingleapi, resourcePath).scoped { eval => val Right(result) = eval.apply(playsingleapi.playVersion) assert( result.value == testPlay28, @@ -27,8 +26,7 @@ object PlaySingleApiModuleTests extends TestSuite with PlayTestSuite { } } test("layout") { - test("fromBuild") { - val eval = UnitTester(playsingleapi, resourcePath) + test("fromBuild") - UnitTester(playsingleapi, resourcePath).scoped { eval => val Right(conf) = eval.apply(playsingleapi.conf) val Right(app) = eval.apply(playsingleapi.app) val Right(sources) = eval.apply(playsingleapi.sources) @@ -55,8 +53,7 @@ object PlaySingleApiModuleTests extends TestSuite with PlayTestSuite { ) } } - test("compile") { - val eval = UnitTester(playsingleapi, resourcePath) + test("compile") - UnitTester(playsingleapi, resourcePath).scoped { eval => val eitherResult = eval.apply(playsingleapi.compile) val Right(result) = eitherResult val outputFiles = os.walk(result.value.classes.path).filter(os.isFile) diff --git a/contrib/playlib/test/src/mill/playlib/PlaySingleModuleTests.scala b/contrib/playlib/test/src/mill/playlib/PlaySingleModuleTests.scala index a0a757ff015..f98a01a6c04 100644 --- a/contrib/playlib/test/src/mill/playlib/PlaySingleModuleTests.scala +++ b/contrib/playlib/test/src/mill/playlib/PlaySingleModuleTests.scala @@ -17,8 +17,7 @@ object PlaySingleModuleTests extends TestSuite with PlayTestSuite { def tests: Tests = Tests { test("layout") { - test("fromBuild") { - val eval = UnitTester(playsingle, resourcePath) + test("fromBuild") - UnitTester(playsingle, resourcePath).scoped { eval => val Right(conf) = eval.apply(playsingle.conf) val Right(app) = eval.apply(playsingle.app) val Right(sources) = eval.apply(playsingle.sources) @@ -41,8 +40,7 @@ object PlaySingleModuleTests extends TestSuite with PlayTestSuite { ) } } - test("compile") { - val eval = UnitTester(playsingle, resourcePath) + test("compile") - UnitTester(playsingle, resourcePath).scoped { eval => val eitherResult = eval.apply(playsingle.compile) val Right(result) = eitherResult val outputFiles = os.walk(result.value.classes.path).filter(os.isFile) diff --git a/contrib/playlib/test/src/mill/playlib/RouterModuleTests.scala b/contrib/playlib/test/src/mill/playlib/RouterModuleTests.scala index 9212a258e39..9431fd47312 100644 --- a/contrib/playlib/test/src/mill/playlib/RouterModuleTests.scala +++ b/contrib/playlib/test/src/mill/playlib/RouterModuleTests.scala @@ -31,87 +31,90 @@ object RouterModuleTests extends TestSuite with PlayTestSuite { test("compileRouter") { matrix.foreach { case (scalaVersion, playVersion) => skipUnsupportedVersions(playVersion) { - val eval = UnitTester(HelloWorld, resourcePath) - val eitherResult = eval.apply(HelloWorld.core(scalaVersion, playVersion).compileRouter) - val Right(result) = eitherResult - val outputFiles = os.walk(result.value.classes.path).filter(os.isFile) - val expectedClassfiles = Seq[os.RelPath]( - os.RelPath("controllers/ReverseRoutes.scala"), - os.RelPath("controllers/routes.java"), - os.RelPath("router/Routes.scala"), - os.RelPath("router/RoutesPrefix.scala"), - os.RelPath("sub/Routes.scala"), - os.RelPath("sub/RoutesPrefix.scala"), - os.RelPath("controllers/javascript/JavaScriptReverseRoutes.scala") - ).map( - eval.outPath / "core" / scalaVersion / playVersion / "compileRouter.dest" / _ - ) - assert( - result.value.classes.path == eval.outPath / "core" / scalaVersion / playVersion / "compileRouter.dest", - outputFiles.nonEmpty, - outputFiles.forall(expectedClassfiles.contains), - outputFiles.size == 7, - result.evalCount > 0 - ) + UnitTester(HelloWorld, resourcePath).scoped { eval => + val eitherResult = eval.apply(HelloWorld.core(scalaVersion, playVersion).compileRouter) + val Right(result) = eitherResult + val outputFiles = os.walk(result.value.classes.path).filter(os.isFile) + val expectedClassfiles = Seq[os.RelPath]( + os.RelPath("controllers/ReverseRoutes.scala"), + os.RelPath("controllers/routes.java"), + os.RelPath("router/Routes.scala"), + os.RelPath("router/RoutesPrefix.scala"), + os.RelPath("sub/Routes.scala"), + os.RelPath("sub/RoutesPrefix.scala"), + os.RelPath("controllers/javascript/JavaScriptReverseRoutes.scala") + ).map( + eval.outPath / "core" / scalaVersion / playVersion / "compileRouter.dest" / _ + ) + assert( + result.value.classes.path == eval.outPath / "core" / scalaVersion / playVersion / "compileRouter.dest", + outputFiles.nonEmpty, + outputFiles.forall(expectedClassfiles.contains), + outputFiles.size == 7, + result.evalCount > 0 + ) - // don't recompile if nothing changed - val Right(result2) = - eval.apply(HelloWorld.core(scalaVersion, playVersion).compileRouter) + // don't recompile if nothing changed + val Right(result2) = + eval.apply(HelloWorld.core(scalaVersion, playVersion).compileRouter) - assert(result2.evalCount == 0) + assert(result2.evalCount == 0) + } } } } test("compileRouterInvalidRoutes") { matrix.foreach { case (scalaVersion, playVersion) => skipUnsupportedVersions(playVersion) { - val eval = UnitTester(HelloWorld, invalidResourcePath) - val project = HelloWorld.core(scalaVersion, playVersion) - val eitherResult = eval.apply(project.compileRouter) - val Left(Failure(message, x)) = eitherResult - val playExpectedMessage = - if (playVersion.startsWith("2.6.")) { - "HTTP Verb (GET, POST, ...), include (->), comment (#), or modifier line (+) expected" - } else { - "end of input expected" - } - val expectedMessage = "Unable to compile play routes, compilation error in " + - project.millSourcePath.toIO.getAbsolutePath.replace( - """\""", - "/" - ) + "/routes/routes at line 4, " + - "column" + " 1: " + playExpectedMessage - // fix windows paths - val normalizeMessage = message.replace("""\""", "/") - assert( - normalizeMessage == expectedMessage - ) + UnitTester(HelloWorld, invalidResourcePath).scoped { eval => + val project = HelloWorld.core(scalaVersion, playVersion) + val eitherResult = eval.apply(project.compileRouter) + val Left(Failure(message, x)) = eitherResult + val playExpectedMessage = + if (playVersion.startsWith("2.6.")) { + "HTTP Verb (GET, POST, ...), include (->), comment (#), or modifier line (+) expected" + } else { + "end of input expected" + } + val expectedMessage = "Unable to compile play routes, compilation error in " + + project.millSourcePath.toIO.getAbsolutePath.replace( + """\""", + "/" + ) + "/routes/routes at line 4, " + + "column" + " 1: " + playExpectedMessage + // fix windows paths + val normalizeMessage = message.replace("""\""", "/") + assert( + normalizeMessage == expectedMessage + ) + } } } } test("compileRouterInvalidSubRoutes") { matrix.foreach { case (scalaVersion, playVersion) => skipUnsupportedVersions(playVersion) { - val eval = UnitTester(HelloWorld, invalidSubResourcePath) - val eitherResult = eval.apply(HelloWorld.core(scalaVersion, playVersion).compileRouter) - val Left(Failure(message, x)) = eitherResult - val playExpectedMessage = - if (playVersion.startsWith("2.6.")) { - "HTTP Verb (GET, POST, ...), include (->), comment (#), or modifier line (+) expected" - } else { - "end of input expected" - } - val expectedMessage = "Unable to compile play routes, compilation error in " + - HelloWorld.core.millSourcePath.toIO.getAbsolutePath.replace( - """\""", - "/" - ) + "/routes/sub.routes at line 3, column" + - " 1: " + playExpectedMessage - // fix windows paths - val normalizeMessage = message.replace("""\""", "/") - assert( - normalizeMessage == expectedMessage - ) + UnitTester(HelloWorld, invalidSubResourcePath).scoped { eval => + val eitherResult = eval.apply(HelloWorld.core(scalaVersion, playVersion).compileRouter) + val Left(Failure(message, x)) = eitherResult + val playExpectedMessage = + if (playVersion.startsWith("2.6.")) { + "HTTP Verb (GET, POST, ...), include (->), comment (#), or modifier line (+) expected" + } else { + "end of input expected" + } + val expectedMessage = "Unable to compile play routes, compilation error in " + + HelloWorld.core.millSourcePath.toIO.getAbsolutePath.replace( + """\""", + "/" + ) + "/routes/sub.routes at line 3, column" + + " 1: " + playExpectedMessage + // fix windows paths + val normalizeMessage = message.replace("""\""", "/") + assert( + normalizeMessage == expectedMessage + ) + } } } } diff --git a/contrib/proguard/test/src/mill/contrib/proguard/ProguardTests.scala b/contrib/proguard/test/src/mill/contrib/proguard/ProguardTests.scala index e247f43edb6..199b9e76bea 100644 --- a/contrib/proguard/test/src/mill/contrib/proguard/ProguardTests.scala +++ b/contrib/proguard/test/src/mill/contrib/proguard/ProguardTests.scala @@ -28,19 +28,19 @@ object ProguardTests extends TestSuite { def tests: Tests = Tests { test("Proguard module") { - test("should download proguard jars") { - val eval = UnitTester(proguard, testModuleSourcesPath) - val Right(result) = eval.apply(proguard.proguardClasspath) - assert( - result.value.iterator.toSeq.nonEmpty, - result.value.iterator.toSeq.head.path.toString().contains("proguard-base") - ) + test("should download proguard jars") - UnitTester(proguard, testModuleSourcesPath).scoped { + eval => + val Right(result) = eval.apply(proguard.proguardClasspath) + assert( + result.value.iterator.toSeq.nonEmpty, + result.value.iterator.toSeq.head.path.toString().contains("proguard-base") + ) } - test("should create a proguarded jar") { - val eval = UnitTester(proguard, testModuleSourcesPath) - val Right(result) = eval.apply(proguard.proguard) - assert(os.exists(result.value.path)) + test("should create a proguarded jar") - UnitTester(proguard, testModuleSourcesPath).scoped { + eval => + val Right(result) = eval.apply(proguard.proguard) + assert(os.exists(result.value.path)) } } } diff --git a/contrib/scalapblib/test/src/mill/contrib/scalapblib/TutorialTests.scala b/contrib/scalapblib/test/src/mill/contrib/scalapblib/TutorialTests.scala index 43fb694f828..503ef2d839c 100644 --- a/contrib/scalapblib/test/src/mill/contrib/scalapblib/TutorialTests.scala +++ b/contrib/scalapblib/test/src/mill/contrib/scalapblib/TutorialTests.scala @@ -71,8 +71,7 @@ object TutorialTests extends TestSuite { def tests: Tests = Tests { test("scalapbVersion") { - test("fromBuild") { - val eval = UnitTester(Tutorial, resourcePath) + test("fromBuild") - UnitTester(Tutorial, resourcePath).scoped { eval => val Right(result) = eval.apply(Tutorial.core.scalaPBVersion) assert( @@ -83,8 +82,7 @@ object TutorialTests extends TestSuite { } test("compileScalaPB") { - test("calledDirectly") { - val eval = UnitTester(Tutorial, resourcePath) + test("calledDirectly") - UnitTester(Tutorial, resourcePath).scoped { eval => val Right(result) = eval.apply(Tutorial.core.compileScalaPB) val outPath = protobufOutPath(eval) @@ -107,8 +105,10 @@ object TutorialTests extends TestSuite { assert(result2.evalCount == 0) } - test("calledWithSpecificFile") { - val eval = UnitTester(TutorialWithSpecificSources, resourcePath) + test("calledWithSpecificFile") - UnitTester( + TutorialWithSpecificSources, + resourcePath + ).scoped { eval => val Right(result) = eval.apply(TutorialWithSpecificSources.core.compileScalaPB) val outPath = protobufOutPath(eval) @@ -166,16 +166,18 @@ object TutorialTests extends TestSuite { /* This ensure that the `scalaPBProtocPath` is properly used. * As the given path is incorrect, the compilation should fail. */ - test("calledWithWrongProtocFile") { - val eval = UnitTester(TutorialWithProtoc, resourcePath) - val result = eval.apply(TutorialWithProtoc.core.compileScalaPB) - assert(result.isLeft) + test("calledWithWrongProtocFile") - UnitTester(TutorialWithProtoc, resourcePath).scoped { + eval => + val result = eval.apply(TutorialWithProtoc.core.compileScalaPB) + assert(result.isLeft) } } test("compilationArgs") { - test("calledWithAdditionalArgs") { - val eval = UnitTester(TutorialWithAdditionalArgs, resourcePath) + test("calledWithAdditionalArgs") - UnitTester( + TutorialWithAdditionalArgs, + resourcePath + ).scoped { eval => val result = eval.apply(TutorialWithAdditionalArgs.core.scalaPBCompileOptions) result match { diff --git a/contrib/scoverage/test/src/mill/contrib/scoverage/HelloWorldTests.scala b/contrib/scoverage/test/src/mill/contrib/scoverage/HelloWorldTests.scala index febc4bdc02d..87c0befa9ff 100644 --- a/contrib/scoverage/test/src/mill/contrib/scoverage/HelloWorldTests.scala +++ b/contrib/scoverage/test/src/mill/contrib/scoverage/HelloWorldTests.scala @@ -64,8 +64,7 @@ trait HelloWorldTests extends utest.TestSuite { def tests: utest.Tests = utest.Tests { test("HelloWorld") { test("core") { - test("scoverageVersion") { - val eval = UnitTester(HelloWorld, resourcePath) + test("scoverageVersion") - UnitTester(HelloWorld, resourcePath).scoped { eval => val Right(result) = eval.apply(HelloWorld.core.scoverageVersion) assert( @@ -74,8 +73,7 @@ trait HelloWorldTests extends utest.TestSuite { ) } test("scoverage") { - test("unmanagedClasspath") { - val eval = UnitTester(HelloWorld, resourcePath) + test("unmanagedClasspath") - UnitTester(HelloWorld, resourcePath).scoped { eval => val Right(result) = eval.apply(HelloWorld.core.scoverage.unmanagedClasspath) @@ -84,8 +82,7 @@ trait HelloWorldTests extends utest.TestSuite { result.evalCount > 0 ) } - test("ivyDeps") { - val eval = UnitTester(HelloWorld, resourcePath) + test("ivyDeps") - UnitTester(HelloWorld, resourcePath).scoped { eval => val Right(result) = eval.apply(HelloWorld.core.scoverage.ivyDeps) @@ -99,8 +96,7 @@ trait HelloWorldTests extends utest.TestSuite { result.evalCount > 0 ) } - test("scalacPluginIvyDeps") { - val eval = UnitTester(HelloWorld, resourcePath) + test("scalacPluginIvyDeps") - UnitTester(HelloWorld, resourcePath).scoped { eval => val Right(result) = eval.apply(HelloWorld.core.scoverage.scalacPluginIvyDeps) @@ -123,8 +119,7 @@ trait HelloWorldTests extends utest.TestSuite { result.evalCount > 0 ) } - test("data") { - val eval = UnitTester(HelloWorld, resourcePath) + test("data") - UnitTester(HelloWorld, resourcePath).scoped { eval => val Right(result) = eval.apply(HelloWorld.core.scoverage.data) val resultPath = result.value.path.toIO.getPath.replace("""\""", "/") @@ -135,8 +130,7 @@ trait HelloWorldTests extends utest.TestSuite { result.evalCount > 0 ) } - test("htmlReport") { - val eval = UnitTester(HelloWorld, resourcePath) + test("htmlReport") - UnitTester(HelloWorld, resourcePath).scoped { eval => val Right(_) = eval.apply(HelloWorld.core.test.compile) val res = eval.apply(HelloWorld.core.scoverage.htmlReport()) if ( @@ -152,8 +146,7 @@ trait HelloWorldTests extends utest.TestSuite { "" } } - test("xmlReport") { - val eval = UnitTester(HelloWorld, resourcePath) + test("xmlReport") - UnitTester(HelloWorld, resourcePath).scoped { eval => val Right(_) = eval.apply(HelloWorld.core.test.compile) val res = eval.apply(HelloWorld.core.scoverage.xmlReport()) if ( @@ -169,8 +162,7 @@ trait HelloWorldTests extends utest.TestSuite { "" } } - test("xmlCoberturaReport") { - val eval = UnitTester(HelloWorld, resourcePath) + test("xmlCoberturaReport") - UnitTester(HelloWorld, resourcePath).scoped { eval => val Right(_) = eval.apply(HelloWorld.core.test.compile) val res = eval.apply(HelloWorld.core.scoverage.xmlCoberturaReport()) if ( @@ -186,16 +178,14 @@ trait HelloWorldTests extends utest.TestSuite { "" } } - test("console") { - val eval = UnitTester(HelloWorld, resourcePath) + test("console") - UnitTester(HelloWorld, resourcePath).scoped { eval => val Right(_) = eval.apply(HelloWorld.core.test.compile) val Right(result) = eval.apply(HelloWorld.core.scoverage.consoleReport()) assert(result.evalCount > 0) } } test("test") - { - test("upstreamAssemblyClasspath") { - val eval = UnitTester(HelloWorld, resourcePath) + test("upstreamAssemblyClasspath") - UnitTester(HelloWorld, resourcePath).scoped { eval => val Right(result) = eval.apply(HelloWorld.core.scoverage.upstreamAssemblyClasspath) @@ -213,8 +203,7 @@ trait HelloWorldTests extends utest.TestSuite { ) } } - test("compileClasspath") { - val eval = UnitTester(HelloWorld, resourcePath) + test("compileClasspath") - UnitTester(HelloWorld, resourcePath).scoped { eval => val Right(result) = eval.apply(HelloWorld.core.scoverage.compileClasspath) @@ -232,8 +221,7 @@ trait HelloWorldTests extends utest.TestSuite { ) } } - test("runClasspath") { - val eval = UnitTester(HelloWorld, resourcePath) + test("runClasspath") - UnitTester(HelloWorld, resourcePath).scoped { eval => val Right(result) = eval.apply(HelloWorld.core.scoverage.runClasspath) val runtimeExistsOnClasspath = @@ -256,20 +244,17 @@ trait HelloWorldTests extends utest.TestSuite { } test("HelloWorldSbt") { test("scoverage") { - test("htmlReport") { - val eval = UnitTester(HelloWorld, sbtResourcePath) + test("htmlReport") - UnitTester(HelloWorld, sbtResourcePath).scoped { eval => val Right(_) = eval.apply(HelloWorldSbt.core.test.compile) val Right(result) = eval.apply(HelloWorldSbt.core.scoverage.htmlReport()) assert(result.evalCount > 0) } - test("xmlReport") { - val eval = UnitTester(HelloWorld, sbtResourcePath) + test("xmlReport") - UnitTester(HelloWorld, sbtResourcePath).scoped { eval => val Right(_) = eval.apply(HelloWorldSbt.core.test.compile) val Right(result) = eval.apply(HelloWorldSbt.core.scoverage.xmlReport()) assert(result.evalCount > 0) } - test("console") { - val eval = UnitTester(HelloWorld, sbtResourcePath) + test("console") - UnitTester(HelloWorld, sbtResourcePath).scoped { eval => val Right(_) = eval.apply(HelloWorldSbt.core.test.compile) val Right(result) = eval.apply(HelloWorldSbt.core.scoverage.consoleReport()) @@ -288,13 +273,11 @@ trait FailedWorldTests extends HelloWorldTests { test("HelloWorld") { val mod = HelloWorld test("shouldFail") { - test("scoverageToolsCp") { - val eval = UnitTester(mod, resourcePath) + test("scoverageToolsCp") - UnitTester(mod, resourcePath).scoped { eval => val Left(Result.Failure(msg, _)) = eval.apply(mod.core.scoverageToolsClasspath) assert(msg == errorMsg) } - test("other") { - val eval = UnitTester(mod, resourcePath) + test("other") - UnitTester(mod, resourcePath).scoped { eval => val Left(Result.Failure(msg, _)) = eval.apply(mod.core.scoverage.xmlReport()) assert(msg == errorMsg) } @@ -303,16 +286,14 @@ trait FailedWorldTests extends HelloWorldTests { test("HelloWorldSbt") { val mod = HelloWorldSbt test("shouldFail") { - test("scoverageToolsCp") { - val eval = UnitTester(mod, resourcePath) + test("scoverageToolsCp") - UnitTester(mod, resourcePath).scoped { eval => val res = eval.apply(mod.core.scoverageToolsClasspath) assert(res.isLeft) println(s"res: ${res}") val Left(Result.Failure(msg, _)) = res assert(msg == errorMsg) } - test("other") { - val eval = UnitTester(mod, resourcePath) + test("other") - UnitTester(mod, resourcePath).scoped { eval => val Left(Result.Failure(msg, _)) = eval.apply(mod.core.scoverage.xmlReport()) assert(msg == errorMsg) } diff --git a/contrib/testng/test/src/mill/testng/TestNGTests.scala b/contrib/testng/test/src/mill/testng/TestNGTests.scala index fa97b3ff0c9..d9cd0694e01 100644 --- a/contrib/testng/test/src/mill/testng/TestNGTests.scala +++ b/contrib/testng/test/src/mill/testng/TestNGTests.scala @@ -42,21 +42,20 @@ object TestNGTests extends TestSuite { def tests: Tests = Tests { test("TestNG") { - test("demo") { - val eval = UnitTester(demo, resourcePath) + test("demo") - UnitTester(demo, resourcePath).scoped { eval => val Right(result) = eval.apply(demo.test.testFramework) assert( result.value == "mill.testng.TestNGFramework", result.evalCount > 0 ) } - test("Test case lookup from inherited annotations") { - val eval = UnitTester(demo, resourcePath) - val Right(result) = eval.apply(demo.test.test()) - val tres = result.value.asInstanceOf[(String, Seq[mill.testrunner.TestResult])] - assert( - tres._2.size == 8 - ) + test("Test case lookup from inherited annotations") - UnitTester(demo, resourcePath).scoped { + eval => + val Right(result) = eval.apply(demo.test.test()) + val tres = result.value.asInstanceOf[(String, Seq[mill.testrunner.TestResult])] + assert( + tres._2.size == 8 + ) } } } diff --git a/contrib/twirllib/test/src/mill/twirllib/HelloWorldTests.scala b/contrib/twirllib/test/src/mill/twirllib/HelloWorldTests.scala index 7972e43a1f5..bf3c7013c6d 100644 --- a/contrib/twirllib/test/src/mill/twirllib/HelloWorldTests.scala +++ b/contrib/twirllib/test/src/mill/twirllib/HelloWorldTests.scala @@ -66,8 +66,7 @@ trait HelloWorldTests extends TestSuite { def tests: Tests = Tests { test("twirlVersion") { - test("fromBuild") { - val eval = UnitTester(HelloWorld, resourcePath / "hello-world") + test("fromBuild") - UnitTester(HelloWorld, resourcePath / "hello-world").scoped { eval => val Right(result) = eval.apply(HelloWorld.core.twirlVersion) @@ -79,79 +78,80 @@ trait HelloWorldTests extends TestSuite { } test("compileTwirl") { skipUnsupportedVersions { - val eval = UnitTester(HelloWorld, resourcePath / "hello-world", debugEnabled = true) - val res = eval.apply(HelloWorld.core.compileTwirl) - assert(res.isRight) - val Right(result) = res - - val outputFiles = os.walk(result.value.classes.path).filter(_.last.endsWith(".scala")) - val expectedClassfiles = compileClassfiles.map( - eval.outPath / "core" / "compileTwirl.dest" / _ - ) + UnitTester(HelloWorld, resourcePath / "hello-world", debugEnabled = true).scoped { eval => + val res = eval.apply(HelloWorld.core.compileTwirl) + assert(res.isRight) + val Right(result) = res + + val outputFiles = os.walk(result.value.classes.path).filter(_.last.endsWith(".scala")) + val expectedClassfiles = compileClassfiles.map( + eval.outPath / "core" / "compileTwirl.dest" / _ + ) - assert( - result.value.classes.path == eval.outPath / "core" / "compileTwirl.dest", - outputFiles.nonEmpty, - outputFiles.forall(expectedClassfiles.contains), - outputFiles.size == 3, - result.evalCount > 0, - outputFiles.forall { p => - val lines = os.read.lines(p).map(_.trim) - (expectedDefaultImports ++ testAdditionalImports.map(s => s"import $s")).forall( - lines.contains - ) - }, - outputFiles.filter(_.toString().contains("hello.template.scala")).forall { p => - val lines = os.read.lines(p).map(_.trim) - val expectedClassDeclaration = s"class hello ${testConstructorAnnotations.mkString}" - lines.exists(_.startsWith(expectedClassDeclaration)) - } - ) + assert( + result.value.classes.path == eval.outPath / "core" / "compileTwirl.dest", + outputFiles.nonEmpty, + outputFiles.forall(expectedClassfiles.contains), + outputFiles.size == 3, + result.evalCount > 0, + outputFiles.forall { p => + val lines = os.read.lines(p).map(_.trim) + (expectedDefaultImports ++ testAdditionalImports.map(s => s"import $s")).forall( + lines.contains + ) + }, + outputFiles.filter(_.toString().contains("hello.template.scala")).forall { p => + val lines = os.read.lines(p).map(_.trim) + val expectedClassDeclaration = s"class hello ${testConstructorAnnotations.mkString}" + lines.exists(_.startsWith(expectedClassDeclaration)) + } + ) - // don't recompile if nothing changed - val Right(result2) = - eval.apply(HelloWorld.core.compileTwirl) + // don't recompile if nothing changed + val Right(result2) = + eval.apply(HelloWorld.core.compileTwirl) - assert(result2.evalCount == 0) + assert(result2.evalCount == 0) + } } } test("compileTwirlInclusiveDot") { skipUnsupportedVersions { - val eval = UnitTester( + UnitTester( HelloWorldWithInclusiveDot, sourceRoot = resourcePath / "hello-world-inclusive-dot" - ) - - val Right(result) = eval.apply(HelloWorldWithInclusiveDot.core.compileTwirl) - - val outputFiles = os.walk(result.value.classes.path).filter(_.last.endsWith(".scala")) - val expectedClassfiles = compileClassfiles.map(name => - eval.outPath / "core" / "compileTwirl.dest" / name / os.RelPath.up / name.last.replace( - ".template.scala", - "$$TwirlInclusiveDot.template.scala" + ).scoped { eval => + val Right(result) = eval.apply(HelloWorldWithInclusiveDot.core.compileTwirl) + + val outputFiles = os.walk(result.value.classes.path).filter(_.last.endsWith(".scala")) + val expectedClassfiles = compileClassfiles.map(name => + eval.outPath / "core" / "compileTwirl.dest" / name / os.RelPath.up / name.last.replace( + ".template.scala", + "$$TwirlInclusiveDot.template.scala" + ) ) - ) - - println(s"outputFiles: $outputFiles") - assert( - result.value.classes.path == eval.outPath / "core" / "compileTwirl.dest", - outputFiles.nonEmpty, - outputFiles.forall(expectedClassfiles.contains), - outputFiles.size == 3, - result.evalCount > 0, - outputFiles.filter(_.toString().contains("hello.template.scala")).forall { p => - val lines = os.read.lines(p).map(_.trim) - lines.exists(_.contains("$$TwirlInclusiveDot")) - } - ) + println(s"outputFiles: $outputFiles") + + assert( + result.value.classes.path == eval.outPath / "core" / "compileTwirl.dest", + outputFiles.nonEmpty, + outputFiles.forall(expectedClassfiles.contains), + outputFiles.size == 3, + result.evalCount > 0, + outputFiles.filter(_.toString().contains("hello.template.scala")).forall { p => + val lines = os.read.lines(p).map(_.trim) + lines.exists(_.contains("$$TwirlInclusiveDot")) + } + ) - // don't recompile if nothing changed - val Right(result2) = - eval.apply(HelloWorld.core.compileTwirl) + // don't recompile if nothing changed + val Right(result2) = + eval.apply(HelloWorld.core.compileTwirl) - assert(result2.evalCount == 0) + assert(result2.evalCount == 0) + } } } } diff --git a/contrib/versionfile/test/src/mill/contrib/versionfile/VersionFileModuleTests.scala b/contrib/versionfile/test/src/mill/contrib/versionfile/VersionFileModuleTests.scala index cc81caf6e14..bbbd23375e8 100644 --- a/contrib/versionfile/test/src/mill/contrib/versionfile/VersionFileModuleTests.scala +++ b/contrib/versionfile/test/src/mill/contrib/versionfile/VersionFileModuleTests.scala @@ -15,8 +15,7 @@ object VersionFileModuleTests extends TestSuite { m: M, vf: M => VersionFileModule, versionText: String - ): UnitTester = { - val eval = UnitTester(m, null) + ): UnitTester = UnitTester(m, null).scoped { eval => os.write.over( vf(m).millSourcePath / "version", versionText, diff --git a/example/extending/plugins/7-writing-mill-plugins/myplugin/test/src/mill/testkit/UnitTests.scala b/example/extending/plugins/7-writing-mill-plugins/myplugin/test/src/mill/testkit/UnitTests.scala index 0f941094f11..8c122f9802b 100644 --- a/example/extending/plugins/7-writing-mill-plugins/myplugin/test/src/mill/testkit/UnitTests.scala +++ b/example/extending/plugins/7-writing-mill-plugins/myplugin/test/src/mill/testkit/UnitTests.scala @@ -6,31 +6,32 @@ import utest._ object UnitTests extends TestSuite { def tests: Tests = Tests { test("unit") { - object build extends TestBaseModule with LineCountJavaModule{ + object build extends TestBaseModule with LineCountJavaModule { def lineCountResourceFileName = "line-count.txt" } val resourceFolder = os.Path(sys.env("MILL_TEST_RESOURCE_FOLDER")) - val eval = UnitTester(build, resourceFolder/ "unit-test-project") + UnitTester(build, resourceFolder / "unit-test-project").scoped { eval => - // Evaluating tasks by direct reference - val Right(result) = eval(build.resources) - assert( - result.value.exists(pathref => - os.exists(pathref.path / "line-count.txt") && - os.read(pathref.path / "line-count.txt") == "17" + // Evaluating tasks by direct reference + val Right(result) = eval(build.resources) + assert( + result.value.exists(pathref => + os.exists(pathref.path / "line-count.txt") && + os.read(pathref.path / "line-count.txt") == "17" + ) ) - ) - // Evaluating tasks by passing in their Mill selector - val Right(result2) = eval("resources") - val Seq(pathrefs: Seq[mill.api.PathRef]) = result2.value - assert( - pathrefs.exists(pathref => - os.exists(pathref.path / "line-count.txt") && - os.read(pathref.path / "line-count.txt") == "17" + // Evaluating tasks by passing in their Mill selector + val Right(result2) = eval("resources") + val Seq(pathrefs: Seq[mill.api.PathRef]) = result2.value + assert( + pathrefs.exists(pathref => + os.exists(pathref.path / "line-count.txt") && + os.read(pathref.path / "line-count.txt") == "17" + ) ) - ) + } } } } diff --git a/main/test/src/mill/main/MainModuleTests.scala b/main/test/src/mill/main/MainModuleTests.scala index 8635b3c3a1c..57f0d777d65 100644 --- a/main/test/src/mill/main/MainModuleTests.scala +++ b/main/test/src/mill/main/MainModuleTests.scala @@ -63,8 +63,7 @@ object MainModuleTests extends TestSuite { override def tests: Tests = Tests { test("inspect") { - val eval = UnitTester(mainModule, null) - test("single") { + test("single") - UnitTester(mainModule, null).scoped { eval => val res = eval.evaluator.evaluate(Agg(mainModule.inspect(eval.evaluator, "hello"))) val Result.Success(Val(value: String)) = res.rawValues.head assert( @@ -73,7 +72,7 @@ object MainModuleTests extends TestSuite { value.contains("MainModuleTests.scala:") ) } - test("multi") { + test("multi") - UnitTester(mainModule, null).scoped { eval => val res = eval.evaluator.evaluate(Agg(mainModule.inspect(eval.evaluator, "hello", "hello2"))) val Result.Success(Val(value: String)) = res.rawValues.head @@ -84,7 +83,7 @@ object MainModuleTests extends TestSuite { value.contains("\n\nhello2(") ) } - test("command") { + test("command") - UnitTester(mainModule, null).scoped { eval => val Right(result) = eval.apply("inspect", "helloCommand") val Seq(res: String) = result.value diff --git a/main/util/src/mill/util/CoursierSupport.scala b/main/util/src/mill/util/CoursierSupport.scala index 9fa405f0282..b662e4bd4cd 100644 --- a/main/util/src/mill/util/CoursierSupport.scala +++ b/main/util/src/mill/util/CoursierSupport.scala @@ -41,9 +41,9 @@ trait CoursierSupport { case Failure(e) if retryCount > 0 && e.getMessage.contains("__sha1.computed") - && (e.isInstanceOf[NoSuchFileException] || e.isInstanceOf[ - java.nio.file.AccessDeniedException - ]) => + && (e.isInstanceOf[NoSuchFileException] || + e.isInstanceOf[java.nio.file.AccessDeniedException] || + e.isInstanceOf[java.io.FileNotFoundException]) => // this one is not detected by coursier itself, so we try-catch handle it // I assume, this happens when another coursier thread already moved or rename dthe temporary file ctx.foreach(_.log.debug( diff --git a/scalajslib/test/src/mill/scalajslib/FullOptESModuleTests.scala b/scalajslib/test/src/mill/scalajslib/FullOptESModuleTests.scala index 78de8f7c11b..91fb3593234 100644 --- a/scalajslib/test/src/mill/scalajslib/FullOptESModuleTests.scala +++ b/scalajslib/test/src/mill/scalajslib/FullOptESModuleTests.scala @@ -22,8 +22,10 @@ object FullOptESModuleTests extends TestSuite { val millSourcePath = os.Path(sys.env("MILL_TEST_RESOURCE_FOLDER")) / "hello-js-world" val tests: Tests = Tests { - test("fullOpt with ESModule moduleKind") { - val eval = UnitTester(FullOptESModuleModule, millSourcePath) + test("fullOpt with ESModule moduleKind") - UnitTester( + FullOptESModuleModule, + millSourcePath + ).scoped { eval => val result = eval(FullOptESModuleModule.fullOptESModuleModule.fullOpt) assert(result.isRight) } diff --git a/scalajslib/test/src/mill/scalajslib/HelloJSWorldTests.scala b/scalajslib/test/src/mill/scalajslib/HelloJSWorldTests.scala index 3d828f3e0f6..12caab47a32 100644 --- a/scalajslib/test/src/mill/scalajslib/HelloJSWorldTests.scala +++ b/scalajslib/test/src/mill/scalajslib/HelloJSWorldTests.scala @@ -28,7 +28,7 @@ object HelloJSWorldTests extends TestSuite { object HelloJSWorld extends TestBaseModule { val scalaVersions = Seq("2.13.3", "3.0.0-RC1", "2.12.12") - val scalaJSVersions = Seq("1.8.0", "1.3.1", "1.0.1") + val scalaJSVersions = Seq("1.8.0", "1.0.1") val matrix = for { scala <- scalaVersions scalaJS <- scalaJSVersions @@ -81,8 +81,7 @@ object HelloJSWorldTests extends TestSuite { val millSourcePath = os.Path(sys.env("MILL_TEST_RESOURCE_FOLDER")) / "hello-js-world" def tests: Tests = Tests { - test("compile") { - val eval = UnitTester(HelloJSWorld, millSourcePath) + test("compile") - UnitTester(HelloJSWorld, millSourcePath).scoped { eval => def testCompileFromScratch(scalaVersion: String, scalaJSVersion: String): Unit = { val Right(result) = eval(HelloJSWorld.build(scalaVersion, scalaJSVersion).compile) @@ -109,8 +108,7 @@ object HelloJSWorldTests extends TestSuite { scalaJSVersion: String, optimize: Boolean, legacy: Boolean - ): Unit = { - val eval = UnitTester(HelloJSWorld, millSourcePath) + ): Unit = UnitTester(HelloJSWorld, millSourcePath).scoped { eval => val module = HelloJSWorld.build(scalaVersion, scalaJSVersion) val jsFile = if (legacy) { @@ -155,8 +153,7 @@ object HelloJSWorldTests extends TestSuite { ) } test("jar") { - test("containsSJSIRs") { - val eval = UnitTester(HelloJSWorld, millSourcePath) + test("containsSJSIRs") - UnitTester(HelloJSWorld, millSourcePath).scoped { eval => val (scala, scalaJS) = HelloJSWorld.matrix.head val Right(result) = eval(HelloJSWorld.build(scala, scalaJS).jar) @@ -169,14 +166,14 @@ object HelloJSWorldTests extends TestSuite { } } test("publish") { - val eval = UnitTester(HelloJSWorld, millSourcePath) - def testArtifactId(scalaVersion: String, scalaJSVersion: String, artifactId: String): Unit = { - val Right(result) = eval(HelloJSWorld.build( - scalaVersion, - scalaJSVersion - ).artifactMetadata) - assert(result.value.id == artifactId) - } + def testArtifactId(scalaVersion: String, scalaJSVersion: String, artifactId: String): Unit = + UnitTester(HelloJSWorld, millSourcePath).scoped { eval => + val Right(result) = eval(HelloJSWorld.build( + scalaVersion, + scalaJSVersion + ).artifactMetadata) + assert(result.value.id == artifactId) + } test("artifactId_10") { testArtifactId( HelloJSWorld.scalaVersions.head, @@ -194,17 +191,17 @@ object HelloJSWorldTests extends TestSuite { } def runTests(testTask: define.NamedTask[(String, Seq[TestResult])]) - : Map[String, Map[String, TestResult]] = { - val eval = UnitTester(HelloJSWorld, millSourcePath) - val Left(Result.Failure(_, Some(res))) = eval(testTask) - - val (doneMsg, testResults) = res - testResults - .groupBy(_.fullyQualifiedName) - .view - .mapValues(_.map(e => e.selector -> e).toMap) - .toMap - } + : Map[String, Map[String, TestResult]] = + UnitTester(HelloJSWorld, millSourcePath).scoped { eval => + val Left(Result.Failure(_, Some(res))) = eval(testTask) + + val (doneMsg, testResults) = res + testResults + .groupBy(_.fullyQualifiedName) + .view + .mapValues(_.map(e => e.selector -> e).toMap) + .toMap + } def checkUtest(scalaVersion: String, scalaJSVersion: String, cached: Boolean) = { val resultMap = runTests( @@ -264,34 +261,34 @@ object HelloJSWorldTests extends TestSuite { ) } - def checkRun(scalaVersion: String, scalaJSVersion: String): Unit = { - val eval = UnitTester(HelloJSWorld, millSourcePath) - val task = HelloJSWorld.build(scalaVersion, scalaJSVersion).run() + def checkRun(scalaVersion: String, scalaJSVersion: String): Unit = + UnitTester(HelloJSWorld, millSourcePath).scoped { eval => + val task = HelloJSWorld.build(scalaVersion, scalaJSVersion).run() - val Right(result) = eval(task) + val Right(result) = eval(task) - val paths = EvaluatorPaths.resolveDestPaths(eval.outPath, task) - val log = os.read(paths.log) - assert( - result.evalCount > 0, - log.contains("node") - // TODO: reenable somehow - // In Scala.js 1.x, println's are sent to the stdout, not to the logger - // log.contains("Scala.js") - ) - } + val paths = EvaluatorPaths.resolveDestPaths(eval.outPath, task) + val log = os.read(paths.log) + assert( + result.evalCount > 0, + log.contains("node") + // TODO: reenable somehow + // In Scala.js 1.x, println's are sent to the stdout, not to the logger + // log.contains("Scala.js") + ) + } test("run") { testAllMatrix((scala, scalaJS) => checkRun(scala, scalaJS)) } - def checkInheritedTargets[A](target: ScalaJSModule => T[A], expected: A) = { - val eval = UnitTester(HelloJSWorld, millSourcePath) - val Right(mainResult) = eval(target(HelloJSWorld.inherited)) - val Right(testResult) = eval(target(HelloJSWorld.inherited.test)) - assert(mainResult.value == expected) - assert(testResult.value == expected) - } + def checkInheritedTargets[A](target: ScalaJSModule => T[A], expected: A) = + UnitTester(HelloJSWorld, millSourcePath).scoped { eval => + val Right(mainResult) = eval(target(HelloJSWorld.inherited)) + val Right(testResult) = eval(target(HelloJSWorld.inherited.test)) + assert(mainResult.value == expected) + assert(testResult.value == expected) + } test("test-scalacOptions") { checkInheritedTargets(_.scalacOptions, Seq("-deprecation")) } diff --git a/scalalib/test/src/mill/scalalib/AssemblyTests.scala b/scalalib/test/src/mill/scalalib/AssemblyTests.scala index 56923034b54..ecb6df6a072 100644 --- a/scalalib/test/src/mill/scalalib/AssemblyTests.scala +++ b/scalalib/test/src/mill/scalalib/AssemblyTests.scala @@ -75,22 +75,19 @@ object AssemblyTests extends TestSuite { def tests: Tests = Tests { test("Assembly") { test("noExe") { - test("small") { - val eval = UnitTester(TestCase, sourceRoot = sources) + test("small") - UnitTester(TestCase, sourceRoot = sources).scoped { eval => val Right(result) = eval(TestCase.noExe.small.assembly) runAssembly(result.value.path, TestCase.millSourcePath) } - test("large") { - val eval = UnitTester(TestCase, sourceRoot = sources) + test("large") - UnitTester(TestCase, sourceRoot = sources).scoped { eval => val Right(result) = eval(TestCase.noExe.large.assembly) runAssembly(result.value.path, TestCase.millSourcePath) } } test("exe") { - test("small") { - val eval = UnitTester(TestCase, sourceRoot = sources) + test("small") - UnitTester(TestCase, sourceRoot = sources).scoped { eval => val Right(result) = eval(TestCase.exe.small.assembly) val originalPath = result.value.path val resolvedPath = @@ -102,8 +99,7 @@ object AssemblyTests extends TestSuite { runAssembly(resolvedPath, TestCase.millSourcePath, checkExe = true) } - test("large-should-fail") { - val eval = UnitTester(TestCase, sourceRoot = sources) + test("large-should-fail") - UnitTester(TestCase, sourceRoot = sources).scoped { eval => val Left(Result.Failure(msg, Some(res))) = eval(TestCase.exe.large.assembly) val expectedMsg = """The created assembly jar contains more than 65535 ZIP entries. diff --git a/scalalib/test/src/mill/scalalib/CoursierMirrorTests.scala b/scalalib/test/src/mill/scalalib/CoursierMirrorTests.scala index 7cf9364a067..b72c882fbd2 100644 --- a/scalalib/test/src/mill/scalalib/CoursierMirrorTests.scala +++ b/scalalib/test/src/mill/scalalib/CoursierMirrorTests.scala @@ -18,8 +18,7 @@ object CoursierMirrorTests extends TestSuite { def tests: Tests = Tests { sys.props("coursier.mirrors") = (resourcePath / "mirror.properties").toString - test("readMirror") { - val eval = UnitTester(CoursierTest, resourcePath) + test("readMirror") - UnitTester(CoursierTest, resourcePath).scoped { eval => val Right(result) = eval.apply(CoursierTest.core.repositoriesTask) val centralReplaced = result.value.exists { repo => repo.repr.contains("https://repo.maven.apache.org/maven2") diff --git a/scalalib/test/src/mill/scalalib/CycleTests.scala b/scalalib/test/src/mill/scalalib/CycleTests.scala index 6b8e296249d..a02e61b8cdf 100644 --- a/scalalib/test/src/mill/scalalib/CycleTests.scala +++ b/scalalib/test/src/mill/scalalib/CycleTests.scala @@ -33,15 +33,13 @@ object CycleTests extends TestSuite { override def tests: Tests = Tests { test("moduleDeps") { - test("self-reference") { - val eval = UnitTester(CycleBase, null) + test("self-reference") - UnitTester(CycleBase, null).scoped { eval => val ex = intercept[BuildScriptException] { eval.apply(CycleBase.a.compile) } assert(ex.getMessage.contains("a.moduleDeps: cycle detected: a -> a")) } - test("cycle-in-deps") { - val eval = UnitTester(CycleBase, null) + test("cycle-in-deps") - UnitTester(CycleBase, null).scoped { eval => val ex = intercept[BuildScriptException] { eval.apply(CycleBase.e.compile) } @@ -49,8 +47,7 @@ object CycleTests extends TestSuite { } } test("compileModuleDeps") { - test("self-reference") { - val eval = UnitTester(CycleBase, null) + test("self-reference") - UnitTester(CycleBase, null).scoped { eval => val ex = intercept[BuildScriptException] { eval.apply(CycleBase.f.compile) } diff --git a/scalalib/test/src/mill/scalalib/DottyDocTests.scala b/scalalib/test/src/mill/scalalib/DottyDocTests.scala index 97e85d3ced8..287f19067eb 100644 --- a/scalalib/test/src/mill/scalalib/DottyDocTests.scala +++ b/scalalib/test/src/mill/scalalib/DottyDocTests.scala @@ -35,8 +35,7 @@ object DottyDocTests extends TestSuite { val resourcePath = os.Path(sys.env("MILL_TEST_RESOURCE_FOLDER")) / "dottydoc" def tests: Tests = Tests { - test("static") { - val eval = UnitTester(StaticDocsModule, resourcePath) + test("static") - UnitTester(StaticDocsModule, resourcePath).scoped { eval => val Right(_) = eval.apply(StaticDocsModule.static.docJar) val dest = eval.outPath / "static" / "docJar.dest" assert( @@ -48,8 +47,7 @@ object DottyDocTests extends TestSuite { os.exists(dest / "javadoc" / "_site" / "api" / "pkg" / "SomeClass.html") ) } - test("empty") { - val eval = UnitTester(EmptyDocsModule, resourcePath) + test("empty") - UnitTester(EmptyDocsModule, resourcePath).scoped { eval => val Right(_) = eval.apply(EmptyDocsModule.empty.docJar) val dest = eval.outPath / "empty" / "docJar.dest" assert( @@ -57,8 +55,7 @@ object DottyDocTests extends TestSuite { os.exists(dest / "javadoc" / "_site" / "api" / "pkg" / "SomeClass.html") ) } - test("multiple") { - val eval = UnitTester(MultiDocsModule, resourcePath) + test("multiple") - UnitTester(MultiDocsModule, resourcePath).scoped { eval => val Right(_) = eval.apply(MultiDocsModule.multidocs.docJar) val dest = eval.outPath / "multidocs" / "docJar.dest" assert( diff --git a/scalalib/test/src/mill/scalalib/HelloWorldTests.scala b/scalalib/test/src/mill/scalalib/HelloWorldTests.scala index 1378774ce2b..3ee241794c4 100644 --- a/scalalib/test/src/mill/scalalib/HelloWorldTests.scala +++ b/scalalib/test/src/mill/scalalib/HelloWorldTests.scala @@ -410,8 +410,7 @@ object HelloWorldTests extends TestSuite { def tests: Tests = Tests { test("scalaVersion") { - test("fromBuild") { - val eval = UnitTester(HelloWorld, resourcePath) + test("fromBuild") - UnitTester(HelloWorld, resourcePath).scoped { eval => val Right(result) = eval.apply(HelloWorld.core.scalaVersion) assert( @@ -419,8 +418,7 @@ object HelloWorldTests extends TestSuite { result.evalCount > 0 ) } - test("override") { - val eval = UnitTester(HelloWorldScalaOverride, resourcePath) + test("override") - UnitTester(HelloWorldScalaOverride, resourcePath).scoped { eval => val Right(result) = eval.apply(HelloWorldScalaOverride.core.scalaVersion) assert( @@ -431,8 +429,7 @@ object HelloWorldTests extends TestSuite { } test("scalacOptions") { - test("emptyByDefault") { - val eval = UnitTester(HelloWorld, resourcePath) + test("emptyByDefault") - UnitTester(HelloWorld, resourcePath).scoped { eval => val Right(result) = eval.apply(HelloWorld.core.scalacOptions) assert( @@ -440,8 +437,7 @@ object HelloWorldTests extends TestSuite { result.evalCount > 0 ) } - test("override") { - val eval = UnitTester(HelloWorldFatalWarnings, resourcePath) + test("override") - UnitTester(HelloWorldFatalWarnings, resourcePath).scoped { eval => val Right(result) = eval.apply(HelloWorldFatalWarnings.core.scalacOptions) assert( @@ -452,24 +448,21 @@ object HelloWorldTests extends TestSuite { } test("scalaDocOptions") { - test("emptyByDefault") { - val eval = UnitTester(HelloWorld, resourcePath) + test("emptyByDefault") - UnitTester(HelloWorld, resourcePath).scoped { eval => val Right(result) = eval.apply(HelloWorld.core.scalaDocOptions) assert( result.value.isEmpty, result.evalCount > 0 ) } - test("override") { - val eval = UnitTester(HelloWorldDocTitle, resourcePath) + test("override") - UnitTester(HelloWorldDocTitle, resourcePath).scoped { eval => val Right(result) = eval.apply(HelloWorldDocTitle.core.scalaDocOptions) assert( result.value == Seq("-doc-title", "Hello World"), result.evalCount > 0 ) } - test("extend") { - val eval = UnitTester(HelloWorldWithDocVersion, resourcePath) + test("extend") - UnitTester(HelloWorldWithDocVersion, resourcePath).scoped { eval => val Right(result) = eval.apply(HelloWorldWithDocVersion.core.scalaDocOptions) assert( result.value == Seq("-Ywarn-unused", "-Xfatal-warnings", "-doc-version", "1.2.3"), @@ -477,11 +470,10 @@ object HelloWorldTests extends TestSuite { ) } // make sure options are passed during ScalaDoc generation - test("docJarWithTitle") { - val eval = UnitTester( - HelloWorldDocTitle, - sourceRoot = os.Path(sys.env("MILL_TEST_RESOURCE_FOLDER")) / "hello-world" - ) + test("docJarWithTitle") - UnitTester( + HelloWorldDocTitle, + sourceRoot = os.Path(sys.env("MILL_TEST_RESOURCE_FOLDER")) / "hello-world" + ).scoped { eval => val Right(result) = eval.apply(HelloWorldDocTitle.core.docJar) assert( result.evalCount > 0, @@ -490,27 +482,24 @@ object HelloWorldTests extends TestSuite { ) ) } - test("docJarWithVersion") { - val eval = UnitTester( - HelloWorldWithDocVersion, - sourceRoot = os.Path(sys.env("MILL_TEST_RESOURCE_FOLDER")) / "hello-world" - ) + test("docJarWithVersion") - UnitTester( + HelloWorldWithDocVersion, + sourceRoot = os.Path(sys.env("MILL_TEST_RESOURCE_FOLDER")) / "hello-world" + ).scoped { eval => // scaladoc generation fails because of "-Xfatal-warnings" flag val Left(Result.Failure(_, None)) = eval.apply(HelloWorldWithDocVersion.core.docJar) } - test("docJarOnlyVersion") { - val eval = UnitTester( - HelloWorldOnlyDocVersion, - sourceRoot = os.Path(sys.env("MILL_TEST_RESOURCE_FOLDER")) / "hello-world" - ) + test("docJarOnlyVersion") - UnitTester( + HelloWorldOnlyDocVersion, + sourceRoot = os.Path(sys.env("MILL_TEST_RESOURCE_FOLDER")) / "hello-world" + ).scoped { eval => // `docJar` requires the `compile` task to succeed (since the addition of Scaladoc 3) val Left(Result.Failure(_, None)) = eval.apply(HelloWorldOnlyDocVersion.core.docJar) } } test("scalacPluginClasspath") { - test("withMacroParadise") { - val eval = UnitTester(HelloWorldTypeLevel, resourcePath) + test("withMacroParadise") - UnitTester(HelloWorldTypeLevel, resourcePath).scoped { eval => val Right(result) = eval.apply(HelloWorldTypeLevel.foo.scalacPluginClasspath) assert( result.value.nonEmpty, @@ -520,242 +509,243 @@ object HelloWorldTests extends TestSuite { } } -// test("scalaDocPluginClasspath") { -// test("extend") { -// val eval = UnitTester(HelloWorldTypeLevel, sourceFileRoot = resourcePath) -// val Right(result) = eval.apply(HelloWorldTypeLevel.foo.scalaDocPluginClasspath) -// assert( -// result.value.iterator.nonEmpty, -// result.value.iterator.exists { pathRef => pathRef.path.segments.contains("scalamacros") }, -// result.value.iterator.exists { pathRef => pathRef.path.segments.contains("genjavadoc") }, -// result.evalCount > 0 -// ) -// } -// } -// -// test("compile") { -// test("fromScratch") { -// val eval = UnitTester(HelloWorld, sourceFileRoot = resourcePath) -// val Right(result) = eval.apply(HelloWorld.core.compile) -// -// val classesPath = eval.outPath / "core" / "compile.dest" / "classes" -// val analysisFile = result.value.analysisFile -// val outputFiles = os.walk(result.value.classes.path) -// val expectedClassfiles = compileClassfiles.map(classesPath / _) -// assert( -// result.value.classes.path == classesPath, -// os.exists(analysisFile), -// outputFiles.nonEmpty, -// outputFiles.forall(expectedClassfiles.contains), -// result.evalCount > 0 -// ) -// -// // don't recompile if nothing changed -// val Right(result2) = eval.apply(HelloWorld.core.compile) -// -// assert(result2.evalCount == 0) -// -// // Make sure we *do not* end up compiling the compiler bridge, since -// // it's using a pre-compiled bridge value -// assert(!os.exists( -// eval.outPath / "mill" / "scalalib" / "ZincWorkerModule" / "worker.dest" / s"zinc-${zincVersion}" -// )) -// } -// -// test("nonPreCompiledBridge") { -// val eval = UnitTester(HelloWorldNonPrecompiledBridge, sourceFileRoot = resourcePath) -// val Right(result) = eval.apply(HelloWorldNonPrecompiledBridge.core.compile) -// -// val classesPath = eval.outPath / "core" / "compile.dest" / "classes" -// -// val analysisFile = result.value.analysisFile -// val outputFiles = os.walk(result.value.classes.path) -// val expectedClassfiles = compileClassfiles.map(classesPath / _) -// assert( -// result.value.classes.path == classesPath, -// os.exists(analysisFile), -// outputFiles.nonEmpty, -// outputFiles.forall(expectedClassfiles.contains), -// result.evalCount > 0 -// ) -// -// // don't recompile if nothing changed -// val Right(result2) = eval.apply(HelloWorldNonPrecompiledBridge.core.compile) -// -// assert(result2.evalCount == 0) -// -// // Make sure we *do* end up compiling the compiler bridge, since it's -// // *not* using a pre-compiled bridge value -// assert(os.exists( -// eval.outPath / "mill" / "scalalib" / "ZincWorkerModule" / "worker.dest" / s"zinc-${zincVersion}" -// )) -// } -// -// test("recompileOnChange") { -// val eval = UnitTester(HelloWorld, sourceFileRoot = resourcePath) -// val Right(result) = eval.apply(HelloWorld.core.compile) -// assert(result.evalCount > 0) -// -// os.write.append(HelloWorld.millSourcePath / "core" / "src" / "Main.scala", "\n") -// -// val Right(result2) = eval.apply(HelloWorld.core.compile) -// assert(result2.evalCount > 0, result2.evalCount < result.evalCount) -// } -// test("failOnError") { -// val eval = UnitTester(HelloWorld, sourceFileRoot = resourcePath) -// os.write.append(HelloWorld.millSourcePath / "core" / "src" / "Main.scala", "val x: ") -// -// val Left(Result.Failure("Compilation failed", _)) = eval.apply(HelloWorld.core.compile) -// -// val paths = EvaluatorPaths.resolveDestPaths(eval.outPath, HelloWorld.core.compile) -// -// assert( -// os.walk(paths.dest / "classes").isEmpty, -// !os.exists(paths.meta) -// ) -// // Works when fixed -// os.write.over( -// HelloWorld.millSourcePath / "core" / "src" / "Main.scala", -// os.read(HelloWorld.millSourcePath / "core" / "src" / "Main.scala").dropRight( -// "val x: ".length -// ) -// ) -// -// val Right(_) = eval.apply(HelloWorld.core.compile) -// } -// test("passScalacOptions") { -// val eval = UnitTester(HelloWorldFatalWarnings, sourceFileRoot = resourcePath) -// // compilation fails because of "-Xfatal-warnings" flag -// val Left(Result.Failure("Compilation failed", _)) = -// eval.apply(HelloWorldFatalWarnings.core.compile) -// } -// } -// -// test("semanticDbData") { -// def semanticDbFiles: Set[os.SubPath] = Set( -// os.sub / "META-INF" / "semanticdb" / "core" / "src" / "Main.scala.semanticdb", -// os.sub / "META-INF" / "semanticdb" / "core" / "src" / "Result.scala.semanticdb" -// ) -// -// test("fromScratch") { -// val eval = UnitTester(SemanticWorld, sourceFileRoot = resourcePath) -// { -// println("first - expected full compile") -// val Right(result) = eval.apply(SemanticWorld.core.semanticDbData) -// -// val dataPath = eval.outPath / "core" / "semanticDbData.dest" / "data" -// val outputFiles = -// os.walk(result.value.path).filter(os.isFile).map(_.relativeTo(result.value.path)) -// -// val expectedSemFiles = semanticDbFiles -// assert( -// result.value.path == dataPath, -// outputFiles.nonEmpty, -// outputFiles.toSet == expectedSemFiles, -// result.evalCount > 0, -// os.exists(dataPath / os.up / "zinc") -// ) -// } -// { -// println("second - expected no compile") -// // don't recompile if nothing changed -// val Right(result2) = eval.apply(SemanticWorld.core.semanticDbData) -// assert(result2.evalCount == 0) -// } -// } -// test("incremental") { -// val eval = UnitTester(SemanticWorld, sourceFileRoot = resourcePath, debugEnabled = true) -// // create some more source file to have a reasonable low incremental change later -// val extraFiles = Seq("Second", "Third", "Fourth").map { f => -// val file = eval.evaluator.workspace / "core" / "src" / "hello" / s"${f}.scala" -// os.write( -// file, -// s"""package hello -// |class ${f} -// |""".stripMargin, -// createFolders = true -// ) -// val sem = -// os.sub / "META-INF" / "semanticdb" / "core" / "src" / "hello" / s"${f}.scala.semanticdb" -// (file, sem) -// } -//// val resultFile = eval.evaluator.workspace / "core" / "src" / "Result.scala" -// -// { -// println("first - expected full compile") -// val Right(result) = eval.apply(SemanticWorld.core.semanticDbData) -// -// val dataPath = eval.outPath / "core" / "semanticDbData.dest" / "data" -// val outputFiles = -// os.walk(result.value.path).filter(os.isFile).map(_.relativeTo(result.value.path)) -// -// val expectedSemFiles = semanticDbFiles ++ extraFiles.map(_._2) -// assert( -// result.value.path == dataPath, -// outputFiles.toSet == expectedSemFiles, -// result.evalCount > 0 -// ) -// } -// // change nothing -// { -// println("second - expect no compile due to Mill caching") -// val Right(result2) = eval.apply(SemanticWorld.core.semanticDbData) -// assert(result2.evalCount == 0) -// } -// -// // change one -// { -// println("third - expect inc compile of one file\n") -// os.write.append(extraFiles.head._1, " ") -// -// val Right(result) = eval.apply(SemanticWorld.core.semanticDbData) -// val outputFiles = -// os.walk(result.value.path).filter(os.isFile).map(_.relativeTo(result.value.path)) -// val expectedFiles = semanticDbFiles ++ extraFiles.map(_._2) -// assert( -// outputFiles.toSet == expectedFiles, -// result.evalCount > 0 -// ) -// } -// // remove one -// { -// println("fourth - expect inc compile with one deleted file") -// os.remove(extraFiles.head._1) -// -// val Right(result) = eval.apply(SemanticWorld.core.semanticDbData) -// val outputFiles = -// os.walk(result.value.path).filter(os.isFile).map(_.relativeTo(result.value.path)) -// val expectedFiles = semanticDbFiles ++ extraFiles.map(_._2).drop(1) -// assert( -// outputFiles.toSet == expectedFiles, -// result.evalCount > 0 -// ) -// } -// } -// } -// -// test("artifactNameCross") { -// val eval = UnitTester(CrossHelloWorld, sourceFileRoot = resourcePath) -// val Right(result) = -// eval.apply(CrossHelloWorld.core(scala213Version).artifactName) -// assert(result.value == "core") -// } -// -// test("scala-33-depend-on-scala-32-works") { -// CrossModuleDeps.cuttingEdge(scala33Version).moduleDeps -// } -// test("scala-213-depend-on-scala-212-fails") { -// val message = intercept[Exception]( -// CrossModuleDeps.cuttingEdge(scala213Version).moduleDeps -// ).getMessage -// assert( -// message == s"Unable to find compatible cross version between ${scala213Version} and 2.12.6,3.2.0" -// ) -// } + test("scalaDocPluginClasspath") { + test("extend") - UnitTester(HelloWorldTypeLevel, sourceRoot = resourcePath).scoped { eval => + val Right(result) = eval.apply(HelloWorldTypeLevel.foo.scalaDocPluginClasspath) + assert( + result.value.iterator.nonEmpty, + result.value.iterator.exists { pathRef => pathRef.path.segments.contains("scalamacros") }, + result.value.iterator.exists { pathRef => pathRef.path.segments.contains("genjavadoc") }, + result.evalCount > 0 + ) + } + } + + test("compile") { + test("fromScratch") - UnitTester(HelloWorld, sourceRoot = resourcePath).scoped { eval => + val Right(result) = eval.apply(HelloWorld.core.compile) + + val classesPath = eval.outPath / "core" / "compile.dest" / "classes" + val analysisFile = result.value.analysisFile + val outputFiles = os.walk(result.value.classes.path) + val expectedClassfiles = compileClassfiles.map(classesPath / _) + assert( + result.value.classes.path == classesPath, + os.exists(analysisFile), + outputFiles.nonEmpty, + outputFiles.forall(expectedClassfiles.contains), + result.evalCount > 0 + ) + + // don't recompile if nothing changed + val Right(result2) = eval.apply(HelloWorld.core.compile) + + assert(result2.evalCount == 0) + + // Make sure we *do not* end up compiling the compiler bridge, since + // it's using a pre-compiled bridge value + assert(!os.exists( + eval.outPath / "mill" / "scalalib" / "ZincWorkerModule" / "worker.dest" / s"zinc-${zincVersion}" + )) + } + + test("nonPreCompiledBridge") - UnitTester( + HelloWorldNonPrecompiledBridge, + sourceRoot = resourcePath + ).scoped { eval => + val Right(result) = eval.apply(HelloWorldNonPrecompiledBridge.core.compile) + + val classesPath = eval.outPath / "core" / "compile.dest" / "classes" + + val analysisFile = result.value.analysisFile + val outputFiles = os.walk(result.value.classes.path) + val expectedClassfiles = compileClassfiles.map(classesPath / _) + assert( + result.value.classes.path == classesPath, + os.exists(analysisFile), + outputFiles.nonEmpty, + outputFiles.forall(expectedClassfiles.contains), + result.evalCount > 0 + ) + + // don't recompile if nothing changed + val Right(result2) = eval.apply(HelloWorldNonPrecompiledBridge.core.compile) + + assert(result2.evalCount == 0) + + // Make sure we *do* end up compiling the compiler bridge, since it's + // *not* using a pre-compiled bridge value + assert(os.exists( + eval.outPath / "mill" / "scalalib" / "ZincWorkerModule" / "worker.dest" / s"zinc-${zincVersion}" + )) + } + + test("recompileOnChange") - UnitTester(HelloWorld, sourceRoot = resourcePath).scoped { eval => + val Right(result) = eval.apply(HelloWorld.core.compile) + assert(result.evalCount > 0) + + os.write.append(HelloWorld.millSourcePath / "core" / "src" / "Main.scala", "\n") + + val Right(result2) = eval.apply(HelloWorld.core.compile) + assert(result2.evalCount > 0, result2.evalCount < result.evalCount) + } + test("failOnError") - UnitTester(HelloWorld, sourceRoot = resourcePath).scoped { eval => + os.write.append(HelloWorld.millSourcePath / "core" / "src" / "Main.scala", "val x: ") + + val Left(Result.Failure("Compilation failed", _)) = eval.apply(HelloWorld.core.compile) + + val paths = EvaluatorPaths.resolveDestPaths(eval.outPath, HelloWorld.core.compile) + + assert( + os.walk(paths.dest / "classes").isEmpty, + !os.exists(paths.meta) + ) + // Works when fixed + os.write.over( + HelloWorld.millSourcePath / "core" / "src" / "Main.scala", + os.read(HelloWorld.millSourcePath / "core" / "src" / "Main.scala").dropRight( + "val x: ".length + ) + ) + + val Right(_) = eval.apply(HelloWorld.core.compile) + } + test("passScalacOptions") - UnitTester( + HelloWorldFatalWarnings, + sourceRoot = resourcePath + ).scoped { eval => + // compilation fails because of "-Xfatal-warnings" flag + val Left(Result.Failure("Compilation failed", _)) = + eval.apply(HelloWorldFatalWarnings.core.compile) + } + } + + test("semanticDbData") { + def semanticDbFiles: Set[os.SubPath] = Set( + os.sub / "META-INF" / "semanticdb" / "core" / "src" / "Main.scala.semanticdb", + os.sub / "META-INF" / "semanticdb" / "core" / "src" / "Result.scala.semanticdb" + ) + + test("fromScratch") - UnitTester(SemanticWorld, sourceRoot = resourcePath).scoped { eval => + { + println("first - expected full compile") + val Right(result) = eval.apply(SemanticWorld.core.semanticDbData) + + val dataPath = eval.outPath / "core" / "semanticDbData.dest" / "data" + val outputFiles = + os.walk(result.value.path).filter(os.isFile).map(_.relativeTo(result.value.path)) + + val expectedSemFiles = semanticDbFiles + assert( + result.value.path == dataPath, + outputFiles.nonEmpty, + outputFiles.toSet == expectedSemFiles, + result.evalCount > 0, + os.exists(dataPath / os.up / "zinc") + ) + } + { + println("second - expected no compile") + // don't recompile if nothing changed + val Right(result2) = eval.apply(SemanticWorld.core.semanticDbData) + assert(result2.evalCount == 0) + } + } + test("incremental") - UnitTester( + SemanticWorld, + sourceRoot = resourcePath, + debugEnabled = true + ).scoped { eval => + // create some more source file to have a reasonable low incremental change later + val extraFiles = Seq("Second", "Third", "Fourth").map { f => + val file = eval.evaluator.workspace / "core" / "src" / "hello" / s"${f}.scala" + os.write( + file, + s"""package hello + |class ${f} + |""".stripMargin, + createFolders = true + ) + val sem = + os.sub / "META-INF" / "semanticdb" / "core" / "src" / "hello" / s"${f}.scala.semanticdb" + (file, sem) + } +// val resultFile = eval.evaluator.workspace / "core" / "src" / "Result.scala" + + { + println("first - expected full compile") + val Right(result) = eval.apply(SemanticWorld.core.semanticDbData) + + val dataPath = eval.outPath / "core" / "semanticDbData.dest" / "data" + val outputFiles = + os.walk(result.value.path).filter(os.isFile).map(_.relativeTo(result.value.path)) + + val expectedSemFiles = semanticDbFiles ++ extraFiles.map(_._2) + assert( + result.value.path == dataPath, + outputFiles.toSet == expectedSemFiles, + result.evalCount > 0 + ) + } + // change nothing + { + println("second - expect no compile due to Mill caching") + val Right(result2) = eval.apply(SemanticWorld.core.semanticDbData) + assert(result2.evalCount == 0) + } + + // change one + { + println("third - expect inc compile of one file\n") + os.write.append(extraFiles.head._1, " ") + + val Right(result) = eval.apply(SemanticWorld.core.semanticDbData) + val outputFiles = + os.walk(result.value.path).filter(os.isFile).map(_.relativeTo(result.value.path)) + val expectedFiles = semanticDbFiles ++ extraFiles.map(_._2) + assert( + outputFiles.toSet == expectedFiles, + result.evalCount > 0 + ) + } + // remove one + { + println("fourth - expect inc compile with one deleted file") + os.remove(extraFiles.head._1) + + val Right(result) = eval.apply(SemanticWorld.core.semanticDbData) + val outputFiles = + os.walk(result.value.path).filter(os.isFile).map(_.relativeTo(result.value.path)) + val expectedFiles = semanticDbFiles ++ extraFiles.map(_._2).drop(1) + assert( + outputFiles.toSet == expectedFiles, + result.evalCount > 0 + ) + } + } + } + + test("artifactNameCross") - UnitTester(CrossHelloWorld, sourceRoot = resourcePath).scoped { + eval => + val Right(result) = + eval.apply(CrossHelloWorld.core(scala213Version).artifactName) + assert(result.value == "core") + } + + test("scala-33-depend-on-scala-32-works") { + CrossModuleDeps.cuttingEdge(scala33Version).moduleDeps + } + test("scala-213-depend-on-scala-212-fails") { + val message = intercept[Exception]( + CrossModuleDeps.cuttingEdge(scala213Version).moduleDeps + ).getMessage + assert( + message == s"Unable to find compatible cross version between ${scala213Version} and 2.12.6,3.2.0" + ) + } test("runMain") { - test("runMainObject") { - val eval = UnitTester(HelloWorld, resourcePath) + test("runMainObject") - UnitTester(HelloWorld, resourcePath).scoped { eval => val runResult = eval.outPath / "core" / "runMain.dest" / "hello-mill" val Right(result) = eval.apply(HelloWorld.core.runMain("Main", runResult.toString)) @@ -783,27 +773,23 @@ object HelloWorldTests extends TestSuite { ) } - test("v2123") - { - val eval = UnitTester(CrossHelloWorld, resourcePath) + test("v2123") - UnitTester(CrossHelloWorld, resourcePath).scoped { eval => cross(eval, scala2123Version, s"${scala2123Version} leet") + } - test("v2124") { - val eval = UnitTester(CrossHelloWorld, resourcePath) + test("v2124") - UnitTester(CrossHelloWorld, resourcePath).scoped { eval => cross(eval, scala212Version, s"${scala212Version} leet") } - test("v2131") { - val eval = UnitTester(CrossHelloWorld, resourcePath) + test("v2131") - UnitTester(CrossHelloWorld, resourcePath).scoped { eval => cross(eval, scala213Version, s"${scala213Version} idk") } } - test("notRunInvalidMainObject") { - val eval = UnitTester(HelloWorld, resourcePath) + test("notRunInvalidMainObject") - UnitTester(HelloWorld, resourcePath).scoped { eval => val Left(Result.Failure("Subprocess failed", _)) = eval.apply(HelloWorld.core.runMain("Invalid")) } - test("notRunWhenCompileFailed") { - val eval = UnitTester(HelloWorld, resourcePath) + test("notRunWhenCompileFailed") - UnitTester(HelloWorld, resourcePath).scoped { eval => os.write.append(HelloWorld.millSourcePath / "core" / "src" / "Main.scala", "val x: ") val Left(Result.Failure("Compilation failed", _)) = @@ -813,8 +799,7 @@ object HelloWorldTests extends TestSuite { } test("forkRun") { - test("runIfMainClassProvided") { - val eval = UnitTester(HelloWorldWithMain, resourcePath) + test("runIfMainClassProvided") - UnitTester(HelloWorldWithMain, resourcePath).scoped { eval => val runResult = eval.outPath / "core" / "run.dest" / "hello-mill" val Right(result) = eval.apply( HelloWorldWithMain.core.run(T.task(Args(runResult.toString))) @@ -827,36 +812,33 @@ object HelloWorldTests extends TestSuite { os.read(runResult) == "hello rockjam, your age is: 25" ) } - test("notRunWithoutMainClass") { - - val eval = UnitTester( - HelloWorldWithoutMain, - sourceRoot = os.Path(sys.env("MILL_TEST_RESOURCE_FOLDER")) / "hello-world-no-main" - ) + test("notRunWithoutMainClass") - UnitTester( + HelloWorldWithoutMain, + sourceRoot = os.Path(sys.env("MILL_TEST_RESOURCE_FOLDER")) / "hello-world-no-main" + ).scoped { eval => val Left(Result.Failure(_, None)) = eval.apply(HelloWorldWithoutMain.core.run()) } - test("runDiscoverMainClass") { - val eval = UnitTester(HelloWorldWithoutMain, resourcePath) - // Make sure even if there isn't a main class defined explicitly, it gets - // discovered by Zinc and used - val runResult = eval.outPath / "core" / "run.dest" / "hello-mill" - val Right(result) = eval.apply( - HelloWorldWithoutMain.core.run(T.task(Args(runResult.toString))) - ) + test("runDiscoverMainClass") - UnitTester(HelloWorldWithoutMain, resourcePath).scoped { + eval => + // Make sure even if there isn't a main class defined explicitly, it gets + // discovered by Zinc and used + val runResult = eval.outPath / "core" / "run.dest" / "hello-mill" + val Right(result) = eval.apply( + HelloWorldWithoutMain.core.run(T.task(Args(runResult.toString))) + ) - assert(result.evalCount > 0) + assert(result.evalCount > 0) - assert( - os.exists(runResult), - os.read(runResult) == "hello rockjam, your age is: 25" - ) + assert( + os.exists(runResult), + os.read(runResult) == "hello rockjam, your age is: 25" + ) } } test("run") { - test("runIfMainClassProvided") { - val eval = UnitTester(HelloWorldWithMain, resourcePath) + test("runIfMainClassProvided") - UnitTester(HelloWorldWithMain, resourcePath).scoped { eval => val runResult = eval.outPath / "core" / "run.dest" / "hello-mill" val Right(result) = eval.apply( HelloWorldWithMain.core.runLocal(T.task(Args(runResult.toString))) @@ -869,8 +851,7 @@ object HelloWorldTests extends TestSuite { os.read(runResult) == "hello rockjam, your age is: 25" ) } - test("runWithDefaultMain") { - val eval = UnitTester(HelloWorldDefaultMain, resourcePath) + test("runWithDefaultMain") - UnitTester(HelloWorldDefaultMain, resourcePath).scoped { eval => val runResult = eval.outPath / "core" / "run.dest" / "hello-mill" val Right(result) = eval.apply( HelloWorldDefaultMain.core.runLocal(T.task(Args(runResult.toString))) @@ -883,18 +864,16 @@ object HelloWorldTests extends TestSuite { os.read(runResult) == "hello rockjam, your age is: 25" ) } - test("notRunWithoutMainClass") { - val eval = UnitTester( - HelloWorldWithoutMain, - sourceRoot = os.Path(sys.env("MILL_TEST_RESOURCE_FOLDER")) / "hello-world-no-main" - ) + test("notRunWithoutMainClass") - UnitTester( + HelloWorldWithoutMain, + sourceRoot = os.Path(sys.env("MILL_TEST_RESOURCE_FOLDER")) / "hello-world-no-main" + ).scoped { eval => val Left(Result.Failure(_, None)) = eval.apply(HelloWorldWithoutMain.core.runLocal()) } } test("jar") { - test("nonEmpty") { - val eval = UnitTester(HelloWorldWithMain, resourcePath) + test("nonEmpty") - UnitTester(HelloWorldWithMain, resourcePath).scoped { eval => val Right(result) = eval.apply(HelloWorldWithMain.core.jar) assert( @@ -922,8 +901,7 @@ object HelloWorldTests extends TestSuite { } } - test("logOutputToFile") { - val eval = UnitTester(HelloWorld, resourcePath) + test("logOutputToFile") - UnitTester(HelloWorld, resourcePath).scoped { eval => val outPath = eval.outPath eval.apply(HelloWorld.core.compile) @@ -933,8 +911,7 @@ object HelloWorldTests extends TestSuite { } test("assembly") { - test("assembly") { - val eval = UnitTester(HelloWorldWithMain, resourcePath) + test("assembly") - UnitTester(HelloWorldWithMain, resourcePath).scoped { eval => val Right(result) = eval.apply(HelloWorldWithMain.core.assembly) assert( os.exists(result.value.path), @@ -952,29 +929,29 @@ object HelloWorldTests extends TestSuite { } test("assemblyRules") { - def checkAppend[M <: mill.testkit.TestBaseModule](module: M, target: Target[PathRef]) = { - val eval = UnitTester(module, resourcePath) - val Right(result) = eval.apply(target) + def checkAppend[M <: mill.testkit.TestBaseModule](module: M, target: Target[PathRef]) = + UnitTester(module, resourcePath).scoped { eval => + val Right(result) = eval.apply(target) - Using.resource(new JarFile(result.value.path.toIO)) { jarFile => - assert(jarEntries(jarFile).contains("reference.conf")) + Using.resource(new JarFile(result.value.path.toIO)) { jarFile => + assert(jarEntries(jarFile).contains("reference.conf")) - val referenceContent = readFileFromJar(jarFile, "reference.conf") + val referenceContent = readFileFromJar(jarFile, "reference.conf") - assert( - // akka modules configs are present - referenceContent.contains("akka-http Reference Config File"), - referenceContent.contains("akka-http-core Reference Config File"), - referenceContent.contains("Akka Actor Reference Config File"), - referenceContent.contains("Akka Stream Reference Config File"), - // our application config is present too - referenceContent.contains("My application Reference Config File"), - referenceContent.contains( - """akka.http.client.user-agent-header="hello-world-client"""" + assert( + // akka modules configs are present + referenceContent.contains("akka-http Reference Config File"), + referenceContent.contains("akka-http-core Reference Config File"), + referenceContent.contains("Akka Actor Reference Config File"), + referenceContent.contains("Akka Stream Reference Config File"), + // our application config is present too + referenceContent.contains("My application Reference Config File"), + referenceContent.contains( + """akka.http.client.user-agent-header="hello-world-client"""" + ) ) - ) + } } - } val helloWorldMultiResourcePath = os.Path(sys.env("MILL_TEST_RESOURCE_FOLDER")) / "hello-world-multi" @@ -982,11 +959,10 @@ object HelloWorldTests extends TestSuite { def checkAppendMulti[M <: mill.testkit.TestBaseModule]( module: M, target: Target[PathRef] - ): Unit = { - val eval = UnitTester( - module, - sourceRoot = helloWorldMultiResourcePath - ) + ): Unit = UnitTester( + module, + sourceRoot = helloWorldMultiResourcePath + ).scoped { eval => val Right(result) = eval.apply(target) Using.resource(new JarFile(result.value.path.toIO)) { jarFile => @@ -1009,11 +985,10 @@ object HelloWorldTests extends TestSuite { def checkAppendWithSeparator[M <: mill.testkit.TestBaseModule]( module: M, target: Target[PathRef] - ): Unit = { - val eval = UnitTester( - module, - sourceRoot = helloWorldMultiResourcePath - ) + ): Unit = UnitTester( + module, + sourceRoot = helloWorldMultiResourcePath + ).scoped { eval => val Right(result) = eval.apply(target) Using.resource(new JarFile(result.value.path.toIO)) { jarFile => @@ -1050,8 +1025,7 @@ object HelloWorldTests extends TestSuite { module: M, target: Target[PathRef], resourcePath: os.Path = resourcePath - ) = { - val eval = UnitTester(module, resourcePath) + ) = UnitTester(module, resourcePath).scoped { eval => val Right(result) = eval.apply(target) Using.resource(new JarFile(result.value.path.toIO)) { jarFile => @@ -1082,8 +1056,7 @@ object HelloWorldTests extends TestSuite { module: M, target: Target[PathRef], resourcePath: os.Path = resourcePath - ) = { - val eval = UnitTester(module, resourcePath) + ) = UnitTester(module, resourcePath).scoped { eval => val Right(result) = eval.apply(target) Using.resource(new JarFile(result.value.path.toIO)) { jarFile => assert(!jarEntries(jarFile).contains("akka/http/scaladsl/model/HttpEntity.class")) @@ -1099,19 +1072,17 @@ object HelloWorldTests extends TestSuite { HelloWorldAkkaHttpRelocate.core.assembly ) - test("run") { - val eval = UnitTester( - HelloWorldAkkaHttpRelocate, - sourceRoot = os.Path(sys.env("MILL_TEST_RESOURCE_FOLDER")) / "hello-world-deps" - ) + test("run") - UnitTester( + HelloWorldAkkaHttpRelocate, + sourceRoot = os.Path(sys.env("MILL_TEST_RESOURCE_FOLDER")) / "hello-world-deps" + ).scoped { eval => val Right(result) = eval.apply(HelloWorldAkkaHttpRelocate.core.runMain("Main")) assert(result.evalCount > 0) } } test("writeDownstreamWhenNoRule") { - test("withDeps") { - val eval = UnitTester(HelloWorldAkkaHttpNoRules, null) + test("withDeps") - UnitTester(HelloWorldAkkaHttpNoRules, null).scoped { eval => val Right(result) = eval.apply(HelloWorldAkkaHttpNoRules.core.assembly) Using.resource(new JarFile(result.value.path.toIO)) { jarFile => @@ -1133,11 +1104,10 @@ object HelloWorldTests extends TestSuite { } } - test("multiModule") { - val eval = UnitTester( - HelloWorldMultiNoRules, - sourceRoot = helloWorldMultiResourcePath - ) + test("multiModule") - UnitTester( + HelloWorldMultiNoRules, + sourceRoot = helloWorldMultiResourcePath + ).scoped { eval => val Right(result) = eval.apply(HelloWorldMultiNoRules.core.assembly) Using.resource(new JarFile(result.value.path.toIO)) { jarFile => @@ -1156,8 +1126,7 @@ object HelloWorldTests extends TestSuite { } } - test("run") { - val eval = UnitTester(HelloWorldWithMain, resourcePath) + test("run") - UnitTester(HelloWorldWithMain, resourcePath).scoped { eval => val Right(result) = eval.apply(HelloWorldWithMain.core.assembly) assert( @@ -1175,8 +1144,7 @@ object HelloWorldTests extends TestSuite { } } - test("ivyDeps") { - val eval = UnitTester(HelloWorldIvyDeps, resourcePath) + test("ivyDeps") - UnitTester(HelloWorldIvyDeps, resourcePath).scoped { eval => val Right(result) = eval.apply(HelloWorldIvyDeps.moduleA.runClasspath) assert( result.value.exists(_.path.last == "sourcecode_2.12-0.1.3.jar"), @@ -1190,8 +1158,7 @@ object HelloWorldTests extends TestSuite { ) } - test("typeLevel") { - val eval = UnitTester(HelloWorldTypeLevel, null) + test("typeLevel") - UnitTester(HelloWorldTypeLevel, null).scoped { eval => val classPathsToCheck = Seq( HelloWorldTypeLevel.foo.runClasspath, HelloWorldTypeLevel.foo.ammoniteReplClasspath, @@ -1219,11 +1186,10 @@ object HelloWorldTests extends TestSuite { // Scala 2.12 does not always work with Java 17+ // make sure macros are applied when compiling/running val mod = HelloWorldMacros212 - test("runMain") { - val eval = UnitTester( - mod, - sourceRoot = os.Path(sys.env("MILL_TEST_RESOURCE_FOLDER")) / "hello-world-macros" - ) + test("runMain") - UnitTester( + mod, + sourceRoot = os.Path(sys.env("MILL_TEST_RESOURCE_FOLDER")) / "hello-world-macros" + ).scoped { eval => if (Properties.isJavaAtLeast(17)) "skipped on Java 17+" else { val Right(result) = eval.apply(mod.core.runMain("Main")) @@ -1231,11 +1197,10 @@ object HelloWorldTests extends TestSuite { } } // make sure macros are applied when compiling during scaladoc generation - test("docJar") { - val eval = UnitTester( - mod, - sourceRoot = os.Path(sys.env("MILL_TEST_RESOURCE_FOLDER")) / "hello-world-macros" - ) + test("docJar") - UnitTester( + mod, + sourceRoot = os.Path(sys.env("MILL_TEST_RESOURCE_FOLDER")) / "hello-world-macros" + ).scoped { eval => if (Properties.isJavaAtLeast(17)) "skipped on Java 17+" else { val Right(result) = eval.apply(mod.core.docJar) @@ -1246,20 +1211,18 @@ object HelloWorldTests extends TestSuite { test("scala-2.13") { // make sure macros are applied when compiling/running val mod = HelloWorldMacros213 - test("runMain") { - val eval = UnitTester( - mod, - sourceRoot = os.Path(sys.env("MILL_TEST_RESOURCE_FOLDER")) / "hello-world-macros" - ) + test("runMain") - UnitTester( + mod, + sourceRoot = os.Path(sys.env("MILL_TEST_RESOURCE_FOLDER")) / "hello-world-macros" + ).scoped { eval => val Right(result) = eval.apply(mod.core.runMain("Main")) assert(result.evalCount > 0) } // make sure macros are applied when compiling during scaladoc generation - test("docJar") { - val eval = UnitTester( - mod, - sourceRoot = os.Path(sys.env("MILL_TEST_RESOURCE_FOLDER")) / "hello-world-macros" - ) + test("docJar") - UnitTester( + mod, + sourceRoot = os.Path(sys.env("MILL_TEST_RESOURCE_FOLDER")) / "hello-world-macros" + ).scoped { eval => val Right(result) = eval.apply(mod.core.docJar) assert(result.evalCount > 0) } @@ -1268,46 +1231,45 @@ object HelloWorldTests extends TestSuite { test("flags") { // make sure flags are passed when compiling/running - test("runMain") { - val eval = UnitTester( - HelloWorldFlags, - sourceRoot = os.Path(sys.env("MILL_TEST_RESOURCE_FOLDER")) / "hello-world-flags" - ) + test("runMain") - UnitTester( + HelloWorldFlags, + sourceRoot = os.Path(sys.env("MILL_TEST_RESOURCE_FOLDER")) / "hello-world-flags" + ).scoped { eval => val Right(result) = eval.apply(HelloWorldFlags.core.runMain("Main")) assert(result.evalCount > 0) } // make sure flags are passed during ScalaDoc generation - test("docJar") { - val eval = UnitTester( - HelloWorldFlags, - sourceRoot = os.Path(sys.env("MILL_TEST_RESOURCE_FOLDER")) / "hello-world-flags" - ) + test("docJar") - UnitTester( + HelloWorldFlags, + sourceRoot = os.Path(sys.env("MILL_TEST_RESOURCE_FOLDER")) / "hello-world-flags" + ).scoped { eval => val Right(result) = eval.apply(HelloWorldFlags.core.docJar) assert(result.evalCount > 0) } } test("color-output") { + val errStream = new ByteArrayOutputStream() - val eval = UnitTester( + UnitTester( HelloWorldColorOutput, sourceRoot = os.Path(sys.env("MILL_TEST_RESOURCE_FOLDER")) / "hello-world-color-output", errStream = new PrintStream(errStream, true) - ) - val Left(Result.Failure("Compilation failed", _)) = - eval.apply(HelloWorldColorOutput.core.compile) - val output = errStream.toString - assert(output.contains(s"${Console.RED}!${Console.RESET}${Console.BLUE}I")) - assert(output.contains( - s"${Console.GREEN}example.Show[scala.Option[java.lang.String]]${Console.RESET}" - )) - } - - test("scalacheck") { - val eval = UnitTester( - HelloScalacheck, - sourceRoot = os.Path(sys.env("MILL_TEST_RESOURCE_FOLDER")) / "hello-scalacheck" - ) + ).scoped { eval => + val Left(Result.Failure("Compilation failed", _)) = + eval.apply(HelloWorldColorOutput.core.compile) + val output = errStream.toString + assert(output.contains(s"${Console.RED}!${Console.RESET}${Console.BLUE}I")) + assert(output.contains( + s"${Console.GREEN}example.Show[scala.Option[java.lang.String]]${Console.RESET}" + )) + } + } + + test("scalacheck") - UnitTester( + HelloScalacheck, + sourceRoot = os.Path(sys.env("MILL_TEST_RESOURCE_FOLDER")) / "hello-scalacheck" + ).scoped { eval => val Right(result) = eval.apply(HelloScalacheck.foo.test.test()) assert( result.evalCount > 0, @@ -1320,17 +1282,15 @@ object HelloWorldTests extends TestSuite { ) } - test("dotty213") { - val eval = UnitTester( - Dotty213, - sourceRoot = os.Path(sys.env("MILL_TEST_RESOURCE_FOLDER")) / "dotty213" - ) + test("dotty213") - UnitTester( + Dotty213, + sourceRoot = os.Path(sys.env("MILL_TEST_RESOURCE_FOLDER")) / "dotty213" + ).scoped { eval => val Right(result) = eval.apply(Dotty213.foo.run()) assert(result.evalCount > 0) } - test("replAmmoniteMainClass") { - val eval = UnitTester(AmmoniteReplMainClass, null) + test("replAmmoniteMainClass") - UnitTester(AmmoniteReplMainClass, null).scoped { eval => val Right(result) = eval.apply(AmmoniteReplMainClass.oldAmmonite.ammoniteMainClass) assert(result.value == "ammonite.Main") val Right(result2) = eval.apply(AmmoniteReplMainClass.newAmmonite.ammoniteMainClass) @@ -1339,82 +1299,82 @@ object HelloWorldTests extends TestSuite { test("validated") { test("PathRef") { - def check(t: Target[PathRef], flip: Boolean) = { - val eval = UnitTester(ValidatedTarget, null) - // we reconstruct faulty behavior - val Right(result) = eval.apply(t) - assert( - result.value.path.last == (t.asInstanceOf[NamedTask[_]].label + ".dest"), - os.exists(result.value.path) - ) - os.remove.all(result.value.path) - val Right(result2) = eval.apply(t) - assert( - result2.value.path.last == (t.asInstanceOf[NamedTask[_]].label + ".dest"), - // as the result was cached but not checked, this path is missing - os.exists(result2.value.path) == flip - ) + def check(t: Target[PathRef], flip: Boolean) = UnitTester(ValidatedTarget, null).scoped { + eval => + // we reconstruct faulty behavior + val Right(result) = eval.apply(t) + assert( + result.value.path.last == (t.asInstanceOf[NamedTask[_]].label + ".dest"), + os.exists(result.value.path) + ) + os.remove.all(result.value.path) + val Right(result2) = eval.apply(t) + assert( + result2.value.path.last == (t.asInstanceOf[NamedTask[_]].label + ".dest"), + // as the result was cached but not checked, this path is missing + os.exists(result2.value.path) == flip + ) } test("unchecked") - check(ValidatedTarget.uncheckedPathRef, false) test("checked") - check(ValidatedTarget.checkedPathRef, true) } test("SeqPathRef") { - def check(t: Target[Seq[PathRef]], flip: Boolean) { - val eval = UnitTester(ValidatedTarget, null) - // we reconstruct faulty behavior - val Right(result) = eval.apply(t) - assert( - result.value.map(_.path.last) == Seq(t.asInstanceOf[NamedTask[_]].label + ".dest"), - result.value.forall(p => os.exists(p.path)) - ) - result.value.foreach(p => os.remove.all(p.path)) - val Right(result2) = eval.apply(t) - assert( - result2.value.map(_.path.last) == Seq(t.asInstanceOf[NamedTask[_]].label + ".dest"), - // as the result was cached but not checked, this path is missing - result2.value.forall(p => os.exists(p.path) == flip) - ) - } + def check(t: Target[Seq[PathRef]], flip: Boolean) = + UnitTester(ValidatedTarget, null).scoped { eval => + // we reconstruct faulty behavior + val Right(result) = eval.apply(t) + assert( + result.value.map(_.path.last) == Seq(t.asInstanceOf[NamedTask[_]].label + ".dest"), + result.value.forall(p => os.exists(p.path)) + ) + result.value.foreach(p => os.remove.all(p.path)) + val Right(result2) = eval.apply(t) + assert( + result2.value.map(_.path.last) == Seq(t.asInstanceOf[NamedTask[_]].label + ".dest"), + // as the result was cached but not checked, this path is missing + result2.value.forall(p => os.exists(p.path) == flip) + ) + } test("unchecked") - check(ValidatedTarget.uncheckedSeqPathRef, false) test("checked") - check(ValidatedTarget.checkedSeqPathRef, true) } test("AggPathRef") { - def check(t: Target[Agg[PathRef]], flip: Boolean) = { - val eval = UnitTester(ValidatedTarget, null) - // we reconstruct faulty behavior - val Right(result) = eval.apply(t) - assert( - result.value.map(_.path.last) == Agg(t.asInstanceOf[NamedTask[_]].label + ".dest"), - result.value.forall(p => os.exists(p.path)) - ) - result.value.foreach(p => os.remove.all(p.path)) - val Right(result2) = eval.apply(t) - assert( - result2.value.map(_.path.last) == Agg(t.asInstanceOf[NamedTask[_]].label + ".dest"), - // as the result was cached but not checked, this path is missing - result2.value.forall(p => os.exists(p.path) == flip) - ) - } + def check(t: Target[Agg[PathRef]], flip: Boolean) = + UnitTester(ValidatedTarget, null).scoped { eval => + // we reconstruct faulty behavior + val Right(result) = eval.apply(t) + assert( + result.value.map(_.path.last) == Agg(t.asInstanceOf[NamedTask[_]].label + ".dest"), + result.value.forall(p => os.exists(p.path)) + ) + result.value.foreach(p => os.remove.all(p.path)) + val Right(result2) = eval.apply(t) + assert( + result2.value.map(_.path.last) == Agg(t.asInstanceOf[NamedTask[_]].label + ".dest"), + // as the result was cached but not checked, this path is missing + result2.value.forall(p => os.exists(p.path) == flip) + ) + } test("unchecked") - check(ValidatedTarget.uncheckedAggPathRef, false) test("checked") - check(ValidatedTarget.checkedAggPathRef, true) } test("other") { - def check(t: Target[Tuple1[PathRef]], flip: Boolean) = { - val eval = UnitTester(ValidatedTarget, null) - // we reconstruct faulty behavior - val Right(result) = eval.apply(t) - assert( - result.value._1.path.last == (t.asInstanceOf[NamedTask[_]].label + ".dest"), - os.exists(result.value._1.path) - ) - os.remove.all(result.value._1.path) - val Right(result2) = eval.apply(t) - assert( - result2.value._1.path.last == (t.asInstanceOf[NamedTask[_]].label + ".dest"), - // as the result was cached but not checked, this path is missing - os.exists(result2.value._1.path) == flip - ) - } + def check(t: Target[Tuple1[PathRef]], flip: Boolean) = + UnitTester(ValidatedTarget, null).scoped { eval => + // we reconstruct faulty behavior + val Right(result) = eval.apply(t) + assert( + result.value._1.path.last == (t.asInstanceOf[NamedTask[_]].label + ".dest"), + os.exists(result.value._1.path) + ) + os.remove.all(result.value._1.path) + val Right(result2) = eval.apply(t) + assert( + result2.value._1.path.last == (t.asInstanceOf[NamedTask[_]].label + ".dest"), + // as the result was cached but not checked, this path is missing + os.exists(result2.value._1.path) == flip + ) + } test("unchecked") - check(ValidatedTarget.uncheckedTuplePathRef, false) test("checked") - check(ValidatedTarget.checkedTuplePathRef, true) } @@ -1460,8 +1420,7 @@ object HelloWorldTests extends TestSuite { ) } - test("modMod") { - val eval = UnitTester(MultiModuleClasspaths, resourcePath) + test("modMod") - UnitTester(MultiModuleClasspaths, resourcePath).scoped { eval => // Make sure that `compileClasspath` has all the same things as `runClasspath`, // but without the `/resources` check( @@ -1526,8 +1485,7 @@ object HelloWorldTests extends TestSuite { ) } - test("modCompile") { - val eval = UnitTester(MultiModuleClasspaths, resourcePath) + test("modCompile") - UnitTester(MultiModuleClasspaths, resourcePath).scoped { eval => // Mostly the same as `modMod` above, but with the dependency // from `qux` to `bar` being a `compileModuleDeps` check( @@ -1591,8 +1549,7 @@ object HelloWorldTests extends TestSuite { ) } - test("compileMod") { - val eval = UnitTester(MultiModuleClasspaths, resourcePath) + test("compileMod") - UnitTester(MultiModuleClasspaths, resourcePath).scoped { eval => // Both the `runClasspath` and `compileClasspath` should not have `foo` on the // classpath, nor should it have the versions of libraries pulled in by `foo` // (e.g. `sourcecode-0.2.4`), because it is a `compileModuleDep` of an upstream diff --git a/scalalib/test/src/mill/scalalib/PublishModuleTests.scala b/scalalib/test/src/mill/scalalib/PublishModuleTests.scala index c83f9bbfc19..022fd252274 100644 --- a/scalalib/test/src/mill/scalalib/PublishModuleTests.scala +++ b/scalalib/test/src/mill/scalalib/PublishModuleTests.scala @@ -81,8 +81,10 @@ object PublishModuleTests extends TestSuite { def tests: Tests = Tests { test("pom") { - test("should include scala-library dependency") { - val eval = UnitTester(HelloWorldWithPublish, resourcePath) + test("should include scala-library dependency") - UnitTester( + HelloWorldWithPublish, + resourcePath + ).scoped { eval => val Right(result) = eval.apply(HelloWorldWithPublish.core.pom) assert( @@ -98,8 +100,7 @@ object PublishModuleTests extends TestSuite { (scalaLibrary \ "groupId").text == "org.scala-lang" ) } - test("versionScheme") { - val eval = UnitTester(HelloWorldWithPublish, resourcePath) + test("versionScheme") - UnitTester(HelloWorldWithPublish, resourcePath).scoped { eval => val Right(result) = eval.apply(HelloWorldWithPublish.core.pom) assert( @@ -117,47 +118,47 @@ object PublishModuleTests extends TestSuite { test( "should retrieve credentials from environment variables if direct argument is empty" ) { - val eval = UnitTester( + UnitTester( HelloWorldWithPublish, sourceRoot = resourcePath, env = Evaluator.defaultEnv ++ Seq( "SONATYPE_USERNAME" -> "user", "SONATYPE_PASSWORD" -> "password" ) - ) - val Right(result) = - eval.apply(HelloWorldWithPublish.core.checkSonatypeCreds("")) + ).scoped { eval => + val Right(result) = + eval.apply(HelloWorldWithPublish.core.checkSonatypeCreds("")) - assert( - result.value == "user:password", - result.evalCount > 0 - ) + assert( + result.value == "user:password", + result.evalCount > 0 + ) + } } test( "should prefer direct argument as credentials over environment variables" ) { - val eval = UnitTester( + UnitTester( HelloWorldWithPublish, sourceRoot = resourcePath, env = Evaluator.defaultEnv ++ Seq( "SONATYPE_USERNAME" -> "user", "SONATYPE_PASSWORD" -> "password" ) - ) - - val directValue = "direct:value" - val Right(result) = - eval.apply(HelloWorldWithPublish.core.checkSonatypeCreds(directValue)) - - assert( - result.value == directValue, - result.evalCount > 0 - ) + ).scoped { eval => + val directValue = "direct:value" + val Right(result) = + eval.apply(HelloWorldWithPublish.core.checkSonatypeCreds(directValue)) + + assert( + result.value == directValue, + result.evalCount > 0 + ) + } } test( "should throw exception if neither environment variables or direct argument were not passed" - ) { - val eval = UnitTester(HelloWorldWithPublish, resourcePath) + ) - UnitTester(HelloWorldWithPublish, resourcePath).scoped { eval => val Left(Result.Failure(msg, None)) = eval.apply(HelloWorldWithPublish.core.checkSonatypeCreds("")) @@ -168,8 +169,10 @@ object PublishModuleTests extends TestSuite { } test("ivy") { - test("should include scala-library dependency") { - val eval = UnitTester(HelloWorldWithPublish, resourcePath) + test("should include scala-library dependency") - UnitTester( + HelloWorldWithPublish, + resourcePath + ).scoped { eval => val Right(result) = eval.apply(HelloWorldWithPublish.core.ivy) assert( @@ -187,8 +190,7 @@ object PublishModuleTests extends TestSuite { } test("pom-packaging-type") - { - test("pom") { - val eval = UnitTester(PomOnly, resourcePath) + test("pom") - UnitTester(PomOnly, resourcePath).scoped { eval => val Right(result) = eval.apply(PomOnly.core.pom) // // assert( diff --git a/scalalib/test/src/mill/scalalib/ScalaDoc3Tests.scala b/scalalib/test/src/mill/scalalib/ScalaDoc3Tests.scala index 22f54506e7f..799cdfa8187 100644 --- a/scalalib/test/src/mill/scalalib/ScalaDoc3Tests.scala +++ b/scalalib/test/src/mill/scalalib/ScalaDoc3Tests.scala @@ -35,8 +35,7 @@ object ScalaDoc3Tests extends TestSuite { val resourcePath = os.Path(sys.env("MILL_TEST_RESOURCE_FOLDER")) / "scaladoc3" def tests: Tests = Tests { - test("static") { - val eval = UnitTester(StaticDocsModule, resourcePath) + test("static") - UnitTester(StaticDocsModule, resourcePath).scoped { eval => val Right(_) = eval.apply(StaticDocsModule.static.docJar) val dest = eval.outPath / "static" / "docJar.dest" assert( @@ -48,8 +47,7 @@ object ScalaDoc3Tests extends TestSuite { os.exists(dest / "javadoc" / "api" / "pkg" / "SomeClass.html") ) } - test("empty") { - val eval = UnitTester(EmptyDocsModule, resourcePath) + test("empty") - UnitTester(EmptyDocsModule, resourcePath).scoped { eval => val Right(_) = eval.apply(EmptyDocsModule.empty.docJar) val dest = eval.outPath / "empty" / "docJar.dest" assert( @@ -57,8 +55,7 @@ object ScalaDoc3Tests extends TestSuite { os.exists(dest / "javadoc" / "api" / "pkg" / "SomeClass.html") ) } - test("multiple") { - val eval = UnitTester(MultiDocsModule, resourcePath) + test("multiple") - UnitTester(MultiDocsModule, resourcePath).scoped { eval => val Right(_) = eval.apply(MultiDocsModule.multidocs.docJar) val dest = eval.outPath / "multidocs" / "docJar.dest" assert( diff --git a/scalalib/test/src/mill/scalalib/ScalaVersionsRangesTests.scala b/scalalib/test/src/mill/scalalib/ScalaVersionsRangesTests.scala index 3350bdfee8a..feef4991855 100644 --- a/scalalib/test/src/mill/scalalib/ScalaVersionsRangesTests.scala +++ b/scalalib/test/src/mill/scalalib/ScalaVersionsRangesTests.scala @@ -21,14 +21,18 @@ object ScalaVersionsRangesTests extends TestSuite { os.Path(sys.env("MILL_TEST_RESOURCE_FOLDER")) / "scala-versions-ranges" val tests = Tests { - test("main with Scala 2.12- and 2.13+ specific code") { - val eval = UnitTester(ScalaVersionsRanges, resourcePath) + test("main with Scala 2.12- and 2.13+ specific code") - UnitTester( + ScalaVersionsRanges, + resourcePath + ).scoped { eval => ScalaVersionsRanges.core.crossModules.map { c => val Right(_) = eval(c.run()) } } - test("test with Scala 2.12- and 2.13+ specific code") { - val eval = UnitTester(ScalaVersionsRanges, resourcePath) + test("test with Scala 2.12- and 2.13+ specific code") - UnitTester( + ScalaVersionsRanges, + resourcePath + ).scoped { eval => ScalaVersionsRanges.core.crossModules.map { c => val Right(_) = eval(c.test.test()) } diff --git a/scalalib/test/src/mill/scalalib/TestClassLoaderTests.scala b/scalalib/test/src/mill/scalalib/TestClassLoaderTests.scala index 3c2a91f3539..fc7f7460f6c 100644 --- a/scalalib/test/src/mill/scalalib/TestClassLoaderTests.scala +++ b/scalalib/test/src/mill/scalalib/TestClassLoaderTests.scala @@ -23,8 +23,10 @@ object TestClassLoaderTests extends TestSuite { val resourcePath = os.Path(sys.env("MILL_TEST_RESOURCE_FOLDER")) / "classloader-test" override def tests: Tests = Tests { - test("com.sun classes exist in tests classpath (Java 8 only)") { - val eval = UnitTester(testclassloader, resourcePath) + test("com.sun classes exist in tests classpath (Java 8 only)") - UnitTester( + testclassloader, + resourcePath + ).scoped { eval => assert(eval.apply(testclassloader.test.test()).isRight) } } diff --git a/scalalib/test/src/mill/scalalib/TestRunnerTests.scala b/scalalib/test/src/mill/scalalib/TestRunnerTests.scala index 13adece9e15..dff11e18c1b 100644 --- a/scalalib/test/src/mill/scalalib/TestRunnerTests.scala +++ b/scalalib/test/src/mill/scalalib/TestRunnerTests.scala @@ -64,8 +64,7 @@ object TestRunnerTests extends TestSuite { override def tests: Tests = Tests { test("TestRunner") - { test("utest") - { - test("test case lookup") { - val eval = UnitTester(testrunner, resourcePath) + test("test case lookup") - UnitTester(testrunner, resourcePath).scoped { eval => val Right(result) = eval.apply(testrunner.utest.test()) val test = result.value.asInstanceOf[(String, Seq[mill.testrunner.TestResult])] assert( @@ -73,8 +72,7 @@ object TestRunnerTests extends TestSuite { ) junitReportIn(eval.outPath, "utest").shouldHave(3 -> Status.Success) } - test("discoveredTestClasses") { - val eval = UnitTester(testrunner, resourcePath) + test("discoveredTestClasses") - UnitTester(testrunner, resourcePath).scoped { eval => val Right(result) = eval.apply(testrunner.utest.discoveredTestClasses) val expected = Seq( "mill.scalalib.BarTests", @@ -93,24 +91,19 @@ object TestRunnerTests extends TestSuite { ) } - test("suffix") { - val eval = UnitTester(testrunner, resourcePath) + test("suffix") - UnitTester(testrunner, resourcePath).scoped { eval => testOnly(eval, Seq("*arTests"), 2) } - test("prefix") { - val eval = UnitTester(testrunner, resourcePath) + test("prefix") - UnitTester(testrunner, resourcePath).scoped { eval => testOnly(eval, Seq("mill.scalalib.FooT*"), 1) } - test("exactly") { - val eval = UnitTester(testrunner, resourcePath) + test("exactly") - UnitTester(testrunner, resourcePath).scoped { eval => testOnly(eval, Seq("mill.scalalib.FooTests"), 1) } - test("multi") { - val eval = UnitTester(testrunner, resourcePath) + test("multi") - UnitTester(testrunner, resourcePath).scoped { eval => testOnly(eval, Seq("*Bar*", "*bar*"), 2) } - test("noMatch") { - val eval = UnitTester(testrunner, resourcePath) + test("noMatch") - UnitTester(testrunner, resourcePath).scoped { eval => val Left(Result.Failure(msg, _)) = eval.apply(testrunner.utest.testOnly("noMatch", "noMatch*2")) assert( @@ -123,44 +116,41 @@ object TestRunnerTests extends TestSuite { test("doneMessage") { test("failure") { val outStream = new ByteArrayOutputStream() - val eval = UnitTester( + UnitTester( testrunner, outStream = new PrintStream(outStream, true), sourceRoot = resourcePath - ) - - val Left(Result.Failure(msg, _)) = eval(testrunner.doneMessageFailure.test()) - val stdout = new String(outStream.toByteArray) - assert(stdout.contains("test failure done message")) - junitReportIn(eval.outPath, "doneMessageFailure").shouldHave(1 -> Status.Failure) + ).scoped { eval => + val Left(Result.Failure(msg, _)) = eval(testrunner.doneMessageFailure.test()) + val stdout = new String(outStream.toByteArray) + assert(stdout.contains("test failure done message")) + junitReportIn(eval.outPath, "doneMessageFailure").shouldHave(1 -> Status.Failure) + } } test("success") { val outStream = new ByteArrayOutputStream() - val eval = UnitTester( + UnitTester( testrunner, outStream = new PrintStream(outStream, true), sourceRoot = resourcePath - ) - - val Right(_) = eval(testrunner.doneMessageSuccess.test()) - val stdout = new String(outStream.toByteArray) - assert(stdout.contains("test success done message")) + ).scoped { eval => + val Right(_) = eval(testrunner.doneMessageSuccess.test()) + val stdout = new String(outStream.toByteArray) + assert(stdout.contains("test success done message")) + } } - test("null") { - val eval = UnitTester(testrunner, resourcePath) + test("null") - UnitTester(testrunner, resourcePath).scoped { eval => val Right(_) = eval(testrunner.doneMessageNull.test()) } } test("ScalaTest") { - test("test") { - val eval = UnitTester(testrunner, resourcePath) + test("test") - UnitTester(testrunner, resourcePath).scoped { eval => val Right(result) = eval(testrunner.scalatest.test()) assert(result.value._2.size == 2) junitReportIn(eval.outPath, "scalatest").shouldHave(2 -> Status.Success) } - test("discoveredTestClasses") { - val eval = UnitTester(testrunner, resourcePath) + test("discoveredTestClasses") - UnitTester(testrunner, resourcePath).scoped { eval => val Right(result) = eval.apply(testrunner.scalatest.discoveredTestClasses) val expected = Seq("mill.scalalib.ScalaTestSpec") assert(result.value == expected) @@ -169,14 +159,12 @@ object TestRunnerTests extends TestSuite { } test("ZioTest") { - test("test") { - val eval = UnitTester(testrunner, resourcePath) + test("test") - UnitTester(testrunner, resourcePath).scoped { eval => val Right(result) = eval(testrunner.ziotest.test()) assert(result.value._2.size == 1) junitReportIn(eval.outPath, "ziotest").shouldHave(1 -> Status.Success) } - test("discoveredTestClasses") { - val eval = UnitTester(testrunner, resourcePath) + test("discoveredTestClasses") - UnitTester(testrunner, resourcePath).scoped { eval => val Right(result) = eval.apply(testrunner.ziotest.discoveredTestClasses) val expected = Seq("mill.scalalib.ZioTestSpec") assert(result.value == expected) diff --git a/scalalib/test/src/mill/scalalib/bsp/BspModuleTests.scala b/scalalib/test/src/mill/scalalib/bsp/BspModuleTests.scala index 8fb4bd9454f..f62b66b4f9d 100644 --- a/scalalib/test/src/mill/scalalib/bsp/BspModuleTests.scala +++ b/scalalib/test/src/mill/scalalib/bsp/BspModuleTests.scala @@ -42,8 +42,7 @@ object BspModuleTests extends TestSuite { override def tests: Tests = Tests { test("bspCompileClasspath") { - test("single module") { - val eval = UnitTester(MultiBase, null) + test("single module") - UnitTester(MultiBase, null).scoped { eval => val Right(result) = eval.apply( MultiBase.HelloBsp.bspCompileClasspath ) @@ -61,8 +60,7 @@ object BspModuleTests extends TestSuite { result.evalCount > 0 ) } - test("dependent module") { - val eval = UnitTester(MultiBase, null) + test("dependent module") - UnitTester(MultiBase, null).scoped { eval => val Right(result) = eval.apply( MultiBase.HelloBsp2.bspCompileClasspath ) @@ -92,8 +90,7 @@ object BspModuleTests extends TestSuite { } test("interdependencies are fast") { test("reference (no BSP)") { - def runNoBsp(entry: Int, maxTime: Int) = { - val eval = UnitTester(InterDeps, null) + def runNoBsp(entry: Int, maxTime: Int) = UnitTester(InterDeps, null).scoped { eval => val start = System.currentTimeMillis() val Right(_) = eval.apply( InterDeps.Mod(entry).compileClasspath @@ -107,14 +104,15 @@ object BspModuleTests extends TestSuite { test("index 15") { runNoBsp(15, 30000) } } def run(entry: Int, maxTime: Int) = retry(3) { - val eval = UnitTester(InterDeps, null) - val start = System.currentTimeMillis() - val Right(_) = eval.apply( - InterDeps.Mod(entry).bspCompileClasspath - ) - val timeSpent = System.currentTimeMillis() - start - assert(timeSpent < maxTime) - s"${timeSpent} msec" + UnitTester(InterDeps, null).scoped { eval => + val start = System.currentTimeMillis() + val Right(_) = eval.apply( + InterDeps.Mod(entry).bspCompileClasspath + ) + val timeSpent = System.currentTimeMillis() - start + assert(timeSpent < maxTime) + s"${timeSpent} msec" + } } test("index 1 (no deps)") { run(1, 500) } test("index 10") { run(10, 5000) } diff --git a/scalalib/test/src/mill/scalalib/scalafmt/ScalafmtTests.scala b/scalalib/test/src/mill/scalalib/scalafmt/ScalafmtTests.scala index 2c636519545..700c5291b48 100644 --- a/scalalib/test/src/mill/scalalib/scalafmt/ScalafmtTests.scala +++ b/scalalib/test/src/mill/scalalib/scalafmt/ScalafmtTests.scala @@ -31,73 +31,73 @@ object ScalafmtTests extends TestSuite { def tests: Tests = Tests { test("scalafmt") { - def checkReformat(reformatCommand: mill.define.Command[Unit], buildSrcIncluded: Boolean) = { - val eval = UnitTester(ScalafmtTestModule, resourcePath) - os.write( - ScalafmtTestModule.millSourcePath / ".scalafmt.conf", - s"""version = $scalafmtTestVersion - |runner.dialect = scala213 - |""".stripMargin - ) - val before = getProjectFiles(ScalafmtTestModule.core, eval) - - // first reformat - val Right(_) = eval.apply(reformatCommand) - - val firstReformat = getProjectFiles(ScalafmtTestModule.core, eval) - - assert( - firstReformat("Main.scala").modifyTime > before("Main.scala").modifyTime, - firstReformat("Main.scala").content != before("Main.scala").content, - firstReformat("Person.scala").modifyTime > before("Person.scala").modifyTime, - firstReformat("Person.scala").content != before("Person.scala").content, - // resources files aren't modified - firstReformat("application.conf").modifyTime == before( - "application.conf" - ).modifyTime - ) - - if (buildSrcIncluded) { - assert( - firstReformat("util.sc").modifyTime > before("util.sc").modifyTime, - firstReformat("util.sc").content != before("util.sc").content + def checkReformat(reformatCommand: mill.define.Command[Unit], buildSrcIncluded: Boolean) = + UnitTester(ScalafmtTestModule, resourcePath).scoped { eval => + os.write( + ScalafmtTestModule.millSourcePath / ".scalafmt.conf", + s"""version = $scalafmtTestVersion + |runner.dialect = scala213 + |""".stripMargin ) - } else { + val before = getProjectFiles(ScalafmtTestModule.core, eval) + + // first reformat + val Right(_) = eval.apply(reformatCommand) + + val firstReformat = getProjectFiles(ScalafmtTestModule.core, eval) + assert( - firstReformat("util.sc").modifyTime == before("util.sc").modifyTime, - firstReformat("util.sc").content == before("util.sc").content + firstReformat("Main.scala").modifyTime > before("Main.scala").modifyTime, + firstReformat("Main.scala").content != before("Main.scala").content, + firstReformat("Person.scala").modifyTime > before("Person.scala").modifyTime, + firstReformat("Person.scala").content != before("Person.scala").content, + // resources files aren't modified + firstReformat("application.conf").modifyTime == before( + "application.conf" + ).modifyTime ) - } - // cached reformat - val Right(_) = eval.apply(reformatCommand) + if (buildSrcIncluded) { + assert( + firstReformat("util.sc").modifyTime > before("util.sc").modifyTime, + firstReformat("util.sc").content != before("util.sc").content + ) + } else { + assert( + firstReformat("util.sc").modifyTime == before("util.sc").modifyTime, + firstReformat("util.sc").content == before("util.sc").content + ) + } + + // cached reformat + val Right(_) = eval.apply(reformatCommand) - val cached = getProjectFiles(ScalafmtTestModule.core, eval) + val cached = getProjectFiles(ScalafmtTestModule.core, eval) - assert( - cached("Main.scala").modifyTime == firstReformat("Main.scala").modifyTime, - cached("Person.scala").modifyTime == firstReformat("Person.scala").modifyTime, - cached("util.sc").modifyTime == firstReformat("util.sc").modifyTime, - cached("application.conf").modifyTime == firstReformat( - "application.conf" - ).modifyTime - ) + assert( + cached("Main.scala").modifyTime == firstReformat("Main.scala").modifyTime, + cached("Person.scala").modifyTime == firstReformat("Person.scala").modifyTime, + cached("util.sc").modifyTime == firstReformat("util.sc").modifyTime, + cached("application.conf").modifyTime == firstReformat( + "application.conf" + ).modifyTime + ) - // reformat after change - os.write.over(cached("Main.scala").path, cached("Main.scala").content + "\n object Foo") + // reformat after change + os.write.over(cached("Main.scala").path, cached("Main.scala").content + "\n object Foo") - val Right(_) = eval.apply(reformatCommand) + val Right(_) = eval.apply(reformatCommand) - val afterChange = getProjectFiles(ScalafmtTestModule.core, eval) + val afterChange = getProjectFiles(ScalafmtTestModule.core, eval) - assert( - afterChange("Main.scala").modifyTime > cached("Main.scala").modifyTime, - afterChange("Person.scala").modifyTime == cached("Person.scala").modifyTime, - afterChange("application.conf").modifyTime == cached( - "application.conf" - ).modifyTime - ) - } + assert( + afterChange("Main.scala").modifyTime > cached("Main.scala").modifyTime, + afterChange("Person.scala").modifyTime == cached("Person.scala").modifyTime, + afterChange("application.conf").modifyTime == cached( + "application.conf" + ).modifyTime + ) + } test("reformat") - checkReformat(ScalafmtTestModule.core.reformat(), false) test("reformatAll") - checkReformat( diff --git a/scalalib/worker/src/mill/scalalib/worker/ZincWorkerImpl.scala b/scalalib/worker/src/mill/scalalib/worker/ZincWorkerImpl.scala index 9a8d730bab8..cd8e3080e8c 100644 --- a/scalalib/worker/src/mill/scalalib/worker/ZincWorkerImpl.scala +++ b/scalalib/worker/src/mill/scalalib/worker/ZincWorkerImpl.scala @@ -641,6 +641,19 @@ class ZincWorkerImpl( } override def close(): Unit = { + val closeableClassloaders = classloaderCache + .flatMap(_._2.get) + .collect { case v: AutoCloseable => v } + + val urlClassLoaders = + classloaderCache.flatMap(_._2.get).collect { case t: java.net.URLClassLoader => t } + + // Make sure we at least pick up all the URLClassLoaders, since we know those are + // AutoCloseable, although there may be other AutoCloseable classloaders as well + assert(urlClassLoaders.toSet[AutoCloseable].subsetOf(closeableClassloaders.toSet)) + + closeableClassloaders.foreach(_.close()) + classloaderCache.clear() javaOnlyCompilersCache.clear() } diff --git a/scalanativelib/test/src/mill/scalanativelib/FeaturesTests.scala b/scalanativelib/test/src/mill/scalanativelib/FeaturesTests.scala index d6e3952fb79..3418092d136 100644 --- a/scalanativelib/test/src/mill/scalanativelib/FeaturesTests.scala +++ b/scalanativelib/test/src/mill/scalanativelib/FeaturesTests.scala @@ -16,8 +16,7 @@ object FeaturesTests extends TestSuite { val millSourcePath = os.Path(sys.env("MILL_TEST_RESOURCE_FOLDER")) / "features" val tests: Tests = Tests { - test("incremental compilation works") { - val eval = UnitTester(Features, millSourcePath) + test("incremental compilation works") - UnitTester(Features, millSourcePath).scoped { eval => val Right(_) = eval(Features.nativeLink) val Right(result) = eval(Features.nativeWorkdir) assert(os.walk(result.value).exists(_.ext == "ll")) diff --git a/scalanativelib/test/src/mill/scalanativelib/HelloNativeWorldTests.scala b/scalanativelib/test/src/mill/scalanativelib/HelloNativeWorldTests.scala index e455521071b..2a56e613c55 100644 --- a/scalanativelib/test/src/mill/scalanativelib/HelloNativeWorldTests.scala +++ b/scalanativelib/test/src/mill/scalanativelib/HelloNativeWorldTests.scala @@ -87,8 +87,7 @@ object HelloNativeWorldTests extends TestSuite { scalaVersion: String, scalaNativeVersion: String, mode: ReleaseMode - ): Unit = { - val eval = UnitTester(HelloNativeWorld, millSourcePath) + ): Unit = UnitTester(HelloNativeWorld, millSourcePath).scoped { eval => val Right(result) = eval(HelloNativeWorld.build( scalaVersion, @@ -120,8 +119,7 @@ object HelloNativeWorldTests extends TestSuite { } test("jar") { - test("containsNirs") { - val eval = UnitTester(HelloNativeWorld, millSourcePath) + test("containsNirs") - UnitTester(HelloNativeWorld, millSourcePath).scoped { eval => val Right(result) = eval(HelloNativeWorld.build( scala213, @@ -139,8 +137,7 @@ object HelloNativeWorldTests extends TestSuite { scalaNativeVersion: String, mode: ReleaseMode, artifactId: String - ): Unit = { - val eval = UnitTester(HelloNativeWorld, millSourcePath) + ): Unit = UnitTester(HelloNativeWorld, millSourcePath).scoped { eval => val Right(result) = eval( HelloNativeWorld.build( scalaVersion, @@ -153,17 +150,17 @@ object HelloNativeWorldTests extends TestSuite { } def runTests(testTask: define.NamedTask[(String, Seq[TestResult])]) - : Map[String, Map[String, TestResult]] = { - val eval = UnitTester(HelloNativeWorld, millSourcePath) - val Left(Result.Failure(_, Some(res))) = eval(testTask) - - val (doneMsg, testResults) = res - testResults - .groupBy(_.fullyQualifiedName) - .view - .mapValues(_.map(e => e.selector -> e).toMap) - .toMap - } + : Map[String, Map[String, TestResult]] = + UnitTester(HelloNativeWorld, millSourcePath).scoped { eval => + val Left(Result.Failure(_, Some(res))) = eval(testTask) + + val (doneMsg, testResults) = res + testResults + .groupBy(_.fullyQualifiedName) + .view + .mapValues(_.map(e => e.selector -> e).toMap) + .toMap + } def checkUtest( scalaVersion: String, @@ -203,31 +200,31 @@ object HelloNativeWorldTests extends TestSuite { ) } - def checkRun(scalaVersion: String, scalaNativeVersion: String, mode: ReleaseMode): Unit = { - val eval = UnitTester(HelloNativeWorld, millSourcePath) - val task = - HelloNativeWorld.build(scalaVersion, scalaNativeVersion, mode).nativeLink - val Right(result) = eval(task) + def checkRun(scalaVersion: String, scalaNativeVersion: String, mode: ReleaseMode): Unit = + UnitTester(HelloNativeWorld, millSourcePath).scoped { eval => + val task = + HelloNativeWorld.build(scalaVersion, scalaNativeVersion, mode).nativeLink + val Right(result) = eval(task) - val paths = EvaluatorPaths.resolveDestPaths(eval.outPath, task) - val stdout = os.proc(paths.dest / "out").call().out.lines() - assert( - stdout.contains("Hello Scala Native"), - result.evalCount > 0 - ) - } + val paths = EvaluatorPaths.resolveDestPaths(eval.outPath, task) + val stdout = os.proc(paths.dest / "out").call().out.lines() + assert( + stdout.contains("Hello Scala Native"), + result.evalCount > 0 + ) + } test("run") { testAllMatrix((scala, scalaNative, releaseMode) => checkRun(scala, scalaNative, releaseMode)) } - def checkInheritedTargets[A](target: ScalaNativeModule => T[A], expected: A) = { - val eval = UnitTester(HelloNativeWorld, millSourcePath) - val Right(mainResult) = eval(target(HelloNativeWorld.inherited)) - val Right(testResult) = eval(target(HelloNativeWorld.inherited.test)) - assert(mainResult.value == expected) - assert(testResult.value == expected) - } + def checkInheritedTargets[A](target: ScalaNativeModule => T[A], expected: A) = + UnitTester(HelloNativeWorld, millSourcePath).scoped { eval => + val Right(mainResult) = eval(target(HelloNativeWorld.inherited)) + val Right(testResult) = eval(target(HelloNativeWorld.inherited.test)) + assert(mainResult.value == expected) + assert(testResult.value == expected) + } test("test-scalacOptions") { checkInheritedTargets(_.scalacOptions, Seq("-deprecation")) } diff --git a/testkit/src/mill/testkit/ExampleTester.scala b/testkit/src/mill/testkit/ExampleTester.scala index a7d29ea3831..8eb287fd758 100644 --- a/testkit/src/mill/testkit/ExampleTester.scala +++ b/testkit/src/mill/testkit/ExampleTester.scala @@ -128,6 +128,7 @@ class ExampleTester( ): Unit = { val commandStr = commandStr0 match { case s"mill $rest" => s"./mill $rest" + case s"curl $rest" => s"curl --retry 5 --retry-all-errors $rest" case s => s } Console.err.println(s"$workspacePath> $commandStr") diff --git a/testkit/src/mill/testkit/UnitTester.scala b/testkit/src/mill/testkit/UnitTester.scala index 1d2919a54c2..c7d3ef2d7fb 100644 --- a/testkit/src/mill/testkit/UnitTester.scala +++ b/testkit/src/mill/testkit/UnitTester.scala @@ -54,7 +54,7 @@ class UnitTester( debugEnabled: Boolean, env: Map[String, String], resetSourcePath: Boolean -)(implicit fullName: sourcecode.FullName) { +)(implicit fullName: sourcecode.FullName) extends AutoCloseable { val outPath: os.Path = module.millSourcePath / "out" if (resetSourcePath) { @@ -181,4 +181,14 @@ class UnitTester( ) } + def scoped[T](tester: UnitTester => T): T = { + try tester(this) + finally close() + } + + def close(): Unit = { + for ((_, Val(obsolete: AutoCloseable)) <- evaluator.workerCache.values) { + obsolete.close() + } + } } diff --git a/testkit/test/src/mill/testkit/UnitTesterTests.scala b/testkit/test/src/mill/testkit/UnitTesterTests.scala index 02bbaad172a..278f8d5c923 100644 --- a/testkit/test/src/mill/testkit/UnitTesterTests.scala +++ b/testkit/test/src/mill/testkit/UnitTesterTests.scala @@ -12,9 +12,10 @@ object UnitTesterTests extends TestSuite { def testTask = T { "test" } } - val eval = UnitTester(build, resourcePath) - val Right(result) = eval(build.testTask) - assert(result.value == "test") + UnitTester(build, resourcePath).scoped { eval => + val Right(result) = eval(build.testTask) + assert(result.value == "test") + } } test("sources") { @@ -23,10 +24,10 @@ object UnitTesterTests extends TestSuite { def testTask = T { os.read(testSource().path).toUpperCase() } } - val eval = UnitTester(build, resourcePath) - - val Right(result) = eval(build.testTask) - assert(result.value == "HELLO WORLD SOURCE FILE") + UnitTester(build, resourcePath).scoped { eval => + val Right(result) = eval(build.testTask) + assert(result.value == "HELLO WORLD SOURCE FILE") + } } } }