summaryrefslogtreecommitdiff
path: root/core/src/test/scala/forge/JavaCompileJarTests.scala
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2017-11-07 21:10:06 -0800
committerLi Haoyi <haoyi.sg@gmail.com>2017-11-07 21:11:03 -0800
commitee080e63971399ceb22fd8f059a97e956d9f0dcb (patch)
treeaa4ce5a9b6647835fbdae11266621f13d24dcfcb /core/src/test/scala/forge/JavaCompileJarTests.scala
parentca02aef2c98079c695fa616c75ab05a693c9d512 (diff)
downloadmill-ee080e63971399ceb22fd8f059a97e956d9f0dcb.tar.gz
mill-ee080e63971399ceb22fd8f059a97e956d9f0dcb.tar.bz2
mill-ee080e63971399ceb22fd8f059a97e956d9f0dcb.zip
- Allow main methods to return `Target[T]`s, so they can then be evaled by an external `Evaluator` that has the `Discovered` mapping available
- Basic integration tests for `T.command` entrypoint running in the `JavaCompilerJarTests` suite
Diffstat (limited to 'core/src/test/scala/forge/JavaCompileJarTests.scala')
-rw-r--r--core/src/test/scala/forge/JavaCompileJarTests.scala51
1 files changed, 50 insertions, 1 deletions
diff --git a/core/src/test/scala/forge/JavaCompileJarTests.scala b/core/src/test/scala/forge/JavaCompileJarTests.scala
index 6ce02149..92e1d0e9 100644
--- a/core/src/test/scala/forge/JavaCompileJarTests.scala
+++ b/core/src/test/scala/forge/JavaCompileJarTests.scala
@@ -1,7 +1,7 @@
package forge
-import ammonite.ops._
+import ammonite.ops._, ImplicitWd._
import forge.define.Target
import forge.discover.Discovered
import forge.eval.{Evaluator, PathRef}
@@ -44,10 +44,20 @@ object JavaCompileJarTests extends TestSuite{
def allSources = T{ ls.rec(sourceRoot().path).map(PathRef(_)) }
def classFiles = T{ compileAll(allSources) }
def jar = T{ jarUp(resourceRoot, classFiles) }
+
+ @forge.discover.Router.main
+ def run(mainClsName: String): Target[CommandResult] = T.command{
+ %%('java, "-cp", classFiles().path, mainClsName)
+ }
}
import Build._
val mapping = Discovered.mapping(Build)
+ def eval[T](t: Target[T]): (T, Int) = {
+ val evaluator = new Evaluator(workspacePath, mapping)
+ val evaluated = evaluator.evaluate(OSet(t))
+ (evaluated.values(0).asInstanceOf[T], evaluated.evaluated.size)
+ }
def check(targets: OSet[Target[_]], expected: OSet[Target[_]]) = {
val evaluator = new Evaluator(workspacePath, mapping)
@@ -113,6 +123,45 @@ object JavaCompileJarTests extends TestSuite{
val executed = %%('java, "-cp", workspacePath/'jar, "test.Foo")(workspacePath).out.string
assert(executed == (31337 + 271828) + "\n")
+
+ println("="*20 + "Run Main" + "="*20)
+ for(i <- 0 until 3){
+ // Build.run is not cached, so every time we eval it it has to
+ // re-evaluate
+ val (runOutput, evalCount) = eval(Build.run("test.Foo"))
+ assert(
+ runOutput.out.string == (31337 + 271828) + "\n",
+ evalCount == 1
+ )
+ }
+
+ val ex = intercept[ammonite.ops.ShelloutException]{
+ eval(Build.run("test.BarFour"))
+ }
+ assert(ex.getMessage.contains("Could not find or load main class"))
+
+ append(
+ sourceRootPath / "Bar.java",
+ """
+ class BarFour{
+ public static void main(String[] args){
+ System.out.println("New Cls!");
+ }
+ }
+ """
+ )
+ val (runOutput2, evalCount2) = eval(Build.run("test.BarFour"))
+ assert(
+ runOutput2.out.string == "New Cls!\n",
+ evalCount2 == 5
+ )
+ val (runOutput3, evalCount3) = eval(Build.run("test.BarFour"))
+ assert(
+ runOutput3.out.string == "New Cls!\n",
+ evalCount3 == 1
+ )
+
+
}
}
}