From 62a18754179d74252668879c42e1c5d6a45fbdce Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Sun, 8 Apr 2018 12:55:30 -0700 Subject: Enable JUnit testing, via sbt-test-interface, for `JavaModule`s --- .../test/src/mill/scalalib/HelloJavaTests.scala | 43 +++++++++++++++++++--- 1 file changed, 37 insertions(+), 6 deletions(-) (limited to 'scalalib/test/src') diff --git a/scalalib/test/src/mill/scalalib/HelloJavaTests.scala b/scalalib/test/src/mill/scalalib/HelloJavaTests.scala index 7794d5a5..bcfdd19f 100644 --- a/scalalib/test/src/mill/scalalib/HelloJavaTests.scala +++ b/scalalib/test/src/mill/scalalib/HelloJavaTests.scala @@ -1,8 +1,10 @@ -package mill.scalalib +package mill +package scalalib import ammonite.ops.{%, %%, cp, ls, mkdir, pwd, rm, up} import ammonite.ops.ImplicitWd._ +import mill.eval.Result import mill.util.{TestEvaluator, TestUtil} import utest._ import utest.framework.TestPath @@ -12,9 +14,17 @@ object HelloJavaTests extends TestSuite { object HelloJava extends TestUtil.BaseModule{ def millSourcePath = TestUtil.getSrcPathBase() / millOuterCtx.enclosing.split('.') - object core extends JavaModule - object main extends JavaModule{ + 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 = pwd / 'scalalib / 'test / 'resources / "hello-java" @@ -28,12 +38,12 @@ object HelloJavaTests extends TestSuite { eval } def tests: Tests = Tests { - 'scalaVersion - { + '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.main.compile) + val Right((res3, n2)) = eval.apply(HelloJava.app.compile) assert( res1 == res2, @@ -49,12 +59,33 @@ object HelloJavaTests extends TestSuite { val eval = init() val Right((ref1, _)) = eval.apply(HelloJava.core.docJar) - val Right((ref2, _)) = eval.apply(HelloJava.main.docJar) + val Right((ref2, _)) = eval.apply(HelloJava.app.docJar) assert( %%("jar", "tf", ref1.path).out.lines.contains("hello/Core.html"), %%("jar", "tf", ref2.path).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" + ) + } } } -- cgit v1.2.3