From 9ba4cb69331386dfde9bac69dc2d5b22401face3 Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Wed, 12 Dec 2018 16:56:02 -0800 Subject: collapse boilerplate folder structure within src/ folders (#505) * collapse boilerplate folder structure within src/ folders * . --- .../resources/multi-module/shared/src/Utils.scala | 5 + .../multi-module/shared/src/shared/Utils.scala | 5 - scalajslib/test/src/HelloJSWorldTests.scala | 247 +++++++++++++++++++++ scalajslib/test/src/MultiModuleTests.scala | 93 ++++++++ scalajslib/test/src/NodeJSConfigTests.scala | 103 +++++++++ scalajslib/test/src/ScalaJsUtils.scala | 21 ++ .../src/mill/scalajslib/HelloJSWorldTests.scala | 247 --------------------- .../src/mill/scalajslib/MultiModuleTests.scala | 93 -------- .../src/mill/scalajslib/NodeJSConfigTests.scala | 103 --------- .../test/src/mill/scalajslib/ScalaJsUtils.scala | 21 -- 10 files changed, 469 insertions(+), 469 deletions(-) create mode 100644 scalajslib/test/resources/multi-module/shared/src/Utils.scala delete mode 100644 scalajslib/test/resources/multi-module/shared/src/shared/Utils.scala create mode 100644 scalajslib/test/src/HelloJSWorldTests.scala create mode 100644 scalajslib/test/src/MultiModuleTests.scala create mode 100644 scalajslib/test/src/NodeJSConfigTests.scala create mode 100644 scalajslib/test/src/ScalaJsUtils.scala delete mode 100644 scalajslib/test/src/mill/scalajslib/HelloJSWorldTests.scala delete mode 100644 scalajslib/test/src/mill/scalajslib/MultiModuleTests.scala delete mode 100644 scalajslib/test/src/mill/scalajslib/NodeJSConfigTests.scala delete mode 100644 scalajslib/test/src/mill/scalajslib/ScalaJsUtils.scala (limited to 'scalajslib/test') diff --git a/scalajslib/test/resources/multi-module/shared/src/Utils.scala b/scalajslib/test/resources/multi-module/shared/src/Utils.scala new file mode 100644 index 00000000..fad61a31 --- /dev/null +++ b/scalajslib/test/resources/multi-module/shared/src/Utils.scala @@ -0,0 +1,5 @@ +package shared + +object Utils { + def add(a: Int, b: Int) = a + b +} diff --git a/scalajslib/test/resources/multi-module/shared/src/shared/Utils.scala b/scalajslib/test/resources/multi-module/shared/src/shared/Utils.scala deleted file mode 100644 index fad61a31..00000000 --- a/scalajslib/test/resources/multi-module/shared/src/shared/Utils.scala +++ /dev/null @@ -1,5 +0,0 @@ -package shared - -object Utils { - def add(a: Int, b: Int) = a + b -} diff --git a/scalajslib/test/src/HelloJSWorldTests.scala b/scalajslib/test/src/HelloJSWorldTests.scala new file mode 100644 index 00000000..1b3e9bb3 --- /dev/null +++ b/scalajslib/test/src/HelloJSWorldTests.scala @@ -0,0 +1,247 @@ +package mill.scalajslib + +import java.util.jar.JarFile +import mill._ +import mill.define.Discover +import mill.eval.{Evaluator, Result} +import mill.scalalib.{CrossScalaModule, DepSyntax, Lib, PublishModule, TestRunner} +import mill.scalalib.publish.{Developer, License, PomSettings, VersionControl} +import mill.util.{TestEvaluator, TestUtil} +import utest._ + + +import scala.collection.JavaConverters._ +import mill.scalajslib.api._ + +object HelloJSWorldTests extends TestSuite { + val workspacePath = TestUtil.getOutPathStatic() / "hello-js-world" + + trait HelloJSWorldModule extends CrossScalaModule with ScalaJSModule with PublishModule { + override def millSourcePath = workspacePath + def publishVersion = "0.0.1-SNAPSHOT" + override def mainClass = Some("Main") + } + + object HelloJSWorld extends TestUtil.BaseModule { + val matrix = for { + scala <- Seq("2.11.8", "2.12.3", "2.12.4") + scalaJS <- Seq("0.6.22", "1.0.0-M2") + } yield (scala, scalaJS) + + object helloJsWorld extends Cross[BuildModule](matrix:_*) + class BuildModule(val crossScalaVersion: String, sjsVersion0: String) extends HelloJSWorldModule { + override def artifactName = "hello-js-world" + def scalaJSVersion = sjsVersion0 + def pomSettings = PomSettings( + organization = "com.lihaoyi", + description = "hello js world ready for real world publishing", + url = "https://github.com/lihaoyi/hello-world-publish", + licenses = Seq(License.Common.Apache2), + versionControl = VersionControl.github("lihaoyi", "hello-world-publish"), + developers = + Seq(Developer("lihaoyi", "Li Haoyi", "https://github.com/lihaoyi")) + ) + } + + object buildUTest extends Cross[BuildModuleUtest](matrix:_*) + class BuildModuleUtest(crossScalaVersion: String, sjsVersion0: String) + extends BuildModule(crossScalaVersion, sjsVersion0) { + object test extends super.Tests { + override def sources = T.sources{ millSourcePath / 'src / 'utest } + def testFrameworks = Seq("utest.runner.Framework") + override def ivyDeps = Agg( + ivy"com.lihaoyi::utest::0.6.3" + ) + } + } + + object buildScalaTest extends Cross[BuildModuleScalaTest](matrix:_*) + class BuildModuleScalaTest(crossScalaVersion: String, sjsVersion0: String) + extends BuildModule(crossScalaVersion, sjsVersion0) { + object test extends super.Tests { + override def sources = T.sources{ millSourcePath / 'src / 'scalatest } + def testFrameworks = Seq("org.scalatest.tools.Framework") + override def ivyDeps = Agg( + ivy"org.scalatest::scalatest::3.0.4" + ) + } + } + override lazy val millDiscover = Discover[this.type] + } + + val millSourcePath = os.pwd / 'scalajslib / 'test / 'resources / "hello-js-world" + + val helloWorldEvaluator = TestEvaluator.static(HelloJSWorld) + + + val mainObject = helloWorldEvaluator.outPath / 'src / "Main.scala" + + def tests: Tests = Tests { + prepareWorkspace() + 'compile - { + def testCompileFromScratch(scalaVersion: String, + scalaJSVersion: String): Unit = { + val Right((result, evalCount)) = + helloWorldEvaluator(HelloJSWorld.helloJsWorld(scalaVersion, scalaJSVersion).compile) + + val outPath = result.classes.path + val outputFiles = os.walk(outPath) + val expectedClassfiles = compileClassfiles(outPath) + assert( + outputFiles.toSet == expectedClassfiles, + evalCount > 0 + ) + + // don't recompile if nothing changed + val Right((_, unchangedEvalCount)) = + helloWorldEvaluator(HelloJSWorld.helloJsWorld(scalaVersion, scalaJSVersion).compile) + assert(unchangedEvalCount == 0) + } + + 'fromScratch_2124_0622 - testCompileFromScratch("2.12.4", "0.6.22") + 'fromScratch_2123_0622 - testCompileFromScratch("2.12.3", "0.6.22") + 'fromScratch_2118_0622 - TestUtil.disableInJava9OrAbove(testCompileFromScratch("2.11.8", "0.6.22")) + 'fromScratch_2124_100M2 - testCompileFromScratch("2.12.4", "1.0.0-M2") + } + + def testRun(scalaVersion: String, + scalaJSVersion: String, + mode: OptimizeMode): Unit = { + val task = mode match { + case FullOpt => HelloJSWorld.helloJsWorld(scalaVersion, scalaJSVersion).fullOpt + case FastOpt => HelloJSWorld.helloJsWorld(scalaVersion, scalaJSVersion).fastOpt + } + val Right((result, evalCount)) = helloWorldEvaluator(task) + val output = ScalaJsUtils.runJS(result.path) + assert(output == "Hello Scala.js") + } + + 'fullOpt - { + 'run_2124_0622 - TestUtil.disableInJava9OrAbove(testRun("2.12.4", "0.6.22", FullOpt)) + 'run_2123_0622 - TestUtil.disableInJava9OrAbove(testRun("2.12.3", "0.6.22", FullOpt)) + 'run_2118_0622 - TestUtil.disableInJava9OrAbove(testRun("2.11.8", "0.6.22", FullOpt)) + 'run_2124_100M2 - TestUtil.disableInJava9OrAbove(testRun("2.12.4", "1.0.0-M2", FullOpt)) + } + 'fastOpt - { + 'run_2124_0622 - TestUtil.disableInJava9OrAbove(testRun("2.12.4", "0.6.22", FastOpt)) + 'run_2123_0622 - TestUtil.disableInJava9OrAbove(testRun("2.12.3", "0.6.22", FastOpt)) + 'run_2118_0622 - TestUtil.disableInJava9OrAbove(testRun("2.11.8", "0.6.22", FastOpt)) + 'run_2124_100M2 - TestUtil.disableInJava9OrAbove(testRun("2.12.4", "1.0.0-M2", FastOpt)) + } + 'jar - { + 'containsSJSIRs - { + val Right((result, evalCount)) = helloWorldEvaluator(HelloJSWorld.helloJsWorld("2.12.4", "0.6.22").jar) + val jar = result.path + val entries = new JarFile(jar.toIO).entries().asScala.map(_.getName) + assert(entries.contains("Main$.sjsir")) + } + } + 'publish - { + def testArtifactId(scalaVersion: String, + scalaJSVersion: String, + artifactId: String): Unit = { + val Right((result, evalCount)) = helloWorldEvaluator(HelloJSWorld.helloJsWorld(scalaVersion, scalaJSVersion).artifactMetadata) + assert(result.id == artifactId) + } + 'artifactId_0622 - testArtifactId("2.12.4", "0.6.22", "hello-js-world_sjs0.6_2.12") + 'artifactId_100M2 - testArtifactId("2.12.4", "1.0.0-M2", "hello-js-world_sjs1.0.0-M2_2.12") + } + 'test - { + def runTests(testTask: define.Command[(String, Seq[TestRunner.Result])]): Map[String, Map[String, TestRunner.Result]] = { + val Left(Result.Failure(_, Some(res))) = helloWorldEvaluator(testTask) + + val (doneMsg, testResults) = res + testResults + .groupBy(_.fullyQualifiedName) + .mapValues(_.map(e => e.selector -> e).toMap) + } + + def checkUtest(scalaVersion: String, scalaJSVersion: String) = { + val resultMap = runTests(HelloJSWorld.buildUTest(scalaVersion, scalaJSVersion).test.test()) + + val mainTests = resultMap("MainTests") + val argParserTests = resultMap("ArgsParserTests") + + assert( + mainTests.size == 2, + mainTests("MainTests.vmName.containJs").status == "Success", + mainTests("MainTests.vmName.containScala").status == "Success", + + argParserTests.size == 2, + argParserTests("ArgsParserTests.one").status == "Success", + argParserTests("ArgsParserTests.two").status == "Failure" + ) + } + + def checkScalaTest(scalaVersion: String, scalaJSVersion: String) = { + val resultMap = runTests(HelloJSWorld.buildScalaTest(scalaVersion, scalaJSVersion).test.test()) + + val mainSpec = resultMap("MainSpec") + val argParserSpec = resultMap("ArgsParserSpec") + + assert( + mainSpec.size == 2, + mainSpec("vmName should contain js").status == "Success", + mainSpec("vmName should contain Scala").status == "Success", + + argParserSpec.size == 2, + argParserSpec("parse should one").status == "Success", + argParserSpec("parse should two").status == "Failure" + ) + } + + 'utest_2118_0622 - TestUtil.disableInJava9OrAbove(checkUtest("2.11.8", "0.6.22")) + 'utest_2124_0622 - checkUtest("2.12.4", "0.6.22") + 'utest_2118_100M2 - TestUtil.disableInJava9OrAbove(checkUtest("2.11.8", "1.0.0-M2")) + 'utest_2124_100M2 - checkUtest("2.12.4", "1.0.0-M2") + + 'scalaTest_2118_0622 - TestUtil.disableInJava9OrAbove(checkScalaTest("2.11.8", "0.6.22")) + 'scalaTest_2124_0622 - checkScalaTest("2.12.4", "0.6.22") +// No scalatest artifact for scala.js 1.0.0-M2 published yet +// 'scalaTest_2118_100M2 - checkScalaTest("2.11.8", "1.0.0-M2") +// 'scalaTest_2124_100M2 - checkScalaTest("2.12.4", "1.0.0-M2") + } + + def checkRun(scalaVersion: String, scalaJSVersion: String): Unit = { + val task = HelloJSWorld.helloJsWorld(scalaVersion, scalaJSVersion).run() + + val Right((_, evalCount)) = helloWorldEvaluator(task) + + val paths = Evaluator.resolveDestPaths( + helloWorldEvaluator.outPath, + task.ctx.segments + ) + val log = os.read(paths.log) + assert( + evalCount > 0, + log.contains("node"), + log.contains("Scala.js") + ) + } + + 'run - { + 'run_2118_0622 - TestUtil.disableInJava9OrAbove(checkRun("2.11.8", "0.6.22")) + 'run_2124_0622 - checkRun("2.12.4", "0.6.22") + 'run_2118_100M2 - TestUtil.disableInJava9OrAbove(checkRun("2.11.8", "1.0.0-M2")) + 'run_2124_100M2 - checkRun("2.12.4", "1.0.0-M2") + } + } + + def compileClassfiles(parentDir: os.Path) = Set( + parentDir / "ArgsParser$.class", + parentDir / "ArgsParser$.sjsir", + parentDir / "ArgsParser.class", + parentDir / "Main.class", + parentDir / "Main$.class", + parentDir / "Main$delayedInit$body.class", + parentDir / "Main$.sjsir", + parentDir / "Main$delayedInit$body.sjsir" + ) + + def prepareWorkspace(): Unit = { + os.remove.all(workspacePath) + os.makeDir.all(workspacePath / os.up) + os.copy(millSourcePath, workspacePath) + } + +} diff --git a/scalajslib/test/src/MultiModuleTests.scala b/scalajslib/test/src/MultiModuleTests.scala new file mode 100644 index 00000000..2ffea2cf --- /dev/null +++ b/scalajslib/test/src/MultiModuleTests.scala @@ -0,0 +1,93 @@ +package mill.scalajslib + +import mill._ +import mill.define.Discover +import mill.eval.Evaluator +import mill.util._ +import mill.scalalib._ +import utest._ +import mill.scalajslib.api._ +object MultiModuleTests extends TestSuite { + val workspacePath = TestUtil.getOutPathStatic() / "multi-module" + val sourcePath = os.pwd / 'scalajslib / 'test / 'resources / "multi-module" + + object MultiModule extends TestUtil.BaseModule { + trait BaseModule extends ScalaJSModule { + def scalaVersion = "2.12.4" + def scalaJSVersion = "0.6.22" + } + + object client extends BaseModule { + override def millSourcePath = workspacePath / 'client + override def moduleDeps = Seq(shared) + override def mainClass = Some("Main") + object test extends Tests { + def testFrameworks = Seq("utest.runner.Framework") + override def ivyDeps = Agg(ivy"com.lihaoyi::utest::0.6.3") + } + } + + object shared extends BaseModule { + override def millSourcePath = workspacePath / 'shared + } + + override lazy val millDiscover = Discover[this.type] + } + + val evaluator = TestEvaluator.static(MultiModule) + + def tests: Tests = Tests { + prepareWorkspace() + + def checkOpt(mode: OptimizeMode) = { + val task = mode match { + case FullOpt => MultiModule.client.fullOpt + case FastOpt => MultiModule.client.fastOpt + } + val Right((linked, evalCount)) = evaluator(task) + + val runOutput = ScalaJsUtils.runJS(linked.path) + assert( + evalCount > 0, + runOutput == "Hello from Scala.js, result is: 3" + ) + } + + 'fastOpt - TestUtil.disableInJava9OrAbove(checkOpt(FastOpt)) + 'fullOpt - TestUtil.disableInJava9OrAbove(checkOpt(FullOpt)) + + 'test - { + val Right(((_, testResults), evalCount)) = evaluator(MultiModule.client.test.test()) + + assert( + evalCount > 0, + testResults.size == 3, + testResults.forall(_.status == "Success") + ) + } + + 'run - { + val command = MultiModule.client.run() + + val Right((_, evalCount)) = evaluator(command) + + val paths = Evaluator.resolveDestPaths( + evaluator.outPath, + command.ctx.segments + ) + val log = os.read(paths.log) + assert( + evalCount > 0, + log.contains("node"), + log.contains("Hello from Scala.js, result is: 3") + ) + } + } + + def prepareWorkspace(): Unit = { + os.remove.all(workspacePath) + os.makeDir.all(workspacePath / os.up) + os.copy(sourcePath, workspacePath) + } + +} diff --git a/scalajslib/test/src/NodeJSConfigTests.scala b/scalajslib/test/src/NodeJSConfigTests.scala new file mode 100644 index 00000000..d9e6b45b --- /dev/null +++ b/scalajslib/test/src/NodeJSConfigTests.scala @@ -0,0 +1,103 @@ +package mill.scalajslib + +import mill._ +import mill.define.Discover +import mill.eval.Evaluator +import mill.scalalib.{CrossScalaModule, DepSyntax} +import mill.util.{TestEvaluator, TestUtil} +import utest._ +import mill.scalajslib.api._ + +object NodeJSConfigTests extends TestSuite { + val workspacePath = TestUtil.getOutPathStatic() / "hello-js-world" + val scalaVersion = "2.12.4" + val scalaJSVersion = "0.6.22" + val utestVersion = "0.6.3" + val nodeArgsEmpty = List() + val nodeArgs2G = List("--max-old-space-size=2048") + val nodeArgs4G = List("--max-old-space-size=4096") + + trait HelloJSWorldModule extends CrossScalaModule with ScalaJSModule { + override def millSourcePath = workspacePath + def publishVersion = "0.0.1-SNAPSHOT" + override def mainClass = Some("Main") + } + + object HelloJSWorld extends TestUtil.BaseModule { + val matrix = for { + scala <- Seq(scalaVersion) + nodeArgs <- Seq(nodeArgsEmpty, nodeArgs2G) + } yield (scala, nodeArgs) + + object helloJsWorld extends Cross[BuildModule](matrix:_*) + class BuildModule(val crossScalaVersion: String, nodeArgs: List[String]) extends HelloJSWorldModule { + override def artifactName = "hello-js-world" + def scalaJSVersion = NodeJSConfigTests.scalaJSVersion + override def nodeJSConfig = T { NodeJSConfig(args = nodeArgs) } + } + + object buildUTest extends Cross[BuildModuleUtest](matrix:_*) + class BuildModuleUtest(crossScalaVersion: String, nodeArgs: List[String]) + extends BuildModule(crossScalaVersion, nodeArgs) { + object test extends super.Tests { + override def sources = T.sources{ millSourcePath / 'src / 'utest } + def testFrameworks = Seq("utest.runner.Framework") + override def ivyDeps = Agg( + ivy"com.lihaoyi::utest::$utestVersion" + ) + override def nodeJSConfig = T { NodeJSConfig(args = nodeArgs) } + } + } + + override lazy val millDiscover = Discover[this.type] + } + + val millSourcePath = os.pwd / 'scalajslib / 'test / 'resources / "hello-js-world" + + val helloWorldEvaluator = TestEvaluator.static(HelloJSWorld) + + val mainObject = helloWorldEvaluator.outPath / 'src / "Main.scala" + + def tests: Tests = Tests { + prepareWorkspace() + + def checkLog(command: define.Command[_], nodeArgs: List[String], notNodeArgs: List[String]) = { + helloWorldEvaluator(command) + val paths = Evaluator.resolveDestPaths( + helloWorldEvaluator.outPath, + command.ctx.segments + ) + val log = os.read(paths.log) + assert( + nodeArgs.forall(log.contains), + notNodeArgs.forall(!log.contains(_)) + ) + } + + 'test - { + + def checkUtest(nodeArgs: List[String], notNodeArgs: List[String]) = { + checkLog(HelloJSWorld.buildUTest(scalaVersion, nodeArgs).test.test(), nodeArgs, notNodeArgs) + } + + 'test - checkUtest(nodeArgsEmpty, nodeArgs2G) + 'test2G - checkUtest(nodeArgs2G, nodeArgs4G) + } + + def checkRun(nodeArgs: List[String], notNodeArgs: List[String]): Unit = { + checkLog(HelloJSWorld.helloJsWorld(scalaVersion, nodeArgs).run(), nodeArgs, notNodeArgs) + } + + 'run - { + 'run - checkRun(nodeArgsEmpty, nodeArgs2G) + 'run2G - checkRun(nodeArgs2G, nodeArgs4G) + } + } + + def prepareWorkspace(): Unit = { + os.remove.all(workspacePath) + os.makeDir.all(workspacePath / os.up) + os.copy(millSourcePath, workspacePath) + } + +} diff --git a/scalajslib/test/src/ScalaJsUtils.scala b/scalajslib/test/src/ScalaJsUtils.scala new file mode 100644 index 00000000..68f2f7ee --- /dev/null +++ b/scalajslib/test/src/ScalaJsUtils.scala @@ -0,0 +1,21 @@ +package mill.scalajslib + +import java.io.{FileReader, StringWriter} +import javax.script.{ScriptContext, ScriptEngineManager} + +object ScalaJsUtils { + def runJS(path: os.Path): String = { + val engineManager = new ScriptEngineManager(null) + val engine = engineManager.getEngineByName("nashorn") + val console = new Console + val bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE) + bindings.put("console", console) + engine.eval(new FileReader(path.toIO)) + console.out.toString + } +} + +class Console { + val out = new StringWriter() + def log(s: String): Unit = out.append(s) +} diff --git a/scalajslib/test/src/mill/scalajslib/HelloJSWorldTests.scala b/scalajslib/test/src/mill/scalajslib/HelloJSWorldTests.scala deleted file mode 100644 index 1b3e9bb3..00000000 --- a/scalajslib/test/src/mill/scalajslib/HelloJSWorldTests.scala +++ /dev/null @@ -1,247 +0,0 @@ -package mill.scalajslib - -import java.util.jar.JarFile -import mill._ -import mill.define.Discover -import mill.eval.{Evaluator, Result} -import mill.scalalib.{CrossScalaModule, DepSyntax, Lib, PublishModule, TestRunner} -import mill.scalalib.publish.{Developer, License, PomSettings, VersionControl} -import mill.util.{TestEvaluator, TestUtil} -import utest._ - - -import scala.collection.JavaConverters._ -import mill.scalajslib.api._ - -object HelloJSWorldTests extends TestSuite { - val workspacePath = TestUtil.getOutPathStatic() / "hello-js-world" - - trait HelloJSWorldModule extends CrossScalaModule with ScalaJSModule with PublishModule { - override def millSourcePath = workspacePath - def publishVersion = "0.0.1-SNAPSHOT" - override def mainClass = Some("Main") - } - - object HelloJSWorld extends TestUtil.BaseModule { - val matrix = for { - scala <- Seq("2.11.8", "2.12.3", "2.12.4") - scalaJS <- Seq("0.6.22", "1.0.0-M2") - } yield (scala, scalaJS) - - object helloJsWorld extends Cross[BuildModule](matrix:_*) - class BuildModule(val crossScalaVersion: String, sjsVersion0: String) extends HelloJSWorldModule { - override def artifactName = "hello-js-world" - def scalaJSVersion = sjsVersion0 - def pomSettings = PomSettings( - organization = "com.lihaoyi", - description = "hello js world ready for real world publishing", - url = "https://github.com/lihaoyi/hello-world-publish", - licenses = Seq(License.Common.Apache2), - versionControl = VersionControl.github("lihaoyi", "hello-world-publish"), - developers = - Seq(Developer("lihaoyi", "Li Haoyi", "https://github.com/lihaoyi")) - ) - } - - object buildUTest extends Cross[BuildModuleUtest](matrix:_*) - class BuildModuleUtest(crossScalaVersion: String, sjsVersion0: String) - extends BuildModule(crossScalaVersion, sjsVersion0) { - object test extends super.Tests { - override def sources = T.sources{ millSourcePath / 'src / 'utest } - def testFrameworks = Seq("utest.runner.Framework") - override def ivyDeps = Agg( - ivy"com.lihaoyi::utest::0.6.3" - ) - } - } - - object buildScalaTest extends Cross[BuildModuleScalaTest](matrix:_*) - class BuildModuleScalaTest(crossScalaVersion: String, sjsVersion0: String) - extends BuildModule(crossScalaVersion, sjsVersion0) { - object test extends super.Tests { - override def sources = T.sources{ millSourcePath / 'src / 'scalatest } - def testFrameworks = Seq("org.scalatest.tools.Framework") - override def ivyDeps = Agg( - ivy"org.scalatest::scalatest::3.0.4" - ) - } - } - override lazy val millDiscover = Discover[this.type] - } - - val millSourcePath = os.pwd / 'scalajslib / 'test / 'resources / "hello-js-world" - - val helloWorldEvaluator = TestEvaluator.static(HelloJSWorld) - - - val mainObject = helloWorldEvaluator.outPath / 'src / "Main.scala" - - def tests: Tests = Tests { - prepareWorkspace() - 'compile - { - def testCompileFromScratch(scalaVersion: String, - scalaJSVersion: String): Unit = { - val Right((result, evalCount)) = - helloWorldEvaluator(HelloJSWorld.helloJsWorld(scalaVersion, scalaJSVersion).compile) - - val outPath = result.classes.path - val outputFiles = os.walk(outPath) - val expectedClassfiles = compileClassfiles(outPath) - assert( - outputFiles.toSet == expectedClassfiles, - evalCount > 0 - ) - - // don't recompile if nothing changed - val Right((_, unchangedEvalCount)) = - helloWorldEvaluator(HelloJSWorld.helloJsWorld(scalaVersion, scalaJSVersion).compile) - assert(unchangedEvalCount == 0) - } - - 'fromScratch_2124_0622 - testCompileFromScratch("2.12.4", "0.6.22") - 'fromScratch_2123_0622 - testCompileFromScratch("2.12.3", "0.6.22") - 'fromScratch_2118_0622 - TestUtil.disableInJava9OrAbove(testCompileFromScratch("2.11.8", "0.6.22")) - 'fromScratch_2124_100M2 - testCompileFromScratch("2.12.4", "1.0.0-M2") - } - - def testRun(scalaVersion: String, - scalaJSVersion: String, - mode: OptimizeMode): Unit = { - val task = mode match { - case FullOpt => HelloJSWorld.helloJsWorld(scalaVersion, scalaJSVersion).fullOpt - case FastOpt => HelloJSWorld.helloJsWorld(scalaVersion, scalaJSVersion).fastOpt - } - val Right((result, evalCount)) = helloWorldEvaluator(task) - val output = ScalaJsUtils.runJS(result.path) - assert(output == "Hello Scala.js") - } - - 'fullOpt - { - 'run_2124_0622 - TestUtil.disableInJava9OrAbove(testRun("2.12.4", "0.6.22", FullOpt)) - 'run_2123_0622 - TestUtil.disableInJava9OrAbove(testRun("2.12.3", "0.6.22", FullOpt)) - 'run_2118_0622 - TestUtil.disableInJava9OrAbove(testRun("2.11.8", "0.6.22", FullOpt)) - 'run_2124_100M2 - TestUtil.disableInJava9OrAbove(testRun("2.12.4", "1.0.0-M2", FullOpt)) - } - 'fastOpt - { - 'run_2124_0622 - TestUtil.disableInJava9OrAbove(testRun("2.12.4", "0.6.22", FastOpt)) - 'run_2123_0622 - TestUtil.disableInJava9OrAbove(testRun("2.12.3", "0.6.22", FastOpt)) - 'run_2118_0622 - TestUtil.disableInJava9OrAbove(testRun("2.11.8", "0.6.22", FastOpt)) - 'run_2124_100M2 - TestUtil.disableInJava9OrAbove(testRun("2.12.4", "1.0.0-M2", FastOpt)) - } - 'jar - { - 'containsSJSIRs - { - val Right((result, evalCount)) = helloWorldEvaluator(HelloJSWorld.helloJsWorld("2.12.4", "0.6.22").jar) - val jar = result.path - val entries = new JarFile(jar.toIO).entries().asScala.map(_.getName) - assert(entries.contains("Main$.sjsir")) - } - } - 'publish - { - def testArtifactId(scalaVersion: String, - scalaJSVersion: String, - artifactId: String): Unit = { - val Right((result, evalCount)) = helloWorldEvaluator(HelloJSWorld.helloJsWorld(scalaVersion, scalaJSVersion).artifactMetadata) - assert(result.id == artifactId) - } - 'artifactId_0622 - testArtifactId("2.12.4", "0.6.22", "hello-js-world_sjs0.6_2.12") - 'artifactId_100M2 - testArtifactId("2.12.4", "1.0.0-M2", "hello-js-world_sjs1.0.0-M2_2.12") - } - 'test - { - def runTests(testTask: define.Command[(String, Seq[TestRunner.Result])]): Map[String, Map[String, TestRunner.Result]] = { - val Left(Result.Failure(_, Some(res))) = helloWorldEvaluator(testTask) - - val (doneMsg, testResults) = res - testResults - .groupBy(_.fullyQualifiedName) - .mapValues(_.map(e => e.selector -> e).toMap) - } - - def checkUtest(scalaVersion: String, scalaJSVersion: String) = { - val resultMap = runTests(HelloJSWorld.buildUTest(scalaVersion, scalaJSVersion).test.test()) - - val mainTests = resultMap("MainTests") - val argParserTests = resultMap("ArgsParserTests") - - assert( - mainTests.size == 2, - mainTests("MainTests.vmName.containJs").status == "Success", - mainTests("MainTests.vmName.containScala").status == "Success", - - argParserTests.size == 2, - argParserTests("ArgsParserTests.one").status == "Success", - argParserTests("ArgsParserTests.two").status == "Failure" - ) - } - - def checkScalaTest(scalaVersion: String, scalaJSVersion: String) = { - val resultMap = runTests(HelloJSWorld.buildScalaTest(scalaVersion, scalaJSVersion).test.test()) - - val mainSpec = resultMap("MainSpec") - val argParserSpec = resultMap("ArgsParserSpec") - - assert( - mainSpec.size == 2, - mainSpec("vmName should contain js").status == "Success", - mainSpec("vmName should contain Scala").status == "Success", - - argParserSpec.size == 2, - argParserSpec("parse should one").status == "Success", - argParserSpec("parse should two").status == "Failure" - ) - } - - 'utest_2118_0622 - TestUtil.disableInJava9OrAbove(checkUtest("2.11.8", "0.6.22")) - 'utest_2124_0622 - checkUtest("2.12.4", "0.6.22") - 'utest_2118_100M2 - TestUtil.disableInJava9OrAbove(checkUtest("2.11.8", "1.0.0-M2")) - 'utest_2124_100M2 - checkUtest("2.12.4", "1.0.0-M2") - - 'scalaTest_2118_0622 - TestUtil.disableInJava9OrAbove(checkScalaTest("2.11.8", "0.6.22")) - 'scalaTest_2124_0622 - checkScalaTest("2.12.4", "0.6.22") -// No scalatest artifact for scala.js 1.0.0-M2 published yet -// 'scalaTest_2118_100M2 - checkScalaTest("2.11.8", "1.0.0-M2") -// 'scalaTest_2124_100M2 - checkScalaTest("2.12.4", "1.0.0-M2") - } - - def checkRun(scalaVersion: String, scalaJSVersion: String): Unit = { - val task = HelloJSWorld.helloJsWorld(scalaVersion, scalaJSVersion).run() - - val Right((_, evalCount)) = helloWorldEvaluator(task) - - val paths = Evaluator.resolveDestPaths( - helloWorldEvaluator.outPath, - task.ctx.segments - ) - val log = os.read(paths.log) - assert( - evalCount > 0, - log.contains("node"), - log.contains("Scala.js") - ) - } - - 'run - { - 'run_2118_0622 - TestUtil.disableInJava9OrAbove(checkRun("2.11.8", "0.6.22")) - 'run_2124_0622 - checkRun("2.12.4", "0.6.22") - 'run_2118_100M2 - TestUtil.disableInJava9OrAbove(checkRun("2.11.8", "1.0.0-M2")) - 'run_2124_100M2 - checkRun("2.12.4", "1.0.0-M2") - } - } - - def compileClassfiles(parentDir: os.Path) = Set( - parentDir / "ArgsParser$.class", - parentDir / "ArgsParser$.sjsir", - parentDir / "ArgsParser.class", - parentDir / "Main.class", - parentDir / "Main$.class", - parentDir / "Main$delayedInit$body.class", - parentDir / "Main$.sjsir", - parentDir / "Main$delayedInit$body.sjsir" - ) - - def prepareWorkspace(): Unit = { - os.remove.all(workspacePath) - os.makeDir.all(workspacePath / os.up) - os.copy(millSourcePath, workspacePath) - } - -} diff --git a/scalajslib/test/src/mill/scalajslib/MultiModuleTests.scala b/scalajslib/test/src/mill/scalajslib/MultiModuleTests.scala deleted file mode 100644 index 2ffea2cf..00000000 --- a/scalajslib/test/src/mill/scalajslib/MultiModuleTests.scala +++ /dev/null @@ -1,93 +0,0 @@ -package mill.scalajslib - -import mill._ -import mill.define.Discover -import mill.eval.Evaluator -import mill.util._ -import mill.scalalib._ -import utest._ -import mill.scalajslib.api._ -object MultiModuleTests extends TestSuite { - val workspacePath = TestUtil.getOutPathStatic() / "multi-module" - val sourcePath = os.pwd / 'scalajslib / 'test / 'resources / "multi-module" - - object MultiModule extends TestUtil.BaseModule { - trait BaseModule extends ScalaJSModule { - def scalaVersion = "2.12.4" - def scalaJSVersion = "0.6.22" - } - - object client extends BaseModule { - override def millSourcePath = workspacePath / 'client - override def moduleDeps = Seq(shared) - override def mainClass = Some("Main") - object test extends Tests { - def testFrameworks = Seq("utest.runner.Framework") - override def ivyDeps = Agg(ivy"com.lihaoyi::utest::0.6.3") - } - } - - object shared extends BaseModule { - override def millSourcePath = workspacePath / 'shared - } - - override lazy val millDiscover = Discover[this.type] - } - - val evaluator = TestEvaluator.static(MultiModule) - - def tests: Tests = Tests { - prepareWorkspace() - - def checkOpt(mode: OptimizeMode) = { - val task = mode match { - case FullOpt => MultiModule.client.fullOpt - case FastOpt => MultiModule.client.fastOpt - } - val Right((linked, evalCount)) = evaluator(task) - - val runOutput = ScalaJsUtils.runJS(linked.path) - assert( - evalCount > 0, - runOutput == "Hello from Scala.js, result is: 3" - ) - } - - 'fastOpt - TestUtil.disableInJava9OrAbove(checkOpt(FastOpt)) - 'fullOpt - TestUtil.disableInJava9OrAbove(checkOpt(FullOpt)) - - 'test - { - val Right(((_, testResults), evalCount)) = evaluator(MultiModule.client.test.test()) - - assert( - evalCount > 0, - testResults.size == 3, - testResults.forall(_.status == "Success") - ) - } - - 'run - { - val command = MultiModule.client.run() - - val Right((_, evalCount)) = evaluator(command) - - val paths = Evaluator.resolveDestPaths( - evaluator.outPath, - command.ctx.segments - ) - val log = os.read(paths.log) - assert( - evalCount > 0, - log.contains("node"), - log.contains("Hello from Scala.js, result is: 3") - ) - } - } - - def prepareWorkspace(): Unit = { - os.remove.all(workspacePath) - os.makeDir.all(workspacePath / os.up) - os.copy(sourcePath, workspacePath) - } - -} diff --git a/scalajslib/test/src/mill/scalajslib/NodeJSConfigTests.scala b/scalajslib/test/src/mill/scalajslib/NodeJSConfigTests.scala deleted file mode 100644 index d9e6b45b..00000000 --- a/scalajslib/test/src/mill/scalajslib/NodeJSConfigTests.scala +++ /dev/null @@ -1,103 +0,0 @@ -package mill.scalajslib - -import mill._ -import mill.define.Discover -import mill.eval.Evaluator -import mill.scalalib.{CrossScalaModule, DepSyntax} -import mill.util.{TestEvaluator, TestUtil} -import utest._ -import mill.scalajslib.api._ - -object NodeJSConfigTests extends TestSuite { - val workspacePath = TestUtil.getOutPathStatic() / "hello-js-world" - val scalaVersion = "2.12.4" - val scalaJSVersion = "0.6.22" - val utestVersion = "0.6.3" - val nodeArgsEmpty = List() - val nodeArgs2G = List("--max-old-space-size=2048") - val nodeArgs4G = List("--max-old-space-size=4096") - - trait HelloJSWorldModule extends CrossScalaModule with ScalaJSModule { - override def millSourcePath = workspacePath - def publishVersion = "0.0.1-SNAPSHOT" - override def mainClass = Some("Main") - } - - object HelloJSWorld extends TestUtil.BaseModule { - val matrix = for { - scala <- Seq(scalaVersion) - nodeArgs <- Seq(nodeArgsEmpty, nodeArgs2G) - } yield (scala, nodeArgs) - - object helloJsWorld extends Cross[BuildModule](matrix:_*) - class BuildModule(val crossScalaVersion: String, nodeArgs: List[String]) extends HelloJSWorldModule { - override def artifactName = "hello-js-world" - def scalaJSVersion = NodeJSConfigTests.scalaJSVersion - override def nodeJSConfig = T { NodeJSConfig(args = nodeArgs) } - } - - object buildUTest extends Cross[BuildModuleUtest](matrix:_*) - class BuildModuleUtest(crossScalaVersion: String, nodeArgs: List[String]) - extends BuildModule(crossScalaVersion, nodeArgs) { - object test extends super.Tests { - override def sources = T.sources{ millSourcePath / 'src / 'utest } - def testFrameworks = Seq("utest.runner.Framework") - override def ivyDeps = Agg( - ivy"com.lihaoyi::utest::$utestVersion" - ) - override def nodeJSConfig = T { NodeJSConfig(args = nodeArgs) } - } - } - - override lazy val millDiscover = Discover[this.type] - } - - val millSourcePath = os.pwd / 'scalajslib / 'test / 'resources / "hello-js-world" - - val helloWorldEvaluator = TestEvaluator.static(HelloJSWorld) - - val mainObject = helloWorldEvaluator.outPath / 'src / "Main.scala" - - def tests: Tests = Tests { - prepareWorkspace() - - def checkLog(command: define.Command[_], nodeArgs: List[String], notNodeArgs: List[String]) = { - helloWorldEvaluator(command) - val paths = Evaluator.resolveDestPaths( - helloWorldEvaluator.outPath, - command.ctx.segments - ) - val log = os.read(paths.log) - assert( - nodeArgs.forall(log.contains), - notNodeArgs.forall(!log.contains(_)) - ) - } - - 'test - { - - def checkUtest(nodeArgs: List[String], notNodeArgs: List[String]) = { - checkLog(HelloJSWorld.buildUTest(scalaVersion, nodeArgs).test.test(), nodeArgs, notNodeArgs) - } - - 'test - checkUtest(nodeArgsEmpty, nodeArgs2G) - 'test2G - checkUtest(nodeArgs2G, nodeArgs4G) - } - - def checkRun(nodeArgs: List[String], notNodeArgs: List[String]): Unit = { - checkLog(HelloJSWorld.helloJsWorld(scalaVersion, nodeArgs).run(), nodeArgs, notNodeArgs) - } - - 'run - { - 'run - checkRun(nodeArgsEmpty, nodeArgs2G) - 'run2G - checkRun(nodeArgs2G, nodeArgs4G) - } - } - - def prepareWorkspace(): Unit = { - os.remove.all(workspacePath) - os.makeDir.all(workspacePath / os.up) - os.copy(millSourcePath, workspacePath) - } - -} diff --git a/scalajslib/test/src/mill/scalajslib/ScalaJsUtils.scala b/scalajslib/test/src/mill/scalajslib/ScalaJsUtils.scala deleted file mode 100644 index 68f2f7ee..00000000 --- a/scalajslib/test/src/mill/scalajslib/ScalaJsUtils.scala +++ /dev/null @@ -1,21 +0,0 @@ -package mill.scalajslib - -import java.io.{FileReader, StringWriter} -import javax.script.{ScriptContext, ScriptEngineManager} - -object ScalaJsUtils { - def runJS(path: os.Path): String = { - val engineManager = new ScriptEngineManager(null) - val engine = engineManager.getEngineByName("nashorn") - val console = new Console - val bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE) - bindings.put("console", console) - engine.eval(new FileReader(path.toIO)) - console.out.toString - } -} - -class Console { - val out = new StringWriter() - def log(s: String): Unit = out.append(s) -} -- cgit v1.2.3