Skip to content

Commit 6db9579

Browse files
committed
Add net6.0 target for Linux testing
* Use Encoding.UTF7 instead of relying on Encoding.GetEncoding, which no longer supports UTF-7 on .NET 6. * Explicitly specify reference assembly target frameworks instead of relying on ReferenceAssemblies.Default. * Update to xunit 2.4.2 which is nullable-annotated. * Fix xUnit1027 (Collection definition classes must be public) * Fix CA1065 (Do not raise exceptions in unexpected locations)
1 parent e1d8e52 commit 6db9579

File tree

12 files changed

+90
-31
lines changed

12 files changed

+90
-31
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/StyleCop.Analyzers.Test.CSharp10.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project Sdk="Microsoft.NET.Sdk">
33

44
<PropertyGroup>
5-
<TargetFramework>net472</TargetFramework>
5+
<TargetFrameworks>net472;net6.0</TargetFrameworks>
66
<EnforceExtendedAnalyzerRules>false</EnforceExtendedAnalyzerRules>
77
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
88
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
@@ -19,7 +19,7 @@
1919

2020
<ItemGroup>
2121
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.0.1" />
22-
<PackageReference Include="xunit" Version="2.4.1" />
22+
<PackageReference Include="xunit" Version="2.4.2" />
2323
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" PrivateAssets="all" />
2424
</ItemGroup>
2525

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp11/StyleCop.Analyzers.Test.CSharp11.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project Sdk="Microsoft.NET.Sdk">
33

44
<PropertyGroup>
5-
<TargetFramework>net472</TargetFramework>
5+
<TargetFrameworks>net472;net6.0</TargetFrameworks>
66
<EnforceExtendedAnalyzerRules>false</EnforceExtendedAnalyzerRules>
77
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
88
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
@@ -19,7 +19,7 @@
1919

2020
<ItemGroup>
2121
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.4.0" />
22-
<PackageReference Include="xunit" Version="2.4.1" />
22+
<PackageReference Include="xunit" Version="2.4.2" />
2323
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" PrivateAssets="all" />
2424
</ItemGroup>
2525

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp12/StyleCop.Analyzers.Test.CSharp12.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project Sdk="Microsoft.NET.Sdk">
33

44
<PropertyGroup>
5-
<TargetFramework>net472</TargetFramework>
5+
<TargetFrameworks>net472;net6.0</TargetFrameworks>
66
<EnforceExtendedAnalyzerRules>false</EnforceExtendedAnalyzerRules>
77
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
88
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
@@ -19,7 +19,7 @@
1919

2020
<ItemGroup>
2121
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.8.0" />
22-
<PackageReference Include="xunit" Version="2.4.1" />
22+
<PackageReference Include="xunit" Version="2.4.2" />
2323
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" PrivateAssets="all" />
2424
</ItemGroup>
2525

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp13/StyleCop.Analyzers.Test.CSharp13.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project Sdk="Microsoft.NET.Sdk">
33

44
<PropertyGroup>
5-
<TargetFramework>net472</TargetFramework>
5+
<TargetFrameworks>net472;net6.0</TargetFrameworks>
66
<EnforceExtendedAnalyzerRules>false</EnforceExtendedAnalyzerRules>
77
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
88
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
@@ -19,7 +19,7 @@
1919

2020
<ItemGroup>
2121
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.12.0" />
22-
<PackageReference Include="xunit" Version="2.4.1" />
22+
<PackageReference Include="xunit" Version="2.4.2" />
2323
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" PrivateAssets="all" />
2424
</ItemGroup>
2525

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project Sdk="Microsoft.NET.Sdk">
33

44
<PropertyGroup>
5-
<TargetFramework>net46</TargetFramework>
5+
<TargetFrameworks>net46;net6.0</TargetFrameworks>
66
<EnforceExtendedAnalyzerRules>false</EnforceExtendedAnalyzerRules>
77
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
88
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
@@ -19,7 +19,7 @@
1919

