Skip to content

Commit 195e199

Browse files
authored
feat: ignore mstest Assert.Fail & Assert.Inconclusive methods (#371)
1 parent e24e463 commit 195e199

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/FluentAssertions.Analyzers.Tests/Tips/MsTestTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@ namespace FluentAssertions.Analyzers.Tests.Tips
88
[TestClass]
99
public class MsTestTests
1010
{
11+
[DataTestMethod]
12+
[AssertionDiagnostic("Assert.Inconclusive({0});")]
13+
[AssertionDiagnostic("Assert.Fail({0});")]
14+
[Implemented]
15+
public void MsTest_NotReportedAsserts_TestAnalyzer(string assertion)
16+
{
17+
DiagnosticVerifier.VerifyDiagnostic(new DiagnosticVerifierArguments()
18+
.WithAllAnalyzers()
19+
.WithSources(GenerateCode.MsTestAssertion(string.Empty, assertion))
20+
.WithPackageReferences(PackageReference.FluentAssertions_6_12_0, PackageReference.MSTestTestFramework_3_1_1)
21+
);
22+
}
23+
1124
[DataTestMethod]
1225
[AssertionDiagnostic("Assert.IsTrue(actual{0});")]
1326
[AssertionDiagnostic("Assert.IsTrue(bool.Parse(\"true\"){0});")]

src/FluentAssertions.Analyzers/Tips/AssertAnalyzer.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ public void AnalyzeMsTestInvocation(OperationAnalysisContext context)
162162
var op = (IInvocationOperation)context.Operation;
163163
if (IsMsTestAssertClass(op.TargetMethod.ContainingType) && !IsMethodExcluded(context.Options, op))
164164
{
165+
if (op.TargetMethod.Name is "Fail" or "Inconclusive" && op.TargetMethod.ContainingType.EqualsSymbol(_msTestsAssertSymbol))
166+
return;
165167
context.ReportDiagnostic(Diagnostic.Create(MSTestsRule, op.Syntax.GetLocation()));
166168
}
167169
}

0 commit comments

Comments
 (0)