Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for testing IIncrementalGenerator #952

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mhutch
Copy link
Member

@mhutch mhutch commented Jan 20, 2022

Draft for now as I'm not certain this is the right approach or whether it's okay to increase the version of the Roslyn dependency.

Fixes #941.

{
public static class IncrementalGeneratorVerifier
{
public static IncrementalGeneratorVerifier<TIncrementalGenerator> Create<TIncrementalGenerator>()
Copy link
Member

@AraHaan AraHaan Apr 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to make new types (I think), one can add , IIncrementalGenerator, new() to the contraints on the ones already accepting an ISourceGenerator that I see so far.

Let me go to definition dive for all that needs changed.

Copy link
Member

@AraHaan AraHaan Apr 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public class CSharpSourceGeneratorTest<TSourceGenerator, TVerifier> : SourceGeneratorTest<TVerifier>
-         where TSourceGenerator : ISourceGenerator, new()
+         where TSourceGenerator : ISourceGenerator, IIncrementalGenerator, new()
        where TVerifier : IVerifier, new()

In SourceGeneratorTest that is inherited from this change:

  • GetSourceGenerators to return object instead of ISourceGenerator so that way CSharpSourceGeneratorTest would just work with it (have it down cast to object) then have SourceGeneratorTest do a type check then cast operation to ISourceGenerator or to IIncrementalGenerator.
  • CreateGeneratorDriver to be defined as protected abstract GeneratorDriver CreateGeneratorDriver(Project project, ImmutableArray<object> sourceGenerators); (again when using it would need to type check and cast to use the instances).
  • ApplySourceGeneratorAsync to be defined as private async Task<(Project project, ImmutableArray<Diagnostic> diagnostics)> ApplySourceGeneratorAsync(ImmutableArray<object> sourceGenerators, Project project, IVerifier verifier, CancellationToken cancellationToken)
  • VerifySourceGeneratorAsync to be defined as private async Task<ImmutableArray<Diagnostic>> VerifySourceGeneratorAsync(string language, ImmutableArray<object> sourceGenerators, SolutionState testState, Func<ImmutableArray<object>, Project, IVerifier, CancellationToken, Task<(Project project, ImmutableArray<Diagnostic> diagnostics)>> getFixedProject, IVerifier verifier, CancellationToken cancellationToken)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for IIncrementalGenerator
2 participants