Skip to content
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

[BUG] Inconsistent filenames with UseSourceLink after .NET 8 #1679

Open
tungi52 opened this issue Jul 29, 2024 · 0 comments · May be fixed by #1681
Open

[BUG] Inconsistent filenames with UseSourceLink after .NET 8 #1679

tungi52 opened this issue Jul 29, 2024 · 0 comments · May be fixed by #1681
Labels
bug Something isn't working Solved The issue is solved and can be closed

Comments

@tungi52
Copy link

tungi52 commented Jul 29, 2024

Describe the bug
Issue is connected to this and partially explained: #1658

From .NET 8 source links are included in the SDK: https://learn.microsoft.com/en-us/dotnet/core/compatibility/sdk/8.0/source-link, https://github.com/dotnet/sourcelink. This means enabling UseSourceLink option results in different filenames compared to previous versions. However if someone has a referenced assembly for a test project which content is fully uncovered filenames could be inconsistent inside a single generated report files. Meaning for example a coverage.cobertura.xml could contain filenames like c:\users\me\...\ProjectA\ClassA.cs and https://github.com/.../ProjectA/ClassA.cs at the same time.

Further problem with this that additional tools like ReportGenerator calculates invalid coverage if filenames are inconsistent through multiple report files.

To Reproduce
Issue can be easily reproduced in a .NET 8 solution if a tesproject has a reference for a covered and non-covered assembly.

Small example can be found here: https://github.com/tungi52/CoverletBug. Running the following command the report XML will be wrong:

dotnet test CoverletBug_net8.sln --collect:"XPlat Code Coverage" --settings TestProject/test.runsettings

Problem is here:

https://github.com/tungi52/CoverletBug/blob/main/TestResults/with_sdk8/coverage.cobertura.xml#L9

https://github.com/tungi52/CoverletBug/blob/main/TestResults/with_sdk8/coverage.cobertura.xml#L25

Expected behavior
Filenames should be consistent inside a single and across multiple report files using the same configuration.

Actual behavior
Filenames are inconsistent inside a single and across multiple a report files with the same configuration. Possible root cause of the error is here: https://github.com/coverlet-coverage/coverlet/blob/master/src/coverlet.core/Coverage.cs#L368 between line 368 and 387. As I mentioned the issue is only reproducable if there is a fully uncovered referenced assembly. The linked code part is exactly shows this problem: if there is no hit for an assembly the source links are not processed and later the physical path will be used.

Configuration (please complete the following information):
Please provide more information on your .NET configuration:
* Coverlet version: v6.0.2, but reproducable with older, .NET 8 compatible versions too
* .NET version: v8.0.303
* OS: Windows 11; Alpine linux
* Architecture: x64
* I think it is not configuration specific issue

Additional context
There was a small discussion here: #1658

❗ Please also read Known Issues

@github-actions github-actions bot added the untriaged To be investigated label Jul 29, 2024
@tungi52 tungi52 changed the title [BUG] Different filenames with UseSourceLink after .NET 8 [BUG] Inconsistent filenames with UseSourceLink after .NET 8 Jul 29, 2024
@Bertk Bertk added bug Something isn't working and removed untriaged To be investigated labels Aug 2, 2024
Bertk added a commit to Bertk/coverlet that referenced this issue Aug 6, 2024
@Bertk Bertk linked a pull request Aug 6, 2024 that will close this issue
@Bertk Bertk added the Solved The issue is solved and can be closed label Aug 7, 2024
Bertk added a commit to Bertk/coverlet that referenced this issue Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Solved The issue is solved and can be closed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants