diff options
Diffstat (limited to 'scalalib')
3 files changed, 21 insertions, 11 deletions
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" |