Skip to content

Commit dc163bf

Browse files
authored
Merge pull request #3145 from sharwell/update-tests
Update tests
2 parents ce8ee2f + 3dc62d4 commit dc163bf

File tree

42 files changed

+882
-637
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+882
-637
lines changed

StyleCop.Analyzers/Directory.Build.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</PropertyGroup>
1111

1212
<PropertyGroup>
13-
<LangVersion>7.2</LangVersion>
13+
<LangVersion>8</LangVersion>
1414
<Features>strict</Features>
1515
</PropertyGroup>
1616

@@ -46,7 +46,7 @@
4646
<PackageReference Include="AsyncUsageAnalyzers" Version="1.0.0-alpha003" PrivateAssets="all" />
4747
<PackageReference Include="DotNetAnalyzers.DocumentationAnalyzers" Version="1.0.0-beta.46" PrivateAssets="all" />
4848
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.66" PrivateAssets="all" />
49-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeStyle" Version="2.11.0-beta2-63603-03" PrivateAssets="all" />
49+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeStyle" Version="3.6.0-4.20251.5" PrivateAssets="all" />
5050
</ItemGroup>
5151

5252
<!-- Public API -->

StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/DocumentationRules/FileHeaderCodeFixProvider.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context)
6666
return SpecializedTasks.CompletedTask;
6767
}
6868

