Skip to content

Commit

Permalink
Remove hard-coded language versions in test projects for c# 8, 9 and …
Browse files Browse the repository at this point in the history
…10. Previously, affected tests were always run with the specified language version, even in test projects for later language versions.

#3493
  • Loading branch information
bjornhellander committed Jun 19, 2022
1 parent 01f7674 commit a25f0f7
Show file tree
Hide file tree
Showing 28 changed files with 51 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace StyleCop.Analyzers.Test.CSharp10.NamingRules
{
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp;
using StyleCop.Analyzers.Test.CSharp9.NamingRules;
using StyleCop.Analyzers.Test.Verifiers;
using Xunit;
Expand Down Expand Up @@ -43,7 +42,7 @@ public R(int a, int b)
}}
";

await new CSharpTest(LanguageVersion.CSharp10)
await new CSharpTest()
{
ReferenceAssemblies = GenericAnalyzerTest.ReferenceAssembliesNet60,
TestCode = testCode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ namespace StyleCop.Analyzers.Test.CSharp10.ReadabilityRules
{
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp;
using StyleCop.Analyzers.Test.CSharp9.ReadabilityRules;
using StyleCop.Analyzers.Test.Verifiers;
using Xunit;
Expand All @@ -30,7 +29,7 @@ public bool Method(Test arg)
}
}";

await new CSharpTest(LanguageVersion.CSharp10)
await new CSharpTest()
{
ReferenceAssemblies = GenericAnalyzerTest.ReferenceAssembliesNet60,
TestCode = testCode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ namespace StyleCop.Analyzers.Test.CSharp8.MaintainabilityRules
using System.Threading;
using System.Threading.Tasks;

using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Testing;
using StyleCop.Analyzers.Test.CSharp7.MaintainabilityRules;

Expand Down Expand Up @@ -38,7 +37,7 @@ public string TestMethod(int n, object a, object b)
}
";

await VerifyCSharpDiagnosticAsync(LanguageVersion.CSharp8, testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

/// <summary>
Expand Down Expand Up @@ -76,7 +75,7 @@ public string TestMethod(int n, object a, object b)
Diagnostic(ParenthesesDiagnosticId).WithLocation(6, 54),
};

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

/// <summary>
Expand All @@ -99,7 +98,7 @@ public async Task<string> TestMethod(int n, Task<string> a, Task<string> b)
}
";

await VerifyCSharpDiagnosticAsync(LanguageVersion.CSharp8, testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

/// <summary>
Expand Down Expand Up @@ -141,7 +140,7 @@ public async Task<string> TestMethod(int n, Task<string> a, Task<string> b)
Diagnostic(ParenthesesDiagnosticId).WithLocation(2),
};

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

/// <summary>
Expand Down Expand Up @@ -179,7 +178,7 @@ public void TestMethod(int n, object a, object b)
Diagnostic(ParenthesesDiagnosticId).WithLocation(6, 48),
};

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

[Theory]
Expand All @@ -200,7 +199,7 @@ public object TestMethod(int n, string a, string b)
}}
";

await VerifyCSharpDiagnosticAsync(LanguageVersion.CSharp8, testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

[Fact]
Expand All @@ -217,7 +216,7 @@ public unsafe string TestMethod(int n, byte* a, byte* b)
}
";

await VerifyCSharpDiagnosticAsync(LanguageVersion.CSharp8, testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

[Fact]
Expand All @@ -235,7 +234,7 @@ public unsafe void TestMethod()
}
";

await VerifyCSharpDiagnosticAsync(LanguageVersion.CSharp8, testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

[Fact]
Expand All @@ -253,7 +252,7 @@ public void TestMethod()
}
";

await new CSharpTest(LanguageVersion.CSharp8)
await new CSharpTest()
{
ReferenceAssemblies = ReferenceAssemblies.NetCore.NetCoreApp31,
TestCode = testCode,
Expand Down Expand Up @@ -300,7 +299,7 @@ public void TestMethod()
Diagnostic(ParenthesesDiagnosticId).WithLocation(9, 27),
};

