diff options
Diffstat (limited to 'scalalib/test')
6 files changed, 80 insertions, 14 deletions
diff --git a/scalalib/test/resources/hello-java/app/src/hello/Main.java b/scalalib/test/resources/hello-java/app/src/hello/Main.java new file mode 100644 index 00000000..23ddd679 --- /dev/null +++ b/scalalib/test/resources/hello-java/app/src/hello/Main.java @@ -0,0 +1,10 @@ +package hello; + +public class Main{ + public static String getMessage(String[] args){ + return Core.msg() + " " + args[0]; + } + public static void main(String[] args){ + System.out.println(getMessage(args)); + } +}
\ No newline at end of file diff --git a/scalalib/test/resources/hello-java/app/test/src/hello/MyAppTests.java b/scalalib/test/resources/hello-java/app/test/src/hello/MyAppTests.java new file mode 100644 index 00000000..df0d0351 --- /dev/null +++ b/scalalib/test/resources/hello-java/app/test/src/hello/MyAppTests.java @@ -0,0 +1,18 @@ +package hello; + +import static org.junit.Assert.assertEquals; +import org.junit.Test; + +public class MyAppTests { + + @Test + public void coreTest() { + assertEquals(Core.msg(), "Hello World"); + } + + @Test + public void appTest() { + assertEquals(Main.getMessage(new String[]{"lols"}), "Hello World lols"); + } + +}
\ No newline at end of file diff --git a/scalalib/test/resources/hello-java/core/src/hello/Core.java b/scalalib/test/resources/hello-java/core/src/hello/Core.java index bef1a5a0..3ecb1f61 100644 --- a/scalalib/test/resources/hello-java/core/src/hello/Core.java +++ b/scalalib/test/resources/hello-java/core/src/hello/Core.java @@ -4,5 +4,4 @@ public class Core{ public static String msg(){ return "Hello World"; } - }
\ No newline at end of file diff --git a/scalalib/test/resources/hello-java/core/test/src/hello/MyCoreTests.java b/scalalib/test/resources/hello-java/core/test/src/hello/MyCoreTests.java new file mode 100644 index 00000000..38bebaeb --- /dev/null +++ b/scalalib/test/resources/hello-java/core/test/src/hello/MyCoreTests.java @@ -0,0 +1,15 @@ +package hello; + +import static org.junit.Assert.assertEquals; +import org.junit.Test; + +public class MyCoreTests { + @Test + public void msgTest() { + assertEquals(Core.msg(), "Hello World!!"); + } + @Test + public void lengthTest() { + assertEquals(Core.msg().length(), 11); + } +}
\ No newline at end of file diff --git a/scalalib/test/resources/hello-java/main/src/hello/Main.java b/scalalib/test/resources/hello-java/main/src/hello/Main.java deleted file mode 100644 index 44b927bd..00000000 --- a/scalalib/test/resources/hello-java/main/src/hello/Main.java +++ /dev/null @@ -1,7 +0,0 @@ -package hello; - -public class Main{ - public static void main(String[] args){ - System.out.println(Core.msg() + " " + args[0]); - } -}
\ No newline at end of file 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" + ) + } } } |