dotnet / roslyn-sdk

Roslyn-SDK templates and Syntax Visualizer
MIT License
509 stars 258 forks source link

Ability to access new state after SourceGeneratorTest.RunAsync #980

Closed HavenDV closed 2 years ago

HavenDV commented 2 years ago

This is useful for cases where the project uses TestBehaviors.SkipGeneratedSourcesCheck and it is not possible to use TestState.GeneratedSources due to frequent generator changes. But programmatic access in such cases allows you to handle the erroneous case and, for example, display erroneous GeneratedTrees as temporary files with correct code highlighting, and not in tests. I think this requires access to the GeneratorDriver obtained after calling RunGenerators.

HavenDV commented 2 years ago

This would also add compatibility with https://github.com/VerifyTests/Verify.SourceGenerators, which is much more convenient in terms of validating Snapshot tests, but not convenient in setting state, especially when it comes to managing references

sharwell commented 2 years ago

I believe the WRITE_EXPECTED directive here achieves the desired outcome: https://github.com/microsoft/vs-extension-testing/blob/main/src/Microsoft.VisualStudio.Extensibility.Testing.SourceGenerator.UnitTests/Verifiers/CSharpSourceGeneratorVerifier%601%2BTest.cs