diff options
author | Nikolay Tatarinov <5min4eq.unity@gmail.com> | 2018-02-01 22:07:39 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-01 22:07:39 +0300 |
commit | 5be2c5aea4527cf637948e6bf2e4c56e3273fbd9 (patch) | |
tree | 38d9c675c68ac7505708f182170589119453db21 /scalajslib/test | |
parent | bc777b3c4e83149f45df7edda245868e22495eb3 (diff) | |
download | mill-5be2c5aea4527cf637948e6bf2e4c56e3273fbd9.tar.gz mill-5be2c5aea4527cf637948e6bf2e4c56e3273fbd9.tar.bz2 mill-5be2c5aea4527cf637948e6bf2e4c56e3273fbd9.zip |
WIP: Scala js testing (#119)
fixes #102. Use scala js testing framework to launch tests
Diffstat (limited to 'scalajslib/test')
7 files changed, 177 insertions, 14 deletions
diff --git a/scalajslib/test/resources/hello-js-world/src/ArgsParser.scala b/scalajslib/test/resources/hello-js-world/src/ArgsParser.scala new file mode 100644 index 00000000..cf13d452 --- /dev/null +++ b/scalajslib/test/resources/hello-js-world/src/ArgsParser.scala @@ -0,0 +1,3 @@ +object ArgsParser { + def parse(s:String): Seq[String] = s.split(":").toSeq +} diff --git a/scalajslib/test/resources/hello-js-world/src/Main.scala b/scalajslib/test/resources/hello-js-world/src/Main.scala index 60cef56d..636d9ea1 100644 --- a/scalajslib/test/resources/hello-js-world/src/Main.scala +++ b/scalajslib/test/resources/hello-js-world/src/Main.scala @@ -1,3 +1,6 @@ object Main extends App { - println("Hello " + sys.props("java.vm.name")) + + println("Hello " + vmName) + + def vmName = sys.props("java.vm.name") } diff --git a/scalajslib/test/resources/hello-js-world/test/src/scalatest/ArgsParserSpec.scala b/scalajslib/test/resources/hello-js-world/test/src/scalatest/ArgsParserSpec.scala new file mode 100644 index 00000000..807decb9 --- /dev/null +++ b/scalajslib/test/resources/hello-js-world/test/src/scalatest/ArgsParserSpec.scala @@ -0,0 +1,18 @@ +import org.scalatest._ + +class ArgsParserSpec extends FlatSpec with Matchers { + + behavior of "ArgsParser" + + "parse" should "one" in { + val result = ArgsParser.parse("hello:world") + result should have length 2 + result should contain only ("hello", "world") + } + + it should "two" in { + val result = ArgsParser.parse("hello:world") + result should have length 80 + } + +} diff --git a/scalajslib/test/resources/hello-js-world/test/src/scalatest/MainSpec.scala b/scalajslib/test/resources/hello-js-world/test/src/scalatest/MainSpec.scala new file mode 100644 index 00000000..0c1eb76f --- /dev/null +++ b/scalajslib/test/resources/hello-js-world/test/src/scalatest/MainSpec.scala @@ -0,0 +1,15 @@ +import org.scalatest._ + +class MainSpec extends FlatSpec with Matchers { + + behavior of "Main" + + "vmName" should "contain js" in { + Main.vmName should include ("js") + } + + it should "contain Scala" in { + Main.vmName should include ("Scala") + } + +} diff --git a/scalajslib/test/resources/hello-js-world/test/src/utest/ArgsParserTests.scala b/scalajslib/test/resources/hello-js-world/test/src/utest/ArgsParserTests.scala new file mode 100644 index 00000000..d0baa965 --- /dev/null +++ b/scalajslib/test/resources/hello-js-world/test/src/utest/ArgsParserTests.scala @@ -0,0 +1,21 @@ +import utest._ + +object ArgsParserTests extends TestSuite { + + def tests: Tests = Tests { + 'one - { + val result = ArgsParser.parse("hello:world") + assert( + result.length == 2, + result == Seq("hello", "world") + ) + } + 'two - { // we fail this test to check testing in scala.js + val result = ArgsParser.parse("hello:world") + assert( + result.length == 80 + ) + } + } + +} diff --git a/scalajslib/test/resources/hello-js-world/test/src/utest/MainTests.scala b/scalajslib/test/resources/hello-js-world/test/src/utest/MainTests.scala new file mode 100644 index 00000000..937d96f8 --- /dev/null +++ b/scalajslib/test/resources/hello-js-world/test/src/utest/MainTests.scala @@ -0,0 +1,20 @@ +import utest._ + +object MainTests extends TestSuite { + + def tests: Tests = Tests { + 'vmName - { + 'containJs - { + assert( + Main.vmName.contains("js") + ) + } + 'containScala - { + assert( + Main.vmName.contains("Scala") + ) + } + } + } + +} diff --git a/scalajslib/test/src/mill/scalajslib/HelloJSWorldTests.scala b/scalajslib/test/src/mill/scalajslib/HelloJSWorldTests.scala index 4cfe464d..88792366 100644 --- a/scalajslib/test/src/mill/scalajslib/HelloJSWorldTests.scala +++ b/scalajslib/test/src/mill/scalajslib/HelloJSWorldTests.scala @@ -26,11 +26,35 @@ object HelloJSWorldTests extends TestSuite { object HelloJSWorld extends TestUtil.BaseModule { val matrix = for { scala <- Seq("2.11.8", "2.12.3", "2.12.4") - scalaJS <- Seq("0.6.20", "0.6.21", "1.0.0-M2") + scalaJS <- Seq("0.6.22", "1.0.0-M2") } yield (scala, scalaJS) object build extends Cross[BuildModule](matrix:_*) + object buildUTest extends Cross[BuildModuleUtest](matrix:_*) + class BuildModuleUtest(scalaVersion0: String, sjsVersion0: String) + extends BuildModule(scalaVersion0: String, sjsVersion0: String) { + object test extends super.Tests { + override def sources = T.input{ Agg(PathRef(basePath / 'src / 'utest)) } + def testFramework: T[String] = "utest.runner.Framework" + override def ivyDeps = Agg( + ivy"com.lihaoyi:utest_sjs${scalaJSBinaryVersion()}_${scalaBinaryVersion()}:0.6.3" + ) + } + } + + object buildScalaTest extends Cross[BuildModuleScalaTest](matrix:_*) + class BuildModuleScalaTest(scalaVersion0: String, sjsVersion0: String) + extends BuildModule(scalaVersion0: String, sjsVersion0: String) { + object test extends super.Tests { + override def sources = T.input{ Agg(PathRef(basePath / 'src / 'scalatest)) } + def testFramework: T[String] = "org.scalatest.tools.Framework" + override def ivyDeps = Agg( + ivy"org.scalatest:scalatest_sjs${scalaJSBinaryVersion()}_${scalaBinaryVersion()}:3.0.4" + ) + } + } + class BuildModule(scalaVersion0: String, sjsVersion0: String) extends HelloJSWorldModule { def scalaVersion = scalaVersion0 def scalaJSVersion = sjsVersion0 @@ -98,9 +122,9 @@ object HelloJSWorldTests extends TestSuite { assert(unchangedEvalCount == 0) } - 'fromScratch_2124_0621 - testCompileFromScratch("2.12.4", "0.6.21") - 'fromScratch_2123_0621 - testCompileFromScratch("2.12.3", "0.6.21") - 'fromScratch_2118_0621 - testCompileFromScratch("2.11.8", "0.6.21") + 'fromScratch_2124_0621 - testCompileFromScratch("2.12.4", "0.6.22") + 'fromScratch_2123_0621 - testCompileFromScratch("2.12.3", "0.6.22") + 'fromScratch_2118_0621 - testCompileFromScratch("2.11.8", "0.6.22") 'fromScratch_2124_100M2 - testCompileFromScratch("2.12.4", "1.0.0-M2") } @@ -117,20 +141,20 @@ object HelloJSWorldTests extends TestSuite { } 'fullOpt - { - 'run_2124_0621 - testRun("2.12.4", "0.6.21", FullOpt) - 'run_2123_0621 - testRun("2.12.3", "0.6.21", FullOpt) - 'run_2118_0621 - testRun("2.11.8", "0.6.21", FullOpt) + 'run_2124_0621 - testRun("2.12.4", "0.6.22", FullOpt) + 'run_2123_0621 - testRun("2.12.3", "0.6.22", FullOpt) + 'run_2118_0621 - testRun("2.11.8", "0.6.22", FullOpt) 'run_2124_100M2 - testRun("2.12.4", "1.0.0-M2", FullOpt) } 'fastOpt - { - 'run_2124_0621 - testRun("2.12.4", "0.6.21", FastOpt) - 'run_2123_0621 - testRun("2.12.3", "0.6.21", FastOpt) - 'run_2118_0621 - testRun("2.11.8", "0.6.21", FastOpt) + 'run_2124_0621 - testRun("2.12.4", "0.6.22", FastOpt) + 'run_2123_0621 - testRun("2.12.3", "0.6.22", FastOpt) + 'run_2118_0621 - testRun("2.11.8", "0.6.22", FastOpt) 'run_2124_100M2 - testRun("2.12.4", "1.0.0-M2", FastOpt) } 'jar - { 'containsSJSIRs - { - val Right((result, evalCount)) = helloWorldEvaluator(HelloJSWorld.build("2.12.4", "0.6.21").jar) + val Right((result, evalCount)) = helloWorldEvaluator(HelloJSWorld.build("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")) @@ -143,12 +167,71 @@ object HelloJSWorldTests extends TestSuite { val Right((result, evalCount)) = helloWorldEvaluator(HelloJSWorld.build(scalaVersion, scalaJSVersion).artifact) assert(result.id == artifactId) } - 'artifactId_0621 - testArtifactId("2.12.4", "0.6.21", "hello-js-world_sjs0.6_2.12") - 'artifactId_0621 - testArtifactId("2.12.4", "1.0.0-M2", "hello-js-world_sjs1.0.0-M2_2.12") + 'artifactId_0621 - 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 Right(((_, testResults), evalCount)) = helloWorldEvaluator(testTask) + + assert(evalCount > 0) + + 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_0621 - checkUtest("2.11.8", "0.6.22") + 'utest_2124_0621 - checkUtest("2.12.4", "0.6.22") + 'utest_2118_100M2 - checkUtest("2.11.8", "1.0.0-M2") + 'utest_2124_100M2 - checkUtest("2.12.4", "1.0.0-M2") + + 'scalaTest_2118_0621 - checkScalaTest("2.11.8", "0.6.22") + 'scalaTest_2124_0621 - 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 compileClassfiles(parentDir: Path) = Set( + parentDir / "ArgsParser$.class", + parentDir / "ArgsParser$.sjsir", + parentDir / "ArgsParser.class", parentDir / "Main.class", parentDir / "Main$.class", parentDir / "Main$delayedInit$body.class", |