summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala5
-rw-r--r--scalaplugin/src/test/scala/mill/scalaplugin/HelloWorldTests.scala25
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),