Skip to content

Commit 49b26d0

Browse files
committed
Use Microsoft.CodeAnalysis.Testing for core test functionality
1 parent e390b13 commit 49b26d0

17 files changed

Lines changed: 296 additions & 1646 deletions

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public void Bar()
7777

7878
DiagnosticResult[] expected =
7979
{
80-
Diagnostic(DiagnosticId).WithLocation(5, 38),
80+
Diagnostic(DiagnosticId).WithSpan(5, 38, 5, 41),
8181
Diagnostic(ParenthesesDiagnosticId).WithLocation(5, 38),
8282
Diagnostic(ParenthesesDiagnosticId).WithLocation(5, 40),
8383
};

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ namespace StyleCop.Analyzers.Test
1010
using System.Threading.Tasks;
1111
using Microsoft.CodeAnalysis;
1212
using Microsoft.CodeAnalysis.CodeFixes;
13+
using Microsoft.CodeAnalysis.CSharp;
1314
using Microsoft.CodeAnalysis.Diagnostics;
14-
using StyleCop.Analyzers.Test.Verifiers;
15+
using Microsoft.CodeAnalysis.Testing;
16+
using Microsoft.CodeAnalysis.Testing.Verifiers;
1517
using Xunit;
1618

1719
public class AnalyzerConfigurationTests
@@ -58,7 +60,7 @@ public void TestHelpLink(Type analyzerType)
5860
}
5961
}
6062

61-
private class CSharpTest : GenericAnalyzerTest
63+
private class CSharpTest : CodeFixTest<XUnitVerifier>
6264
{
6365
private readonly Type analyzerType;
6466

@@ -69,6 +71,11 @@ public CSharpTest(Type analyzerType)
6971

7072
public override string Language => LanguageNames.CSharp;
7173

74+
protected override string DefaultFileExt => "cs";
75+
76+
protected override CompilationOptions CreateCompilationOptions()
77+
=> new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, allowUnsafe: true);
78+
7279
protected override IEnumerable<CodeFixProvider> GetCodeFixProviders()
7380
=> new CodeFixProvider[0];
7481

StyleCop.Analyzers/StyleCop.Analyzers.Test/HelperTests/IndentationHelperTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace StyleCop.Analyzers.Test.HelperTests
1010
using Microsoft.CodeAnalysis.CSharp;
1111
using Microsoft.CodeAnalysis.Formatting;
1212
using Microsoft.CodeAnalysis.Testing;
13+
using Microsoft.CodeAnalysis.Testing.Verifiers;
1314
using Microsoft.CodeAnalysis.Text;
1415
using StyleCop.Analyzers.Helpers;
1516
using StyleCop.Analyzers.Settings.ObjectModel;

StyleCop.Analyzers/StyleCop.Analyzers.Test/LayoutRules/SA1501UnitTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ public void Bar(string x, string y)
648648
/// Tests the behavior of SA1503 when SA1503 is suppressed for many different forms of <c>if</c> statements.
649649
/// </summary>
650650
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
651-
[Fact]
651+
[Fact(Skip = "https://github.com/dotnet/roslyn-sdk/pull/191")]
652652
public async Task TestNoSA1503IfStatementsAsync()
653653
{
654654
var testCode = @"using System.Diagnostics;

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

Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ namespace StyleCop.Analyzers.Test.MaintainabilityRules
77
using System.Threading.Tasks;
88
using Microsoft.CodeAnalysis.Testing;
99
using StyleCop.Analyzers.MaintainabilityRules;
10-
using TestHelper;
1110
using Xunit;
1211
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
1312
StyleCop.Analyzers.MaintainabilityRules.SA1119StatementMustNotUseUnnecessaryParenthesis,
@@ -44,7 +43,7 @@ public void Bar()
4443

4544
DiagnosticResult[] expected =
4645
{
47-
Diagnostic(DiagnosticId).WithLocation(5, 17),
46+
Diagnostic(DiagnosticId).WithSpan(5, 17, 5, 20),
4847
Diagnostic(ParenthesesDiagnosticId).WithLocation(5, 17),
4948
Diagnostic(ParenthesesDiagnosticId).WithLocation(5, 19),
5049
};
@@ -72,9 +71,9 @@ public void Bar()
7271

7372
DiagnosticResult[] expected =
7473
{
75-
Diagnostic(DiagnosticId).WithLocation(5, 17),
74+
Diagnostic(DiagnosticId).WithSpan(5, 17, 5, 22),
7675
Diagnostic(ParenthesesDiagnosticId).WithLocation(5, 17),
77-
Diagnostic(DiagnosticId).WithLocation(5, 18),
76+
Diagnostic(DiagnosticId).WithSpan(5, 18, 5, 21),
7877
Diagnostic(ParenthesesDiagnosticId).WithLocation(5, 18),
7978
Diagnostic(ParenthesesDiagnosticId).WithLocation(5, 20),
8079
Diagnostic(ParenthesesDiagnosticId).WithLocation(5, 21),
@@ -116,7 +115,7 @@ public void Bar()
116115

117116
DiagnosticResult[] expected =
118117
{
119-
Diagnostic(DiagnosticId).WithLocation(5, 20),
118+
Diagnostic(DiagnosticId).WithSpan(5, 20, 5, 32),
120119
Diagnostic(ParenthesesDiagnosticId).WithLocation(5, 20),
121120
Diagnostic(ParenthesesDiagnosticId).WithLocation(5, 31),
122121
};
@@ -158,10 +157,10 @@ public void Bar()
158157
}";
159158
DiagnosticResult[] expected =
160159
{
161-
Diagnostic(DiagnosticId).WithLocation(6, 20),
160+
Diagnostic(DiagnosticId).WithSpan(6, 20, 6, 27),
162161
Diagnostic(ParenthesesDiagnosticId).WithLocation(6, 20),
163162
Diagnostic(ParenthesesDiagnosticId).WithLocation(6, 26),
164-
Diagnostic(DiagnosticId).WithLocation(6, 55),
163+
Diagnostic(DiagnosticId).WithSpan(6, 55, 6, 60),
165164
Diagnostic(ParenthesesDiagnosticId).WithLocation(6, 55),
166165
Diagnostic(ParenthesesDiagnosticId).WithLocation(6, 59),
167166
};
@@ -205,7 +204,7 @@ public void Bar()
205204

206205
DiagnosticResult[] expected =
207206
{
208-
Diagnostic(DiagnosticId).WithLocation(6, 9),
207+
Diagnostic(DiagnosticId).WithSpan(6, 9, 6, 21),
209208
Diagnostic(ParenthesesDiagnosticId).WithLocation(6, 9),
210209
Diagnostic(ParenthesesDiagnosticId).WithLocation(6, 20),
211210
};
@@ -234,7 +233,7 @@ public void Bar()
234233
}";
235234
DiagnosticResult[] expected =
236235
{
237-
Diagnostic(DiagnosticId).WithLocation(6, 17),
236+
Diagnostic(DiagnosticId).WithSpan(6, 17, 6, 24),
238237
Diagnostic(ParenthesesDiagnosticId).WithLocation(6, 17),
239238
Diagnostic(ParenthesesDiagnosticId).WithLocation(6, 23),
240239
};
@@ -276,7 +275,7 @@ public void Bar()
276275

277276
DiagnosticResult[] expected =
278277
{
279-
Diagnostic(DiagnosticId).WithLocation(5, 17),
278+
Diagnostic(DiagnosticId).WithSpan(5, 17, 5, 25),
280279
Diagnostic(ParenthesesDiagnosticId).WithLocation(5, 17),
281280
Diagnostic(ParenthesesDiagnosticId).WithLocation(5, 24),
282281
};
@@ -318,7 +317,7 @@ public void Bar()
318317
}";
319318
DiagnosticResult[] expected =
320319
{
321-
Diagnostic(DiagnosticId).WithLocation(6, 13),
320+
Diagnostic(DiagnosticId).WithSpan(6, 13, 6, 21),
322321
Diagnostic(ParenthesesDiagnosticId).WithLocation(6, 13),
323322
Diagnostic(ParenthesesDiagnosticId).WithLocation(6, 20),
324323
};
@@ -398,22 +397,22 @@ public void Bar()
398397
}";
399398
DiagnosticResult[] expected =
400399
{
401-
Diagnostic(DiagnosticId).WithLocation(6, 13),
400+
Diagnostic(DiagnosticId).WithSpan(6, 13, 6, 18),
402401
Diagnostic(ParenthesesDiagnosticId).WithLocation(6, 13),
403402
Diagnostic(ParenthesesDiagnosticId).WithLocation(6, 17),
404-
Diagnostic(DiagnosticId).WithLocation(7, 13),
403+
Diagnostic(DiagnosticId).WithSpan(7, 13, 7, 18),
405404
Diagnostic(ParenthesesDiagnosticId).WithLocation(7, 13),
406405
Diagnostic(ParenthesesDiagnosticId).WithLocation(7, 17),
407-
Diagnostic(DiagnosticId).WithLocation(8, 13),
406+
Diagnostic(DiagnosticId).WithSpan(8, 13, 8, 18),
408407
Diagnostic(ParenthesesDiagnosticId).WithLocation(8, 13),
409408
Diagnostic(ParenthesesDiagnosticId).WithLocation(8, 17),
410-
Diagnostic(DiagnosticId).WithLocation(9, 13),
409+
Diagnostic(DiagnosticId).WithSpan(9, 13, 9, 17),
411410
Diagnostic(ParenthesesDiagnosticId).WithLocation(9, 13),
412411
Diagnostic(ParenthesesDiagnosticId).WithLocation(9, 16),
413-
Diagnostic(DiagnosticId).WithLocation(10, 13),
412+
Diagnostic(DiagnosticId).WithSpan(10, 13, 10, 17),
414413
Diagnostic(ParenthesesDiagnosticId).WithLocation(10, 13),
415414
Diagnostic(ParenthesesDiagnosticId).WithLocation(10, 16),
416-
Diagnostic(DiagnosticId).WithLocation(11, 13),
415+
Diagnostic(DiagnosticId).WithSpan(11, 13, 11, 17),
417416
Diagnostic(ParenthesesDiagnosticId).WithLocation(11, 13),
418417
Diagnostic(ParenthesesDiagnosticId).WithLocation(11, 16),
419418
};
@@ -462,10 +461,10 @@ public void Bar()
462461

