Skip to content

Commit 48c7c73

Browse files
committed
Remove non incremental generator paths from unit tests
1 parent 2428765 commit 48c7c73

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

tests/CommunityToolkit.Mvvm.SourceGenerators.UnitTests/Test_SourceGeneratorsDiagnostics.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ private void GreetUser(User user)
561561
/// <param name="source">The input source to process.</param>
562562
/// <param name="diagnosticsIds">The diagnostic ids to expect for the input source code.</param>
563563
private static void VerifyGeneratedDiagnostics<TGenerator>(string source, params string[] diagnosticsIds)
564-
where TGenerator : class, new()
564+
where TGenerator : class, IIncrementalGenerator, new()
565565
{
566566
VerifyGeneratedDiagnostics<TGenerator>(CSharpSyntaxTree.ParseText(source), diagnosticsIds);
567567
}
@@ -573,7 +573,7 @@ private static void VerifyGeneratedDiagnostics<TGenerator>(string source, params
573573
/// <param name="syntaxTree">The input source tree to process.</param>
574574
/// <param name="diagnosticsIds">The diagnostic ids to expect for the input source code.</param>
575575
private static void VerifyGeneratedDiagnostics<TGenerator>(SyntaxTree syntaxTree, params string[] diagnosticsIds)
576-
where TGenerator : class, new()
576+
where TGenerator : class, IIncrementalGenerator, new()
577577
{
578578
Type observableObjectType = typeof(ObservableObject);
579579
Type validationAttributeType = typeof(ValidationAttribute);
@@ -590,12 +590,9 @@ from assembly in AppDomain.CurrentDomain.GetAssemblies()
590590
references,
591591
new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
592592

593-
GeneratorDriver driver = new TGenerator() switch
594-
{
595-
ISourceGenerator generator => CSharpGeneratorDriver.Create(generator).WithUpdatedParseOptions((CSharpParseOptions)syntaxTree.Options),
596-
IIncrementalGenerator incrementalGenerator => CSharpGeneratorDriver.Create(incrementalGenerator).WithUpdatedParseOptions((CSharpParseOptions)syntaxTree.Options),
597-
_ => throw new ArgumentException("Invalid generator type", nameof(TGenerator))
598-
};
593+
IIncrementalGenerator generator = new TGenerator();
594+
595+
GeneratorDriver driver = CSharpGeneratorDriver.Create(generator).WithUpdatedParseOptions((CSharpParseOptions)syntaxTree.Options);
599596

600597
_ = driver.RunGeneratorsAndUpdateCompilation(compilation, out Compilation outputCompilation, out ImmutableArray<Diagnostic> diagnostics);
601598

0 commit comments

Comments
 (0)