forked from com-lihaoyi/mill
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Isolate scoverage modules from their parent modules (com-lihaoyi#3118)
## Context I encountered an issue with the way scoverage plugin alters the dependency tree of the test module by changing its module dependency from the `outer` module to the `outer.scoverage` module. This shadow modification of the dependency tree produces a side effect that impacts the IDEA configuration generation. When the IDEA configuration generation resolves the dependencies instead of using the outer module as a dependency for the test project it depends on the `outer.scoverage` module which should not be generated as it does not exist factually but more virtually. ## Solution Instead of modifying the dependency tree at compile-time I change it at runtime by removing the `outer.localRunClasspath()` from the `test.runClasspath()` and appending, instead, the `outer.scoverage.localRunClasspath()` This resolves the issue of modifying the dependency tree but introduces one more compilation as when the `outer.localRunClasspath()` is resolved it will force the compilation of the outer module. In the previous version only the `outer.scoverage` was compiled and not both of them. Pull request: com-lihaoyi#3118
- Loading branch information
1 parent
5023c65
commit a68c09b
Showing
4 changed files
with
107 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import mill._, scalalib._ | ||
import $ivy.`com.lihaoyi::mill-contrib-scoverage:` | ||
|
||
import mill.contrib.scoverage._ | ||
|
||
object foo extends RootModule with ScoverageModule { | ||
def scoverageVersion = "2.1.0" | ||
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 ScoverageTests /*with TestModule.Utest */{ | ||
def ivyDeps = Agg(ivy"com.lihaoyi::utest:0.7.11") | ||
def testFramework = "utest.runner.Framework" | ||
} | ||
} | ||
|
||
// This is a basic Mill build for a single `ScalaModule`, enhanced with | ||
// Scoverage plugin. The root module extends the `ScoverageModule` and | ||
// specifies the version of scoverage version to use here: `2.1.0`. This | ||
// version can be changed if there is a newer one. Now you can call the | ||
// scoverage targets to produce coverage reports. | ||
// The sub test module extends `ScoverageTests` to transform the | ||
// execution of the various testXXX targets to use scoverage and produce | ||
// coverage data. | ||
// This lets us perform the coverage operations but before that you | ||
// must first run the test. | ||
// `./mill test` then `./mill scoverage.consoleReport` and get your | ||
// coverage into your console output. | ||
// | ||
// You can download this example project using the *download* link above | ||
// if you want to try out the commands below yourself. The only requirement is | ||
// that you have some version of the JVM installed; the `./mill` script takes | ||
// care of any further dependencies that need to be downloaded. | ||
|
||
/** Usage | ||
> ./mill test # Run the tests and produce the coverage data | ||
... | ||
+ foo.FooTests.simple ... <h1>hello</h1> | ||
+ foo.FooTests.escaping ... <h1><hello></h1> | ||
> ./mill resolve scoverage._ # List what tasks are available to run from scoverage | ||
... | ||
scoverage.consoleReport | ||
... | ||
scoverage.htmlReport | ||
... | ||
scoverage.xmlCoberturaReport | ||
... | ||
scoverage.xmlReport | ||
... | ||
> ./mill scoverage.consoleReport | ||
... | ||
Statement coverage.: 16.67% | ||
Branch coverage....: 100.00% | ||
*/ |
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) | ||
} |
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 | ||
} | ||
} | ||
} |