463462
DiagnosticResult[] expected =
464463
{
465-
Diagnostic(DiagnosticId).WithLocation(5, 21),
464+
Diagnostic(DiagnosticId).WithSpan(5, 21, 5, 33),
466465
Diagnostic(ParenthesesDiagnosticId).WithLocation(5, 21),
467466
Diagnostic(ParenthesesDiagnosticId).WithLocation(5, 32),
468-
Diagnostic(DiagnosticId).WithLocation(6, 17),
467+
Diagnostic(DiagnosticId).WithSpan(6, 17, 6, 31),
469468
Diagnostic(ParenthesesDiagnosticId).WithLocation(6, 17),
470469
Diagnostic(ParenthesesDiagnosticId).WithLocation(6, 30),
471470
};
@@ -506,7 +505,7 @@ public void Bar()
506505
}";
507506
DiagnosticResult[] expected =
508507
{
509-
Diagnostic(DiagnosticId).WithLocation(5, 20),
508+
Diagnostic(DiagnosticId).WithSpan(5, 20, 5, 33),
510509
Diagnostic(ParenthesesDiagnosticId).WithLocation(5, 20),
511510
Diagnostic(ParenthesesDiagnosticId).WithLocation(5, 32),
512511
};
@@ -560,10 +559,10 @@ public void Bar()
560559
}";
561560
DiagnosticResult[] expected =
562561
{
563-
Diagnostic(DiagnosticId).WithLocation(5, 18),
562+
Diagnostic(DiagnosticId).WithSpan(5, 18, 5, 32),
564563
Diagnostic(ParenthesesDiagnosticId).WithLocation(5, 18),
565564
Diagnostic(ParenthesesDiagnosticId).WithLocation(5, 31),
566-
Diagnostic(DiagnosticId).WithLocation(6, 13),
565+
Diagnostic(DiagnosticId).WithSpan(6, 13, 6, 27),
567566
Diagnostic(ParenthesesDiagnosticId).WithLocation(6, 13),
568567
Diagnostic(ParenthesesDiagnosticId).WithLocation(6, 26),
569568
};
@@ -606,7 +605,7 @@ public void Bar()
606605
}";
607606
DiagnosticResult[] expected =
608607
{
609-
Diagnostic(DiagnosticId).WithLocation(6, 20),
608+
Diagnostic(DiagnosticId).WithSpan(6, 20, 6, 31),
610609
Diagnostic(ParenthesesDiagnosticId).WithLocation(6, 20),
611610
Diagnostic(ParenthesesDiagnosticId).WithLocation(6, 30),
612611
};
@@ -662,7 +661,7 @@ public void Bar()
662661
}";
663662
DiagnosticResult[] expected =
664663
{
665-
Diagnostic(DiagnosticId).WithLocation(5, 20),
664+
Diagnostic(DiagnosticId).WithSpan(5, 20, 5, 42),
666665
Diagnostic(ParenthesesDiagnosticId).WithLocation(5, 20),
667666
Diagnostic(ParenthesesDiagnosticId).WithLocation(5, 41),
668667
};
@@ -716,7 +715,7 @@ public void Bar()
716715
}";
717716
DiagnosticResult[] expected =
718717
{
719-
Diagnostic(DiagnosticId).WithLocation(5, 20),
718+
Diagnostic(DiagnosticId).WithSpan(5, 20, 5, 36),
720719
Diagnostic(ParenthesesDiagnosticId).WithLocation(5, 20),
721720
Diagnostic(ParenthesesDiagnosticId).WithLocation(5, 35),
722721
};
@@ -772,10 +771,10 @@ public void Bar()
772771
}";
773772
DiagnosticResult[] expected =
774773
{
775-
Diagnostic(DiagnosticId).WithLocation(5, 41),
774+
Diagnostic(DiagnosticId).WithSpan(5, 41, 5, 49),
776775
Diagnostic(ParenthesesDiagnosticId).WithLocation(5, 41),
777776
Diagnostic(ParenthesesDiagnosticId).WithLocation(5, 48),
778-
Diagnostic(DiagnosticId).WithLocation(6, 41),
777+
Diagnostic(DiagnosticId).WithSpan(6, 41, 6, 51),
779778
Diagnostic(ParenthesesDiagnosticId).WithLocation(6, 41),
780779
Diagnostic(ParenthesesDiagnosticId).WithLocation(6, 50),
781780
};
@@ -830,7 +829,7 @@ public void Bar()
830829
}";
831830
DiagnosticResult[] expected =
832831
{
833-
Diagnostic(DiagnosticId).WithLocation(5, 19),
832+
Diagnostic(DiagnosticId).WithSpan(5, 19, 5, 32),
834833
Diagnostic(ParenthesesDiagnosticId).WithLocation(5, 19),
835834
Diagnostic(ParenthesesDiagnosticId).WithLocation(5, 31),
836835
};
@@ -885,7 +884,7 @@ public void Bar()
885884
}";
886885
DiagnosticResult[] expected =
887886
{
888-
Diagnostic(DiagnosticId).WithLocation(6, 17),
887+
Diagnostic(DiagnosticId).WithSpan(6, 17, 6, 53),
889888
Diagnostic(ParenthesesDiagnosticId).WithLocation(6, 17),
890889
Diagnostic(ParenthesesDiagnosticId).WithLocation(6, 52),
891890
};
@@ -972,7 +971,7 @@ private bool Test()
972971
}";
973972
DiagnosticResult[] expected =
974973
{
975-
Diagnostic(DiagnosticId).WithLocation(6, 20),
974+
Diagnostic(DiagnosticId).WithSpan(6, 20, 10, 18),
976975
Diagnostic(ParenthesesDiagnosticId).WithLocation(6, 20),
977976
Diagnostic(ParenthesesDiagnosticId).WithLocation(10, 17),
978977
};
@@ -992,7 +991,7 @@ public async Task TestCodeFixWorksInTriviaAsync()
992991

