Open jmarolf opened 2 years ago
This is not implemented yet due to the testing apis using older versions of the roslyn packages.
Alternatively one could add new libraries for testing incremental generators:
IncrementalGeneratorVerifier
(a new verifier)CSharpIncrementalGeneratorTest
CSharpIncrementalGeneratorVerifier
As for integrating with the existing testers new packages for those can be added as well which depends on these additional projects, but have these depend on roslyn 4.0.1 (so it does not break those who test source generator v1 apis).
I even have a local implementation of the above too that I will post below that can be pull requested in by someone here (all you have to do is place them in the required namespaces):
public class CSharpIncrementalGeneratorTest<TSourceGenerator, TVerifier> : SourceGeneratorTest<TVerifier>
where TSourceGenerator : IIncrementalGenerator, new()
where TVerifier : IVerifier, new()
{
protected override IEnumerable<ISourceGenerator> GetSourceGenerators()
=> new[] { new TSourceGenerator().AsSourceGenerator() };
protected override string DefaultFileExt => "cs";
public override string Language => LanguageNames.CSharp;
protected override GeneratorDriver CreateGeneratorDriver(Project project, ImmutableArray<ISourceGenerator> sourceGenerators)
{
return CSharpGeneratorDriver.Create(
sourceGenerators,
project.AnalyzerOptions.AdditionalFiles,
(CSharpParseOptions)project.ParseOptions!,
project.AnalyzerOptions.AnalyzerConfigOptionsProvider);
}
protected override CompilationOptions CreateCompilationOptions()
=> new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, allowUnsafe: true);
protected override ParseOptions CreateParseOptions()
=> new CSharpParseOptions(LanguageVersion.Default, DocumentationMode.Diagnose);
}
public class CSharpIncrementalGeneratorVerifier<TSourceGenerator, TVerifier> : IncrementalGeneratorVerifier<TSourceGenerator, CSharpIncrementalGeneratorTest<TSourceGenerator, TVerifier>, TVerifier>
where TSourceGenerator : IIncrementalGenerator, new()
where TVerifier : IVerifier, new()
{
}
/// <summary>A default verifier for incremental source generators.</summary>
/// <typeparam name="TSourceGenerator">The <see cref="T:Microsoft.CodeAnalysis.IIncrementalGenerator" /> to test.</typeparam>
/// <typeparam name="TTest">The test implementation to use.</typeparam>
/// <typeparam name="TVerifier">The type of verifier to use.</typeparam>
public class IncrementalGeneratorVerifier<TSourceGenerator, TTest, TVerifier>
where TSourceGenerator : IIncrementalGenerator, new()
where TTest : SourceGeneratorTest<TVerifier>, new()
where TVerifier : IVerifier, new()
{
}
In the topic of Microsoft.CodeAnalysis.CSharp.Analyzer.Testing.MSTest - when can we expect new version published?
@stan-sz My recommendation would be to reference it from the feed where each new build is published. This is what we do for our own open-source projects. There's a bunch of manual overhead for attempting to prepare a NuGet release from this repository, so they tend to be infrequent (it's more complicated than other projects for release due to the way it's tied in with the internal signed build pipelines, and there isn't any overlap between the people who can publish it to NuGet and the people who work in this repository regularly).
Discussed in https://github.com/dotnet/roslyn/discussions/58345