Skip to content

Commit e7306b5

Browse files
committed
Fix tests for C# 9
1 parent 94efd2f commit e7306b5

6 files changed

Lines changed: 52 additions & 15 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/DocumentationRules/SA1600CSharp9UnitTests.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,29 @@
33

44
namespace StyleCop.Analyzers.Test.CSharp9.DocumentationRules
55
{
6+
using Microsoft.CodeAnalysis.Testing;
67
using StyleCop.Analyzers.Test.CSharp8.DocumentationRules;
78

89
public class SA1600CSharp9UnitTests : SA1600CSharp8UnitTests
910
{
11+
protected override DiagnosticResult[] GetExpectedResultTestRegressionMethodGlobalNamespace(string code, int column)
12+
{
13+
if (code == "public void TestMember() { }" && column == 13)
14+
{
15+
return new[]
16+
{
17+
// error CS8805: Program using top-level statements must be an executable.
18+
DiagnosticResult.CompilerError("CS8805"),
19+
20+
// /0/Test0.cs(4,1): error CS0106: The modifier 'public' is not valid for this item
21+
DiagnosticResult.CompilerError("CS0106").WithSpan(4, 1, 4, 7).WithArguments("public"),
22+
23+
// /0/Test0.cs(4,1): error CS8652: The feature 'top-level statements' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version.
24+
DiagnosticResult.CompilerError("CS8652").WithSpan(4, 1, 4, 29).WithArguments("top-level statements"),
25+
};
26+
}
27+
28+
return base.GetExpectedResultTestRegressionMethodGlobalNamespace(code, column);
29+
}
1030
}
1131
}

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,7 @@ public async Task TestRegressionMethodGlobalNamespaceAsync(string code, int colu
3434
3535
{code}";
3636

37-
DiagnosticResult[] expected =
38-
{
39-
DiagnosticResult.CompilerError("CS0116").WithMessage("A namespace cannot directly contain members such as fields or methods").WithLocation(4, column),
40-
Diagnostic().WithLocation(4, column),
41-
};
42-
37+
var expected = this.GetExpectedResultTestRegressionMethodGlobalNamespace(code, column);
4338
await VerifyCSharpDiagnosticAsync(this.LanguageVersion, testCode, expected, CancellationToken.None).ConfigureAwait(false);
4439
}
4540

@@ -1389,6 +1384,15 @@ public class OuterClass
13891384
await VerifyCSharpDiagnosticAsync(this.LanguageVersion, string.Format(hasDocumentation ? testCodeWithDocumentation : testCodeWithoutDocumentation, modifiers), requiresDiagnostic ? expected : DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
13901385
}
13911386

1387+
protected virtual DiagnosticResult[] GetExpectedResultTestRegressionMethodGlobalNamespace(string code, int column)
1388+
{
1389+
return new[]
1390+
{
1391+
DiagnosticResult.CompilerError("CS0116").WithMessage("A namespace cannot directly contain members such as fields or methods").WithLocation(4, column),
1392+
Diagnostic().WithLocation(4, column),
1393+
};
1394+
}
1395+
13921396
protected virtual async Task TestTypeWithoutDocumentationAsync(string type, bool isInterface)
13931397
{
13941398
await this.TestTypeDeclarationDocumentationAsync(type, string.Empty, true, false).ConfigureAwait(false);

StyleCop.Analyzers/StyleCop.Analyzers.Test/OrderingRules/SA1201UnitTests.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,11 @@ public string
285285
// We don't care about the syntax errors.
286286
var expected = new[]
287287
{
288-
DiagnosticResult.CompilerError("CS1585").WithLocation(5, 5).WithMessage("Member modifier 'public' must precede the member type and name"),
289-
DiagnosticResult.CompilerError("CS1519").WithLocation(6, 1).WithMessage("Invalid token '}' in class, struct, or interface member declaration"),
288+
// /0/Test0.cs(5,5): error CS1585: Member modifier 'public' must precede the member type and name
289+
DiagnosticResult.CompilerError("CS1585").WithLocation(5, 5).WithArguments("public"),
290+
291+
// /0/Test0.cs(6,1): error CS1519: Invalid token '}' in class, record, struct, or interface member declaration
292+
DiagnosticResult.CompilerError("CS1519").WithLocation(6, 1).WithArguments("}"),
290293
};
291294

292295
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);

