summaryrefslogtreecommitdiff
path: root/scalalib/test
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2018-04-07 07:24:47 -0700
committerLi Haoyi <haoyi.sg@gmail.com>2018-04-07 09:04:55 -0700
commit3e43a5f3b56ed65ec9ce0d68b28033b71da5a06f (patch)
treea39394ea100eca1bafb551c793075e475a26ddd3 /scalalib/test
parent953321ead7b278912529ef34b50e403d1e533c05 (diff)
downloadmill-3e43a5f3b56ed65ec9ce0d68b28033b71da5a06f.tar.gz
mill-3e43a5f3b56ed65ec9ce0d68b28033b71da5a06f.tar.bz2
mill-3e43a5f3b56ed65ec9ce0d68b28033b71da5a06f.zip
First unit tests for `JavaModule`
Diffstat (limited to 'scalalib/test')
-rw-r--r--scalalib/test/resources/hello-java/core/src/hello/Core.java8
-rw-r--r--scalalib/test/resources/hello-java/main/src/hello/Main.java7
-rw-r--r--scalalib/test/src/mill/scalalib/HelloJavaTests.scala60
3 files changed, 75 insertions, 0 deletions
diff --git a/scalalib/test/resources/hello-java/core/src/hello/Core.java b/scalalib/test/resources/hello-java/core/src/hello/Core.java
new file mode 100644
index 00000000..bef1a5a0
--- /dev/null
+++ b/scalalib/test/resources/hello-java/core/src/hello/Core.java
@@ -0,0 +1,8 @@
+package hello;
+
+public class Core{
+ public static String msg(){
+ return "Hello World";
+ }
+
+} \ 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
new file mode 100644
index 00000000..44b927bd
--- /dev/null
+++ b/scalalib/test/resources/hello-java/main/src/hello/Main.java
@@ -0,0 +1,7 @@
+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
new file mode 100644
index 00000000..7794d5a5
--- /dev/null
+++ b/scalalib/test/src/mill/scalalib/HelloJavaTests.scala
@@ -0,0 +1,60 @@
+package mill.scalalib
+
+
+import ammonite.ops.{%, %%, cp, ls, mkdir, pwd, rm, up}
+import ammonite.ops.ImplicitWd._
+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('.')
+ object core extends JavaModule
+ object main extends JavaModule{
+ def moduleDeps = Seq(core)
+ }
+ }
+ val resourcePath = pwd / 'scalalib / 'test / 'resources / "hello-java"
+
+ def init()(implicit tp: TestPath) = {
+ val eval = new TestEvaluator(HelloJava)
+ rm(HelloJava.millSourcePath)
+ rm(eval.outPath)
+ mkdir(HelloJava.millSourcePath / up)
+ cp(resourcePath, HelloJava.millSourcePath)
+ eval
+ }
+ def tests: Tests = Tests {
+ 'scalaVersion - {
+ 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)
+
+ assert(
+ res1 == res2,
+ n1 != 0,
+ n2 != 0,
+ ls.rec(res1.classes.path).exists(_.last == "Core.class"),
+ !ls.rec(res1.classes.path).exists(_.last == "Main.class"),
+ ls.rec(res3.classes.path).exists(_.last == "Main.class"),
+ !ls.rec(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.main.docJar)
+
+ assert(
+ %%("jar", "tf", ref1.path).out.lines.contains("hello/Core.html"),
+ %%("jar", "tf", ref2.path).out.lines.contains("hello/Main.html")
+ )
+ }
+ }
+}