Skip to content

Commit

Permalink
Fix dotnet#1074: AnalyzerTesting: Make the generated syntax trees of …
Browse files Browse the repository at this point in the history
…source generators available
  • Loading branch information
tom-englert committed Mar 25, 2023
1 parent d4e8061 commit af56aa9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ public string TestCode
/// </summary>
public List<Func<Solution, ProjectId, Solution>> SolutionTransforms { get; } = new List<Func<Solution, ProjectId, Solution>>();

/// <summary>
/// Gets the syntax trees generated by the source generators during the test run.
/// </summary>
public ImmutableArray<SyntaxTree> GeneratedTrees { get; private set; } = ImmutableArray<SyntaxTree>.Empty;

/// <summary>
/// Gets or sets the timeout to use when matching expected and actual diagnostics. The default value is 2
/// seconds.
Expand Down Expand Up @@ -1171,6 +1176,8 @@ private protected static bool IsNonLocalDiagnostic(Diagnostic diagnostic)
var driver = CreateGeneratorDriver(project, sourceGenerators, verifier).RunGenerators(compilation, cancellationToken);
var result = driver.GetRunResult();

GeneratedTrees = result.GeneratedTrees;

var updatedProject = project;
foreach (var tree in result.GeneratedTrees)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Microsoft.CodeAnalysis.Testing.AnalyzerTest<TVerifier>.DiagnosticVerifier.set ->
Microsoft.CodeAnalysis.Testing.AnalyzerTest<TVerifier>.DisabledDiagnostics.get -> System.Collections.Generic.List<string>
Microsoft.CodeAnalysis.Testing.AnalyzerTest<TVerifier>.ExpectedDiagnostics.get -> System.Collections.Generic.List<Microsoft.CodeAnalysis.Testing.DiagnosticResult>
Microsoft.CodeAnalysis.Testing.AnalyzerTest<TVerifier>.FormatVerifierMessage(System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.Diagnostics.DiagnosticAnalyzer> analyzers, Microsoft.CodeAnalysis.Diagnostic actual, Microsoft.CodeAnalysis.Testing.DiagnosticResult expected, string message) -> string
Microsoft.CodeAnalysis.Testing.AnalyzerTest<TVerifier>.GeneratedTrees.get -> System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.SyntaxTree>
Microsoft.CodeAnalysis.Testing.AnalyzerTest<TVerifier>.GetNameAndFoldersFromPath(string projectPathPrefix, string path) -> (string fileName, System.Collections.Generic.IEnumerable<string> folders)
Microsoft.CodeAnalysis.Testing.AnalyzerTest<TVerifier>.GetSortedDiagnosticsAsync(Microsoft.CodeAnalysis.Solution solution, System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.Diagnostics.DiagnosticAnalyzer> analyzers, System.Collections.Immutable.ImmutableArray<(Microsoft.CodeAnalysis.Project project, Microsoft.CodeAnalysis.Diagnostic diagnostic)> additionalDiagnostics, Microsoft.CodeAnalysis.Testing.CompilerDiagnostics compilerDiagnostics, Microsoft.CodeAnalysis.Testing.IVerifier verifier, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<System.Collections.Immutable.ImmutableArray<(Microsoft.CodeAnalysis.Project project, Microsoft.CodeAnalysis.Diagnostic diagnostic)>>
Microsoft.CodeAnalysis.Testing.AnalyzerTest<TVerifier>.MarkupOptions.get -> Microsoft.CodeAnalysis.Testing.MarkupOptions
Expand Down

0 comments on commit af56aa9

Please sign in to comment.