StyleCop.Analyzers/StyleCop.Analyzers.Test/OrderingRules/SA1202UnitTests.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -880,8 +880,11 @@ public string
880880
// We don't care about the syntax errors.
881881
var expected = new[]
882882
{
883-
DiagnosticResult.CompilerError("CS1585").WithMessage("Member modifier 'public' must precede the member type and name").WithLocation(5, 5),
884-
DiagnosticResult.CompilerError("CS1519").WithMessage("Invalid token '}' in class, struct, or interface member declaration").WithLocation(6, 1),
883+
// /0/Test0.cs(5,5): error CS1585: Member modifier 'public' must precede the member type and name
884+
DiagnosticResult.CompilerError("CS1585").WithLocation(5, 5).WithArguments("public"),
885+
886+
// /0/Test0.cs(6,1): error CS1519: Invalid token '}' in class, record, struct, or interface member declaration
887+
DiagnosticResult.CompilerError("CS1519").WithLocation(6, 1).WithArguments("}"),
885888
};
886889

887890
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
@@ -905,8 +908,11 @@ public string
905908
// We don't care about the syntax errors.
906909
DiagnosticResult[] expected =
907910
{
908-
DiagnosticResult.CompilerError("CS1585").WithMessage("Member modifier 'public' must precede the member type and name").WithLocation(5, 5),
909-
DiagnosticResult.CompilerError("CS1519").WithMessage("Invalid token '}' in class, struct, or interface member declaration").WithLocation(6, 1),
911+
// /0/Test0.cs(5,5): error CS1585: Member modifier 'public' must precede the member type and name
912+
DiagnosticResult.CompilerError("CS1585").WithLocation(5, 5).WithArguments("public"),
913+
914+
// /0/Test0.cs(6,1): error CS1519: Invalid token '}' in class, record, struct, or interface member declaration
915+
DiagnosticResult.CompilerError("CS1519").WithLocation(6, 1).WithArguments("}"),
910916
};
911917

912918
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);

StyleCop.Analyzers/StyleCop.Analyzers.Test/OrderingRules/SA1204UnitTests.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -545,8 +545,11 @@ public static string
545545
// We don't care about the syntax errors.
546546
DiagnosticResult[] expected =
547547
{
548-
DiagnosticResult.CompilerError("CS1585").WithMessage("Member modifier 'public' must precede the member type and name").WithLocation(5, 5),
549-
DiagnosticResult.CompilerError("CS1519").WithMessage("Invalid token '}' in class, struct, or interface member declaration").WithLocation(6, 1),
548+
// /0/Test0.cs(5,5): error CS1585: Member modifier 'public' must precede the member type and name
549+
DiagnosticResult.CompilerError("CS1585").WithLocation(5, 5).WithArguments("public"),
550+
551+
// /0/Test0.cs(6,1): error CS1519: Invalid token '}' in class, record, struct, or interface member declaration
552+
DiagnosticResult.CompilerError("CS1519").WithLocation(6, 1).WithArguments("}"),
550553
};
551554

552555
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);

StyleCop.Analyzers/StyleCop.Analyzers.Test/OrderingRules/SA1206UnitTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,8 @@ public async Task TestWithIncompleteMembersAsync()
191191

192192
DiagnosticResult[] expected =
193193
{
194-
DiagnosticResult.CompilerError("CS1519").WithMessage("Invalid token '}' in class, struct, or interface member declaration").WithLocation(4, 1),
194+
// /0/Test0.cs(4,1): error CS1519: Invalid token '}' in class, record, struct, or interface member declaration
195+
DiagnosticResult.CompilerError("CS1519").WithSpan(4, 1, 4, 2).WithArguments("}"),
195196
};
196197

197198
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);

0 commit comments

Comments
 (0)