diff options
author | Tobias Roeser <le.petit.fou@web.de> | 2019-10-16 08:25:45 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-16 08:25:45 +0200 |
commit | 9354e9311118ca23a44f72e463875a2769e53716 (patch) | |
tree | 81670fe46f77ae00d1b36911551077303c6c8f60 | |
parent | 395a9bd5f4a66492bb5366bc370108ea441fbcca (diff) | |
download | mill-9354e9311118ca23a44f72e463875a2769e53716.tar.gz mill-9354e9311118ca23a44f72e463875a2769e53716.tar.bz2 mill-9354e9311118ca23a44f72e463875a2769e53716.zip |
Added new target TestModule.testCached which caches the last test result (#712)
* Added new target TestModule.testCached which caches the last test result
Implements https://github.com/lihaoyi/mill/issues/711
* Fixed task-in-task evaluation issue
-rw-r--r-- | scalalib/src/JavaModule.scala | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/scalalib/src/JavaModule.scala b/scalalib/src/JavaModule.scala index b9987ca1..dc412f3b 100644 --- a/scalalib/src/JavaModule.scala +++ b/scalalib/src/JavaModule.scala @@ -5,8 +5,7 @@ import java.io.ByteArrayInputStream import java.io.ByteArrayOutputStream import coursier.Repository -import mill.define.Task -import mill.define.TaskModule +import mill.define.{Command, Task, TaskModule} import mill.eval.{PathRef, Result} import mill.modules.{Assembly, Jvm} import mill.modules.Jvm.{createAssembly, createJar} @@ -565,9 +564,29 @@ trait TestModule extends JavaModule with TaskModule { def testFrameworks: T[Seq[String]] /** * Discovers and runs the module's tests in a subprocess, reporting the - * results to the console + * results to the console. + * @see [[testCached]] */ - def test(args: String*) = T.command{ + def test(args: String*): Command[(String, Seq[TestRunner.Result])] = T.command { + testTask(T.task{args})() + } + + /** + * Args to be used by [[testCached]]. + */ + def testCachedArgs: T[Seq[String]] = T{ Seq[String]() } + + /** + * Discovers and runs the module's tests in a subprocess, reporting the + * results to the console. + * If no input has changed since the last run, no test were executed. + * @see [[test()]] + */ + def testCached: T[(String, Seq[TestRunner.Result])] = T { + testTask(testCachedArgs)() + } + + protected def testTask(args: Task[Seq[String]]): Task[(String, Seq[TestRunner.Result])] = T.task { val outputPath = T.ctx().dest/"out.json" Jvm.runSubprocess( @@ -580,8 +599,8 @@ trait TestModule extends JavaModule with TaskModule { testFrameworks() ++ Seq(runClasspath().length.toString) ++ runClasspath().map(_.path.toString) ++ - Seq(args.length.toString) ++ - args ++ + Seq(args().length.toString) ++ + args() ++ Seq(outputPath.toString, T.ctx().log.colored.toString, compile().classes.path.toString, T.ctx().home.toString), workingDir = forkWorkingDir() ) @@ -593,14 +612,13 @@ trait TestModule extends JavaModule with TaskModule { }catch{case e: Throwable => Result.Failure("Test reporting failed: " + e) } - } /** * Discovers and runs the module's tests in-process in an isolated classloader, * reporting the results to the console */ - def testLocal(args: String*) = T.command{ + def testLocal(args: String*) = T.command { val outputPath = T.ctx().dest/"out.json" val (doneMsg, results) = TestRunner.runTests( |