Skip to content

Commit

Permalink
Merge pull request #3616 from bjornhellander/feature/languageversion
Browse files Browse the repository at this point in the history
Update so that c# 7 tests will be run with the expected language version in test projects for c# 8 and above
  • Loading branch information
sharwell committed Jun 21, 2023
2 parents 26e3c69 + b7d86f1 commit a69732f
Show file tree
Hide file tree
Showing 18 changed files with 88 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace StyleCop.Analyzers.Test.CSharp7.LayoutRules
using Microsoft.CodeAnalysis.Testing;
using StyleCop.Analyzers.Test.LayoutRules;
using Xunit;
using static StyleCop.Analyzers.Test.Helpers.LanguageVersionTestExtensions;
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
StyleCop.Analyzers.LayoutRules.SA1500BracesForMultiLineStatementsMustNotShareLine,
StyleCop.Analyzers.LayoutRules.SA1500CodeFixProvider>;
Expand Down Expand Up @@ -199,7 +200,7 @@ public unsafe void TestMethod()
};
}
}";
await VerifyCSharpDiagnosticAsync(LanguageVersion.CSharp7_3, testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
await VerifyCSharpDiagnosticAsync(LanguageVersion.CSharp7_3.OrLaterDefault(), testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

/// <summary>
Expand Down Expand Up @@ -277,7 +278,7 @@ public unsafe void TestMethod()
Diagnostic().WithLocation(23, 22),
};

await VerifyCSharpFixAsync(LanguageVersion.CSharp7_3, testCode, expectedDiagnostics, fixedTestCode, CancellationToken.None).ConfigureAwait(false);
await VerifyCSharpFixAsync(LanguageVersion.CSharp7_3.OrLaterDefault(), testCode, expectedDiagnostics, fixedTestCode, CancellationToken.None).ConfigureAwait(false);
}

/// <summary>
Expand Down Expand Up @@ -335,7 +336,7 @@ public unsafe void TestMethod()
Diagnostic().WithLocation(15, 22),
};

await VerifyCSharpFixAsync(LanguageVersion.CSharp7_3, testCode, expectedDiagnostics, fixedTestCode, CancellationToken.None).ConfigureAwait(false);
await VerifyCSharpFixAsync(LanguageVersion.CSharp7_3.OrLaterDefault(), testCode, expectedDiagnostics, fixedTestCode, CancellationToken.None).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace StyleCop.Analyzers.Test.CSharp7.LayoutRules
using Microsoft.CodeAnalysis.Testing;
using StyleCop.Analyzers.Test.LayoutRules;
using Xunit;
using static StyleCop.Analyzers.Test.Helpers.LanguageVersionTestExtensions;
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
StyleCop.Analyzers.LayoutRules.SA1505OpeningBracesMustNotBeFollowedByBlankLine,
StyleCop.Analyzers.LayoutRules.SA1505CodeFixProvider>;
Expand Down Expand Up @@ -129,7 +130,7 @@ public unsafe void TestMethod()
";

var expectedDiagnostic = Diagnostic().WithLocation(8, 13);
await VerifyCSharpFixAsync(LanguageVersion.CSharp7_3, testCode, expectedDiagnostic, fixedTestCode, CancellationToken.None).ConfigureAwait(false);
await VerifyCSharpFixAsync(LanguageVersion.CSharp7_3.OrLaterDefault(), testCode, expectedDiagnostic, fixedTestCode, CancellationToken.None).ConfigureAwait(false);
}

[Fact]
Expand Down Expand Up @@ -171,7 +172,7 @@ public unsafe void TestMethod()
";

var expectedDiagnostic = Diagnostic().WithLocation(8, 13);
await VerifyCSharpFixAsync(LanguageVersion.CSharp7_3, testCode, expectedDiagnostic, fixedTestCode, CancellationToken.None).ConfigureAwait(false);
await VerifyCSharpFixAsync(LanguageVersion.CSharp7_3.OrLaterDefault(), testCode, expectedDiagnostic, fixedTestCode, CancellationToken.None).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace StyleCop.Analyzers.Test.CSharp7.LayoutRules
using Microsoft.CodeAnalysis.Testing;
using StyleCop.Analyzers.Test.LayoutRules;
using Xunit;
using static StyleCop.Analyzers.Test.Helpers.LanguageVersionTestExtensions;
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
StyleCop.Analyzers.LayoutRules.SA1508ClosingBracesMustNotBePrecededByBlankLine,
StyleCop.Analyzers.LayoutRules.SA1508CodeFixProvider>;
Expand Down Expand Up @@ -129,7 +130,7 @@ public unsafe void TestMethod()
";

var expectedDiagnostic = Diagnostic().WithLocation(13, 13);
await VerifyCSharpFixAsync(LanguageVersion.CSharp7_3, testCode, expectedDiagnostic, fixedTestCode, CancellationToken.None).ConfigureAwait(false);
await VerifyCSharpFixAsync(LanguageVersion.CSharp7_3.OrLaterDefault(), testCode, expectedDiagnostic, fixedTestCode, CancellationToken.None).ConfigureAwait(false);
}

[Fact]
Expand Down Expand Up @@ -171,7 +172,7 @@ public unsafe void TestMethod()
";

var expectedDiagnostic = Diagnostic().WithLocation(13, 13);
await VerifyCSharpFixAsync(LanguageVersion.CSharp7_3, testCode, expectedDiagnostic, fixedTestCode, CancellationToken.None).ConfigureAwait(false);
await VerifyCSharpFixAsync(LanguageVersion.CSharp7_3.OrLaterDefault(), testCode, expectedDiagnostic, fixedTestCode, CancellationToken.None).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace StyleCop.Analyzers.Test.CSharp7.LayoutRules
using Microsoft.CodeAnalysis.Testing;
using StyleCop.Analyzers.Test.LayoutRules;
using Xunit;
using static StyleCop.Analyzers.Test.Helpers.LanguageVersionTestExtensions;
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
StyleCop.Analyzers.LayoutRules.SA1509OpeningBracesMustNotBePrecededByBlankLine,
StyleCop.Analyzers.LayoutRules.SA1509CodeFixProvider>;
Expand Down Expand Up @@ -116,7 +117,7 @@ public unsafe void TestMethod()
";

var expectedDiagnostic = Diagnostic().WithLocation(9, 13);
await VerifyCSharpFixAsync(LanguageVersion.CSharp7_3, testCode, expectedDiagnostic, fixedTestCode, CancellationToken.None).ConfigureAwait(false);
await VerifyCSharpFixAsync(LanguageVersion.CSharp7_3.OrLaterDefault(), testCode, expectedDiagnostic, fixedTestCode, CancellationToken.None).ConfigureAwait(false);
}

[Fact]
Expand Down Expand Up @@ -158,7 +159,7 @@ public unsafe void TestMethod()
";

var expectedDiagnostic = Diagnostic().WithLocation(9, 13);
await VerifyCSharpFixAsync(LanguageVersion.CSharp7_3, testCode, expectedDiagnostic, fixedTestCode, CancellationToken.None).ConfigureAwait(false);
await VerifyCSharpFixAsync(LanguageVersion.CSharp7_3.OrLaterDefault(), testCode, expectedDiagnostic, fixedTestCode, CancellationToken.None).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace StyleCop.Analyzers.Test.CSharp7.LayoutRules
using Microsoft.CodeAnalysis.Testing;
using StyleCop.Analyzers.Test.LayoutRules;
using Xunit;
using static StyleCop.Analyzers.Test.Helpers.LanguageVersionTestExtensions;
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
StyleCop.Analyzers.LayoutRules.SA1513ClosingBraceMustBeFollowedByBlankLine,
StyleCop.Analyzers.LayoutRules.SA1513CodeFixProvider>;
Expand Down Expand Up @@ -171,7 +172,7 @@ public unsafe void TestMethod()
}
";

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

[Fact]
Expand Down Expand Up @@ -200,7 +201,7 @@ public unsafe void TestMethod()
}
";

await VerifyCSharpFixAsync(LanguageVersion.CSharp7_3, testCode, DiagnosticResult.EmptyDiagnosticResults, testCode, CancellationToken.None).ConfigureAwait(false);
await VerifyCSharpFixAsync(LanguageVersion.CSharp7_3.OrLaterDefault(), testCode, DiagnosticResult.EmptyDiagnosticResults, testCode, CancellationToken.None).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace StyleCop.Analyzers.Test.CSharp7.MaintainabilityRules
using Microsoft.CodeAnalysis.Testing;
using StyleCop.Analyzers.Test.MaintainabilityRules;
using Xunit;
using static StyleCop.Analyzers.Test.Helpers.LanguageVersionTestExtensions;
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
StyleCop.Analyzers.MaintainabilityRules.SA1413UseTrailingCommasInMultiLineInitializers,
StyleCop.Analyzers.MaintainabilityRules.SA1413CodeFixProvider>;
Expand Down Expand Up @@ -61,7 +62,7 @@ public unsafe void TestMethod()
Diagnostic().WithLocation(12, 17),
};

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

