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

AnalyzerTesting: Make the generated syntax trees of source generators available #1074

Open
tom-englert opened this issue Mar 25, 2023 · 5 comments
Labels
Area-MS.CA.Testing Microsoft.CodeAnalysis.Testing feature-request This issue tracks implementing a new feature

Comments

@tom-englert
Copy link
Contributor

The current approach to test source generators by providing the expected generated code upfront is not very convenient, since the generated sources can be very large, making the test unreadable.

It would be great to support another scenario, where the analyzer test is run with TestBehaviors.SkipGeneratedSourcesCheck, and then the generated sources can be fetched and verified with custom logic, e.g. using https://github.com/VerifyTests/ like in this sample https://github.com/Fody/PropertyChanged/blob/dee9d81bab0202dc2e5d985910072ad6e6c94fa4/PropertyChanged.Fody.Analyzer.Tests/CodeGeneratorTest.cs#L55-L71

tom-englert added a commit to tom-englert/roslyn-sdk that referenced this issue Mar 25, 2023
tom-englert added a commit to tom-englert/roslyn-sdk that referenced this issue Mar 25, 2023
tom-englert added a commit to tom-englert/roslyn-sdk that referenced this issue Mar 25, 2023
@tom-englert tom-englert mentioned this issue Mar 25, 2023
tom-englert added a commit to tom-englert/roslyn-sdk that referenced this issue Mar 25, 2023
tom-englert added a commit to tom-englert/roslyn-sdk that referenced this issue Mar 25, 2023
@tom-englert
Copy link
Contributor Author

Yes, you already can do many things if you dig into the details and rewrite the test framework, but it's very annoying that you need to do this again and again for every test - see #1080

@tom-englert
Copy link
Contributor Author

tom-englert commented Apr 1, 2023

I believe microsoft/vs-extension-testing offers what you are looking for

That example mimics the very basic approach, but not with the full power and comfort of VerifyTests

Also this sample rewrites a big part of the test, and of course depends on the test verifier, so it has to be rewritten for every verifier.

I already know how to do it with a custom written test, I was looking for a solution that runs out of the box, with the default test framework.

@sharwell
Copy link
Member

This is similar to #1087, in that I'm not planning to directly implement it in the short term, but hopefully the future API to test the incrementality of source generators will allow for more direct validation of syntax trees produced by the source generators.

@sharwell sharwell added Area-MS.CA.Testing Microsoft.CodeAnalysis.Testing Feature Request and removed question labels Apr 20, 2023
@tom-englert
Copy link
Contributor Author

@sharwell sharwell added feature-request This issue tracks implementing a new feature and removed Feature Request labels May 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-MS.CA.Testing Microsoft.CodeAnalysis.Testing feature-request This issue tracks implementing a new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants