Skip to content

Commit c0fc688

Browse files
authored
Merge pull request #2584 from pdelvo/SA1206TestUpdate
SA1206 C# 7.2 test update
2 parents 8e24044 + 9fd3ef0 commit c0fc688

3 files changed

Lines changed: 45 additions & 14 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/OrderingRules/SA1206CSharp7UnitTests.cs

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,66 @@ namespace StyleCop.Analyzers.Test.CSharp7.OrderingRules
55
{
66
using System.Threading;
77
using System.Threading.Tasks;
8+
using Microsoft.CodeAnalysis;
9+
using Microsoft.CodeAnalysis.CSharp;
810
using StyleCop.Analyzers.Test.OrderingRules;
911
using TestHelper;
1012
using Xunit;
1113

1214
public class SA1206CSharp7UnitTests : SA1206UnitTests
1315
{
14-
[Fact(Skip = "The version of the compiler used in these tests does not yet support this feature.")]
16+
[Fact]
1517
public async Task TestRefKeywordInStructDeclarationAsync()
1618
{
17-
var testCode = @"private ref struct BitHelper
19+
var testCode = @"class OuterClass
1820
{
21+
private ref struct BitHelper
22+
{
23+
}
24+
}
25+
";
26+
await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
27+
}
28+
29+
[Fact]
30+
public async Task TestReadonlyKeywordInStructDeclarationAsync()
31+
{
32+
var testCode = @"class OuterClass
33+
{
34+
private readonly struct BitHelper
35+
{
36+
}
1937
}
2038
";
2139
await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
2240
}
2341

24-
[Fact(Skip = "The version of the compiler used in these tests does not yet support this feature.")]
25-
public async Task TestRefKeywordInStructDeclarationWrongOrderAsync()
42+
[Fact]
43+
public async Task TestReadonlyKeywordInStructDeclarationWrongOrderAsync()
2644
{
27-
var testCode = @"ref private struct BitHelper
45+
// Note that we don't need a test for ref with the wrong order, because this would be a compile time error
46+
var testCode = @"class OuterClass
2847
{
48+
readonly private struct BitHelper
49+
{
50+
}
2951
}
3052
";
3153

3254
DiagnosticResult[] expected = new[]
3355
{
34-
this.CSharpDiagnostic().WithLocation(1, 13).WithArguments("ref", "private"),
56+
this.CSharpDiagnostic().WithLocation(3, 14).WithArguments("private", "readonly"),
3557
};
3658
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
3759
}
60+
61+
protected override Project ApplyCompilationOptions(Project project)
62+
{
63+
var newProject = base.ApplyCompilationOptions(project);
64+
65+
var parseOptions = (CSharpParseOptions)newProject.ParseOptions;
66+
67+
return newProject.WithParseOptions(parseOptions.WithLanguageVersion(LanguageVersion.Latest));
68+
}
3869
}
3970
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/StyleCop.Analyzers.Test.CSharp7.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
</PropertyGroup>
1616

1717
<ItemGroup>
18-
<PackageReference Include="Microsoft.CodeAnalysis" Version="2.1.0" />
19-
<PackageReference Include="xunit" Version="2.3.0" />
20-
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.0" PrivateAssets="all" />
18+
<PackageReference Include="Microsoft.CodeAnalysis" Version="2.6.0" />
19+
<PackageReference Include="xunit" Version="2.3.1" />
20+
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" PrivateAssets="all" />
2121
</ItemGroup>
2222

2323
<ItemGroup>

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/app.config

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@
44
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
55
<dependentAssembly>
66
<assemblyIdentity name="Microsoft.CodeAnalysis" publicKeyToken="31bf3856ad364e35" culture="neutral" />
7-
<bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
7+
<bindingRedirect oldVersion="0.0.0.0-2.6.0.0" newVersion="2.6.0.0" />
88
</dependentAssembly>
99
<dependentAssembly>
1010
<assemblyIdentity name="Microsoft.CodeAnalysis.CSharp" publicKeyToken="31bf3856ad364e35" culture="neutral" />
11-
<bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
11+
<bindingRedirect oldVersion="0.0.0.0-2.6.0.0" newVersion="2.6.0.0" />
1212
</dependentAssembly>
1313
<dependentAssembly>
1414
<assemblyIdentity name="Microsoft.CodeAnalysis.CSharp.Workspaces" publicKeyToken="31bf3856ad364e35" culture="neutral" />
15-
<bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
15+
<bindingRedirect oldVersion="0.0.0.0-2.6.0.0" newVersion="2.6.0.0" />
1616
</dependentAssembly>
1717
<dependentAssembly>
1818
<assemblyIdentity name="Microsoft.CodeAnalysis.Workspaces" publicKeyToken="31bf3856ad364e35" culture="neutral" />
19-
<bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
19+
<bindingRedirect oldVersion="0.0.0.0-2.6.0.0" newVersion="2.6.0.0" />
2020
</dependentAssembly>
2121
<dependentAssembly>
2222
<assemblyIdentity name="Microsoft.CodeAnalysis.Workspaces.Desktop" publicKeyToken="31bf3856ad364e35" culture="neutral" />
23-
<bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
23+
<bindingRedirect oldVersion="0.0.0.0-2.6.0.0" newVersion="2.6.0.0" />
2424
</dependentAssembly>
2525
<dependentAssembly>
2626
<assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />

0 commit comments

Comments
 (0)