Skip to content

Commit 8eb1db3

Browse files
committed
Match default reference assemblies to default language version
1 parent b209e4e commit 8eb1db3

File tree

12 files changed

+88
-137
lines changed

12 files changed

+88
-137
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/NamingRules/SA1313CSharp10UnitTests.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4-
#nullable disable
5-
64
namespace StyleCop.Analyzers.Test.CSharp10.NamingRules
75
{
86
using System.Threading;
97
using System.Threading.Tasks;
8+
using Microsoft.CodeAnalysis.Testing;
109
using StyleCop.Analyzers.Test.CSharp9.NamingRules;
11-
using StyleCop.Analyzers.Test.Verifiers;
1210
using Xunit;
1311
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
1412
StyleCop.Analyzers.NamingRules.SA1313ParameterNamesMustBeginWithLowerCaseLetter,
@@ -42,12 +40,7 @@ public R(int a, int b)
4240
}}
4341
";
4442

45-
await new CSharpTest()
46-
{
47-
ReferenceAssemblies = GenericAnalyzerTest.ReferenceAssembliesNet60,
48-
TestCode = testCode,
49-
FixedCode = fixedCode,
50-
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
43+
await VerifyCSharpFixAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, fixedCode, CancellationToken.None).ConfigureAwait(false);
5144
}
5245
}
5346
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/ReadabilityRules/SA1101CSharp10UnitTests.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ namespace StyleCop.Analyzers.Test.CSharp10.ReadabilityRules
55
{
66
using System.Threading;
77
using System.Threading.Tasks;
8+
using Microsoft.CodeAnalysis.Testing;
89
using StyleCop.Analyzers.Test.CSharp9.ReadabilityRules;
9-
using StyleCop.Analyzers.Test.Verifiers;
1010
using Xunit;
1111
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
1212
StyleCop.Analyzers.ReadabilityRules.SA1101PrefixLocalCallsWithThis,
@@ -29,11 +29,7 @@ public bool Method(Test arg)
2929
}
3030
}";
3131

32-
await new CSharpTest()
33-
{
34-
ReferenceAssemblies = GenericAnalyzerTest.ReferenceAssembliesNet60,
35-
TestCode = testCode,
36-
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
32+
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
3733
}
3834
}
3935
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp11/OrderingRules/SA1206CSharp11CodeFixProviderUnitTests.cs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ namespace StyleCop.Analyzers.Test.CSharp11.OrderingRules
55
{
66
using System.Threading;
77
using System.Threading.Tasks;
8+
using Microsoft.CodeAnalysis.Testing;
89
using StyleCop.Analyzers.Test.CSharp10.OrderingRules;
9-
using StyleCop.Analyzers.Test.Verifiers;
1010
using Xunit;
1111
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
1212
StyleCop.Analyzers.OrderingRules.SA1206DeclarationKeywordsMustFollowOrder,
@@ -43,17 +43,13 @@ internal struct SomeStruct
4343
public required int Field;
4444
}";
4545

46-
await new CSharpTest()
46+
DiagnosticResult[] expected =
4747
{
48-
ReferenceAssemblies = GenericAnalyzerTest.ReferenceAssembliesNet70,
49-
TestCode = testCode,
50-
FixedCode = fixedCode,
51-
ExpectedDiagnostics =
52-
{
53-
Diagnostic().WithLocation(0).WithArguments("public", "required"),
54-
Diagnostic().WithLocation(1).WithArguments("public", "required"),
55-
},
56-
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
48+
Diagnostic().WithLocation(0).WithArguments("public", "required"),
49+
Diagnostic().WithLocation(1).WithArguments("public", "required"),
50+
};
51+
52+
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
5753
}
5854
}
5955
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp11/SpacingRules/SA1010CSharp11UnitTests.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ namespace StyleCop.Analyzers.Test.CSharp11.SpacingRules
55
{
66
using System.Threading;
77
using System.Threading.Tasks;
8+
using Microsoft.CodeAnalysis.Testing;
89
using StyleCop.Analyzers.Test.CSharp10.SpacingRules;
9-
using StyleCop.Analyzers.Test.Verifiers;
1010
using Xunit;
1111

1212
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
@@ -40,11 +40,7 @@ public void TestMethod(List<int> x)
4040
}}
4141
";
4242

43-
await new CSharpTest()
44-
{
45-
ReferenceAssemblies = GenericAnalyzerTest.ReferenceAssembliesNet50,
46-
TestCode = testCode,
47-
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
43+
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
4844
}
4945
}
5046
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp11/SpacingRules/SA1012CSharp11UnitTests.cs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ namespace StyleCop.Analyzers.Test.CSharp11.SpacingRules
55
{
66
using System.Threading;
77
using System.Threading.Tasks;
8+
using Microsoft.CodeAnalysis.Testing;
89
using StyleCop.Analyzers.Test.CSharp10.SpacingRules;
9-
using StyleCop.Analyzers.Test.Verifiers;
1010
using Xunit;
1111
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
1212
StyleCop.Analyzers.SpacingRules.SA1012OpeningBracesMustBeSpacedCorrectly,
@@ -40,20 +40,16 @@ void M(string[] a)
4040
}
4141
";
4242

