Skip to content

Code coverage stops working if assembly contains interfaces from source generators #1084

Closed
@martincostello

Description

@martincostello

Originally posted as reactiveui/refit#1073

Describe the bug

In a project using Refit 6.0.8 and coverlet.msbuild 3.0.2, upon updating from Refit 5.2.4, code coverage is no longer being collected for the assembly containing Refit interfaces.

Using coverlet's troubleshooting guide here, I narrowed my investigation down to this line of interest:

[coverlet] Unable to instrument module: C:\Coding\Projects\MyProject\tests\MyProject.Tests\bin\debug\net5.0\MyProject.dll, pdb without local source files, [C:\Coding\Projects\MyProject\src\MyProject\InterfaceStubGenerator.Core\Refit.Generator.InterfaceStubGenerator\IMyApi.g.cs]

As there's no file on disk here, that sort of makes sense, but causes an issue as it breaks all code coverage for the project for the sake of the one interface.

I'm guessing this is something to do with the usage of source generators in Refit.

The failure then slipped through several CI jobs for Refit updates until it was noticed due to #1083.

Steps To Reproduce

Clone https://github.com/martincostello/alexa-london-travel and run ./build.ps1.

The build script will eventually output something like this:

+--------+------+--------+--------+
| Module | Line | Branch | Method |
+--------+------+--------+--------+

+---------+------+--------+--------+
|         | Line | Branch | Method |
+---------+------+--------+--------+
| Total   | 100% | 100%   | 100%   |
+---------+------+--------+--------+
| Average | NaN% | NaN%   | NaN%   |
+---------+------+--------+--------+

Example build: https://github.com/martincostello/alexa-london-travel/runs/1869767942?check_suite_focus=true#step:4:78

This seems to be affecting multiple repos I have using Refit, not just this one.

Here's another example: https://github.com/martincostello/alexa-london-travel-site/runs/1870035564?check_suite_focus=true#step:4:160

Expected behavior

Assemblies containing Refit interfaces are instrumented correctly.

For the referenced repository, it should output something like this from build.ps1:

+--------------------+-------+--------+--------+
| Module             | Line  | Branch | Method |
+--------------------+-------+--------+--------+
| LondonTravel.Skill | 99.1% | 94.82% | 97.9%  |
+--------------------+-------+--------+--------+

+---------+-------+--------+--------+
|         | Line  | Branch | Method |
+---------+-------+--------+--------+
| Total   | 99.1% | 94.82% | 97.9%  |
+---------+-------+--------+--------+
| Average | 99.1% | 94.82% | 97.9%  |
+---------+-------+--------+--------+

Example build: https://github.com/martincostello/alexa-london-travel/runs/1869465349?check_suite_focus=true#step:4:80

Metadata

Metadata

Assignees

No one assigned

    Labels

    Priority:0Critical to the releasebugSomething isn't workingenhancementGeneral enhancement request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions