Closed Flash0ver closed 2 years ago
Here are the two verifier classes for an incremental generator: https://github.com/tunnelvisionlabs/language-types/blob/main/test/TunnelVisionLabs.LanguageTypes.SourceGenerator.UnitTests/Verifiers/CSharpSourceGeneratorVerifier%601.cs https://github.com/tunnelvisionlabs/language-types/blob/main/test/TunnelVisionLabs.LanguageTypes.SourceGenerator.UnitTests/Verifiers/CSharpSourceGeneratorVerifier%601%2BTest.cs
Great! Thank you! I'll try it out over next weekend.
And I got my IIncrementalGenerator
tests running.
I didn't know about the combination of
EmptySourceGeneratorProvider
for our CSharpSourceGeneratorTest
derivationGetSourceGenerators()
so that we can AsSourceGenerator()
the IIncrementalGenerator
under testThank you very much @sharwell for the example!
I think it should now be safe to use 4.0.1 on Microsoft.CodeAnalysis.CSharp.Workspaces due to .NET 6 LTS and .NET 5 being close to EOL. Besides I do not think many are using the .NET 5 SDK anymore and are instead using the .NET 6 or newer SDK and targeting .NET 5 making it able to use generators using v4.0.1 of the roslyn packages without issues because they will be using a newer compiler that uses those versions anyway.
For
ISourceGenerator
that were introduced in3.8
, I was able to adopt theMicrosoft.CodeAnalysis.CSharp.SourceGenerators.Testing.[Test-Framework]
package quickly, since I'm also familiar with theAnalyzer
/CodeFix
/CodeRefactoring
variants.Now I would love to see an
IncrementalGenerators
variant. An alternative would be to add support forIIncrementalGenerator
to the already existingSourceGenerators
package, but I guess this is not preferable since the update of the dependencyMicrosoft.CodeAnalysis.CSharp.Workspaces
to4.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 byMicrosoft.CodeAnalysis.Testing
, because the genericCSharpSourceGeneratorVerifier
andCSharpSourceGeneratorTest
types are constrained toISourceGenerator, new()
. I also tried to apply theISourceGenerator
-types from Microsoft.CodeAnalysis.Testing, and then useCSharpSourceGeneratorTest
with a custom IncrementalGenerator-to-SourceGenerator-wrapper. But this approach failed, because the methods of the instance returned by Microsoft.CodeAnalysis.GeneratorExtensions.AsSourceGenerator() throw anInvalidOperationException
with messageThis program location is thought to be unreachable.
. I have just learnt that theCSharpGeneratorDriver
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