scoverage / sbt-scoverage

sbt plugin for scoverage
Apache License 2.0
649 stars 156 forks source link

Package / file exclusion does not work with Scala 3 #525

Closed kyri-petrou closed 3 months ago

kyri-petrou commented 9 months ago

Hi there. There seems that some coverage settings (primarily coverageExcludedPackages and coverageExcludedFiles, but I believe some other ones might be affected) are not working with Scala 3.

The easiest way to reproduce is by cloning the sbt-scoverage-samples repo, adding the following line to build.sbt:

coverageExcludedPackages := ".*"

and then running

sbt coverage +test +coverageReport

This yields the following:

Scala 2:

[success] Total time: 13 s, completed 23 Dec 2023, 12:55:46 pm
[info] Statement coverage.: 100.00%
[info] Branch coverage....: 100.00%
[info] Coverage reports completed

Scala 3:

[info] Statement coverage.: 65.20%
[info] Branch coverage....: 33.33%
[info] Coverage reports completed
ckipp01 commented 9 months ago

Hey @kyri-petrou, this is actually a limitation in the implementation of how coverage works with Scala 3. You can read more about it here. So it'd need to be added upstream in order for this to work.

kyri-petrou commented 9 months ago

@ckipp01 aghh I see. Thanks!

ivanobulo commented 7 months ago

I created an MR to address the issue. It would benefit from the upstream changes, but it is not required. Coverage data can be filtered after it was collected.

mcanlas commented 6 months ago

What is an "MR"?

eschizoid commented 6 months ago

hey @ivanobulo I just tried release 3.4.2-RC1 and I am still unable to exclude packages or files using any of these options:

coverageExcludedPackages := ...
coverageExcludedFile     := ...

Wondering if I could be missing something else?

EDIT: I was able to exclude files and packages passing the filter flags to the compiler options.

thank you so much for the fix 🙂

alberto-spadoni3 commented 5 months ago

Could someone kindly explain me how can i exclude an entire package and all its subpackages from the scoverage report on Scala 3.4? How can i exclude files and packages by passing the filter flags to the compiler options?

eschizoid commented 5 months ago

Could someone kindly explain me how can i exclude an entire package and all its subpackages from the scoverage report on Scala 3.4? How can i exclude files and packages by passing the filter flags to the compiler options?

https://docs.scala-lang.org/overviews/compiler-options/index.html

and i just added this flag:

"-coverage-exclude-files:packages_to_be_excluded"
TonioGela commented 3 months ago

@ckipp01 is upstream now fixed? Can we proceed implementing the fix that passes the proper flag to the compiler?

jozic commented 3 months ago

Scala 3 supports file and class/package exclusions since 3.4.2 scoverage-maven-plugin was updated recently to support Scala 3 compiler flags

https://github.com/scoverage/scoverage-maven-plugin/pull/237

ckipp01 commented 3 months ago

@ckipp01 is upstream now fixed? Can we proceed implementing the fix that passes the proper flag to the compiler?

Yes, I believe this is fixed, but I also haven't been following. Please do submit a PR for it.

TonioGela commented 3 months ago

Scala 3 supports file and class/package exclusions since 3.4.2 scoverage-maven-plugin was updated recently to support Scala 3 compiler flags

scoverage/scoverage-maven-plugin#237

@jozic can you work on a PR for sbt-scoverage too please :D ? I would do that but I assume you're more proficient with it given that you did it for maven :)

jozic commented 3 months ago

@TonioGela @ckipp01 #541