Skip to content

New parameter ExcludeAssembliesWithoutSources to control automatic assembly exclusion #1164

Closed
@petli

Description

@petli

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:

// We verify all docs and return false if not all are present in local
// We could have false negative if doc is not a source
// Btw check for all possible extension could be weak approach
// We exlude from the check the autogenerated source file(i.e. source generators)
if (!_fileSystem.Exists(docName) && !docName.EndsWith(".g.cs"))
)

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)

Metadata

Metadata

Assignees

Labels

Priority:1Very important to release, not a ship blockerfeature-requestNew feature request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions