Skip to content

Coverlet doesn't collect coverage for modules referencing ThisAssembly.* #159

@trympet

Description

@trympet

Describe the Bug

Generated files are not excluded from code coverage, causing Coverlet coverage collection to fail for any module that contains generated sources.

Coverlet error:
TpTrace Verbose: 0 : 22984, 1, 2023/01/09, 18:02:20.108, 21604793925156, datacollector.dll, [coverlet]Unable to instrument module: C:\Users\trym\source\repos\FizzBuzz\bin\FizzBuzz.dll, pdb without local source files, [C:\Users\trym\source\repos\FizzBuzz\src\FizzBuzz\FizzBuzz\ThisAssembly.AssemblyInfo\ThisAssembly.AssemblyInfoGenerator\ThisAssembly.Info.cs]

If the source generator emits files using the g.cs-suffix, Coverlet ignores the file [1], thus, the fix is trivial.

I'd be happy to submit a PR to resolve the issue! 😄

Steps to Reproduce

  1. Create a new NUnit/xUnit test project.
  2. dotnet test /v:q /nologo --results-directory TestResults --logger "trx" --collect:"XPlat Code Coverage" --diag:log.txt
  3. Observe that TestResults\[...]\coverage.cobertura.xml contains no reference to the module under test. Observe the error in log.datacollector[...].txt.

Expected Behavior

The generator should
a) emit files using a g.cs-suffix, or
b) decorate any generated files with the ExcludeFromCodeCoverage-attribute.

Version Info

ThisAssembly.AssemblyInfo version 1.0.10.
coverlet.collector version 3.2.0

Additional Info

[1] - coverlet-coverage/coverlet#1084 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions