Skip to content

Commit

Permalink
Remove explicit language version configuration in test cases for c# 8…
Browse files Browse the repository at this point in the history
…, so that they will be run with the expected (later) language version in later test projects

DotNetAnalyzers#3493
  • Loading branch information
bjornhellander committed May 9, 2022
1 parent 2e8680d commit 61fee6e
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 38 deletions.
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);
}
}
}

0 comments on commit 61fee6e

Please sign in to comment.