Skip to content

Commit c933da1

Browse files
Upgraded the new test project to Microsoft.CodeAnalysis.CSharp.Workspaces version 4.2.0-4.final
1 parent d09a2e2 commit c933da1

File tree

7 files changed

+123
-39
lines changed

7 files changed

+123
-39
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp11/LayoutRules/SA1516CSharp11UnitTests.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,33 @@
55

66
namespace StyleCop.Analyzers.Test.CSharp11.LayoutRules
77
{
8+
using Microsoft.CodeAnalysis.Testing;
89
using StyleCop.Analyzers.Test.CSharp10.LayoutRules;
910

11+
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
12+
StyleCop.Analyzers.LayoutRules.SA1516ElementsMustBeSeparatedByBlankLine,
13+
StyleCop.Analyzers.LayoutRules.SA1516CodeFixProvider>;
14+
1015
public class SA1516CSharp11UnitTests : SA1516CSharp10UnitTests
1116
{
17+
protected override DiagnosticResult[] GetExpectedResultTestUsingAndGlobalStatementSpacingInTopLevelProgram()
18+
{
19+
// NOTE: Roslyn bug fix. Earlier versions made diagnostics be reported twice.
20+
return new[]
21+
{
22+
// /0/Test0.cs(3,1): warning SA1516: Elements should be separated by blank line
23+
Diagnostic().WithLocation(0),
24+
};
25+
}
26+
27+
protected override DiagnosticResult[] GetExpectedResultTestGlobalStatementAndRecordSpacingInTopLevelProgram()
28+
{
29+
// NOTE: Roslyn bug fix. Earlier versions made diagnostics be reported twice.
30+
return new[]
31+
{
32+
// /0/Test0.cs(2,1): warning SA1516: Elements should be separated by blank line
33+
Diagnostic().WithLocation(0),
34+
};
35+
}
1236
}
1337
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp11/MaintainabilityRules/SA1119CSharp11UnitTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,18 @@ namespace StyleCop.Analyzers.Test.CSharp11.MaintainabilityRules
99

1010
public class SA1119CSharp11UnitTests : SA1119CSharp10UnitTests
1111
{
12+
// In earlier Roslyn versions, we ended up with an extra space between the opening brace
13+
// and the identifier. Does not happen anymore.
14+
protected override string GetFixedCodeTestParenthesisInInterpolatedStringThatShouldBeRemoved()
15+
{
16+
return @"class Foo
17+
{
18+
public void Bar()
19+
{
20+
bool flag = false;
21+
string data = $""{flag}"";
22+
}
23+
}";
24+
}
1225
}
1326
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp11/NamingRules/SA1300CSharp11UnitTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,22 @@
55

66
namespace StyleCop.Analyzers.Test.CSharp11.NamingRules
77
{
8+
using Microsoft.CodeAnalysis.Testing;
89
using StyleCop.Analyzers.Test.CSharp10.NamingRules;
10+
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
11+
StyleCop.Analyzers.NamingRules.SA1300ElementMustBeginWithUpperCaseLetter,
12+
StyleCop.Analyzers.NamingRules.RenameToUpperCaseCodeFixProvider>;
913

1014
public class SA1300CSharp11UnitTests : SA1300CSharp10UnitTests
1115
{
16+
protected override DiagnosticResult[] GetExpectedResultTestPositionalRecord1()
17+
{
18+
// NOTE: Roslyn bug fix. Earlier versions made diagnostics be reported twice.
19+
return new[]
20+
{
21+
// /0/Test0.cs(2,15): warning SA1300: Element 'r' should begin with an uppercase letter
22+
Diagnostic().WithLocation(0).WithArguments("r"),
23+
};
24+
}
1225
}
1326
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp11/StyleCop.Analyzers.Test.CSharp11.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</PropertyGroup>
1818

1919
<ItemGroup>
20-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.0.1" />
20+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.2.0-4.final" />
2121
<PackageReference Include="xunit" Version="2.4.1" />
2222
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" PrivateAssets="all" />
2323
</ItemGroup>

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/LayoutRules/SA1516CSharp9UnitTests.cs

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,19 @@ public async Task TestUsingAndGlobalStatementSpacingInTopLevelProgramAsync()
3636
return 0;
3737
";
3838

39-
await new CSharpTest(LanguageVersion.CSharp9)
39+
var test = new CSharpTest(LanguageVersion.CSharp9)
4040
{
4141
ReferenceAssemblies = ReferenceAssemblies.Net.Net50,
4242
TestState =
4343
{
4444
OutputKind = OutputKind.ConsoleApplication,
4545
Sources = { testCode },
46-
ExpectedDiagnostics =
47-
{
48-
// /0/Test0.cs(3,1): warning SA1516: Elements should be separated by blank line
49-
Diagnostic().WithLocation(0),
50-
51-
// /0/Test0.cs(3,1): warning SA1516: Elements should be separated by blank line
52-
Diagnostic().WithLocation(0),
53-
},
5446
},
5547
FixedCode = fixedCode,
56-
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
48+
};
49+
var expectedDiagnostics = this.GetExpectedResultTestUsingAndGlobalStatementSpacingInTopLevelProgram();
50+
test.TestState.ExpectedDiagnostics.AddRange(expectedDiagnostics);
51+
await test.RunAsync(CancellationToken.None).ConfigureAwait(false);
5752
}
5853

5954
/// <summary>
@@ -95,24 +90,45 @@ public async Task TestGlobalStatementAndRecordSpacingInTopLevelProgramAsync()
9590
record A();
9691
";
9792

98-
await new CSharpTest(LanguageVersion.CSharp9)
93+
var test = new CSharpTest(LanguageVersion.CSharp9)
9994
{
10095
ReferenceAssemblies = ReferenceAssemblies.Net.Net50,
10196
TestState =
10297
{
10398
OutputKind = OutputKind.ConsoleApplication,
10499
Sources = { testCode },
105-
ExpectedDiagnostics =
106-
{
107-
// /0/Test0.cs(2,1): warning SA1516: Elements should be separated by blank line
108-
Diagnostic().WithLocation(0),
109-
110-
// /0/Test0.cs(2,1): warning SA1516: Elements should be separated by blank line
111-
Diagnostic().WithLocation(0),
112-
},
113100
},
114101
FixedCode = fixedCode,
115-
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
102+
};
103+
var expectedDiagnostics = this.GetExpectedResultTestGlobalStatementAndRecordSpacingInTopLevelProgram();
104+
test.TestState.ExpectedDiagnostics.AddRange(expectedDiagnostics);
105+
await test.RunAsync(CancellationToken.None).ConfigureAwait(false);
106+
}
107+
108+
protected virtual DiagnosticResult[] GetExpectedResultTestUsingAndGlobalStatementSpacingInTopLevelProgram()
109+
{
110+
// NOTE: Seems like a Roslyn bug made diagnostics be reported twice. Fixed in a later version.
111+
return new[]
112+
{
113+
// /0/Test0.cs(3,1): warning SA1516: Elements should be separated by blank line
114+
Diagnostic().WithLocation(0),
115+
116+
// /0/Test0.cs(3,1): warning SA1516: Elements should be separated by blank line
117+
Diagnostic().WithLocation(0),
118+
};
119+
}
120+
121+
protected virtual DiagnosticResult[] GetExpectedResultTestGlobalStatementAndRecordSpacingInTopLevelProgram()
122+
{
123+
// NOTE: Seems like a Roslyn bug made diagnostics be reported twice. Fixed in a later version.
124+
return new[]
125+
{
126+
// /0/Test0.cs(2,1): warning SA1516: Elements should be separated by blank line
127+
Diagnostic().WithLocation(0),
128+
129+
// /0/Test0.cs(2,1): warning SA1516: Elements should be separated by blank line
130+
Diagnostic().WithLocation(0),
131+
};
116132
}
117133
}
118134
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/NamingRules/SA1300CSharp9UnitTests.cs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace StyleCop.Analyzers.Test.CSharp9.NamingRules
88
using System.Threading;
99
using System.Threading.Tasks;
1010
using Microsoft.CodeAnalysis.CSharp;
11+
using Microsoft.CodeAnalysis.Testing;
1112
using StyleCop.Analyzers.Test.CSharp8.NamingRules;
1213
using StyleCop.Analyzers.Test.Verifiers;
1314
using Xunit;
@@ -40,20 +41,15 @@ public R(int a, int b)
4041
}
4142
";
4243

