diff options
author | rockjam <5min4eq.unity@gmail.com> | 2017-11-29 19:29:03 +0300 |
---|---|---|
committer | rockjam <5min4eq.unity@gmail.com> | 2017-11-30 13:30:45 +0300 |
commit | 2ac4cb2263812d2edc16faaf376b0386b990144e (patch) | |
tree | c86fbb56158eea299a13c3aa8f1d3ebd1f620e86 /scalaplugin | |
parent | 2222c14b405e5f2c429380293ed8165cb84fa156 (diff) | |
download | mill-2ac4cb2263812d2edc16faaf376b0386b990144e.tar.gz mill-2ac4cb2263812d2edc16faaf376b0386b990144e.tar.bz2 mill-2ac4cb2263812d2edc16faaf376b0386b990144e.zip |
implment runMain command
Diffstat (limited to 'scalaplugin')
-rw-r--r-- | scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala | 5 | ||||
-rw-r--r-- | scalaplugin/src/test/scala/mill/scalaplugin/HelloWorldTests.scala | 25 |
2 files changed, 29 insertions, 1 deletions
diff --git a/scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala b/scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala index b87ba6b3..3eae0f81 100644 --- a/scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala +++ b/scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala @@ -354,6 +354,11 @@ trait ScalaModule extends Module with TaskModule{ outer => PathRef(dest) } + def runMain() = T.command{ + val main = mainClass().getOrElse(throw new RuntimeException("No mainClass provided!")) + subprocess(main, runDepClasspath().map(_.path) :+ compile().path) + } + def run(mainClass: String) = T.command{ subprocess(mainClass, runDepClasspath().map(_.path) :+ compile().path) } diff --git a/scalaplugin/src/test/scala/mill/scalaplugin/HelloWorldTests.scala b/scalaplugin/src/test/scala/mill/scalaplugin/HelloWorldTests.scala index f4a4e993..f2a428e5 100644 --- a/scalaplugin/src/test/scala/mill/scalaplugin/HelloWorldTests.scala +++ b/scalaplugin/src/test/scala/mill/scalaplugin/HelloWorldTests.scala @@ -40,6 +40,7 @@ object HelloWorldTests extends TestSuite { TestEvaluator.eval(mapping, outputPath)(t) val helloWorldMapping = Discovered.mapping(HelloWorld) + val helloWorldWithMainMapping = Discovered.mapping(HelloWorldWithMain) def tests: Tests = Tests { prepareWorkspace() @@ -178,6 +179,28 @@ object HelloWorldTests extends TestSuite { ) } } + 'runMain - { + 'runIfMainClassProvided - { + val Right((_, evalCount)) = + eval(HelloWorldWithMain.runMain(), helloWorldWithMainMapping) + + assert(evalCount > 0) + + val runResult = workspacePath / "hello-mill" + assert( + exists(runResult), + read(runResult) == "hello rockjam, your age is: 25" + ) + } + 'notRunWithoutMainClass - { + val Left(Result.Exception(err)) = + eval(HelloWorld.runMain(), helloWorldMapping) + + assert( + err.isInstanceOf[RuntimeException] + ) + } + } 'jar - { 'nonEmpty - { val Right((result, evalCount)) = @@ -206,7 +229,7 @@ object HelloWorldTests extends TestSuite { } 'runJar - { val Right((result, evalCount)) = - eval(HelloWorldWithMain.jar, Discovered.mapping(HelloWorldWithMain)) + eval(HelloWorldWithMain.jar, helloWorldWithMainMapping) assert( exists(result.path), |