[Fact]
Expand Down Expand Up @@ -108,7 +109,7 @@ public unsafe void TestMethod()
Diagnostic().WithLocation(12, 17),
};

await VerifyCSharpFixAsync(LanguageVersion.CSharp7_3, testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
await VerifyCSharpFixAsync(LanguageVersion.CSharp7_3.OrLaterDefault(), testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ namespace StyleCop.Analyzers.Test.CSharp7.NamingRules
{
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Testing;
using StyleCop.Analyzers.Lightup;
using StyleCop.Analyzers.NamingRules;
using Xunit;
using static StyleCop.Analyzers.Test.Helpers.LanguageVersionTestExtensions;
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
StyleCop.Analyzers.NamingRules.SA1316TupleElementNamesShouldUseCorrectCasing,
StyleCop.Analyzers.NamingRules.SA1316CodeFixProvider>;
Expand Down Expand Up @@ -116,7 +117,7 @@ public class TestClass
}}
";

await VerifyCSharpDiagnosticAsync(LanguageVersionEx.CSharp7, testCode, settings, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
await VerifyCSharpDiagnosticAsync(testCode, settings, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

/// <summary>
Expand All @@ -136,7 +137,7 @@ public class TestClass
}
";

await VerifyCSharpDiagnosticAsync(LanguageVersionEx.CSharp7, testCode, DefaultTestSettings, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
await VerifyCSharpDiagnosticAsync(testCode, DefaultTestSettings, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

/// <summary>
Expand Down Expand Up @@ -168,7 +169,7 @@ public void TestMethod()
}}
";

await VerifyCSharpDiagnosticAsync(LanguageVersionEx.CSharp7_1, testCode, settings, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
await VerifyCSharpDiagnosticAsync(LanguageVersion.CSharp7_1.OrLaterDefault(), testCode, settings, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

/// <summary>
Expand Down Expand Up @@ -204,7 +205,7 @@ public void TestMethod2()
}}
";

await VerifyCSharpDiagnosticAsync(LanguageVersionEx.CSharp7_1, testCode, settings, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
await VerifyCSharpDiagnosticAsync(LanguageVersion.CSharp7_1.OrLaterDefault(), testCode, settings, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

/// <summary>
Expand Down Expand Up @@ -257,7 +258,7 @@ public class TestClass
// diagnostics are specified inline
};

await VerifyCSharpFixAsync(LanguageVersionEx.CSharp7, testCode, settings, expectedDiagnostics, fixedCode, CancellationToken.None).ConfigureAwait(false);
await VerifyCSharpFixAsync(testCode, settings, expectedDiagnostics, fixedCode, CancellationToken.None).ConfigureAwait(false);
}

/// <summary>
Expand Down Expand Up @@ -287,7 +288,7 @@ public void TestMethod()
}}
";

await VerifyCSharpDiagnosticAsync(LanguageVersionEx.CSharp7_1, testCode, settings, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
await VerifyCSharpDiagnosticAsync(LanguageVersion.CSharp7_1.OrLaterDefault(), testCode, settings, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

/// <summary>
Expand Down Expand Up @@ -327,7 +328,7 @@ public void TestMethod2()
// diagnostics are specified inline
};

await VerifyCSharpDiagnosticAsync(LanguageVersionEx.CSharp7_1, testCode, settings, expectedDiagnostics, CancellationToken.None).ConfigureAwait(false);
await VerifyCSharpDiagnosticAsync(LanguageVersion.CSharp7_1.OrLaterDefault(), testCode, settings, expectedDiagnostics, CancellationToken.None).ConfigureAwait(false);
}

[Fact]
Expand Down Expand Up @@ -398,7 +399,7 @@ public void MethodName((string Name, string Value) obj)
}
";

await VerifyCSharpDiagnosticAsync(LanguageVersionEx.CSharp7, testCode, DefaultTestSettings, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
await VerifyCSharpDiagnosticAsync(testCode, DefaultTestSettings, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace StyleCop.Analyzers.Test.CSharp7.ReadabilityRules
using Microsoft.CodeAnalysis.Testing;
using StyleCop.Analyzers.Test.ReadabilityRules;
using Xunit;
using static StyleCop.Analyzers.Test.Helpers.LanguageVersionTestExtensions;
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
StyleCop.Analyzers.ReadabilityRules.SA1137ElementsShouldHaveTheSameIndentation,
StyleCop.Analyzers.ReadabilityRules.IndentationCodeFixProvider>;
Expand Down Expand Up @@ -160,7 +161,7 @@ public unsafe void TestMethod()
Diagnostic().WithLocation(17, 1),
};

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

[Fact]
Expand Down Expand Up @@ -220,7 +221,7 @@ public unsafe void TestMethod()
Diagnostic().WithLocation(17, 1),
};

await VerifyCSharpFixAsync(LanguageVersion.CSharp7_3, testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
await VerifyCSharpFixAsync(LanguageVersion.CSharp7_3.OrLaterDefault(), testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace StyleCop.Analyzers.Test.CSharp7.SpacingRules
using Microsoft.CodeAnalysis.Testing;
using StyleCop.Analyzers.Test.SpacingRules;
using Xunit;
using static StyleCop.Analyzers.Test.Helpers.LanguageVersionTestExtensions;
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
StyleCop.Analyzers.SpacingRules.SA1000KeywordsMustBeSpacedCorrectly,
StyleCop.Analyzers.SpacingRules.TokenSpacingCodeFixProvider>;
Expand Down Expand Up @@ -246,10 +247,10 @@ public async Task TestStackAllocImplicitArrayStatementAsync()

string statementWithSpace = @"int* x = stackalloc [] { 3 };";

await this.TestKeywordStatementAsync(statementWithoutSpace, DiagnosticResult.EmptyDiagnosticResults, statementWithoutSpace, languageVersion: LanguageVersion.CSharp7_3).ConfigureAwait(false);
await this.TestKeywordStatementAsync(statementWithoutSpace, DiagnosticResult.EmptyDiagnosticResults, statementWithoutSpace, languageVersion: LanguageVersion.CSharp7_3.OrLaterDefault()).ConfigureAwait(false);

// this case is handled by SA1026, so it shouldn't be reported here
await this.TestKeywordStatementAsync(statementWithSpace, DiagnosticResult.EmptyDiagnosticResults, statementWithSpace, languageVersion: LanguageVersion.CSharp7_3).ConfigureAwait(false);
await this.TestKeywordStatementAsync(statementWithSpace, DiagnosticResult.EmptyDiagnosticResults, statementWithSpace, languageVersion: LanguageVersion.CSharp7_3.OrLaterDefault()).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace StyleCop.Analyzers.Test.CSharp7.SpacingRules
using Microsoft.CodeAnalysis.Testing;
using StyleCop.Analyzers.Test.SpacingRules;
using Xunit;
using static StyleCop.Analyzers.Test.Helpers.LanguageVersionTestExtensions;
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
StyleCop.Analyzers.SpacingRules.SA1001CommasMustBeSpacedCorrectly,
StyleCop.Analyzers.SpacingRules.TokenSpacingCodeFixProvider>;
Expand Down Expand Up @@ -158,7 +159,7 @@ public unsafe void TestMethod()
Diagnostic().WithLocation(8, 47).WithArguments(string.Empty, "followed"),
};

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

[Fact]
Expand Down Expand Up @@ -197,7 +198,7 @@ public unsafe void TestMethod()
Diagnostic().WithLocation(8, 43).WithArguments(string.Empty, "followed"),
};

await VerifyCSharpFixAsync(LanguageVersion.CSharp7_3, testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
await VerifyCSharpFixAsync(LanguageVersion.CSharp7_3.OrLaterDefault(), testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace StyleCop.Analyzers.Test.CSharp7.SpacingRules
using Microsoft.CodeAnalysis.Testing;
using StyleCop.Analyzers.Test.SpacingRules;
using Xunit;
using static StyleCop.Analyzers.Test.Helpers.LanguageVersionTestExtensions;
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
StyleCop.Analyzers.SpacingRules.SA1002SemicolonsMustBeSpacedCorrectly,
StyleCop.Analyzers.SpacingRules.TokenSpacingCodeFixProvider>;
Expand Down Expand Up @@ -49,7 +50,7 @@ public unsafe void TestMethod()
Diagnostic().WithArguments(" not", "preceded").WithLocation(7, 51),
};

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

[Fact]
Expand Down Expand Up @@ -84,7 +85,7 @@ public unsafe void TestMethod()
Diagnostic().WithArguments(" not", "preceded").WithLocation(7, 47),
};

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

0 comments on commit a69732f

Please sign in to comment.