43-
await new CSharpTest(LanguageVersion.CSharp9)
44+
var test = new CSharpTest(LanguageVersion.CSharp9)
4445
{
4546
ReferenceAssemblies = GenericAnalyzerTest.ReferenceAssembliesNet50,
4647
TestCode = testCode,
47-
ExpectedDiagnostics =
48-
{
49-
// /0/Test0.cs(2,15): warning SA1300: Element 'r' should begin with an uppercase letter
50-
Diagnostic().WithLocation(0).WithArguments("r"),
51-
52-
// /0/Test0.cs(2,15): warning SA1300: Element 'r' should begin with an uppercase letter
53-
Diagnostic().WithLocation(0).WithArguments("r"),
54-
},
5548
FixedCode = fixedCode,
56-
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
49+
};
50+
var expectedDiagnostics = this.GetExpectedResultTestPositionalRecord1();
51+
test.TestState.ExpectedDiagnostics.AddRange(expectedDiagnostics);
52+
await test.RunAsync(CancellationToken.None).ConfigureAwait(false);
5753
}
5854

5955
[Fact]
@@ -86,5 +82,18 @@ public R(int a, int b)
8682
FixedCode = fixedCode,
8783
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
8884
}
85+
86+
protected virtual DiagnosticResult[] GetExpectedResultTestPositionalRecord1()
87+
{
88+
// NOTE: Seems like a Roslyn bug made diagnostics be reported twice. Fixed in a later version.
89+
return new[]
90+
{
91+
// /0/Test0.cs(2,15): warning SA1300: Element 'r' should begin with an uppercase letter
92+
Diagnostic().WithLocation(0).WithArguments("r"),
93+
94+
// /0/Test0.cs(2,15): warning SA1300: Element 'r' should begin with an uppercase letter
95+
Diagnostic().WithLocation(0).WithArguments("r"),
96+
};
97+
}
8998
}
9099
}

StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1119UnitTests.cs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,14 +1042,9 @@ public void Bar()
10421042
string data = $""{(flag)}"";
10431043
}
10441044
}";
1045-
string fixedCode = @"class Foo
1046-
{
1047-
public void Bar()
1048-
{
1049-
bool flag = false;
1050-
string data = $""{ flag}"";
1051-
}
1052-
}";
1045+
1046+
string fixedCode = this.GetFixedCodeTestParenthesisInInterpolatedStringThatShouldBeRemoved();
1047+
10531048
DiagnosticResult[] expected =
10541049
{
10551050
Diagnostic(DiagnosticId).WithSpan(6, 26, 6, 32),
@@ -1477,5 +1472,19 @@ private static void Main()
14771472

14781473
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
14791474
}
1475+
1476+
// In this version of Roslyn, we end up with an extra space between the opening brace
1477+
// and the identifier. Fixed in a later version.
1478+
protected virtual string GetFixedCodeTestParenthesisInInterpolatedStringThatShouldBeRemoved()
1479+
{
1480+
return @"class Foo
1481+
{
1482+
public void Bar()
1483+
{
1484+
bool flag = false;
1485+
string data = $""{ flag}"";
1486+
}
1487+
}";
1488+
}
14801489
}
14811490
}

0 commit comments

Comments
 (0)