-
Notifications
You must be signed in to change notification settings - Fork 386
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
C# record constructors are not covered when SkipAutoProps is true #1561
Comments
Thanks for reporting. I didn't find time to look into this in detail but I guess the problem is the primary constructor. When there a new C# language features we often need to adapt to them. Especially if it's a feature where the compiler generates a lot of things like with primary constructors. |
@daveMueller @MarcoRossignoli I am not sure whether it is possible to always ignore primary constructors. Maybe the skip auto property solution will be possible. By the way, the current VS2022 preview (Version 17.9.0 Preview 1.1) also shows it as "Not Covered (Lines)" There is a roslyn issue "Primary constructor properties have sequence points but breakpoints can't be placed" which has some additional information. Maybe we should implement this as default behavior.
|
@jlawrence Could you please use the latest coverlet.collector preview from main branch and add ExcludeByAttribute option (see below). This will ignore the primary constructor and generate a coverage.opencover.xml with nuget.config: <?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
<clear />
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
<add key="coverlet-nightly" value="https://pkgs.dev.azure.com/tonerdo/coverlet/_packaging/coverlet-nightly/nuget/v3/index.json" />
</packageSources>
</configuration> coverlet.runsetting: <?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<DataCollectionRunSettings>
<DataCollectors>
<DataCollector friendlyName="XPlat code coverage">
<Configuration>
<SkipAutoProps>true</SkipAutoProps>
<ExcludeByAttribute>Obsolete,GeneratedCodeAttribute,CompilerGeneratedAttribute</ExcludeByAttribute>
</Configuration>
</DataCollector>
</DataCollectors>
</DataCollectionRunSettings>
</RunSettings> |
For |
@Bertk I tried out your solution, but excluding CompilerGeneratedAttribute has the undesired side effect of not covering async methods. Here are steps to reproduce:
|
@jlawrence I see, So you have to wait until @daveMueller will provide a better solution. |
OK I found some time to look into this now. It seems we don't have an issue with primary constructors on What I noticed while analyzing this is that there already is a unit test for this scenario that should have failed our CI build ( TpTrace Verbose: 0 : 5880, 11, 2023/12/22, 08:42:59.352 ... Coverlet.Core.Tests.CoverageTests.SkipRecordWithProperties [SKIP]"}} And a bit deeper in the test log it says it failed for unknown reason, but the build job still succeeds? "TestCase": {
"Id": "f1fa401c-81a1-f20c-97b5-c97033736c40",
"FullyQualifiedName": "Coverlet.Core.Tests.CoverageTests.SkipRecordWithProperties",
"DisplayName": "Coverlet.Core.Tests.CoverageTests.SkipRecordWithProperties",
"ExecutorUri": "executor://xunit/VsTestRunner2/netcoreapp",
"Source": "D:\\a\\1\\s\\artifacts\\bin\\coverlet.core.tests\\debug\\coverlet.core.tests.dll",
"CodeFilePath": null,
"LineNumber": 0,
"Properties": []
},
"Attachments": [],
"Outcome": 3,
"ErrorMessage": "fails reason unknown (no session debug possible)",
"ErrorStackTrace": null,
"DisplayName": "Coverlet.Core.Tests.CoverageTests.SkipRecordWithProperties",
"Messages": [],
"ComputerName": "fv-az902-962",
"Duration": "00:00:00.0010000",
"StartTime": "2023-12-22T08:42:59.3532843+00:00",
"EndTime": "2023-12-22T08:42:59.3532844+00:00",
"Properties": [] @MarcoRossignoli @Bertk Any idea why this test is skipped on CI build? |
@daveMueller I am not sure why the test is skipped but I noticed failed tests of CoverageTests.SkipRecordWithProperties with PR #1570. |
OK thanks, I'll check this again once I'm finalizing the fix. |
Describe the bug
C# record constructors are marked as uncovered whenever SkipAutoProps is true. But if SkipAutoProps is false, the coverage is correct.
To Reproduce
Create a file with a simple record
public record MyRecord(int A);
Create a test that constructs the record
var myRecord = new MyRecord(1);
Minimal Example: https://github.com/jlawrence/coverlet-missing-line-example/tree/main
Expected behavior
The record constructor should be covered regardless of the value of SkipAutoProps.
Actual behavior
Observed behavior: If SkipAutoProps is true, the record constructor will not be covered. If it is false, the record constructor will be covered.
Configuration:
* Coverlet package: "coverlet.collector" Version="6.0.0"
* .NET 8
* Windows 10 x64
The text was updated successfully, but these errors were encountered: