You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My solution uses LoggerMessage source generators [[https://learn.microsoft.com/en-us/dotnet/core/extensions/logger-message-generator]].
When I define a class with static field initialization code and I also use LoggerMessageAttribute to generate logger methods, then static init code will be spread across two partial class definition files.
One is from my own code and another one generated by the LoggerMessage.
When I run coverage report I get coverage which includes the source code generated file:
Use the <ExcludeByFile>**/*.g.cs</ExcludeByFile> filter and generate code coverage report.
Expected behavior
DemoTheBug.g.cs file is not listed in code coverage report.
Actual behavior
DemoTheBug.g.cs file is listed in code coverage report
Configuration (please complete the following information):
Please provide more information on your .NET configuration:
* Which coverlet package and version was used? 6.0.0
* Which version of .NET is the code running on? .net 8
* What OS and version, and what distro if applicable? Windows.
* What is the architecture (x64, x86, ARM, ARM64)? x64
* Do you know whether it is specific to that configuration? The issue is not specific to the config.
Additional context
The issues appears in Coverlet.Core.Instrumentation.Instrumenter when instrumenting cctor:
private void InstrumentMethod(MethodDefinition method)
{
string sourceFile = method.DebugInformation.SequencePoints.Select(s => _sourceRootTranslator.ResolveFilePath(s.Document.Url)).FirstOrDefault();
if (string.IsNullOrEmpty(sourceFile)) return;
if (!string.IsNullOrEmpty(sourceFile) && _excludedFilesHelper.Exclude(sourceFile))
{
if (!(_excludedSourceFiles ??= new List<string>()).Contains(sourceFile))
{
_excludedSourceFiles.Add(sourceFile);
}
return;
}
Notice that _sourceRootTranslator.ResolveFilePath(s.Document.Url)).FirstOrDefault(); usually refers to my own source code file, and the _excludedFilesHelper is not going to exclude it, so we will instrument the code by eventually calling:
Notice that _result.Documents.Add(document.Path, document); can point to source code generated file and it will be added to the report, so the ExcludeByFile gets ignored.
The text was updated successfully, but these errors were encountered:
Describe the bug
I would like to exclude source generated code from my coverage report. I use following filter in my runsettingsfile:
My solution uses
LoggerMessage
source generators [[https://learn.microsoft.com/en-us/dotnet/core/extensions/logger-message-generator]].When I define a class with static field initialization code and I also use LoggerMessageAttribute to generate logger methods, then static init code will be spread across two partial class definition files.
One is from my own code and another one generated by the LoggerMessage.
When I run coverage report I get coverage which includes the source code generated file:
Notice that I have specifically excluded code coverage for
**/*.g.cs
files.To Reproduce
Use the
<ExcludeByFile>**/*.g.cs</ExcludeByFile>
filter and generate code coverage report.Expected behavior
DemoTheBug.g.cs file is not listed in code coverage report.
Actual behavior
DemoTheBug.g.cs file is listed in code coverage report
Configuration (please complete the following information):
Please provide more information on your .NET configuration:
* Which coverlet package and version was used? 6.0.0
* Which version of .NET is the code running on? .net 8
* What OS and version, and what distro if applicable? Windows.
* What is the architecture (x64, x86, ARM, ARM64)? x64
* Do you know whether it is specific to that configuration? The issue is not specific to the config.
Additional context
The issues appears in
Coverlet.Core.Instrumentation.Instrumenter
when instrumenting cctor:Notice that
_sourceRootTranslator.ResolveFilePath(s.Document.Url)).FirstOrDefault();
usually refers to my own source code file, and the_excludedFilesHelper
is not going to exclude it, so we will instrument the code by eventually calling:Notice that
_result.Documents.Add(document.Path, document);
can point to source code generated file and it will be added to the report, so theExcludeByFile
gets ignored.The text was updated successfully, but these errors were encountered: