CommunityToolkit / dotnet

.NET Community Toolkit is a collection of helpers and APIs that work for all .NET developers and are agnostic of any specific UI platform. The toolkit is maintained and published by Microsoft, and part of the .NET Foundation.
https://docs.microsoft.com/dotnet/communitytoolkit/?WT.mc_id=dotnet-0000-bramin
Other
3k stars 294 forks source link

Coverlet Cannot Cover Module Using MVVM Toolkit #264

Closed will-jj closed 2 years ago

will-jj commented 2 years ago

Describe the bug

With a module containing code generated by the MVVM Toolkit coverage information from Coverlet will not be created.

Regression

No response

Steps to reproduce

1. Create a project using the MVVM toolkit
2. Add a class which uses features from the toolkit & generates code
3. Run  dotnet test /p:CollectCoverage=true
4. Observe that modules without MVVM toolkit have coverage & those with do not

Expected behavior

Expect to observe coverage information of all modules with tests.

Screenshots

No response

IDE and version

VS 2022

IDE version

17.1.3

Nuget packages

Nuget package version(s)

8.0.0-preview3

Additional context

Example repo with action running test here: https://github.com/will-jj/MVVM-Coverage

Coverlet log information here:

[coverlet] Unable to instrument module: C:\x\CoverageIssue\CoverageIssue.Tests\bin\Debug\net6.0-windows\CoverageIssue.dll, pdb without local source files, [C:\x\CoverageIssue\CoverageIssue\CommunityToolkit.Mvvm.SourceGenerators\CommunityToolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator\CoverageIssue.ViewModelUsesObservableProperty.cs]

Help us help you

No, just wanted to report this

Sergio0694 commented 2 years ago

Hey @will-jj, did you open an issue about this in the Coverlet repo? If so we should reference it here too. Also if they confirm this is just an issue with that library we can close this. Thanks! 🙂

will-jj commented 2 years ago

Hi @Sergio0694, they have got back to me and without too much repetition: it is a known issue https://github.com/coverlet-coverage/coverlet/issues/1164

The proposed solution would be to suffix the generated files with .g.cs rather than .cs

Sergio0694 commented 2 years ago

Thank you for linking that issue. I do believe this is technically external, but no harm in using ".g.cs" ourselves too 🙂

will-jj commented 2 years ago

Thanks very much for making the change, I've updated my repo with the build from the PR & it is now providing coverage results.