-
-
Notifications
You must be signed in to change notification settings - Fork 345
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This idea of this change is to restructure the `TestModule` to decouple it from the concept of compilation. After this change, only a `runClasspath` and a `testClasspath` is needed to run tests. This makes adding test modules for the sake of using a different test framework a breeze. See the following example: the `test2` module is an additional test framework on the same classes of `test`. ```scala import mill._ import mill.scalalib._ import mill.scalalib.api.CompilationResult object foo extends RootModule with ScalaModule { def scalaVersion = "2.13.11" def ivyDeps = Agg( ivy"com.lihaoyi::scalatags:0.12.0", ivy"com.lihaoyi::mainargs:0.6.2" ) object test extends ScalaTests { def ivyDeps = Agg( ivy"com.lihaoyi::utest:0.7.11", ivy"org.scalatest::scalatest-freespec:3.2.18" ) def testFramework = "utest.runner.Framework" } object test2 extends TestModule with TestModule.ScalaTest { override def compile: T[CompilationResult] = ??? override def runClasspath: T[Seq[PathRef]] = foo.test.runClasspath() override def testClasspath = foo.test.testClasspath() } } ``` Please note the `compile` target is a legacy to our binary-compatibility promise. The target is not used directly in `TestModule`. This pull request additionally contains the following changes: * Introduces a new `RunModule` and moved some `run`-related task previously in `TestModule` up. * Extend `RunModule` in `JavaModule` to share run-releated targets and resolve super-hierarchy * Introduces a `WithZincWorker` as a shared base trait to resolve super-hierarchies for using and overriding a common worker. I plan to move more run-releated target from `JavaModule` to `RunModule` in a subsequent PR. (See #3090) See also the following discussion: * #3076 Pull request: #3064
- Loading branch information
Showing
13 changed files
with
264 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import mill._ | ||
import mill.scalalib._ | ||
import mill.scalalib.api.CompilationResult | ||
|
||
object foo extends RootModule with ScalaModule { | ||
def scalaVersion = "2.13.11" | ||
def ivyDeps = Agg( | ||
ivy"com.lihaoyi::scalatags:0.12.0", | ||
ivy"com.lihaoyi::mainargs:0.6.2" | ||
) | ||
|
||
object test extends ScalaTests { | ||
def ivyDeps = Agg( | ||
ivy"com.lihaoyi::utest:0.7.11", | ||
ivy"org.scalatest::scalatest-freespec:3.2.18" | ||
) | ||
def testFramework = "utest.runner.Framework" | ||
} | ||
object test2 extends TestModule with TestModule.ScalaTest { | ||
override def compile: T[CompilationResult] = ??? | ||
override def runClasspath: T[Seq[PathRef]] = foo.test.runClasspath() | ||
override def testClasspath = foo.test.testClasspath() | ||
} | ||
} | ||
|
||
// format: off | ||
/** Usage | ||
> mill resolve __:TestModule.test | ||
... | ||
test.test | ||
test2.test | ||
> mill test | ||
... | ||
+ foo.FooTests.simple ... <h1>hello</h1> | ||
+ foo.FooTests.escaping ... <h1><hello></h1> | ||
Tests: 2, Passed: 2, Failed: 0 | ||
> mill test2 | ||
... | ||
FooScalaTests: | ||
Foo | ||
- simple | ||
- escaping | ||
... | ||
Total number of tests run: 2 | ||
Suites: completed 1, aborted 0 | ||
Tests: succeeded 2, failed 0, canceled 0, ignored 0, pending 0 | ||
*/ | ||
// format: on |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package foo | ||
import scalatags.Text.all._ | ||
import mainargs.{main, ParserForMethods} | ||
|
||
object Foo { | ||
def generateHtml(text: String) = { | ||
h1(text).toString | ||
} | ||
|
||
@main | ||
def main(text: String) = { | ||
println(generateHtml(text)) | ||
} | ||
|
||
def main(args: Array[String]): Unit = ParserForMethods(this).runOrExit(args) | ||
} |
18 changes: 18 additions & 0 deletions
18
example/basic/5-multiple-test-frameworks/test/src/FooScalaTests.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package foo | ||
|
||
import org.scalatest.freespec._ | ||
|
||
class FooScalaTests extends AnyFreeSpec { | ||
"Foo" - { | ||
"simple" in { | ||
val result = Foo.generateHtml("hello") | ||
assert(result == "<h1>hello</h1>") | ||
result | ||
} | ||
"escaping" in { | ||
val result = Foo.generateHtml("<hello>") | ||
assert(result == "<h1><hello></h1>") | ||
result | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
example/basic/5-multiple-test-frameworks/test/src/FooTests.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package foo | ||
import utest._ | ||
object FooTests extends TestSuite { | ||
def tests = Tests { | ||
test("simple") { | ||
val result = Foo.generateHtml("hello") | ||
assert(result == "<h1>hello</h1>") | ||
result | ||
} | ||
test("escaping") { | ||
val result = Foo.generateHtml("<hello>") | ||
assert(result == "<h1><hello></h1>") | ||
result | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package mill.scalalib | ||
|
||
import mill.T | ||
import mill.define.Module | ||
import mill.api.JsonFormatters.pathReadWrite | ||
import mill.api.PathRef | ||
|
||
trait RunModule extends Module { | ||
|
||
/** | ||
* Any command-line parameters you want to pass to the forked JVM. | ||
*/ | ||
def forkArgs: T[Seq[String]] = T { Seq.empty[String] } | ||
|
||
/** | ||
* Any environment variables you want to pass to the forked JVM. | ||
*/ | ||
def forkEnv: T[Map[String, String]] = T.input { T.env } | ||
|
||
def forkWorkingDir: T[os.Path] = T { T.workspace } | ||
|
||
/** | ||
* All classfiles and resources including upstream modules and dependencies | ||
* necessary to run this module's code. | ||
*/ | ||
def runClasspath: T[Seq[PathRef]] = T { Seq.empty[PathRef] } | ||
|
||
/** | ||
* Control whether `run*`-targets should use an args file to pass command line args, if possible. | ||
*/ | ||
def runUseArgsFile: T[Boolean] = T { scala.util.Properties.isWin } | ||
|
||
// def zincWorker: ModuleRef[ZincWorkerModule] = ModuleRef(mill.scalalib.ZincWorkerModule) | ||
|
||
} |
Oops, something went wrong.