提交 2190ca1f 编写于 作者: M Manish Vasani
上级 8813f49a
......@@ -1105,6 +1105,20 @@ void Method()
TestGenericNameCore(source, new AnalyzerWithNoActions(), new CSharpGenericNameAnalyzer());
}
[Fact, WorkItem(4055, "https://github.com/dotnet/roslyn/issues/4055")]
public void TestAnalyzerWithNoSupportedDiagnostics()
{
var source = @"
class MyClass
{
}";
// Ensure that adding a dummy analyzer with no supported diagnostics doesn't bring down entire analysis.
var analyzers = new DiagnosticAnalyzer[] { new AnalyzerWithNoSupportedDiagnostics() };
CreateCompilationWithMscorlib45(source)
.VerifyDiagnostics()
.VerifyAnalyzerDiagnostics(analyzers);
}
private static void TestEffectiveSeverity(
DiagnosticSeverity defaultSeverity,
ReportDiagnostic expectedEffectiveSeverity,
......
......@@ -1685,5 +1685,43 @@ namespace ConsoleApplication1
' See https//github.com/dotnet/roslyn/issues/2980 for details.
TestGenericNameCore(test, CSharpGenericNameAnalyzer.Message, CSharpGenericNameAnalyzer.DiagnosticId, New AnalyzerWithNoActions, New CSharpGenericNameAnalyzer)
End Sub
<Fact, WorkItem(4055, "https://github.com/dotnet/roslyn/issues/4055")>
Public Sub TestAnalyzerWithNoSupportedDiagnostics()
Dim test = <Workspace>
<Project Language="C#" CommonReferences="true">
<Document><![CDATA[
class MyClass
{
}]]>
</Document>
</Project>
</Workspace>
' Ensure that adding a dummy analyzer with no supported diagnostics doesn't bring down entire analysis.
Using workspace = TestWorkspaceFactory.CreateWorkspace(test)
Dim project = workspace.CurrentSolution.Projects.Single()
' Add analyzer
Dim analyzer = New AnalyzerWithNoSupportedDiagnostics()
Dim analyzerReference = New AnalyzerImageReference(ImmutableArray.Create(Of DiagnosticAnalyzer)(analyzer))
project = project.AddAnalyzerReference(analyzerReference)
Dim diagnosticService = New TestDiagnosticAnalyzerService()
Dim incrementalAnalyzer = diagnosticService.CreateIncrementalAnalyzer(workspace)
' Verify available diagnostic descriptors/analyzers
Dim descriptorsMap = diagnosticService.GetDiagnosticDescriptors(project)
Assert.Equal(1, descriptorsMap.Count)
Assert.Equal(0, descriptorsMap.First().Value.Length)
Dim document = project.Documents.Single()
Dim diagnostics = diagnosticService.GetDiagnosticsForSpanAsync(document,
document.GetSyntaxRootAsync().WaitAndGetResult(CancellationToken.None).FullSpan,
CancellationToken.None).WaitAndGetResult(CancellationToken.None)
Assert.Equal(0, diagnostics.Count())
End Using
End Sub
End Class
End Namespace
......@@ -291,6 +291,13 @@ public sealed class AnalyzerWithNoActions : DiagnosticAnalyzer
public override void Initialize(AnalysisContext context) { }
}
[DiagnosticAnalyzer(LanguageNames.CSharp, LanguageNames.VisualBasic)]
public sealed class AnalyzerWithNoSupportedDiagnostics : DiagnosticAnalyzer
{
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; }
public override void Initialize(AnalysisContext context) { }
}
[DiagnosticAnalyzer(LanguageNames.CSharp, LanguageNames.VisualBasic)]
public sealed class AnalyzerThatThrowsInGetMessage : DiagnosticAnalyzer
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册