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

Feature request: add markup to specify supressed/unsuppressed diagnostics #1093

Open
DoctorKrolic opened this issue May 1, 2023 · 0 comments
Labels
Area-MS.CA.Testing Microsoft.CodeAnalysis.Testing

Comments

@DoctorKrolic
Copy link

Right now in order to test diagnostic suppressor it is required to use code instead of more visual markup. It might be a good thing to add a pair of markup rules to express this directly there instead of having to dive into code. Therefore I suggest the following:

  • if a named span ends with ? treat it as suppressed diagnostic name
  • if a named span ends with ! verify that this diagnostic is not suppressed

Consider the following example:

[Fact]
public async Task Test1()
{
    var source = """
        class C
        {
            public string {|#0:Prop|} { get; set; }
            public string {|#1:OtherProp|} { get; set; }
        }
        """;

    await new MyAnalyzerVerifier<MySuppressor>.Test
    {
        TestCode = source,
        ExpectedDiagnostics =
        {
            DiagnosticResult.CompilerWarning("CS8618").WithLocation(0).WithLocation(0).WithIsSuppressed(true)
            DiagnosticResult.CompilerWarning("CS8618").WithLocation(1).WithLocation(1).WithIsSuppressed(false)
        },
        CompilerDiagnostics = CompilerDiagnostics.Warnings
    }.RunAsync();
}

Using proposed rules this test can be simplified to:

[Fact]
public async Task Test1()
{
    var source = """
        class C
        {
            public string {|CS8618?:Prop|} { get; set; }
            public string {|CS8618!:OtherProp|} { get; set; }
        }
        """;

    await new MyAnalyzerVerifier<MySuppressor>.Test
    {
        TestCode = source,
        CompilerDiagnostics = CompilerDiagnostics.Warnings
    }.RunAsync();
}

Not a big deal, just a little quality of life thing.

@sharwell sharwell added the Area-MS.CA.Testing Microsoft.CodeAnalysis.Testing label Jul 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-MS.CA.Testing Microsoft.CodeAnalysis.Testing
Projects
None yet
Development

No branches or pull requests

2 participants