-
Notifications
You must be signed in to change notification settings - Fork 256
Description
For ISourceGenerator that were introduced in 3.8, I was able to adopt the Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing.[Test-Framework] package quickly, since I'm also familiar with the Analyzer/CodeFix/CodeRefactoring variants.
Now I would love to see an IncrementalGenerators variant.
An alternative would be to add support for IIncrementalGenerator to the already existing SourceGenerators package, but I guess this is not preferable since the update of the dependency Microsoft.CodeAnalysis.CSharp.Workspaces to 4.0.1 would be a breaking change for existing consumers.
I built a custom testing helpers (inspired by the Source Generators Cookbook), which are continuously growing (across my source generator projects), but are missing the really powerful features such as ReferenceAssemblies and {|#0:Location|}-Syntax.
I also noticed #933, but if I understand correctly, then IIncrementalGenerator are not suppored by Microsoft.CodeAnalysis.Testing, because the generic CSharpSourceGeneratorVerifier and CSharpSourceGeneratorTest types are constrained to ISourceGenerator, new().
I also tried to apply the ISourceGenerator-types from Microsoft.CodeAnalysis.Testing, and then use CSharpSourceGeneratorTest with a custom IncrementalGenerator-to-SourceGenerator-wrapper. But this approach failed, because the methods of the instance returned by Microsoft.CodeAnalysis.GeneratorExtensions.AsSourceGenerator() throw an InvalidOperationException with message This program location is thought to be unreachable.. I have just learnt that the CSharpGeneratorDriver unwraps that type again and does not use it directly.
Here's a link this failed experiment: https://github.com/Flash0ver/F0.Compatibility/blob/test/microsoft-codeanalysis-testing/src/tests/F0.Compatibility.Generator.Tests/Testing/CSharpIncrementalGeneratorVerifier.Test.cs