-
-
Notifications
You must be signed in to change notification settings - Fork 766
Description
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.
In the first instance I'm raising the issue here as the delta in the project where I'm having this issue is the Refit version, with coverlet.msbuild being the same version as before and working as expected with Refit 5.2.4.
If it's a latent issue with coverlet.msbuild that's just being uncovered by the latest version of Refit, then I can open an issue on the coverlet repo.
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. It might be that there's an MSBuild variable I need to set somewhere to either skip this (I tried skipping the individual file with an ExcludeByFile
filter of **/*.g.cs
but it didn't seem to work).
It looks like this initially skipped detection in my CI jobs (where there is a coverage threshold) because if there are no modules coverlet is reporting 100%/NAN% coverage, which is greater than the threshold so the build passes despite there being no actual coverage data at all. I'll open a separate issue with coverlet for this one, if there isn't already. coverlet-coverage/coverlet#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
Screenshots
N/A