diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2018-12-12 16:56:02 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-12 16:56:02 -0800 |
commit | 9ba4cb69331386dfde9bac69dc2d5b22401face3 (patch) | |
tree | 120349e8015ae5717d36bd44209cde6ff9543518 /scalalib/test/src/HelloJavaTests.scala | |
parent | ea7fceb6e56f53bde3517586dfc57e10a605a524 (diff) | |
download | mill-9ba4cb69331386dfde9bac69dc2d5b22401face3.tar.gz mill-9ba4cb69331386dfde9bac69dc2d5b22401face3.tar.bz2 mill-9ba4cb69331386dfde9bac69dc2d5b22401face3.zip |
collapse boilerplate folder structure within src/ folders (#505)
* collapse boilerplate folder structure within src/ folders
* .
Diffstat (limited to 'scalalib/test/src/HelloJavaTests.scala')
-rw-r--r-- | scalalib/test/src/HelloJavaTests.scala | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/scalalib/test/src/HelloJavaTests.scala b/scalalib/test/src/HelloJavaTests.scala new file mode 100644 index 00000000..02c2567f --- /dev/null +++ b/scalalib/test/src/HelloJavaTests.scala @@ -0,0 +1,114 @@ +package mill +package scalalib + + +import mill.api.Result +import mill.util.{TestEvaluator, TestUtil} +import utest._ +import utest.framework.TestPath + + +object HelloJavaTests extends TestSuite { + + object HelloJava extends TestUtil.BaseModule{ + def millSourcePath = TestUtil.getSrcPathBase() / millOuterCtx.enclosing.split('.') + trait JUnitTests extends TestModule{ + def testFrameworks = Seq("com.novocode.junit.JUnitFramework") + def ivyDeps = Agg(ivy"com.novocode:junit-interface:0.11") + } + + object core extends JavaModule{ + object test extends Tests with JUnitTests + } + object app extends JavaModule{ + def moduleDeps = Seq(core) + object test extends Tests with JUnitTests + } + } + val resourcePath = os.pwd / 'scalalib / 'test / 'resources / "hello-java" + + def init()(implicit tp: TestPath) = { + val eval = new TestEvaluator(HelloJava) + os.remove.all(HelloJava.millSourcePath) + os.remove.all(eval.outPath) + os.makeDir.all(HelloJava.millSourcePath / os.up) + os.copy(resourcePath, HelloJava.millSourcePath) + eval + } + def tests: Tests = Tests { + 'compile - { + val eval = init() + + val Right((res1, n1)) = eval.apply(HelloJava.core.compile) + val Right((res2, 0)) = eval.apply(HelloJava.core.compile) + val Right((res3, n2)) = eval.apply(HelloJava.app.compile) + + assert( + res1 == res2, + n1 != 0, + n2 != 0, + os.walk(res1.classes.path).exists(_.last == "Core.class"), + !os.walk(res1.classes.path).exists(_.last == "Main.class"), + os.walk(res3.classes.path).exists(_.last == "Main.class"), + !os.walk(res3.classes.path).exists(_.last == "Core.class") + ) + } + 'docJar - { + val eval = init() + + val Right((ref1, _)) = eval.apply(HelloJava.core.docJar) + val Right((ref2, _)) = eval.apply(HelloJava.app.docJar) + + assert( + os.proc("jar", "tf", ref1.path).call().out.lines.contains("hello/Core.html"), + os.proc("jar", "tf", ref2.path).call().out.lines.contains("hello/Main.html") + ) + } + 'test - { + val eval = init() + + val Left(Result.Failure(ref1, Some(v1))) = eval.apply(HelloJava.core.test.test()) + + assert( + v1._2(0).fullyQualifiedName == "hello.MyCoreTests.lengthTest", + v1._2(0).status == "Success", + v1._2(1).fullyQualifiedName == "hello.MyCoreTests.msgTest", + v1._2(1).status == "Failure" + ) + + val Right((v2, _)) = eval.apply(HelloJava.app.test.test()) + + assert( + v2._2(0).fullyQualifiedName == "hello.MyAppTests.appTest", + v2._2(0).status == "Success", + v2._2(1).fullyQualifiedName == "hello.MyAppTests.coreTest", + v2._2(1).status == "Success" + ) + } + 'failures - { + val eval = init() + + val mainJava = HelloJava.millSourcePath / 'app / 'src / "Main.java" + val coreJava = HelloJava.millSourcePath / 'core / 'src / "Core.java" + + val Right(_) = eval.apply(HelloJava.core.compile) + val Right(_) = eval.apply(HelloJava.app.compile) + + ammonite.ops.write.over(mainJava, ammonite.ops.read(mainJava) + "}") + + val Right(_) = eval.apply(HelloJava.core.compile) + val Left(_) = eval.apply(HelloJava.app.compile) + + ammonite.ops.write.over(coreJava, ammonite.ops.read(coreJava) + "}") + + val Left(_) = eval.apply(HelloJava.core.compile) + val Left(_) = eval.apply(HelloJava.app.compile) + + ammonite.ops.write.over(mainJava, ammonite.ops.read(mainJava).dropRight(1)) + ammonite.ops.write.over(coreJava, ammonite.ops.read(coreJava).dropRight(1)) + + val Right(_) = eval.apply(HelloJava.core.compile) + val Right(_) = eval.apply(HelloJava.app.compile) + } + } +} |