43-
await new CSharpTest()
43+
DiagnosticResult[] expected =
4444
{
45-
ReferenceAssemblies = GenericAnalyzerTest.ReferenceAssembliesNet50,
46-
TestCode = testCode,
47-
ExpectedDiagnostics =
48-
{
49-
// Opening brace should not be preceded by a space
50-
Diagnostic().WithLocation(0).WithArguments(" not", "preceded"),
45+
// Opening brace should not be preceded by a space
46+
Diagnostic().WithLocation(0).WithArguments(" not", "preceded"),
5147

52-
// Opening brace should be preceded by a space
53-
Diagnostic().WithLocation(1).WithArguments(string.Empty, "preceded"),
54-
},
55-
FixedCode = fixedCode,
56-
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
48+
// Opening brace should be preceded by a space
49+
Diagnostic().WithLocation(1).WithArguments(string.Empty, "preceded"),
50+
};
51+
52+
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
5753
}
5854
}
5955
}

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

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4-
#nullable disable
5-
64
namespace StyleCop.Analyzers.Test.CSharp9.NamingRules
75
{
86
using System.Threading;
97
using System.Threading.Tasks;
108
using Microsoft.CodeAnalysis.Testing;
119
using StyleCop.Analyzers.Test.CSharp8.NamingRules;
12-
using StyleCop.Analyzers.Test.Verifiers;
1310
using Xunit;
1411
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
1512
StyleCop.Analyzers.NamingRules.SA1300ElementMustBeginWithUpperCaseLetter,
@@ -40,15 +37,7 @@ public R(int a, int b)
4037
}
4138
";
4239

43-
var test = new CSharpTest()
44-
{
45-
ReferenceAssemblies = GenericAnalyzerTest.ReferenceAssembliesNet50,
46-
TestCode = testCode,
47-
FixedCode = fixedCode,
48-
};
49-
var expectedDiagnostics = this.GetExpectedResultTestPositionalRecord1();
50-
test.TestState.ExpectedDiagnostics.AddRange(expectedDiagnostics);
51-
await test.RunAsync(CancellationToken.None).ConfigureAwait(false);
40+
await VerifyCSharpFixAsync(testCode, this.GetExpectedResultTestPositionalRecord1(), fixedCode, CancellationToken.None).ConfigureAwait(false);
5241
}
5342

5443
[Fact]
@@ -74,12 +63,7 @@ public R(int a, int b)
7463
}
7564
";
7665

77-
await new CSharpTest()
78-
{
79-
ReferenceAssemblies = GenericAnalyzerTest.ReferenceAssembliesNet50,
80-
TestCode = testCode,
81-
FixedCode = fixedCode,
82-
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
66+
await VerifyCSharpFixAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, fixedCode, CancellationToken.None).ConfigureAwait(false);
8367
}
8468

8569
protected virtual DiagnosticResult[] GetExpectedResultTestPositionalRecord1()

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4-
#nullable disable
5-
64
namespace StyleCop.Analyzers.Test.CSharp9.NamingRules
75
{
86
using System.Threading;
97
using System.Threading.Tasks;
8+
using Microsoft.CodeAnalysis.Testing;
109
using StyleCop.Analyzers.Test.CSharp8.NamingRules;
11-
using StyleCop.Analyzers.Test.Verifiers;
1210
using Xunit;
1311
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
1412
StyleCop.Analyzers.NamingRules.SA1313ParameterNamesMustBeginWithLowerCaseLetter,
@@ -41,12 +39,7 @@ public R(int a, int b)
4139
}
4240
";
4341

44-
await new CSharpTest()
45-
{
46-
ReferenceAssemblies = GenericAnalyzerTest.ReferenceAssembliesNet50,
47-
TestCode = testCode,
48-
FixedCode = fixedCode,
49-
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
42+
await VerifyCSharpFixAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, fixedCode, CancellationToken.None).ConfigureAwait(false);
5043
}
5144
}
5245
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/ReadabilityRules/SA1101CSharp9UnitTests.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ namespace StyleCop.Analyzers.Test.CSharp9.ReadabilityRules
55
{
66
using System.Threading;
77
using System.Threading.Tasks;
8+
using Microsoft.CodeAnalysis.Testing;
89
using StyleCop.Analyzers.Test.CSharp8.ReadabilityRules;
9-
using StyleCop.Analyzers.Test.Verifiers;
1010
using Xunit;
1111
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
1212
StyleCop.Analyzers.ReadabilityRules.SA1101PrefixLocalCallsWithThis,
@@ -31,11 +31,7 @@ public A UpdateA(A value)
3131
}
3232
}";
3333

