Skip to content

Commit ac7d7c9

Browse files
committed
Update to Microsoft.CodeAnalysis.CSharp.CodeFix.Testing.XUnit 1.0.0-beta1-63810-01
1 parent 3f87552 commit ac7d7c9

11 files changed

Lines changed: 120 additions & 32 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/MaintainabilityRules/SA1119CSharp7UnitTests.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ namespace StyleCop.Analyzers.Test.CSharp7.MaintainabilityRules
99
using StyleCop.Analyzers.Test.MaintainabilityRules;
1010
using TestHelper;
1111
using Xunit;
12-
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
13-
StyleCop.Analyzers.MaintainabilityRules.SA1119StatementMustNotUseUnnecessaryParenthesis,
14-
StyleCop.Analyzers.MaintainabilityRules.SA1119CodeFixProvider>;
12+
using static StyleCop.Analyzers.Test.Verifiers.StyleCopDiagnosticVerifier<StyleCop.Analyzers.MaintainabilityRules.SA1119StatementMustNotUseUnnecessaryParenthesis>;
1513

1614
public class SA1119CSharp7UnitTests : SA1119UnitTests
1715
{

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/FileHeaderTestBase.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ protected Task VerifyCSharpFixAsync(string source, DiagnosticResult[] expected,
121121
Settings = this.GetSettings(),
122122
};
123123

124+
test.Exclusions &= ~AnalysisExclusions.Suppression;
124125
test.ExpectedDiagnostics.AddRange(expected);
125126
test.RemainingDiagnostics.AddRange(remainingDiagnostics);
126127
test.DisabledDiagnostics.AddRange(this.GetDisabledDiagnostics());

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/NoXmlFileHeaderUnitTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ private static Task VerifyCSharpFixAsync(string source, string testSettings, Dia
410410
Settings = testSettings,
411411
};
412412

413+
test.Exclusions &= ~AnalysisExclusions.Suppression;
413414
test.ExpectedDiagnostics.AddRange(expected);
414415
return test.RunAsync(cancellationToken);
415416
}

StyleCop.Analyzers/StyleCop.Analyzers.Test/ExclusionTests.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace StyleCop.Analyzers.Test
66
using System.Collections.Generic;
77
using System.Threading;
88
using System.Threading.Tasks;
9+
using Microsoft.CodeAnalysis.Testing;
910
using Xunit;
1011
using static StyleCop.Analyzers.Test.Verifiers.StyleCopDiagnosticVerifier<TestHelper.ExclusionTestAnalyzer>;
1112

@@ -82,7 +83,7 @@ public async Task TestIsNotExcludedAsync(string filename, string testCode)
8283
{
8384
var result = Diagnostic().WithLocation(filename, 1, 1);
8485

85-
await new CSharpTest
86+
var test = new CSharpTest
8687
{
8788
TestSources =
8889
{
@@ -92,7 +93,10 @@ public async Task TestIsNotExcludedAsync(string filename, string testCode)
9293
{
9394
result,
9495
},
95-
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
96+
};
97+
98+
test.Exclusions &= ~AnalysisExclusions.Suppression;
99+
await test.RunAsync(CancellationToken.None).ConfigureAwait(false);
96100
}
97101
}
98102
}

StyleCop.Analyzers/StyleCop.Analyzers.Test/LayoutRules/SA1503UnitTests.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,15 @@ public void Bar(int i)
350350
}
351351
}";
352352

353-
var expected = Diagnostic().WithLocation(8, 13);
354-
await VerifyCSharpFixAsync(testCode, expected, fixedTestCode, CancellationToken.None).ConfigureAwait(false);
353+
var test = new CSharpTest
354+
{
355+
TestCode = testCode,
356+
ExpectedDiagnostics = { Diagnostic().WithLocation(8, 13) },
357+
FixedCode = fixedTestCode,
358+
};
359+
360+
test.Exclusions &= ~AnalysisExclusions.Suppression;
361+
await test.RunAsync(CancellationToken.None).ConfigureAwait(false);
355362
}
356363

357364
/// <summary>

