提交 6878398e 编写于 作者: B Brett V. Forsgren

make any analyzer exceptions cause IDE tests to fail

also add missing tests around the auto-property analyzer when a getter has
no body
上级 0c730afa
......@@ -199,7 +199,7 @@ public void TestFieldAndPropertyInDifferentParts()
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUseAutoProperty)]
public void TestNotWithFieldWithAttirbute()
public void TestNotWithFieldWithAttribute()
{
TestMissing(
@"class Class { [|[A]int i|]; int P { get { return i; } } }");
......@@ -244,5 +244,17 @@ public void TestWriteInNotInConstructor2()
@"class Class { [|int i|]; public int P { get { return i; } } public Foo() { i = 1; } }",
@"class Class { public int P { get; private set; } public Foo() { P = 1; } }");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUseAutoProperty)]
public void TestAlreadyAutoPropertyWithGetterWithNoBody()
{
TestMissing(@"class Class { public int [|P|] { get; } }");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUseAutoProperty)]
public void TestAlreadyAutoPropertyWithGetterAndSetterWithNoBody()
{
TestMissing(@"class Class { public int [|P|] { get; set; } }");
}
}
}
......@@ -36,7 +36,9 @@ internal override IEnumerable<Diagnostic> GetDiagnostics(TestWorkspace workspace
var provider = providerAndFixer.Item1;
TextSpan span;
var document = GetDocumentAndSelectSpan(workspace, out span);
return DiagnosticProviderTestUtilities.GetAllDiagnostics(provider, document, span);
var allDiagnostics = DiagnosticProviderTestUtilities.GetAllDiagnostics(provider, document, span);
AssertNoAnalyzerExceptionDiagnostics(allDiagnostics);
return allDiagnostics;
}
internal override IEnumerable<Tuple<Diagnostic, CodeFixCollection>> GetDiagnosticAndFixes(TestWorkspace workspace, string fixAllActionId)
......@@ -55,11 +57,25 @@ internal override IEnumerable<Diagnostic> GetDiagnostics(TestWorkspace workspace
using (var testDriver = new TestDiagnosticAnalyzerDriver(document.Project, provider))
{
var diagnostics = testDriver.GetAllDiagnostics(provider, document, span);
AssertNoAnalyzerExceptionDiagnostics(diagnostics);
var fixer = providerAndFixer.Item2;
var ids = new HashSet<string>(fixer.FixableDiagnosticIds);
var dxs = diagnostics.Where(d => ids.Contains(d.Id)).ToList();
return GetDiagnosticAndFixes(dxs, provider, fixer, testDriver, document, span, annotation, fixAllActionId);
}
}
/// <summary>
/// The internal method <see cref="AnalyzerExecutor.IsAnalyzerExceptionDiagnostic(Diagnostic)"/> does
/// essentially this, but due to linked files between projects, this project cannot have internals visible
/// access to the Microsoft.CodeAnalysis project without the cascading effect of many extern aliases, so it
/// is re-implemented here in a way that is potentially overly agressive with the knowledge that if this method
/// starts failing on non-analyzer exception diagnostics, it can be appropriately tuned or re-evaluated.
/// </summary>
private void AssertNoAnalyzerExceptionDiagnostics(IEnumerable<Diagnostic> diagnostics)
{
Assert.Equal(0, diagnostics.Count(diag => diag.Descriptor.CustomTags.Contains(WellKnownDiagnosticTags.AnalyzerException)));
}
}
}
......@@ -177,7 +177,7 @@ NewLines("partial class Class1 \n end class \n partial class Class1 \n ReadOnly
End Sub
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUseAutoProperty)>
Public Sub TestNotWithFieldWithAttirbute()
Public Sub TestNotWithFieldWithAttribute()
TestMissing(
NewLines("class Class1 \n [|<A>dim i as integer|] \n property P as Integer \n get \n return i \n end property \n end class"))
End Sub
......@@ -221,5 +221,10 @@ NewLines("class Class1 \n [|dim i as integer|] \n public property P as Integer \
NewLines("class Class1 \n [|dim i as integer|] \n public property P as Integer \n get \n return i \n end get \n set \n i = value \n end set \n end property \n public sub Foo() \n i = 1 \n end sub \n end class"),
NewLines("class Class1 \n public property P as Integer \n public sub Foo() P = 1 \n end sub \n end class"))
End Sub
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUseAutoProperty)>
Public Sub TestAlreadyAutoProperty()
TestMissing(NewLines("Class Class1 \n Public Property [|P|] As Integer \n End Class"))
End Sub
End Class
End Namespace
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册