Open hilcode opened 5 days ago
The Scoverage design is to write some files to a hardcoded location. Depending on your use case, it can be desirable to run different tests with the same code, e.g. unit tests and integration tests (I use that to collect coverage data for Mill plugins from integration tests, example: https://app.codecov.io/gh/lefou/mill-osgi). But all coverage data for a specific class will be written to the same location. Hence, it's not possible or meaningful to directly couple it to a specific set of test runs by default.
Each module collects it's own coverage data. To clear all scoverage data, run:
> mill clean __.scoverage.data
To clear just the scoverage data of foo
and bar
, run:
> mill clean "{foo,bar}.scoverage.data"
Until https://github.com/com-lihaoyi/mill/issues/3898 is implemented, there is no easy way to run the cleanup task and the test and coverage task in one run. You could use a evaluator command though, but that's beyond a simple one-liner.
[For multi module builds]
I have noticed that tests and their coverage data are not kept (entirely) in sync. If a Scala file disappears (by going back to an older commit, for example), the coverage still refers to that file, and the build breaks. Similarly, you will not necessarily get the correct coverage numbers (
scoverage.consoleReportAll
) when (re)running tests (especially after test failures, I have noticed).I "solve" this by running a script that removes all
scoverage
directories underout
. This works but it is obviously not efficient. What Mill target/task should be called before running, say,foo.test
? Or which file/directory (underout
) should be removed prior to runningfoo.test
?Again, this is for multi module builds. I get the impression that for single module builds things work correctly (with
scoverage.consoleReport
).In a project with
foo
andbar
modules, it seems that iffoo.test
must run thenout/foo/scoverage
should be removed. And only if eitherfoo.test
orbar.test
were run thenout/scoverage
should be removed as well.I found no obvious way to find the correct
out/foo/scoverage
directory when running thetestTask
task, is there? I would prefer not to have to hardcode it. Ditto forout/scoverage
.It was quite simple to add
"__.testCached"
toreportTask
(called byscoverage.consoleReportAll
), very similar to"__.allSources"
and"__.scoverage.data"
that are already there. But how would I know that at least 1 of them (i.e.foo.testCached
orbar.testCached
) actually caused tests to be run (indicating that I should removeout/scoverage
prior to callingconsoleReportAll
?The below
build.mill
illustrates what I have managed to create so far.Main questions:
out
to delete, without hardcoding it? Or is there some sort ofinvalidate
task?testCached
targets actually ran any tests?There are also these files:
bar/src/main/scala/org/example/Bar.scala
bar/src/test/scala/org/example/BarTest.scala
foo/src/main/scala/org/example/Foo.scala
foo/src/test/scala/org/example/FooTest.scala
that I will leave to your imagination.