Description
I noticed a peculiar behavior; I fire up sbt
from the shell and the first time I collect the coverage with clean;coverage;test;coverageAggregate
I get about 37% coverage on my example project but if I run it again immediately after I get 0% and also for all consecutive runs. I obviously expected to get the same coverage every time.
If I exit sbt
and run coverage again I get the same behavior; first run gives correct coverage but consecutive runs give 0%.
My test project can be found here: https://github.com/olatheander/scala-code-coverage-test
It seems to be a Scala 3 issue, I created an equivalent Scala 2 project and then it worked as expected.
Below is the output of the first run followed by a second run:
sbt:Scala Code Coverage Test> clean;coverage;test;coverageAggregate
[success] Total time: 0 s, completed 18 nov. 2023 13:38:41
[info] Defining ThisBuild / coverageEnabled
[info] The new value will be used by Compile / compile / scalacOptions, libraryDependencies
[info] Reapplying settings...
[info] set current project to Scala Code Coverage Test (in build file:/home/olathe/Git/scala-code-coverage-test/)
[info] compiling 1 Scala source to /home/olathe/Git/scala-code-coverage-test/target/scala-3.3.1/classes ...
[info] compiling 1 Scala source to /home/olathe/Git/scala-code-coverage-test/target/scala-3.3.1/test-classes ...
com.example.MySuite:
+ Person test 0.036s
+ Person test 2 0.0s
[info] Passed: Total 2, Failed 0, Errors 0, Passed 2
[success] Total time: 4 s, completed 18 nov. 2023 13:38:46
[info] Aggregating coverage from subprojects...
[info] Found 1 subproject scoverage data directories [/home/olathe/Git/scala-code-coverage-test/target/scala-3.3.1/scoverage-data]
[info] Generating scoverage reports...
[info] Written Cobertura report [/home/olathe/Git/scala-code-coverage-test/target/scala-3.3.1/coverage-report/cobertura.xml]
[info] Written XML coverage report [/home/olathe/Git/scala-code-coverage-test/target/scala-3.3.1/scoverage-report/scoverage.xml]
[info] Written HTML coverage report [/home/olathe/Git/scala-code-coverage-test/target/scala-3.3.1/scoverage-report/index.html]
[info] Statement coverage.: 37.50%
[info] Branch coverage....: 100.00%
[info] Coverage reports completed
[info] Aggregation complete. Coverage was [37.50]
[error] Coverage is below minimum [37.50% < 70.00%]: Stmt:Total
[info] All done. Coverage was stmt=[37.50%] branch=[100.00%]
[success] Total time: 0 s, completed 18 nov. 2023 13:38:46
sbt:Scala Code Coverage Test> clean;coverage;test;coverageAggregate
[success] Total time: 0 s, completed 18 nov. 2023 13:38:48
[info] Defining ThisBuild / coverageEnabled
[info] The new value will be used by Compile / compile / scalacOptions, libraryDependencies
[info] Reapplying settings...
[info] set current project to Scala Code Coverage Test (in build file:/home/olathe/Git/scala-code-coverage-test/)
[info] compiling 1 Scala source to /home/olathe/Git/scala-code-coverage-test/target/scala-3.3.1/classes ...
[info] compiling 1 Scala source to /home/olathe/Git/scala-code-coverage-test/target/scala-3.3.1/test-classes ...
com.example.MySuite:
+ Person test 0.004s
+ Person test 2 0.0s
[info] Passed: Total 2, Failed 0, Errors 0, Passed 2
[success] Total time: 1 s, completed 18 nov. 2023 13:38:49
[info] Aggregating coverage from subprojects...
[info] Found 1 subproject scoverage data directories [/home/olathe/Git/scala-code-coverage-test/target/scala-3.3.1/scoverage-data]
[info] Generating scoverage reports...
[info] Written Cobertura report [/home/olathe/Git/scala-code-coverage-test/target/scala-3.3.1/coverage-report/cobertura.xml]
[info] Written XML coverage report [/home/olathe/Git/scala-code-coverage-test/target/scala-3.3.1/scoverage-report/scoverage.xml]
[info] Written HTML coverage report [/home/olathe/Git/scala-code-coverage-test/target/scala-3.3.1/scoverage-report/index.html]
[info] Statement coverage.: 0.00%
[info] Branch coverage....: 0.00%
[info] Coverage reports completed
[info] Aggregation complete. Coverage was [0.00]
[error] Coverage is below minimum [0.00% < 70.00%]: Branch:Total
[info] All done. Coverage was stmt=[0.00%] branch=[0.00%]
[success] Total time: 0 s, completed 18 nov. 2023 13:38:49
sbt:Scala Code Coverage Test>
Scala version: 3.3.1
sbt-coverage version: 2.0.9