dotnet/roslyn-sdk

Allow "SkipGeneratedSourcesCheck" for specific generator when a test is using multiple generators

Youssef1313 opened this issue · 5 comments

I have a case where I'm testing two generators in the same test, but I only want to verify the generated sources for one of them.

Currently, there is no way to do so.

@sharwell Is this a reasonable request? If you can suggest an API shape, I can try to implement this.

Can you provide more information about why it doesn't work to just validate both?

Eventually, the incremental testing features should allow selecting and validating the outputs from a specific generator. Those APIs haven't been designed yet though.

@sharwell Scenario:

  • Uno Platform generates C# from XAML via a source generator.
  • CommunityToolkit.Mvvm helps implementing Mvvm pattern and generates observable property by their own source generators.

If I try to use a property generated by Mvvm in XAML file (e.g, in x:Bind), the XAML source generator can't see that info and fails to generate.

I'm working around that by unoplatform/uno#11854. The trick is that I'm adding code to anticipate what will be generated instead of failing. https://github.com/unoplatform/uno/blob/284f2a4401b0efe75ac0ccb0ba31093de7821ba8/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/ThirdPartyGenerators/CommunityToolkitMvvm/MvvmTypeProvider.cs

In tests, I'm referencing both Uno's XAML generator and CommunityToolkit.Mvvm's observable property generator. But it doesn't make sense to test the actual output from CommunityToolkit.Mvvm:

  1. It's not code I care about as long as it compiles properly.
  2. I don't want to have to update the expected output when I update the package version.
  3. It needed unnecessary tweak to CSGenerator that you suggested for some who asked. unoplatform/uno@284f2a4

I don't have any immediate plans to implement this, but I'll keep the use case in mind when we're building the new API to test incrementality.