2020
<ItemGroup>
2121
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="2.8.2" />
22-
<PackageReference Include="xunit" Version="2.4.1" />
22+
<PackageReference Include="xunit" Version="2.4.2" />
2323
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" PrivateAssets="all" />
2424
</ItemGroup>
2525

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp8/StyleCop.Analyzers.Test.CSharp8.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project Sdk="Microsoft.NET.Sdk">
33

44
<PropertyGroup>
5-
<TargetFramework>net472</TargetFramework>
5+
<TargetFrameworks>net472;net6.0</TargetFrameworks>
66
<EnforceExtendedAnalyzerRules>false</EnforceExtendedAnalyzerRules>
77
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
88
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
@@ -19,7 +19,7 @@
1919

2020
<ItemGroup>
2121
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.6.0" />
22-
<PackageReference Include="xunit" Version="2.4.1" />
22+
<PackageReference Include="xunit" Version="2.4.2" />
2323
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" PrivateAssets="all" />
2424

2525
<!-- Increase the NuGet.Framworks version to the minimum supported by the net472 build of the testing library -->

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/StyleCop.Analyzers.Test.CSharp9.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project Sdk="Microsoft.NET.Sdk">
33

44
<PropertyGroup>
5-
<TargetFramework>net472</TargetFramework>
5+
<TargetFrameworks>net472;net6.0</TargetFrameworks>
66
<EnforceExtendedAnalyzerRules>false</EnforceExtendedAnalyzerRules>
77
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
88
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
@@ -19,7 +19,7 @@
1919

2020
<ItemGroup>
2121
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.8.0" />
22-
<PackageReference Include="xunit" Version="2.4.1" />
22+
<PackageReference Include="xunit" Version="2.4.2" />
2323
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" PrivateAssets="all" />
2424
</ItemGroup>
2525

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

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,37 @@ namespace StyleCop.Analyzers.Test.MaintainabilityRules
1919

