diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2018-01-01 01:48:28 -0800 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2018-01-01 10:10:19 -0800 |
commit | cb5e3291155ba0d29c1a530d6c217d22a3a743f4 (patch) | |
tree | 3f441311ed0c3c0f122c0cefef5cee560df02e2c | |
parent | b1e622a42de5d48b82c108f2d7931b170a460f5e (diff) | |
download | mill-cb5e3291155ba0d29c1a530d6c217d22a3a743f4.tar.gz mill-cb5e3291155ba0d29c1a530d6c217d22a3a743f4.tar.bz2 mill-cb5e3291155ba0d29c1a530d6c217d22a3a743f4.zip |
Make `HelloWorldTests` take an explicit output path so they are less sensitive to working directories
Make `run` and `runMain` take option CLI args
4 files changed, 22 insertions, 12 deletions
diff --git a/integration/src/test/resource/jawn/build.sc b/integration/src/test/resource/jawn/build.sc index 9c9b41dc..167407bd 100644 --- a/integration/src/test/resource/jawn/build.sc +++ b/integration/src/test/resource/jawn/build.sc @@ -32,7 +32,7 @@ class Jawn(crossVersion: String) extends mill.Module{ object Ast extends JawnModule{ def projectDeps = Seq(Parser, Util) def testProjectDeps = Seq(Parser.test, Util.test) - def basePath = ammonite.ops.pwd / 'target / 'workspace / 'jawn / 'acyclic + def basePath = ammonite.ops.pwd / 'target / 'workspace / 'jawn / 'ast } class Support(name: String, ivyDeps0: Dep*) extends JawnModule{ def projectDeps = Seq[Module](Parser) diff --git a/scalalib/src/main/scala/mill/scalalib/Module.scala b/scalalib/src/main/scala/mill/scalalib/Module.scala index 453a25df..3cd4cde0 100644 --- a/scalalib/src/main/scala/mill/scalalib/Module.scala +++ b/scalalib/src/main/scala/mill/scalalib/Module.scala @@ -255,19 +255,21 @@ trait Module extends mill.Module with TaskModule { outer => def forkArgs = T{ Seq.empty[String] } - def run() = T.command{ + def run(args: String*) = T.command{ subprocess( mainClass().getOrElse(throw new RuntimeException("No mainClass provided!")), runDepClasspath().map(_.path) :+ compile().classes.path, forkArgs(), + args, workingDir = ammonite.ops.pwd) } - def runMain(mainClass: String) = T.command{ + def runMain(mainClass: String, args: String*) = T.command{ subprocess( mainClass, runDepClasspath().map(_.path) :+ compile().classes.path, forkArgs(), + args, workingDir = ammonite.ops.pwd ) } diff --git a/scalalib/src/test/resource/hello-world/src/main/scala/Main.scala b/scalalib/src/test/resource/hello-world/src/main/scala/Main.scala index 1e686f11..14139d6f 100644 --- a/scalalib/src/test/resource/hello-world/src/main/scala/Main.scala +++ b/scalalib/src/test/resource/hello-world/src/main/scala/Main.scala @@ -2,9 +2,11 @@ import scala.collection._ // unused import to check unused imports warning import java.nio.file.{Files, Paths} object Main extends App { + val person = Person.fromString("rockjam:25") val greeting = s"hello ${person.name}, your age is: ${person.age}" println(greeting) - val resultPath = Paths.get("hello-mill") + val resultPath = Paths.get(args(0)) + Files.createDirectories(resultPath.getParent) Files.write(resultPath, greeting.getBytes) } diff --git a/scalalib/src/test/scala/mill/scalalib/HelloWorldTests.scala b/scalalib/src/test/scala/mill/scalalib/HelloWorldTests.scala index ee24e70a..0f4b1223 100644 --- a/scalalib/src/test/scala/mill/scalalib/HelloWorldTests.scala +++ b/scalalib/src/test/scala/mill/scalalib/HelloWorldTests.scala @@ -197,11 +197,11 @@ object HelloWorldTests extends TestSuite { } 'runMain - { 'runMainObject - { - val Right((_, evalCount)) = helloWorldEvaluator(HelloWorld.runMain("Main")) + val runResult = basePath / 'out / 'runMain / 'dest / "hello-mill" + val Right((_, evalCount)) = helloWorldEvaluator(HelloWorld.runMain("Main", runResult.toString)) assert(evalCount > 0) - val runResult = basePath / 'out / 'runMain / 'dest / "hello-mill" assert( exists(runResult), read(runResult) == "hello rockjam, your age is: 25" @@ -210,13 +210,15 @@ object HelloWorldTests extends TestSuite { 'runCross{ def cross(v: String) { + val runResult = basePath / 'out / 'cross / v / 'runMain / 'dest / "hello-mill" + val Right((_, evalCount)) = helloWorldCrossEvaluator( - CrossHelloWorld.cross(v).runMain("Main") + CrossHelloWorld.cross(v).runMain("Main", runResult.toString) ) assert(evalCount > 0) - val runResult = basePath / 'out / 'cross / v / 'runMain / 'dest / "hello-mill" + assert( exists(runResult), read(runResult) == "hello rockjam, your age is: 25" @@ -248,11 +250,14 @@ object HelloWorldTests extends TestSuite { } 'run - { 'runIfMainClassProvided - { - val Right((_, evalCount)) = helloWorldWithMainEvaluator(HelloWorldWithMain.run()) + val runResult = basePath / 'out / 'run / 'dest / "hello-mill" + val Right((_, evalCount)) = helloWorldWithMainEvaluator( + HelloWorldWithMain.run(runResult.toString) + ) assert(evalCount > 0) - val runResult = basePath / 'out / 'run / 'dest / "hello-mill" + assert( exists(runResult), read(runResult) == "hello rockjam, your age is: 25" @@ -294,10 +299,11 @@ object HelloWorldTests extends TestSuite { exists(result.path), evalCount > 0 ) + val runResult = basePath / "hello-mill" + + %("scala", result.path, runResult)(wd = basePath) - %("scala", result.path)(wd = basePath) - val runResult = basePath / "hello-mill" assert( exists(runResult), read(runResult) == "hello rockjam, your age is: 25" |