var test = new CSharpTest(LanguageVersion.CSharp8)
var test = new CSharpTest()
{
ReferenceAssemblies = ReferenceAssemblies.NetCore.NetCoreApp31,
TestCode = testCode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace StyleCop.Analyzers.Test.CSharp8.MaintainabilityRules
{
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Testing;
using StyleCop.Analyzers.Test.CSharp7.MaintainabilityRules;
using Xunit;
Expand Down Expand Up @@ -57,7 +56,7 @@ public void TestMethod(int input)
}
";

await VerifyCSharpFixAsync(LanguageVersion.CSharp8, testCode, DiagnosticResult.EmptyDiagnosticResults, fixedCode, CancellationToken.None).ConfigureAwait(false);
await VerifyCSharpFixAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, fixedCode, CancellationToken.None).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace StyleCop.Analyzers.Test.CSharp8.SpacingRules
{
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Testing;
using StyleCop.Analyzers.Test.CSharp7.SpacingRules;
using Xunit;
Expand Down Expand Up @@ -55,7 +54,7 @@ public void TestMethod(object?[] arguments)
Diagnostic().WithArguments(" not", "preceded").WithLocation(9, 40),
};

await VerifyCSharpFixAsync(LanguageVersion.CSharp8, testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace StyleCop.Analyzers.Test.CSharp8.SpacingRules
{
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Testing;
using StyleCop.Analyzers.Test.CSharp7.SpacingRules;
using Xunit;
Expand Down Expand Up @@ -59,7 +58,7 @@ public void TestMethod()
}
";

await new CSharpTest(LanguageVersion.CSharp8)
await new CSharpTest()
{
ReferenceAssemblies = ReferenceAssemblies.NetCore.NetCoreApp31,
TestCode = testCode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace StyleCop.Analyzers.Test.CSharp8.SpacingRules
{
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Testing;
using StyleCop.Analyzers.Test.CSharp7.SpacingRules;
using Xunit;
Expand Down Expand Up @@ -66,7 +65,7 @@ public void TestMethod()
}
";

await new CSharpTest(LanguageVersion.CSharp8)
await new CSharpTest()
{
ReferenceAssemblies = ReferenceAssemblies.NetCore.NetCoreApp31,
TestCode = testCode,
Expand Down Expand Up @@ -108,7 +107,6 @@ void M((string A, string B) tuple)
};

await VerifyCSharpFixAsync(
LanguageVersion.CSharp8,
testCode,
expectedResults,
fixedCode,
Expand Down Expand Up @@ -146,7 +144,6 @@ void M((bool A, bool B) tuple)
};

await VerifyCSharpFixAsync(
LanguageVersion.CSharp8,
testCode,
expectedResults,
fixedCode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ namespace StyleCop.Analyzers.Test.CSharp8.SpacingRules
{
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Testing;
using StyleCop.Analyzers.Test.CSharp7.SpacingRules;
using StyleCop.Analyzers.Test.Verifiers;
using Xunit;
using static StyleCop.Analyzers.SpacingRules.SA1009ClosingParenthesisMustBeSpacedCorrectly;
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
Expand Down Expand Up @@ -44,7 +42,7 @@ public void TestMethod<T>()
}
}";

await VerifyCSharpFixAsync(LanguageVersion.CSharp8, testCode, DiagnosticResult.EmptyDiagnosticResults, fixedCode, CancellationToken.None).ConfigureAwait(false);
await VerifyCSharpFixAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, fixedCode, CancellationToken.None).ConfigureAwait(false);
}

[Fact]
Expand Down Expand Up @@ -100,7 +98,7 @@ public Derived()
Diagnostic(DescriptorNotPreceded).WithLocation(2),
};

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

[Fact]
Expand All @@ -124,7 +122,7 @@ public class Foo
public IDisposable Service => this.TestMethod<IDisposable>()!;
}";

await VerifyCSharpFixAsync(LanguageVersion.CSharp8, testCode, DiagnosticResult.EmptyDiagnosticResults, fixedCode, CancellationToken.None).ConfigureAwait(false);
await VerifyCSharpFixAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, fixedCode, CancellationToken.None).ConfigureAwait(false);
}

[Fact]
Expand Down Expand Up @@ -154,7 +152,7 @@ public IDisposable Service()
}
}";

