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

Generated source files should end with .g.cs to mark them as autogenerated #18

Closed
jhartmann123 opened this issue Nov 3, 2022 · 1 comment · Fixed by #19
Closed

Generated source files should end with .g.cs to mark them as autogenerated #18

jhartmann123 opened this issue Nov 3, 2022 · 1 comment · Fixed by #19

Comments

@jhartmann123
Copy link
Contributor

Source issue

Long story short: for all our libs that use Expressionify, coverlet does not generate coverage reports anymore. Briefly explained, coverlet does not detect the source generated by Expressionify as generated and won't instrument the assembly, as it doesn't have all the sources.

Why is this an issue with Expressionify?
If the generated source files follow a naming convention, coverlet detects the files as auto generated and magically starts working again. (see coverlet-coverage/coverlet#1084 (comment))

Fix

The file names simply have to end in .g.cs or .generated.cs

This naming convention isn't something random invented by coverlet, but is also hidden in plain sight in multiple docs. Examples:
https://learn.microsoft.com/en-us/dotnet/csharp/roslyn-sdk/source-generators-overview#get-started-with-source-generators
In the tip in point 6:

It's common to provide an explicit C# file extension such as ".g.cs" or ".generated.cs" for the name. The file name helps identify the file as being source generated.

https://learn.microsoft.com/en-us/dotnet/csharp/nullable-references#nullable-contexts
In the "Important"-block

[...]
There are four ways a file is marked as generated:
[...]
4. End the file name with .designer.cs, .generated.cs, .g.cs, or .g.i.cs.

@jhartmann123
Copy link
Contributor Author

Attached a repro:
Expressionify.Coverage.zip

Steps:

  • Run test with dotnet test --collect:"XPlat Code Coverage"
  • At the end of the test run it outputs the path to a coverage.cobertura.xml. It is basically an empty XML at this point.
  • Remove [Expressionify] in Class1.cs
  • Rerun test
  • The new XML now has coverage info.

Debug output of coverlet can be retrieved with dotnet test --collect:"XPlat Code Coverage" --diag:log.txt
With the current version of Expressionify, the datacollector log contains a line
[coverlet]Unable to instrument module: ... Expressionify.Coverage.dll, pdb without local source files

This is fixed once the generated source files end with .g.cs

@jhartmann123 jhartmann123 changed the title Generated source files should be marked as auto generated Generated source files should end with .g.cs to mark them as autogenerated Nov 4, 2022
@slashP slashP closed this as completed in #19 Nov 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant