From 5a6dca9faba7afaf3cc389f7a75dce9ded0cd8ef Mon Sep 17 00:00:00 2001 From: Fredric Silberberg Date: Mon, 30 Dec 2024 11:18:33 -0800 Subject: [PATCH] Add output compilation verification --- .../Test/Semantic/SourceGeneration/GeneratorDriverTests.cs | 4 +++- .../Test/Semantic/SourceGeneration/GeneratorDriverTests.vb | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Compilers/CSharp/Test/Semantic/SourceGeneration/GeneratorDriverTests.cs b/src/Compilers/CSharp/Test/Semantic/SourceGeneration/GeneratorDriverTests.cs index 0474ac461cf45..7c4742331b40a 100644 --- a/src/Compilers/CSharp/Test/Semantic/SourceGeneration/GeneratorDriverTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/SourceGeneration/GeneratorDriverTests.cs @@ -2464,7 +2464,7 @@ class C { } })); GeneratorDriver driver = CSharpGeneratorDriver.Create([generator], parseOptions: parseOptions, driverOptions: TestOptions.GeneratorDriverOptions); - driver = driver.RunGenerators(compilation); + driver = driver.RunGeneratorsAndUpdateCompilation(compilation, out var outputCompilation, out _); var runResult = driver.GetRunResult().Results[0]; Assert.Single(runResult.GeneratedSources); @@ -2480,6 +2480,8 @@ internal sealed partial class EmbeddedAttribute : global::System.Attribute } """, generatedSource.SourceText.ToString()); Assert.Equal("Microsoft.CodeAnalysis.EmbeddedAttribute.cs", generatedSource.HintName); + + outputCompilation.VerifyDiagnostics(); } [Fact] diff --git a/src/Compilers/VisualBasic/Test/Semantic/SourceGeneration/GeneratorDriverTests.vb b/src/Compilers/VisualBasic/Test/Semantic/SourceGeneration/GeneratorDriverTests.vb index ccb85fc269b5e..d03d308196d16 100644 --- a/src/Compilers/VisualBasic/Test/Semantic/SourceGeneration/GeneratorDriverTests.vb +++ b/src/Compilers/VisualBasic/Test/Semantic/SourceGeneration/GeneratorDriverTests.vb @@ -646,7 +646,9 @@ End Class End Sub)) Dim driver As GeneratorDriver = VisualBasicGeneratorDriver.Create(ImmutableArray.Create(Of ISourceGenerator)(generator), parseOptions:=parseOptions, driverOptions:=TestOptions.GeneratorDriverOptions) - driver = driver.RunGenerators(compilation) + Dim outputCompilation As Compilation = Nothing + Dim diagnostics As ImmutableArray(Of Diagnostic) = Nothing + driver = driver.RunGeneratorsAndUpdateCompilation(compilation, outputCompilation, diagnostics) Dim runResult = driver.GetRunResult().Results(0) Assert.Single(runResult.GeneratedSources) @@ -659,6 +661,8 @@ End Class End Class End Namespace", generatedSource.SourceText.ToString()) Assert.Equal("Microsoft.CodeAnalysis.EmbeddedAttribute.vb", generatedSource.HintName) + + outputCompilation.VerifyDiagnostics() End Sub