2020
public class SA1412UnitTests
2121
{
22+
#if NET
23+
static SA1412UnitTests()
24+
{
25+
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
26+
}
27+
#endif
28+
2229
public static IEnumerable<object[]> NonUtf8Encodings
2330
{
2431
get
2532
{
2633
yield return new object[] { Encoding.ASCII.CodePage };
2734
yield return new object[] { Encoding.BigEndianUnicode.CodePage };
35+
#if NETFRAMEWORK
2836
yield return new object[] { Encoding.Default.CodePage };
37+
#else
38+
yield return new object[] { 1252 };
39+
#endif
2940
yield return new object[] { Encoding.Unicode.CodePage };
3041
yield return new object[] { Encoding.UTF32.CodePage };
42+
#pragma warning disable SYSLIB0001 // Type or member is obsolete
3143
yield return new object[] { Encoding.UTF7.CodePage };
44+
#pragma warning restore SYSLIB0001 // Type or member is obsolete
3245
}
3346
}
3447

3548
[Theory]
3649
[MemberData(nameof(NonUtf8Encodings))]
3750
public async Task TestFileWithWrongEncodingAsync(int codepage)
3851
{
39-
var testCode = SourceText.From("class TypeName { }", Encoding.GetEncoding(codepage));
52+
var testCode = SourceText.From("class TypeName { }", GetEncoding(codepage));
4053
var fixedCode = SourceText.From(testCode.ToString(), Encoding.UTF8);
4154

4255
var expected = Diagnostic().WithLocation(1, 1);
@@ -88,7 +101,9 @@ public async Task TestFixAllWithMultipleEncodingsAsync()
88101
{
89102
SourceText.From("class Foo { }", Encoding.Unicode),
90103
SourceText.From("class Bar { }", Encoding.Unicode),
104+
#pragma warning disable SYSLIB0001 // Type or member is obsolete
91105
SourceText.From("class FooBar { }", Encoding.UTF7),
106+
#pragma warning restore SYSLIB0001 // Type or member is obsolete
92107
},
93108
ExpectedDiagnostics =
94109
{
@@ -110,6 +125,18 @@ public async Task TestFixAllWithMultipleEncodingsAsync()
110125
await test.RunAsync(CancellationToken.None).ConfigureAwait(false);
111126
}
112127

128+
private static Encoding GetEncoding(int codepage)
129+
{
130+
#pragma warning disable SYSLIB0001 // Type or member is obsolete
131+
if (codepage == Encoding.UTF7.CodePage)
132+
{
133+
return Encoding.UTF7;
134+
}
135+
#pragma warning restore SYSLIB0001 // Type or member is obsolete
136+
137+
return Encoding.GetEncoding(codepage);
138+
}
139+
113140
private async Task TestFixAllExecuterAsync(int codepage, FixAllScope scope)
114141
{
115142
// Currently unused
@@ -119,8 +146,8 @@ private async Task TestFixAllExecuterAsync(int codepage, FixAllScope scope)
119146
{
120147
TestSources =
121148
{
122-
SourceText.From("class Foo { }", Encoding.GetEncoding(codepage)),
123-
SourceText.From("class Bar { }", Encoding.GetEncoding(codepage)),
149+
SourceText.From("class Foo { }", GetEncoding(codepage)),
150+
SourceText.From("class Bar { }", GetEncoding(codepage)),
124151
},
125152
ExpectedDiagnostics =
126153
{

StyleCop.Analyzers/StyleCop.Analyzers.Test/SequentialTestCollection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace StyleCop.Analyzers.Test
99
/// Defines a collection for tests which cannot run in parallel with other tests.
1010
/// </summary>
1111
[CollectionDefinition(nameof(SequentialTestCollection), DisableParallelization = true)]
12-
internal sealed class SequentialTestCollection
12+
public sealed class SequentialTestCollection
1313
{
1414
}
1515
}

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project Sdk="Microsoft.NET.Sdk">
33

44
<PropertyGroup>
5-
<TargetFramework>net452</TargetFramework>
5+
<TargetFrameworks>net452;net6.0</TargetFrameworks>
66
<EnforceExtendedAnalyzerRules>false</EnforceExtendedAnalyzerRules>
77
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
88
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
@@ -20,16 +20,28 @@
2020
<ItemGroup>
2121
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="1.3.2" />
2222
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing.XUnit" Version="1.1.2-beta1.23509.1" />
23-
<PackageReference Include="Microsoft.VisualStudio.Composition" Version="16.1.8" />
24-
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
25-
<PackageReference Include="xunit" Version="2.4.1" />
23+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
24+
<PackageReference Include="xunit" Version="2.4.2" />
2625
<PackageReference Include="Xunit.Combinatorial" Version="1.4.1" />
2726
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" PrivateAssets="all" />
27+
</ItemGroup>
28+
29+
<ItemGroup Condition="'$(TargetFramework)' == 'net452'">
30+
<PackageReference Include="Microsoft.VisualStudio.Composition" Version="16.1.8" />
31+
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
2832

2933
<!-- Make sure NuGet can parse the 'net5.0' TFM -->
3034
<PackageReference Include="NuGet.Frameworks" Version="5.9.3" />
3135
</ItemGroup>
3236

37+
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
38+
<!-- Exclude Microsoft.Composition which is only needed for .NET Framework execution -->
39+
<PackageReference Include="Microsoft.Composition" Version="1.0.31" ExcludeAssets="all" />
40+
41+
<!-- Make sure Windows-1252 is available for testing -->
42+
<PackageReference Include="System.Text.Encoding.CodePages" Version="6.0.0" />
43+
</ItemGroup>
44+
3345
<ItemGroup>
3446
<ProjectReference Include="..\StyleCop.Analyzers.CodeFixes\StyleCop.Analyzers.CodeFixes.csproj" />
3547
<ProjectReference Include="..\StyleCop.Analyzers\StyleCop.Analyzers.csproj" />

0 commit comments

Comments
 (0)