StyleCop.Analyzers/StyleCop.Analyzers.Test/LayoutRules/SA1519UnitTests.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,8 +582,15 @@ public void Bar(int i)
582582
}
583583
}";
584584

585-
var expected = Diagnostic().WithLocation(8, 13);
586-
await VerifyCSharpFixAsync(testCode, expected, fixedTestCode, CancellationToken.None).ConfigureAwait(false);
585+
var test = new CSharpTest
586+
{
587+
TestCode = testCode,
588+
ExpectedDiagnostics = { Diagnostic().WithLocation(8, 13) },
589+
FixedCode = fixedTestCode,
590+
};
591+
592+
test.Exclusions &= ~AnalysisExclusions.Suppression;
593+
await test.RunAsync(CancellationToken.None).ConfigureAwait(false);
587594
}
588595

589596
/// <summary>

StyleCop.Analyzers/StyleCop.Analyzers.Test/LayoutRules/SA1520UnitTests.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,15 @@ public void Bar(int i)
395395
}
396396
}";
397397

398-
var expected = Diagnostic().WithLocation(8, 13);
399-
await VerifyCSharpFixAsync(testCode, expected, fixedTestCode, CancellationToken.None).ConfigureAwait(false);
398+
var test = new CSharpTest
399+
{
400+
TestCode = testCode,
401+
ExpectedDiagnostics = { Diagnostic().WithLocation(8, 13) },
402+
FixedCode = fixedTestCode,
403+
};
404+
405+
test.Exclusions &= ~AnalysisExclusions.Suppression;
406+
await test.RunAsync(CancellationToken.None).ConfigureAwait(false);
400407
}
401408

402409
/// <summary>

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

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ namespace StyleCop.Analyzers.Test.MaintainabilityRules
77
using System.Threading.Tasks;
88
using Microsoft.CodeAnalysis.Testing;
99
using StyleCop.Analyzers.MaintainabilityRules;
10+
using StyleCop.Analyzers.Test.Verifiers;
1011
using Xunit;
11-
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
12-
StyleCop.Analyzers.MaintainabilityRules.SA1119StatementMustNotUseUnnecessaryParenthesis,
13-
StyleCop.Analyzers.MaintainabilityRules.SA1119CodeFixProvider>;
12+
using static StyleCop.Analyzers.Test.Verifiers.StyleCopDiagnosticVerifier<StyleCop.Analyzers.MaintainabilityRules.SA1119StatementMustNotUseUnnecessaryParenthesis>;
1413

1514
public class SA1119UnitTests
1615
{
@@ -1039,6 +1038,14 @@ public void Bar()
10391038
bool flag = false;
10401039
string data = $""{(flag)}"";
10411040
}
1041+
}";
1042+
string fixedCode = @"class Foo
1043+
{
1044+
public void Bar()
1045+
{
1046+
bool flag = false;
1047+
string data = $""{ flag}"";
1048+
}
10421049
}";
10431050
DiagnosticResult[] expected =
10441051
{
@@ -1047,7 +1054,7 @@ public void Bar()
10471054
Diagnostic(ParenthesesDiagnosticId).WithLocation(6, 31),
10481055
};
10491056

1050-
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
1057+
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
10511058
}
10521059

10531060
[Fact]
@@ -1429,5 +1436,20 @@ public static void Main(string[] args)
14291436

14301437
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
14311438
}
1439+
1440+
protected static async Task VerifyCSharpFixAsync(string source, DiagnosticResult[] expected, string fixedSource, CancellationToken cancellationToken)
1441+
{
1442+
var test = new StyleCopCodeFixVerifier<SA1119StatementMustNotUseUnnecessaryParenthesis, SA1119CodeFixProvider>.CSharpTest
1443+
{
1444+
TestCode = source,
1445+
FixedCode = fixedSource,
1446+
};
1447+
1448+
// Workaround for https://github.com/dotnet/roslyn-sdk/pull/252
1449+
test.Exclusions &= ~AnalysisExclusions.Suppression;
1450+
1451+
test.ExpectedDiagnostics.AddRange(expected);
1452+
await test.RunAsync(cancellationToken).ConfigureAwait(false);
1453+
}
14321454
}
14331455
}

StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1412UnitTests.cs

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace StyleCop.Analyzers.Test.MaintainabilityRules
88
using System.Threading;
99
using System.Threading.Tasks;
1010
using Microsoft.CodeAnalysis.CodeFixes;
11+
using Microsoft.CodeAnalysis.Testing;
1112
using Microsoft.CodeAnalysis.Text;
1213
using Xunit;
1314
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
@@ -38,12 +39,19 @@ public async Task TestFileWithWrongEncodingAsync(int codepage)
3839

3940
var expected = Diagnostic().WithLocation(1, 1);
4041

41-
await new CSharpTest
42+
var test = new CSharpTest
4243
{
4344
TestSources = { testCode },
4445
ExpectedDiagnostics = { expected },
4546
FixedSources = { fixedCode },
46-
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
47+
};
48+
49+
// Workaround for https://github.com/dotnet/roslyn-sdk/pull/251
50+
test.FixedState.InheritanceMode = StateInheritanceMode.AutoInherit;
51+
test.BatchFixedState.InheritanceMode = StateInheritanceMode.AutoInherit;
52+
53+
test.Exclusions &= ~AnalysisExclusions.Suppression;
54+
await test.RunAsync(CancellationToken.None).ConfigureAwait(false);
4755
}
4856

4957
[Fact]
@@ -54,12 +62,19 @@ public async Task TestFileWithUtf8EncodingWithoutBOMAsync()
5462

5563
var expected = Diagnostic().WithLocation(1, 1);
5664

57-
await new CSharpTest
65+
var test = new CSharpTest
5866
{
5967
TestSources = { testCode },
6068
ExpectedDiagnostics = { expected },
6169
FixedSources = { fixedCode },
62-
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
70+
};
71+
72+
// Workaround for https://github.com/dotnet/roslyn-sdk/pull/251
73+
test.FixedState.InheritanceMode = StateInheritanceMode.AutoInherit;
74+
test.BatchFixedState.InheritanceMode = StateInheritanceMode.AutoInherit;
75+
76+
test.Exclusions &= ~AnalysisExclusions.Suppression;
77+
await test.RunAsync(CancellationToken.None).ConfigureAwait(false);
6378
}
6479

6580
[Theory]
@@ -73,7 +88,7 @@ public async Task TestFixAllAsync(int codepage)
7388
[Fact]
7489
public async Task TestFixAllWithMultipleEncodingsAsync()
7590
{
76-
await new CSharpTest
91+
var test = new CSharpTest
7792
{
7893
TestSources =
7994
{
@@ -95,12 +110,19 @@ public async Task TestFixAllWithMultipleEncodingsAsync()
95110
},
96111
NumberOfFixAllIterations = 2,
97112
NumberOfFixAllInDocumentIterations = 3,
98-
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
113+
};
114+
115+
// Workaround for https://github.com/dotnet/roslyn-sdk/pull/251
116+
test.FixedState.InheritanceMode = StateInheritanceMode.AutoInherit;
117+
test.BatchFixedState.InheritanceMode = StateInheritanceMode.AutoInherit;
118+
119+
test.Exclusions &= ~AnalysisExclusions.Suppression;
120+
await test.RunAsync(CancellationToken.None).ConfigureAwait(false);
99121
}
100122

101123
private async Task TestFixAllExecuterAsync(int codepage, FixAllScope scope)
102124
{
103-
await new CSharpTest
125+
var test = new CSharpTest
104126
{
105127
TestSources =
106128
{
@@ -119,7 +141,14 @@ private async Task TestFixAllExecuterAsync(int codepage, FixAllScope scope)
119141
},
120142
NumberOfFixAllIterations = 1,
121143
NumberOfFixAllInDocumentIterations = 2,
122-
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
144+
};
145+
146+
// Workaround for https://github.com/dotnet/roslyn-sdk/pull/251
147+
test.FixedState.InheritanceMode = StateInheritanceMode.AutoInherit;
148+
test.BatchFixedState.InheritanceMode = StateInheritanceMode.AutoInherit;
149+
150+
test.Exclusions &= ~AnalysisExclusions.Suppression;
151+
await test.RunAsync(CancellationToken.None).ConfigureAwait(false);
123152
}
124153
}
125154
}

