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

Incorrect coverage - only one module detected #1322

Closed
klemmchr opened this issue Apr 12, 2022 · 3 comments · Fixed by #1323
Closed

Incorrect coverage - only one module detected #1322

klemmchr opened this issue Apr 12, 2022 · 3 comments · Fixed by #1323
Labels
with repro Issue with repro

Comments

@klemmchr
Copy link

When using the MSBuild collector I get an incorrect coverage result. Coverlet only detects one module while the test project references multiple projects that are being tested.

Here you can find a sample run that shows this issue. The project references can be found here.

@daveMueller
Copy link
Collaborator

Hi @klemmchr and thanks for reporting. I think this is a dup of #1262. The log shows

[coverlet] Unable to instrument module: D:\Repos\MvvmBlazor\src\MvvmBlazor.Tests\bin\Debug\net6.0\MvvmBlazor.Core.dll, pdb without local source files, [D:\Repos\MvvmBlazor\src\MvvmBlazor.Core\MvvmBlazor.CodeGenerators\MvvmBlazor.CodeGenerators.Components.MvvmComponentGenerator\MvvmComponentBase.Generated.cs]

Coverlet skip by default all dlls that don't have a corresponding local source files. For source generators coverlet can't find the source file and thus skips the dll. However, by convention coverlet skips source files with the suffix .g.cs.

So in your MvvmComponentGenerator just change the two lines

context.AddSource(componentClass.Identifier + ".Generated.cs", componentSourceText);
...
context.AddSource(componentClass.Identifier + "T.Generated.cs", genericComponentSourceText);

to

context.AddSource(componentClass.Identifier + ".g.cs", componentSourceText);
...
context.AddSource(componentClass.Identifier + "T.g.cs", genericComponentSourceText);

and it should work.

grafik

@daveMueller daveMueller added waiting for customer Waiting for customer action with repro Issue with repro labels Apr 13, 2022
@klemmchr
Copy link
Author

Thanks for the quick response, I did not expect that this is an issue related to source generators. I changed the file name and while the test itself now runs properly I get a source link error. This probably isn't related to this issue here but maybe you could give me a hint on what the resolution could be. Surely I could also create a new issue if this is desired.

These are the changes I made and this is the failing test run. The stack trace is

The given key '' was not present in the dictionary. [/home/runner/work/MvvmBlazor/MvvmBlazor/src/MvvmBlazor.Tests/MvvmBlazor.Tests.csproj]
   at System.Collections.Generic.Dictionary`2.get_Item(TKey key) [/home/runner/work/MvvmBlazor/MvvmBlazor/src/MvvmBlazor.Tests/MvvmBlazor.Tests.csproj]
   at Coverlet.Core.Coverage.GetSourceLinkUrl(Dictionary`2 sourceLinkDocuments, String document) in /_/src/coverlet.core/Coverage.cs:line 516 [/home/runner/work/MvvmBlazor/MvvmBlazor/src/MvvmBlazor.Tests/MvvmBlazor.Tests.csproj]
   at Coverlet.Core.Coverage.CalculateCoverage() in /_/src/coverlet.core/Coverage.cs:line 379 [/home/runner/work/MvvmBlazor/MvvmBlazor/src/MvvmBlazor.Tests/MvvmBlazor.Tests.csproj]
   at Coverlet.Core.Coverage.GetCoverageResult() in /_/src/coverlet.core/Coverage.cs:line 161 [/home/runner/work/MvvmBlazor/MvvmBlazor/src/MvvmBlazor.Tests/MvvmBlazor.Tests.csproj]
   at Coverlet.MSbuild.Tasks.CoverageResultTask.Execute() in /_/src/coverlet.msbuild.tasks/CoverageResultTask.cs:line 83 [/home/runner/work/MvvmBlazor/MvvmBlazor/src/MvvmBlazor.Tests/MvvmBlazor.Tests.csproj]

I'm building the project with -p:ContinuousIntegrationBuild=true and also set the Deterministic property in the project itself when running in the CI. I validated that those flags are set properly on the latest working build of the feature branch I'm working on.
image

The repository contains three projects of which two are not really supported by Source Link or don't need them. MvvmBlazor.SourceGenerators has no need for them and MvvmBlazor itself is just a glue package that has a dependency on the source generators and MvvmBlazor.Core. Maybe this is the issue but I'm not sure about that.

@daveMueller
Copy link
Collaborator

OK this only happens with the UseSourceLink switch set to true. Maybe you can run your tests without this parameter and meanwhile I try to find some time to debug this. Could really be a new bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
with repro Issue with repro
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants