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 just tried writing unit tests for a DiagnosticSuppressor via Microsoft.CodeAnalysis.Testing, but I have not succeeded.
Although DiagnosticSuppressor does derive from DiagnosticAnalyzer, and with that already inheriting support in the available infrastructure of Microsoft.CodeAnalysis.Testing, I was still unable to get it working.
My approach was to always add a custom DiagnosticAnalyzer which reports all diagnostics defined in the Assert-Phase of the test through a custom collection of DiagnosticResults.
After this Testing-Internal DiagnosticAnalyzer has reported all arranged diagnostics, the DiagnosticSuppressor under test could then suppress these, so that there are no ExpectedDiagnostics left.
But I couldn't really get the Markup-Syntax working, nor manually setting the Location/Span of the arranged diagnostic(s) to be suppressed during the Act-Phase, so that the Assert-Phase can expect zero ExpectedDiagnostics, or at least a set of ExpectedDiagnostics without the previously reported and suppressed DiagnosticResults. Maybe I got something wrong with the Location/TextSpan/Path: the DiagnosticSuppressor did receive the ReportedDiagnostics, but even after invoking ReportSuppression the test still failed with the message "Mismatch between number of diagnostics returned, expected "0" actual "1"".
Perhaps adding such a DiagnosticResult-Collection to the AnalyzerTest`1 or ProjectState (or another suitable type), which is iterated and diagnostics produced from, which are then subject to be passed to the DiagnosticSuppressor under test if supported, would be of great benefit for all authors of analyzers utilizing the might of Microsoft.CodeAnalysis.Testing.
I guess there is also a different perhaps more intuitive approach to be discussed.
The text was updated successfully, but these errors were encountered:
I just tried writing unit tests for a DiagnosticSuppressor via
Microsoft.CodeAnalysis.Testing
, but I have not succeeded.Although
DiagnosticSuppressor
does derive from DiagnosticAnalyzer, and with that already inheriting support in the available infrastructure ofMicrosoft.CodeAnalysis.Testing
, I was still unable to get it working.My approach was to always add a custom
DiagnosticAnalyzer
which reports all diagnostics defined in the Assert-Phase of the test through a custom collection of DiagnosticResults.After this Testing-Internal
DiagnosticAnalyzer
has reported all arranged diagnostics, theDiagnosticSuppressor
under test could then suppress these, so that there are noExpectedDiagnostics
left.But I couldn't really get the Markup-Syntax working, nor manually setting the Location/Span of the arranged diagnostic(s) to be suppressed during the Act-Phase, so that the Assert-Phase can expect zero
ExpectedDiagnostics
, or at least a set ofExpectedDiagnostics
without the previously reported and suppressedDiagnosticResult
s. Maybe I got something wrong with the Location/TextSpan/Path: theDiagnosticSuppressor
did receive theReportedDiagnostics
, but even after invokingReportSuppression
the test still failed with the message "Mismatch between number of diagnostics returned, expected "0" actual "1"
".Perhaps adding such a
DiagnosticResult
-Collection to theAnalyzerTest`1
orProjectState
(or another suitable type), which is iterated and diagnostics produced from, which are then subject to be passed to theDiagnosticSuppressor
under test if supported, would be of great benefit for all authors of analyzers utilizing the might ofMicrosoft.CodeAnalysis.Testing
.I guess there is also a different perhaps more intuitive approach to be discussed.
The text was updated successfully, but these errors were encountered: