Skip to content

Commit f4a000b

Browse files
committed
Separate testing of SA1600 and CS1591
1 parent 2d94e50 commit f4a000b

File tree

2 files changed

+50
-52
lines changed

2 files changed

+50
-52
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/InheritdocCodeFixProviderUnitTests.cs

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class InheritdocCodeFixProviderUnitTests
2020
{
2121
private static readonly DiagnosticDescriptor SA1600 = new SA1600ElementsMustBeDocumented().SupportedDiagnostics[0];
2222
private static readonly DiagnosticDescriptor CS1591 =
23-
new DiagnosticDescriptor(nameof(CS1591), "Title", "Missing XML comment for publicly visible type or member '{0}'", "Category", DiagnosticSeverity.Error, AnalyzerConstants.EnabledByDefault);
23+
new DiagnosticDescriptor(nameof(CS1591), "Title", "Missing XML comment for publicly visible type or member '{0}'", "Category", DiagnosticSeverity.Warning, AnalyzerConstants.EnabledByDefault);
2424

2525
[Theory]
2626
[InlineData(false, null, "string TestMember { get; set; }")]
@@ -83,12 +83,7 @@ public override {memberData}
8383
},
8484
};
8585

86-
if (compilerWarning)
87-
{
88-
test.DisabledDiagnostics.Add(SA1600.Id);
89-
test.SolutionTransforms.Add(SetCompilerDocumentationWarningToError);
90-
}
91-
86+
test.DisabledDiagnostics.Add(compilerWarning ? SA1600.Id : CS1591.Id);
9287
await test.RunAsync(CancellationToken.None).ConfigureAwait(false);
9388
}
9489

@@ -153,12 +148,7 @@ public class ChildClass : IParent
153148
},
154149
};
155150

156-
if (compilerWarning)
157-
{
158-
test.DisabledDiagnostics.Add(SA1600.Id);
159-
test.SolutionTransforms.Add(SetCompilerDocumentationWarningToError);
160-
}
161-
151+
test.DisabledDiagnostics.Add(compilerWarning ? SA1600.Id : CS1591.Id);
162152
await test.RunAsync(CancellationToken.None).ConfigureAwait(false);
163153
}
164154

@@ -193,6 +183,7 @@ public class ChildClass : ParentClass
193183
Diagnostic(SA1600).WithLocation(10, 14),
194184
Diagnostic(SA1600).WithLocation(12, 35),
195185
},
186+
DisabledDiagnostics = { CS1591.Id },
196187
FixedCode = testCode,
197188
NumberOfIncrementalIterations = 1,
198189
NumberOfFixAllIterations = 1,
@@ -230,21 +221,11 @@ public class ChildClass : ParentClass
230221
Diagnostic(SA1600).WithLocation(10, 14),
231222
Diagnostic(SA1600).WithLocation(12, 35),
232223
},
224+
DisabledDiagnostics = { CS1591.Id },
233225
FixedCode = testCode,
234226
NumberOfIncrementalIterations = 1,
235227
NumberOfFixAllIterations = 1,
236228
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
237229
}
238-
239-
private static Solution SetCompilerDocumentationWarningToError(Solution solution, ProjectId projectId)
240-
{
241-
var project = solution.GetProject(projectId);
242-
243-
// update the project compilation options
244-
var modifiedSpecificDiagnosticOptions = project.CompilationOptions.SpecificDiagnosticOptions.SetItem(CS1591.Id, ReportDiagnostic.Error);
245-
var modifiedCompilationOptions = project.CompilationOptions.WithSpecificDiagnosticOptions(modifiedSpecificDiagnosticOptions);
246-
247-
return solution.WithProjectCompilationOptions(projectId, modifiedCompilationOptions);
248-
}
249230
}
250231
}

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1600UnitTests.cs

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -613,14 +613,18 @@ public Test2(int param1, bool param2)
613613
}
614614
";
615615

616-
DiagnosticResult[] expectedResults =
616+
await new CSharpTest(this.LanguageVersion)
617617
{
618-
Diagnostic().WithLocation(7, 12),
619-
Diagnostic().WithLocation(11, 12),
620-
Diagnostic().WithLocation(21, 12),
621-
};
622-
623-
await VerifyCSharpFixAsync(this.LanguageVersion, testCode, expectedResults, fixedTestCode, CancellationToken.None).ConfigureAwait(false);
618+
TestCode = testCode,
619+
ExpectedDiagnostics =
620+
{
621+
Diagnostic().WithLocation(7, 12),
622+
Diagnostic().WithLocation(11, 12),
623+
Diagnostic().WithLocation(21, 12),
624+
},
625+
FixedCode = fixedTestCode,
626+
DisabledDiagnostics = { "CS1591" },
627+
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
624628
}
625629

626630
/// <summary>
@@ -657,12 +661,16 @@ public class TestClass
657661
}
658662
";
659663

660-
DiagnosticResult[] expectedResults =
664+
await new CSharpTest(this.LanguageVersion)
661665
{
662-
Diagnostic().WithLocation(7, 6),
663-
};
664-
665-
await VerifyCSharpFixAsync(this.LanguageVersion, testCode, expectedResults, fixedTestCode, CancellationToken.None).ConfigureAwait(false);
666+
TestCode = testCode,
667+
ExpectedDiagnostics =
668+
{
669+
Diagnostic().WithLocation(7, 6),
670+
},
671+
FixedCode = fixedTestCode,
672+
DisabledDiagnostics = { "CS1591" },
673+
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
666674
}
667675

668676
/// <summary>
@@ -689,13 +697,17 @@ public int DoSomething2()
689697
}
690698
";
691699

692-
DiagnosticResult[] expectedResults =
700+
await new CSharpTest(this.LanguageVersion)
693701
{
694-
Diagnostic().WithLocation(7, 17),
695-
Diagnostic().WithLocation(11, 16),
696-
};
697-
698-
await VerifyCSharpFixAsync(this.LanguageVersion, testCode, expectedResults, testCode, CancellationToken.None).ConfigureAwait(false);
702+
TestCode = testCode,
703+
ExpectedDiagnostics =
704+
{
705+
Diagnostic().WithLocation(7, 17),
706+
Diagnostic().WithLocation(11, 16),
707+
},
708+
FixedCode = testCode,
709+
DisabledDiagnostics = { "CS1591" },
710+
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
699711
}
700712

701713
/// <summary>
@@ -820,17 +832,21 @@ public Task<T> TestMethod6<T>(T param1, int param2)
820832
}}
821833
";
822834

823-
DiagnosticResult[] expectedResults =
835+
await new CSharpTest(this.LanguageVersion)
824836
{
825-
Diagnostic().WithLocation(9, 17),
826-
Diagnostic().WithLocation(14, 22),
827-
Diagnostic().WithLocation(19, 20),
828-
Diagnostic().WithLocation(24, 17),
829-
Diagnostic().WithLocation(29, 22),
830-
Diagnostic().WithLocation(34, 20),
831-
};
832-
833-
await VerifyCSharpFixAsync(this.LanguageVersion, testCode, expectedResults, fixedTestCode, CancellationToken.None).ConfigureAwait(false);
837+
TestCode = testCode,
838+
ExpectedDiagnostics =
839+
{
840+
Diagnostic().WithLocation(9, 17),
841+
Diagnostic().WithLocation(14, 22),
842+
Diagnostic().WithLocation(19, 20),
843+
Diagnostic().WithLocation(24, 17),
844+
Diagnostic().WithLocation(29, 22),
845+
Diagnostic().WithLocation(34, 20),
846+
},
847+
FixedCode = fixedTestCode,
848+
DisabledDiagnostics = { "CS1591" },
849+
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
834850
}
835851

836852
protected async Task TestTypeDeclarationDocumentationAsync(string type, string modifiers, bool requiresDiagnostic, bool hasDocumentation)
@@ -1333,6 +1349,7 @@ public class OuterClass
13331349
{
13341350
TestCode = string.Format(hasDocumentation ? testCodeWithDocumentation : testCodeWithoutDocumentation, modifiers),
13351351
Settings = testSettings,
1352+
DisabledDiagnostics = { "CS1591" },
13361353
};
13371354

13381355
if (requiresDiagnostic)

0 commit comments

Comments
 (0)