coverlet-coverage / coverlet

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

Code coverage excludes .NET Framework VB projects using portable pdb files #1100

Open mattwildgoose opened 3 years ago

mattwildgoose commented 3 years ago

I've been using coverlet for a while now on a large solution containing many .NET Framework 4.8 projects in both VB and C#. It was all working fine until recently we updated the projects to generate portable pdb files instead of the legacy windows format. Now the coverage data only includes C# projects despite tests being executed for the VB projects.

I've created a repository on github to demonstrate the issue https://github.com/mattwildgoose/CovertletNet48PortablePdbIssue

I believe that the issue lies in InstrumentationHelper.PortablePdbHasLocalSource which iterates over the Documents inside the portable pdb meta data and if it cannot locate the relevant file then it will not instrument the module.

For VB projects compiled on .NET 4.8 it appears that the portable pdb contains a strange empty item (shown below using JetBrains dotPeek) which means the entire module is skipped

image

I don't know enough about the pdb generation to know whether this entry should be there or not (feels like it shouldn't). But is this something that you can account for in coverlet so I'm able to collect coverage data without going back to the legacy pdb format which is Windows only and significantly larger?

daveMueller commented 3 years ago

I opened a ticket at the roslyn repo for this https://github.com/dotnet/roslyn/issues/51611.

What I see is that this entry in the document table still has a language guid. So we could ignore entries that have a empty Name and a VB language guid?

Somewhere in this area: https://github.com/coverlet-coverage/coverlet/blob/master/src/coverlet.core/Helpers/InstrumentationHelper.cs#L168-L182