69+
private static string GetFileName(Document document)
70+
=> Path.GetFileName(document.FilePath ?? document.Name);
71+
6972
private static async Task<Document> GetTransformedDocumentAsync(Document document, CancellationToken cancellationToken)
7073
{
7174
return document.WithSyntaxRoot(await GetTransformedSyntaxRootAsync(document, cancellationToken).ConfigureAwait(false));
@@ -80,7 +83,7 @@ private static async Task<SyntaxNode> GetTransformedSyntaxRootAsync(Document doc
8083
SyntaxNode newSyntaxRoot;
8184
if (fileHeader.IsMissing)
8285
{
83-
newSyntaxRoot = AddHeader(document, root, document.Name, settings);
86+
newSyntaxRoot = AddHeader(document, root, GetFileName(document), settings);
8487
}
8588
else
8689
{
@@ -144,9 +147,9 @@ private static SyntaxNode ReplaceWellFormedMultiLineCommentHeader(Document docum
144147
// Pad line that used to be next to a /*
145148
triviaStringParts[0] = commentIndentation + interlinePadding + " " + triviaStringParts[0];
146149
StringBuilder sb = StringBuilderPool.Allocate();
147-
string fileName = Path.GetFileName(document.FilePath);
150+
string fileName = GetFileName(document);
148151
var copyrightText = GetCopyrightText(commentIndentation + interlinePadding, settings.DocumentationRules.GetCopyrightText(fileName), newLineText);
149-
var newHeader = WrapInXmlComment(commentIndentation + interlinePadding, copyrightText, document.Name, settings, newLineText);
152+
var newHeader = WrapInXmlComment(commentIndentation + interlinePadding, copyrightText, fileName, settings, newLineText);
150153

151154
sb.Append(commentIndentation);
152155
sb.Append("/*");
@@ -310,7 +313,7 @@ private static SyntaxNode ReplaceHeader(Document document, SyntaxNode root, Styl
310313
string newLineText = document.Project.Solution.Workspace.Options.GetOption(FormattingOptions.NewLine, LanguageNames.CSharp);
311314
var newLineTrivia = SyntaxFactory.EndOfLine(newLineText);
312315

313-
var newHeaderTrivia = CreateNewHeader(leadingSpaces + "//", document.Name, settings, newLineText);
316+
var newHeaderTrivia = CreateNewHeader(leadingSpaces + "//", GetFileName(document), settings, newLineText);
314317
if (!isMalformedHeader && copyrightTriviaIndex.HasValue)
315318
{
316319
// Does the copyright element have leading whitespace? If so remove it.

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/SpacingRules/SA1009CSharp7UnitTests.cs

Lines changed: 228 additions & 228 deletions
Large diffs are not rendered by default.

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/SpacingRules/SA1010CSharp7UnitTests.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace StyleCop.Analyzers.Test.CSharp7.SpacingRules
99
using Microsoft.CodeAnalysis.Testing;
1010
using StyleCop.Analyzers.Test.SpacingRules;
1111
using Xunit;
12+
using static StyleCop.Analyzers.SpacingRules.SA1010OpeningSquareBracketsMustBeSpacedCorrectly;
1213
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
1314
StyleCop.Analyzers.SpacingRules.SA1010OpeningSquareBracketsMustBeSpacedCorrectly,
1415
StyleCop.Analyzers.SpacingRules.TokenSpacingCodeFixProvider>;
@@ -52,9 +53,9 @@ public unsafe void TestMethod()
5253

5354
DiagnosticResult[] expected =
5455
{
55-
Diagnostic().WithArguments("not be preceded").WithLocation(7, 41),
56-
Diagnostic().WithArguments("not be followed").WithLocation(7, 41),
57-
Diagnostic().WithArguments("not be preceded").WithLocation(8, 41),
56+
Diagnostic(DescriptorNotPreceded).WithLocation(7, 41),
57+
Diagnostic(DescriptorNotFollowed).WithLocation(7, 41),
58+
Diagnostic(DescriptorNotPreceded).WithLocation(8, 41),
5859
};
5960

6061
await VerifyCSharpFixAsync(LanguageVersion.CSharp7_3, testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
@@ -97,7 +98,7 @@ public unsafe void TestMethod()
9798

9899
DiagnosticResult[] expected =
99100
{
100-
Diagnostic().WithArguments("not be followed").WithLocation(7, 37),
101+
Diagnostic(DescriptorNotFollowed).WithLocation(7, 37),
101102
};
102103

103104
await VerifyCSharpFixAsync(LanguageVersion.CSharp7_3, testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/SpacingRules/SA1015CSharp7UnitTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ namespace StyleCop.Analyzers.Test.CSharp7.SpacingRules
77
using System.Threading.Tasks;
88
using Microsoft.CodeAnalysis.Testing;
99
using StyleCop.Analyzers.Test.SpacingRules;
10-
using TestHelper;
1110
using Xunit;
11+
using static StyleCop.Analyzers.SpacingRules.SA1015ClosingGenericBracketsMustBeSpacedCorrectly;
1212
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
1313
StyleCop.Analyzers.SpacingRules.SA1015ClosingGenericBracketsMustBeSpacedCorrectly,
1414
StyleCop.Analyzers.SpacingRules.TokenSpacingCodeFixProvider>;
@@ -45,9 +45,9 @@ public void TestMethod()
4545

4646
DiagnosticResult[] expected =
4747
{
48-
Diagnostic().WithLocation(7, 19).WithArguments(" not", "preceded"),
49-
Diagnostic().WithLocation(7, 19).WithArguments(" not", "followed"),
50-
Diagnostic().WithLocation(7, 32).WithArguments(" not", "preceded"),
48+
Diagnostic(DescriptorNotPreceded).WithLocation(7, 19),
49+
Diagnostic(DescriptorNotFollowed).WithLocation(7, 19),
50+
Diagnostic(DescriptorNotPreceded).WithLocation(7, 32),
5151
};
5252

5353
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/SpacingRules/SA1024CSharp7UnitTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ namespace StyleCop.Analyzers.Test.CSharp7.SpacingRules
77
using System.Threading.Tasks;
88
using Microsoft.CodeAnalysis.Testing;
99
using StyleCop.Analyzers.Test.SpacingRules;
10-
using TestHelper;
1110
using Xunit;
11+
using static StyleCop.Analyzers.SpacingRules.SA1024ColonsMustBeSpacedCorrectly;
1212
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
1313
StyleCop.Analyzers.SpacingRules.SA1024ColonsMustBeSpacedCorrectly,
1414
StyleCop.Analyzers.SpacingRules.TokenSpacingCodeFixProvider>;
@@ -43,10 +43,10 @@ public void TestMethod()
4343

4444
DiagnosticResult[] expected =
4545
{
46-
Diagnostic().WithLocation(7, 25).WithArguments(" not", "preceded", string.Empty),
47-
Diagnostic().WithLocation(7, 25).WithArguments(string.Empty, "followed", string.Empty),
48-
Diagnostic().WithLocation(7, 31).WithArguments(" not", "preceded", string.Empty),
49-
Diagnostic().WithLocation(7, 31).WithArguments(string.Empty, "followed", string.Empty),
46+
Diagnostic(DescriptorNotPreceded).WithLocation(7, 25),
47+
Diagnostic(DescriptorFollowed).WithLocation(7, 25),
48+
Diagnostic(DescriptorNotPreceded).WithLocation(7, 31),
49+
Diagnostic(DescriptorFollowed).WithLocation(7, 31),
5050
};
5151

5252
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
@@ -90,8 +90,8 @@ public void TestMethod()
9090

9191
DiagnosticResult[] expected =
9292
{
93-
Diagnostic().WithLocation(9, 35).WithArguments(" not", "preceded", string.Empty),
94-
Diagnostic().WithLocation(11, 22).WithArguments(" not", "preceded", string.Empty),
93+
Diagnostic(DescriptorNotPreceded).WithLocation(9, 35),
94+
Diagnostic(DescriptorNotPreceded).WithLocation(11, 22),
9595
};
9696

9797
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp8/SpacingRules/SA1009CSharp8UnitTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ namespace StyleCop.Analyzers.Test.CSharp8.SpacingRules
77
using System.Threading.Tasks;
88
using Microsoft.CodeAnalysis.CSharp;
99
using Microsoft.CodeAnalysis.Testing;
10-
using StyleCop.Analyzers.SpacingRules;
1110
using StyleCop.Analyzers.Test.CSharp7.SpacingRules;
1211
using StyleCop.Analyzers.Test.Verifiers;
1312
using Xunit;
13+
using static StyleCop.Analyzers.SpacingRules.SA1009ClosingParenthesisMustBeSpacedCorrectly;
1414
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
1515
StyleCop.Analyzers.SpacingRules.SA1009ClosingParenthesisMustBeSpacedCorrectly,
1616
StyleCop.Analyzers.SpacingRules.TokenSpacingCodeFixProvider>;
@@ -142,7 +142,7 @@ public string TestMethod()
142142
}
143143
}
144144
";
145-
DiagnosticResult expected = Diagnostic().WithSpan(28, 37, 28, 38).WithArguments(" not", "followed");
145+
DiagnosticResult expected = Diagnostic(DescriptorNotFollowed).WithSpan(28, 37, 28, 38);
146146
await VerifyCSharpFixAsync(LanguageVersion.CSharp8, testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
147147
}
148148
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp8/SpacingRules/SA1019CSharp8UnitTests.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace StyleCop.Analyzers.Test.CSharp8.SpacingRules
99
using Microsoft.CodeAnalysis.Testing;
1010
using StyleCop.Analyzers.Test.CSharp7.SpacingRules;
1111
using Xunit;
12+
using static StyleCop.Analyzers.SpacingRules.SA1019MemberAccessSymbolsMustBeSpacedCorrectly;
1213
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
1314
StyleCop.Analyzers.SpacingRules.SA1019MemberAccessSymbolsMustBeSpacedCorrectly,
1415
StyleCop.Analyzers.SpacingRules.TokenSpacingCodeFixProvider>;
@@ -55,10 +56,10 @@ public void TestMethod(object?[] arguments)
5556

5657
DiagnosticResult[] expected =
5758
{
58-
Diagnostic().WithArguments(".", "preceded").WithLocation(8, 39),
59-
Diagnostic().WithArguments(".", "preceded").WithLocation(9, 40),
60-
Diagnostic().WithArguments("?", "preceded").WithLocation(11, 39),
61-
Diagnostic().WithArguments("?", "preceded").WithLocation(12, 40),
59+
Diagnostic(DescriptorNotPreceded).WithArguments(".").WithLocation(8, 39),
60+
Diagnostic(DescriptorNotPreceded).WithArguments(".").WithLocation(9, 40),
61+
Diagnostic(DescriptorNotPreceded).WithArguments("?").WithLocation(11, 39),
62+
Diagnostic(DescriptorNotPreceded).WithArguments("?").WithLocation(12, 40),
6263
};
6364

6465
await VerifyCSharpFixAsync(LanguageVersion.CSharp8, testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp8/SpacingRules/SA1024CSharp8UnitTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace StyleCop.Analyzers.Test.CSharp8.SpacingRules
77
using System.Threading.Tasks;
88
using StyleCop.Analyzers.Test.CSharp7.SpacingRules;
99
using Xunit;
10+
using static StyleCop.Analyzers.SpacingRules.SA1024ColonsMustBeSpacedCorrectly;
1011
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
1112
StyleCop.Analyzers.SpacingRules.SA1024ColonsMustBeSpacedCorrectly,
1213
StyleCop.Analyzers.SpacingRules.TokenSpacingCodeFixProvider>;
@@ -49,7 +50,7 @@ public void TestMethod(object value)
4950
}
5051
}";
5152

52-
var expected = Diagnostic().WithSpan(9, 49, 9, 50).WithArguments(" not", "preceded", string.Empty);
53+
var expected = Diagnostic(DescriptorNotPreceded).WithSpan(9, 49, 9, 50);
5354
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
5455
}
5556
}

StyleCop.Analyzers/StyleCop.Analyzers.Test/AnalyzerConfigurationTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ public CSharpTest(Type analyzerType)
7878
protected override CompilationOptions CreateCompilationOptions()
7979
=> new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, allowUnsafe: true);
8080

81+
protected override ParseOptions CreateParseOptions()
82+
=> new CSharpParseOptions(LanguageVersion.CSharp6);
83+
8184
protected override IEnumerable<CodeFixProvider> GetCodeFixProviders()
8285
=> new CodeFixProvider[0];
8386

0 commit comments

Comments
 (0)