Description
Problem
Coverlet automatically excludes third-party assemblies from the coverage analysis, since they are usually not interesting to the user. The heuristic for determining if an assembly is a third-party dependency is if any of its source documents does not have a corresponding source file.
(Ref:
coverlet/src/coverlet.core/Helpers/InstrumentationHelper.cs
Lines 125 to 129 in 3ae1976
C# source generators and some F# constructs add source documents to firsrt-party assemblies, causing them to be excluded by this heuristic, and compiler bugs may also trigger this. See e.g. #1084 #1145 #1100 #1297
The C# source generators are handled by identifying them using a best practice that the document names should end in ".g.cs", and similar logic can be added for the other issues. But the source generator naming is but a best practice and not all projects will follow it, and new compiler issues will likely turn up in the future, so this heuristic will continue to cause issues.
Suggested solution
Add a new parameter ExcludeAssembliesWithoutSources
with the values MissingAny
, MissingAll
and None
. MissingAny
is the current behaviour, but MissingAll
would be the new default behaviour to avoid these and future issues with generators. None
would be a new setting to never filter on source files, for those rare cases where it may not make sense. Explicit include/exclude settings would override any filtering from this parameter.
Changing the default to include an assembly in the coverage if at least one source document exist may cause some third-party documents to be included, if the same file name exists in the project being analysed with coverlet (pointed out by @daveMueller). Users affected by this can then either change the setting to MissingAny
to revert to the old behaviour, or explicitly exclude those assemblies.
Coverlet should still have a heuristic to ignore generated source files according to conventions, but now to avoid logging those cases.
(Edit: change parameter name in feature description to ExcludeAssembliesWithoutSources
)