Repository navigation
Validate generator diagnostics after incremental updates #82113
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
Merged
+60
−8
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,11 +20,14 @@ | |
| using Roslyn.Test.Utilities.TestGenerators; | ||
| using Roslyn.Utilities; | ||
| using Xunit; | ||
| using Xunit.Abstractions; | ||
| namespace Microsoft.CodeAnalysis.CSharp.Semantic.UnitTests.SourceGeneration | ||
| { | ||
| public class GeneratorDriverTests | ||
| public class GeneratorDriverTests(ITestOutputHelper output) | ||
| : CSharpTestBase | ||
| { | ||
| private readonly ITestOutputHelper _output = output; | ||
|
|
||
| [Fact] | ||
| public void Running_With_No_Changes_Is_NoOp() | ||
| { | ||
|
|
@@ -3891,6 +3894,48 @@ public void Diagnostic_SpanOutsideRange_Incremental() | |
| compilation.VerifyDiagnostics(); | ||
| } | ||
|
|
||
| [Fact] | ||
| [WorkItem("https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1805836")] | ||
| [WorkItem("https://github.com/dotnet/roslyn/issues/82032")] | ||
| public void Diagnostic_SpanOutsideRange_Incremental_Update() | ||
| { | ||
| var source = "class SomewhatLongClassName {}"; | ||
| var parseOptions = TestOptions.RegularPreview; | ||
| Compilation compilation = CreateCompilation(source, options: TestOptions.DebugDll, parseOptions: parseOptions, sourceFileName: "/original"); | ||
| compilation.VerifyDiagnostics(); | ||
|
|
||
| var generator = new PipelineCallbackGenerator(ctx => | ||
| { | ||
| var inputs = ctx.SyntaxProvider.CreateSyntaxProvider( | ||
| static (node, ct) => node.IsKind(SyntaxKind.ClassDeclaration), | ||
| static (ctx, ct) => 0); | ||
| ctx.RegisterSourceOutput(inputs, (ctx, input) => | ||
| { | ||
| var tree = compilation.SyntaxTrees.Single(); | ||
| ctx.ReportDiagnostic(CodeAnalysis.Diagnostic.Create( | ||
| "TEST0001", | ||
| "Test", | ||
| "Test diagnostic", | ||
| DiagnosticSeverity.Warning, | ||
| DiagnosticSeverity.Warning, | ||
| isEnabledByDefault: true, | ||
| warningLevel: 1, | ||
| location: Location.Create(tree, TextSpan.FromBounds(20, 21)))); | ||
| }); | ||
| }).AsSourceGenerator(); | ||
|
|
||
| GeneratorDriver driver = CSharpGeneratorDriver.Create(new[] { generator }, parseOptions: parseOptions); | ||
| driver = driver.RunGeneratorsAndUpdateCompilation(compilation, out compilation, out var diagnostics); | ||
| diagnostics.Verify(Diagnostic("TEST0001", "a").WithLocation(1, 21)); | ||
|
|
||
| source = "class C {}"; | ||
| compilation = compilation.ReplaceSyntaxTree(compilation.SyntaxTrees.Single(), CSharpSyntaxTree.ParseText(source, parseOptions, path: "/original")); | ||
| driver = driver.RunGeneratorsAndUpdateCompilation(compilation, out compilation, out diagnostics); | ||
|
|
||
| VerifyArgumentExceptionDiagnostic(diagnostics.Single(), nameof(PipelineCallbackGenerator), string.Format(CodeAnalysisResources.InvalidDiagnosticLocationReported, "TEST0001", "/original"), "diagnostic"); | ||
| compilation.VerifyDiagnostics(); | ||
| } | ||
|
|
||
| [ConditionalFact(typeof(IsEnglishLocal))] | ||
| [WorkItem("https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1805836")] | ||
| public void Diagnostic_SpanOutsideRange_Incremental_AdditionalLocations() | ||
|
|
@@ -4237,13 +4282,15 @@ static void replace(ref Compilation compilation, CSharpParseOptions parseOptions | |
| } | ||
| } | ||
|
|
||
| private static void VerifyArgumentExceptionDiagnostic( | ||
| private void VerifyArgumentExceptionDiagnostic( | ||
| Diagnostic diagnostic, | ||
| string generatorName, | ||
| string message, | ||
| string parameterName, | ||
| bool initialization = false) | ||
| { | ||
| _output.WriteLine(diagnostic.ToString()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. needed?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was useful to see the stacktrace that customers will see even though we don't validate it in the test obviously |
||
|
|
||
| var expectedMessage = | ||
| #if NET | ||
| $"{message} (Parameter '{parameterName}')"; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.