993992
DiagnosticResult[] expected =
994993
{
995-
Diagnostic(DiagnosticId).WithLocation(1, 5),
994+
Diagnostic(DiagnosticId).WithSpan(1, 5, 1, 21),
996995
Diagnostic(ParenthesesDiagnosticId).WithLocation(1, 5),
997996
Diagnostic(ParenthesesDiagnosticId).WithLocation(1, 20),
998997
};
@@ -1013,7 +1012,7 @@ public string Bar()
10131012
}";
10141013
DiagnosticResult[] expected =
10151014
{
1016-
Diagnostic(DiagnosticId).WithLocation(6, 15),
1015+
Diagnostic(DiagnosticId).WithSpan(6, 15, 6, 20),
10171016
Diagnostic(ParenthesesDiagnosticId).WithLocation(6, 15),
10181017
Diagnostic(ParenthesesDiagnosticId).WithLocation(6, 19),
10191018
};
@@ -1043,7 +1042,7 @@ public void Bar()
10431042
}";
10441043
DiagnosticResult[] expected =
10451044
{
1046-
Diagnostic(DiagnosticId).WithLocation(6, 26),
1045+
Diagnostic(DiagnosticId).WithSpan(6, 26, 6, 32),
10471046
Diagnostic(ParenthesesDiagnosticId).WithLocation(6, 26),
10481047
Diagnostic(ParenthesesDiagnosticId).WithLocation(6, 31),
10491048
};
@@ -1108,7 +1107,7 @@ public string Bar()
11081107

