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

Improve Source Generator Test Validation - Validate Generator Output #193

Open
michael-hawker opened this issue Jul 11, 2022 · 1 comment
Labels
Milestone

Comments

@michael-hawker
Copy link
Member

michael-hawker commented Jul 11, 2022

I've fixed this issue locally and created a new analyzer with an improved error message, but I'm not able to write unit tests for that diagnostic error (yet).

This particular test requires you to apply a generator to an assembly, and check symbols in all referenced assemblies. Our unit tests here are, in their current form, lacking the flexibility required to pull this off.

I can do a small refactor and add the flexibility needed to accommodate this and future unit tests for our primary source generator (CommunityToolkit.Labs.Core.SourceGenerators), but it'll take a few more hours of work.

Originally posted by @Arlodotexe in #180 (comment)

As part of #189 I discovered there were cases for the [LabsUITestMethod] was not generating code, this was due to an extra line of filter code when searching for methods. This wasn't caught by our existing tests, as our SG tests are only looking for non-failure state of the roslyn compiler (which means it may not just be outputting code as well) OR a diagnostic failure during compile time.

We need to look at the actual generated output as well to ensure our correct behavior.

I've started doing this in #189 for the [LabsUITestMethod], albeit naively. Initially just checking that there was some output with driver.GetRunResult().GeneratedTrees.Length > 0.

The GeneratedTrees can contain the actual generated source text, as well as a walkable SyntaxTree. I added some basic text comparison on the source for now, but we should take time with this issue to shore this up to be a bit more robust to renaming things for re-use or refactoring. As well as apply this to our other source generator tests for samples/docs.

@michael-hawker michael-hawker added this to the Future milestone Jul 11, 2022
@Arlodotexe
Copy link
Member

Thanks for filing this @michael-hawker.

There's a number of improvements that need to be made to our source generator tests, both functional and semantic. I'll list them out at a later date when I have a bit more time, or on request if this becomes a priority.

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

No branches or pull requests

2 participants