34-
await new CSharpTest()
35-
{
36-
ReferenceAssemblies = GenericAnalyzerTest.ReferenceAssembliesNet50,
37-
TestCode = testCode,
38-
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
34+
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
3935
}
4036
}
4137
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/SpacingRules/SA1023CSharp9UnitTests.cs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4-
#nullable disable
5-
64
namespace StyleCop.Analyzers.Test.CSharp9.SpacingRules
75
{
86
using System.Threading;
97
using System.Threading.Tasks;
8+
using Microsoft.CodeAnalysis.Testing;
109
using StyleCop.Analyzers.Test.CSharp8.SpacingRules;
11-
using StyleCop.Analyzers.Test.Verifiers;
1210
using Xunit;
1311
using static StyleCop.Analyzers.SpacingRules.SA1023DereferenceAndAccessOfSymbolsMustBeSpacedCorrectly;
1412
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
@@ -68,21 +66,17 @@ public async Task TestFunctionPointerTypeInvalidSpacingAsync()
6866
}
6967
";
7068

71-
await new CSharpTest()
69+
DiagnosticResult[] expected =
7270
{
73-
ReferenceAssemblies = GenericAnalyzerTest.ReferenceAssembliesNet50,
74-
TestCode = testCode,
75-
FixedCode = fixedCode,
76-
ExpectedDiagnostics =
77-
{
78-
Diagnostic(DescriptorNotPreceded).WithLocation(0),
79-
Diagnostic(DescriptorNotFollowed).WithLocation(1),
80-
Diagnostic(DescriptorNotPreceded).WithLocation(2),
81-
Diagnostic(DescriptorFollowed).WithLocation(3),
82-
Diagnostic(DescriptorNotPreceded).WithLocation(4),
83-
Diagnostic(DescriptorFollowed).WithLocation(5),
84-
},
85-
}.RunAsync().ConfigureAwait(false);
71+
Diagnostic(DescriptorNotPreceded).WithLocation(0),
72+
Diagnostic(DescriptorNotFollowed).WithLocation(1),
73+
Diagnostic(DescriptorNotPreceded).WithLocation(2),
74+
Diagnostic(DescriptorFollowed).WithLocation(3),
75+
Diagnostic(DescriptorNotPreceded).WithLocation(4),
76+
Diagnostic(DescriptorFollowed).WithLocation(5),
77+
};
78+
79+
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
8680
}
8781
}
8882
}

StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/DebugMessagesUnitTestsBase.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace StyleCop.Analyzers.Test.MaintainabilityRules
77
{
88
using System.Collections.Generic;
9+
using System.Diagnostics;
910
using System.Linq;
1011
using System.Text;
1112
using System.Threading;
@@ -14,6 +15,7 @@ namespace StyleCop.Analyzers.Test.MaintainabilityRules
1415
using Microsoft.CodeAnalysis.Diagnostics;
1516
using Microsoft.CodeAnalysis.Testing;
1617
using Microsoft.CodeAnalysis.Text;
18+
using StyleCop.Analyzers.Lightup;
1719
using StyleCop.Analyzers.Test.Verifiers;
1820
using Xunit;
1921

@@ -98,10 +100,23 @@ public async Task TestConstantMessage_Inline_PassWrongTypeAsync()
98100
{
99101
var startLinePosition = new LinePosition(5, 15 + this.MethodName.Length + this.InitialArguments.Sum(i => i.Length + ", ".Length));
100102
var endLinePosition = new LinePosition(startLinePosition.Line, startLinePosition.Character + 1);
101-
DiagnosticResult[] expected =
103+
DiagnosticResult[] expected;
104+
if (LightupHelpers.SupportsCSharp11 && this.MethodName == nameof(Debug.Assert))
102105
{
103-
DiagnosticResult.CompilerError("CS1503").WithSpan(new FileLinePositionSpan("/0/Test0.cs", startLinePosition, endLinePosition)).WithMessage($"Argument {1 + this.InitialArguments.Count()}: cannot convert from 'int' to 'string'"),
104-
};
106+
// For some reason this case wants to bind to Debug.Assert(bool, ref Debug.AssertInterpolatedStringHandler)
107+
expected = new[]
108+
{
109+
DiagnosticResult.CompilerError("CS1620").WithSpan(new FileLinePositionSpan("/0/Test0.cs", startLinePosition, endLinePosition)).WithMessage($"Argument {1 + this.InitialArguments.Count()} must be passed with the 'ref' keyword"),
110+
};
111+
}
112+
else
113+
{
114+
var expectedType = LightupHelpers.SupportsCSharp8 ? "string?" : "string";
115+
expected = new[]
116+
{
117+
DiagnosticResult.CompilerError("CS1503").WithSpan(new FileLinePositionSpan("/0/Test0.cs", startLinePosition, endLinePosition)).WithMessage($"Argument {1 + this.InitialArguments.Count()}: cannot convert from 'int' to '{expectedType}'"),
118+
};
119+
}
105120

106121
await this.TestConstantMessage_Inline_PassExecuterAsync("3", expected).ConfigureAwait(false);
107122
}

0 commit comments

Comments
 (0)