11091108
DiagnosticResult[] expected =
11101109
{
1111-
Diagnostic(DiagnosticId).WithLocation(6, 20),
1110+
Diagnostic(DiagnosticId).WithSpan(6, 20, 6, 35),
11121111
Diagnostic(ParenthesesDiagnosticId).WithLocation(6, 20),
11131112
Diagnostic(ParenthesesDiagnosticId).WithLocation(6, 34),
11141113
};
@@ -1191,7 +1190,7 @@ public void Bar()
11911190
}";
11921191
DiagnosticResult[] expected =
11931192
{
1194-
Diagnostic(DiagnosticId).WithLocation(6, 23),
1193+
Diagnostic(DiagnosticId).WithSpan(6, 23, 6, 43),
11951194
Diagnostic(ParenthesesDiagnosticId).WithLocation(6, 23),
11961195
Diagnostic(ParenthesesDiagnosticId).WithLocation(6, 42),
11971196
};
@@ -1251,7 +1250,7 @@ public void Bar()
12511250
}";
12521251
DiagnosticResult[] expected =
12531252
{
1254-
Diagnostic(DiagnosticId).WithLocation(6, 22),
1253+
Diagnostic(DiagnosticId).WithSpan(6, 22, 6, 36),
12551254
Diagnostic(ParenthesesDiagnosticId).WithLocation(6, 22),
12561255
Diagnostic(ParenthesesDiagnosticId).WithLocation(6, 35),
12571256
};
@@ -1311,7 +1310,7 @@ public void Bar()
13111310
}";
13121311
DiagnosticResult[] expected =
13131312
{
1314-
Diagnostic(DiagnosticId).WithLocation(6, 22),
1313+
Diagnostic(DiagnosticId).WithSpan(6, 22, 6, 31),
13151314
Diagnostic(ParenthesesDiagnosticId).WithLocation(6, 22),
13161315
Diagnostic(ParenthesesDiagnosticId).WithLocation(6, 30),
13171316
};
@@ -1371,7 +1370,7 @@ public void Bar()
13711370
}";
13721371
DiagnosticResult[] expected =
13731372
{
1374-
Diagnostic(DiagnosticId).WithLocation(6, 22),
1373+
Diagnostic(DiagnosticId).WithSpan(6, 22, 6, 30),
13751374
Diagnostic(ParenthesesDiagnosticId).WithLocation(6, 22),
13761375
Diagnostic(ParenthesesDiagnosticId).WithLocation(6, 29),
13771376
};
@@ -1420,10 +1419,10 @@ public static void Main(string[] args)
14201419
";
14211420
DiagnosticResult[] expected =
14221421
{
1423-
Diagnostic(DiagnosticId).WithLocation(6, 4),
1422+
Diagnostic(DiagnosticId).WithSpan(6, 4, 6, 11),
14241423
Diagnostic(ParenthesesDiagnosticId).WithLocation(6, 4),
14251424
Diagnostic(ParenthesesDiagnosticId).WithLocation(6, 10),
1426-
Diagnostic(DiagnosticId).WithLocation(10, 5),
1425+
Diagnostic(DiagnosticId).WithSpan(10, 5, 10, 12),
14271426
Diagnostic(ParenthesesDiagnosticId).WithLocation(10, 5),
14281427
Diagnostic(ParenthesesDiagnosticId).WithLocation(10, 11),
14291428
};

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,15 @@ public async Task TestFileWithUtf8EncodingWithoutBOMAsync()
6262
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
6363
}
6464

65-
[Theory]
65+
[Theory(Skip = "https://github.com/dotnet/roslyn-sdk/issues/147")]
6666
[MemberData(nameof(NonUtf8Encodings))]
6767
public async Task TestFixAllAsync(int codepage)
6868
{
6969
await this.TestFixAllExecuterAsync(codepage, FixAllScope.Project).ConfigureAwait(false);
7070
await this.TestFixAllExecuterAsync(codepage, FixAllScope.Solution).ConfigureAwait(false);
7171
}
7272

73-
[Fact]
73+
[Fact(Skip = "https://github.com/dotnet/roslyn-sdk/issues/147")]
7474
public async Task TestFixAllWithMultipleEncodingsAsync()
7575
{
7676
await new CSharpTest
@@ -94,7 +94,7 @@ public async Task TestFixAllWithMultipleEncodingsAsync()
9494
SourceText.From("class FooBar { }", Encoding.UTF8),
9595
},
9696
NumberOfFixAllIterations = 2,
97-
NumberOfFixAllInDocumentIterations = 3,
97+
////NumberOfFixAllInDocumentIterations = 3,
9898
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
9999
}
100100

@@ -118,7 +118,7 @@ private async Task TestFixAllExecuterAsync(int codepage, FixAllScope scope)
118118
SourceText.From("class Bar { }", Encoding.UTF8),
119119
},
120120
NumberOfFixAllIterations = 1,
121-
NumberOfFixAllInDocumentIterations = 2,
121+
////NumberOfFixAllInDocumentIterations = 2,
122122
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
123123
}
124124
}

0 commit comments

Comments
 (0)