await VerifyCSharpFixAsync(LanguageVersion.CSharp8, testCode, DiagnosticResult.EmptyDiagnosticResults, fixedCode, CancellationToken.None).ConfigureAwait(false);
await VerifyCSharpFixAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, fixedCode, CancellationToken.None).ConfigureAwait(false);
}

/// <summary>
Expand Down Expand Up @@ -201,7 +199,7 @@ public string TestMethod()
}
";

await new CSharpTest(LanguageVersion.CSharp8)
await new CSharpTest()
{
ReferenceAssemblies = ReferenceAssemblies.NetCore.NetCoreApp31,
TestCode = testCode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace StyleCop.Analyzers.Test.CSharp8.SpacingRules
{
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Testing;
using StyleCop.Analyzers.Test.CSharp7.SpacingRules;
using Xunit;
Expand Down Expand Up @@ -37,7 +36,7 @@ public void TestMethod()
}
";

await VerifyCSharpDiagnosticAsync(LanguageVersion.CSharp8, testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

[Fact]
Expand All @@ -56,7 +55,7 @@ public class TestClass
}
";

await VerifyCSharpDiagnosticAsync(LanguageVersion.CSharp8, testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

[Fact]
Expand Down Expand Up @@ -105,7 +104,7 @@ public void TestMethod(object?[] arguments)
Diagnostic().WithArguments(" not", "followed").WithLocation(12, 36),
};

await VerifyCSharpFixAsync(LanguageVersion.CSharp8, testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace StyleCop.Analyzers.Test.CSharp8.SpacingRules
{
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Testing;
using StyleCop.Analyzers.Test.CSharp7.SpacingRules;
using Xunit;
Expand Down Expand Up @@ -56,7 +55,6 @@ void M((string A, string B) tuple)
};

await VerifyCSharpFixAsync(
LanguageVersion.CSharp8,
testCode,
expectedResults,
fixedCode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ namespace StyleCop.Analyzers.Test.CSharp8.SpacingRules
using System.Threading;
using System.Threading.Tasks;

using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Testing;

using StyleCop.Analyzers.Test.CSharp7.SpacingRules;
Expand Down Expand Up @@ -91,7 +90,7 @@ public void TestMethod()
}
";

await VerifyCSharpDiagnosticAsync(LanguageVersion.CSharp8, testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace StyleCop.Analyzers.Test.CSharp8.SpacingRules
{
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Testing;
using StyleCop.Analyzers.Test.CSharp7.SpacingRules;
using Xunit;
Expand Down Expand Up @@ -64,7 +63,7 @@ public void TestMethod(object?[] arguments)
Diagnostic(DescriptorNotPreceded).WithArguments("?").WithLocation(12, 40),
};

await VerifyCSharpFixAsync(LanguageVersion.CSharp8, testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ namespace StyleCop.Analyzers.Test.CSharp9.LayoutRules
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Testing;
using StyleCop.Analyzers.Test.CSharp8.LayoutRules;
using Xunit;
Expand Down Expand Up @@ -36,7 +35,7 @@ public async Task TestUsingAndGlobalStatementSpacingInTopLevelProgramAsync()
return 0;
";

var test = new CSharpTest(LanguageVersion.CSharp9)
var test = new CSharpTest()
{
ReferenceAssemblies = ReferenceAssemblies.Net.Net50,
TestState =
Expand All @@ -63,7 +62,7 @@ public async Task TestGlobalStatementSpacingInTopLevelProgramAsync()
return i;
";

await new CSharpTest(LanguageVersion.CSharp9)
await new CSharpTest()
{
ReferenceAssemblies = ReferenceAssemblies.Net.Net50,
TestState =
Expand All @@ -90,7 +89,7 @@ public async Task TestGlobalStatementAndRecordSpacingInTopLevelProgramAsync()
record A();
";

var test = new CSharpTest(LanguageVersion.CSharp9)
var test = new CSharpTest()
{
ReferenceAssemblies = ReferenceAssemblies.Net.Net50,
TestState =
Expand Down
Loading

0 comments on commit a25f0f7

Please sign in to comment.