coverlet-coverage / coverlet

Cross platform code coverage for .NET
MIT License
2.96k stars 386 forks source link

Unable to instrument module, pdb without local source files #1368

Closed X9VoiD closed 2 years ago

X9VoiD commented 2 years ago

Code coverage is reporting less than what it should have, a major module is not instrumented.

[coverlet] Unable to instrument module: /path/to/a/<Library>.dll, pdb without local source files, [/path/to/a/<Library>/<SourceGenerator>.<Namespace>.<GeneratorClass>/GeneratedFile.Generated.cs]

This line is taken from a .binlog as described here.

Seems like coverlet is somehow confused by a source generator? Unfortunately, this is a closed-sourced project for now so I can't share the link to the repo yet. The source generator itself is instrumented and appears in code coverage (source generator is tested), but not the library that used the source generator.

The library has <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles> if that bit of information helps, and the source code is also available, contrary to what the logs are saying.

repo_root/
  gen/
    SourceGenerator
  src/
    Library
    <other libraries and an executable>
  tests/
    Library.Tests  // this is the test project that I passed to `dotnet test`
    <other test projects>

Interestingly, /path/to/a/<Library>/<SourceGenerator>.<Namespace>.<GeneratorClass>/GeneratedFile.Generated.cs is a non-existent file.

MarcoRossignoli commented 2 years ago

Dup/similar issue of https://github.com/coverlet-coverage/coverlet/issues/1364#issuecomment-1194119193

This are the recognized generated name by coverlet...if you're generated file follow this convention heuristic won't skip the module https://github.com/coverlet-coverage/coverlet/blob/master/src/coverlet.core/Helpers/InstrumentationHelper.cs#L473 Bump to last version of coverlet if it doesn't work it's possible that it's not released yet so you can dogfood the nightly build, let me know https://github.com/coverlet-coverage/coverlet#Consume-nightly-build

X9VoiD commented 2 years ago

It's a little bit different though, the code coverage for the whole "Library" assembly is missing, not just the generated files. I am also running dotnet test directly on the .csproj, dotnet test repo_root/tests/Library.Tests/Library.Tests.csproj so it's impossible to "not have access to the source files".

Bump to last version

I'm currently using "Code Coverage" instead of "XPlat Code Coverage" for now so when I get the chance to test out then will do so.

MarcoRossignoli commented 2 years ago

Sorry for similar I meant the reason, coverlet heuristic checks that all source file for a module are available if one is missing the module is skipped, but on main we merge an update to that logic that relax this constraint.

"Code Coverage" collector doesn't need it because based on dynamic coverage(it doesn't rewrite before the run like coverlet and uses .NET profiler) and pdb only.

MarcoRossignoli commented 2 years ago

Sorry for similar I meant the reason, coverlet heuristic checks that all source file for a module are available if one is missing the module is skipped, but on main we merged an update to that logic that relax this constraint.

"CodeCoverage" collectors doesn't need it because based on dynamic coverage (profiler) and pdb only.

I'm going to close because looks like you solved. Feel free to re-open if needed.