diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2017-11-25 08:01:24 -0800 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2017-11-25 08:01:24 -0800 |
commit | c3f2dc919cff83f105a60061456090f0c907f0b1 (patch) | |
tree | 83cfa7e36649eddfe2e2e797f3baaaa782507a49 | |
parent | ac62721c10cc61d3913cf71c3ef2e9e0680ddeb9 (diff) | |
download | mill-c3f2dc919cff83f105a60061456090f0c907f0b1.tar.gz mill-c3f2dc919cff83f105a60061456090f0c907f0b1.tar.bz2 mill-c3f2dc919cff83f105a60061456090f0c907f0b1.zip |
First pass at simplifying test suite definition & running
Added a `TaskModule` subclass of `Module`, which delegates to a `self` task that you can run directly from bash
Fixed `GenIdea` to fix reversing of module path in generating module name
-rwxr-xr-x | build.sc | 2 | ||||
-rw-r--r-- | core/src/main/scala/mill/Main.scala | 13 | ||||
-rw-r--r-- | core/src/main/scala/mill/define/Task.scala | 4 | ||||
-rw-r--r-- | readme.md | 3 | ||||
-rw-r--r-- | scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala | 7 |
5 files changed, 24 insertions, 5 deletions
@@ -36,7 +36,7 @@ object Core extends ScalaModule { } } - object tests extends this.Tests{ + object test extends this.Tests{ def basePath = pwd / 'core override def ivyDeps = Seq(Dep("com.lihaoyi", "utest", "0.6.0")) override def sources = pwd/'core/'src/'test/'scala diff --git a/core/src/main/scala/mill/Main.scala b/core/src/main/scala/mill/Main.scala index 6f1d3bd3..7b48c9c7 100644 --- a/core/src/main/scala/mill/Main.scala +++ b/core/src/main/scala/mill/Main.scala @@ -10,6 +10,7 @@ import mill.eval.{Evaluator, Result} import mill.util.OSet import ammonite.main.Scripts.pathScoptRead import ammonite.repl.Repl +import mill.define.Task.TaskModule object Main { @@ -52,13 +53,23 @@ object Main { case Left(last) :: Nil => def target: Option[Task[Any]] = hierarchy.targets.find(_.label == last).map(_.run(hierarchy.node(obj, crossSelectors))) + + def targetModule: Seq[Task[Any]] = for{ + (label, child) <- hierarchy.children + if label == last + node <- child.node(obj, crossSelectors) match{ + case x: TaskModule => Some(x) + case _ => None + } + } yield node.self + def command: Option[Task[Any]] = hierarchy.commands.find(_.name == last).flatMap( _.invoke(hierarchy.node(obj, crossSelectors), ammonite.main.Scripts.groupArgs(rest.toList)) match{ case Router.Result.Success(v) => Some(v) case _ => None } ) - target orElse command + target orElse command orElse targetModule.headOption case head :: tail => head match{ case Left(singleLabel) => diff --git a/core/src/main/scala/mill/define/Task.scala b/core/src/main/scala/mill/define/Task.scala index 5aa97eff..91eb3793 100644 --- a/core/src/main/scala/mill/define/Task.scala +++ b/core/src/main/scala/mill/define/Task.scala @@ -145,6 +145,10 @@ object Task { trait Module extends mill.define.Cacher[Target]{ def wrapCached[T](t: Target[T], enclosing: String): Target[T] = t } + trait TaskModule extends Module { + def self(): Task[_] + } + class Task0[T](t: T) extends Task[T]{ lazy val t0 = t val inputs = Nil @@ -23,7 +23,8 @@ core unit tests e.g.: ```bash ./scalaplugin/target/mill run Core.compile -./scalaplugin/target/mill run Core.tests.run +./scalaplugin/target/mill run Core.test.compile +./scalaplugin/target/mill run Core.test ./scalaplugin/target/mill run ScalaPlugin.assembly ``` diff --git a/scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala b/scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala index d2c37782..5a1f261a 100644 --- a/scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala +++ b/scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala @@ -7,7 +7,7 @@ import java.util.Optional import ammonite.ops._ import coursier.{Cache, Fetch, MavenRepository, Repository, Resolution} import mill.define.Task -import mill.define.Task.Module +import mill.define.Task.{Module, TaskModule} import mill.eval.{Evaluator, PathRef} import mill.modules.Jvm.{createAssembly, createJar} import mill.util.OSet @@ -161,7 +161,7 @@ object ScalaModule{ ) } import ScalaModule._ -trait TestScalaModule extends ScalaModule{ +trait TestScalaModule extends ScalaModule with TaskModule{ def testFramework: T[String] def run() = T.command{ TestRunner( @@ -170,6 +170,7 @@ trait TestScalaModule extends ScalaModule{ Seq(compile().path) ) } + def self() = run() } trait ScalaModule extends Module{ outer => trait Tests extends TestScalaModule{ @@ -267,6 +268,8 @@ trait ScalaModule extends Module{ outer => PathRef(dest) } + + def run(mainClass: String) = T.command{ import ammonite.ops._, ImplicitWd._ %('java, "-cp", (runDepClasspath().map(_.path) :+ compile().path).mkString(":"), mainClass) |