You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've written a diagnostic suppressor that suppresses SA1615 from the StyleCop.Analyzers NuGet package.
I've also written a unit test for the suppressor, but I can't get the diagnostic to trigger in it. I get Mismatch between number of diagnostics returned, expected "1" actual "0".
If I copy the code to a new project with the NuGet package installed, the diagnostic is reported.
namespaceMyCustomDiagnosticSuppressions.Test{usingSystem.Threading.Tasks;usingMicrosoft.CodeAnalysis.CSharp.Testing;usingMicrosoft.CodeAnalysis.Testing;usingMicrosoft.VisualStudio.TestTools.UnitTesting;[TestClass]publicsealedclassSA1615SuppressorTests{[TestMethod]publicasyncTaskShould_Be_Suppressed(){stringtestSourceCode=$$""" namespace TestNamespace { using System; using System.Threading.Tasks; /// <summary> /// Some class. /// </summary> public class TestClass { /// <summary> /// Some method. /// </summary> public async Task TestMethod() => throw new NotSupportedException("Test"); } }""";awaitnewCSharpAnalyzerTest<SA1615Suppressor,DefaultVerifier>{TestState={ReferenceAssemblies=ReferenceAssemblies.Net.Net90.AddPackages([newPackageIdentity("StyleCop.Analyzers","1.2.0-beta.556")]),Sources={testSourceCode},ExpectedDiagnostics={DiagnosticResult.CompilerWarning("SA1615").WithIsSuppressed(true)},},}.RunAsync().ConfigureAwait(false);}}}
Unit test output
Test method MyCustomDiagnosticSuppressions.Test.SA1615SuppressorTests.Should_Be_Suppressed threw exception:
System.InvalidOperationException: Mismatch between number of diagnostics returned, expected "1" actual "0"
Diagnostics:
NONE.
Stack Trace:
DefaultVerifier.Equal[T](T expected, T actual, String message)
AnalyzerTest`1.VerifyDiagnosticResults(IEnumerable`1 actualResults, ImmutableArray`1 analyzers, DiagnosticResult[] expectedResults, IVerifier verifier)
AnalyzerTest`1.VerifyDiagnosticsAsync(EvaluatedProjectState primaryProject, ImmutableArray`1 additionalProjects, DiagnosticResult[] expected, IVerifier verifier, CancellationToken cancellationToken)
AnalyzerTest`1.RunImplAsync(CancellationToken cancellationToken)
AnalyzerTest`1.RunAsync(CancellationToken cancellationToken)
SA1615SuppressorTests.Should_Be_Suppressed() line 34
I've written a diagnostic suppressor that suppresses SA1615 from the StyleCop.Analyzers NuGet package.
I've also written a unit test for the suppressor, but I can't get the diagnostic to trigger in it. I get
Mismatch between number of diagnostics returned, expected "1" actual "0".If I copy the code to a new project with the NuGet package installed, the diagnostic is reported.
Suppressor code
Unit test code
Unit test output
Screenshot showing SA1615 for the test code