StyleCop.Analyzers/StyleCop.Analyzers.Test/Settings/SettingsFileCodeFixProviderUnitTests.cs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ namespace NamespaceName
3131
[Fact]
3232
public async Task TestMissingFileHeaderWithLeadingTriviaAsync()
3333
{
34-
await new CSharpTest
34+
var test = new CSharpTest
3535
{
3636
TestCode = TestCode,
3737
ExpectedDiagnostics = { Diagnostic(FileHeaderAnalyzers.SA1633DescriptorMissing).WithLocation(1, 1) },
@@ -42,7 +42,10 @@ public async Task TestMissingFileHeaderWithLeadingTriviaAsync()
4242
(SettingsHelper.SettingsFileName, SettingsFileCodeFixProvider.DefaultSettingsFileContent),
4343
},
4444
Settings = null,
45-
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
45+
};
46+
47+
test.Exclusions &= ~AnalysisExclusions.Suppression;
48+
await test.RunAsync(CancellationToken.None).ConfigureAwait(false);
4649
}
4750

4851
/// <summary>
@@ -52,7 +55,7 @@ public async Task TestMissingFileHeaderWithLeadingTriviaAsync()
5255
[Fact]
5356
public async Task TestSettingsFileDoesNotExistAsync()
5457
{
55-
await new CSharpTest
58+
var test = new CSharpTest
5659
{
5760
TestCode = TestCode,
5861
ExpectedDiagnostics = { Diagnostic(FileHeaderAnalyzers.SA1633DescriptorMissing).WithLocation(1, 1) },
@@ -63,7 +66,10 @@ public async Task TestSettingsFileDoesNotExistAsync()
6366
(SettingsHelper.SettingsFileName, SettingsFileCodeFixProvider.DefaultSettingsFileContent),
6467
},
6568
Settings = null,
66-
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
69+
};
70+
71+
test.Exclusions &= ~AnalysisExclusions.Suppression;
72+
await test.RunAsync(CancellationToken.None).ConfigureAwait(false);
6773
}
6874

6975
/// <summary>
@@ -73,15 +79,18 @@ public async Task TestSettingsFileDoesNotExistAsync()
7379
[Fact]
7480
public async Task TestSettingsFileAlreadyExistsAsync()
7581
{
76-
await new CSharpTest
82+
var test = new CSharpTest
7783
{
7884
TestCode = TestCode,
7985
ExpectedDiagnostics = { Diagnostic(FileHeaderAnalyzers.SA1633DescriptorMissing).WithLocation(1, 1) },
8086
FixedCode = TestCode,
8187
FixedState = { InheritanceMode = StateInheritanceMode.AutoInheritAll },
8288
Settings = "{}",
8389
SettingsFileName = SettingsHelper.SettingsFileName,
84-
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
90+
};
91+
92+
test.Exclusions &= ~AnalysisExclusions.Suppression;
93+
await test.RunAsync(CancellationToken.None).ConfigureAwait(false);
8594
}
8695

8796
/// <summary>
@@ -91,15 +100,18 @@ public async Task TestSettingsFileAlreadyExistsAsync()
91100
[Fact]
92101
public async Task TestDotPrefixedSettingsFileAlreadyExistsAsync()
93102
{
94-
await new CSharpTest
103+
var test = new CSharpTest
95104
{
96105
TestCode = TestCode,
97106
ExpectedDiagnostics = { Diagnostic(FileHeaderAnalyzers.SA1633DescriptorMissing).WithLocation(1, 1) },
98107
FixedCode = TestCode,
99108
FixedState = { InheritanceMode = StateInheritanceMode.AutoInheritAll },
100109
Settings = "{}",
101110
SettingsFileName = SettingsHelper.AltSettingsFileName,
102-
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
111+
};
112+
113+
test.Exclusions &= ~AnalysisExclusions.Suppression;
114+
await test.RunAsync(CancellationToken.None).ConfigureAwait(false);
103115
}
104116
}
105117
}

0 commit comments

Comments
 (0)