From eb0f6b40ee2f47ddc3f647b7340650db1905b8b1 Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Mon, 12 Oct 2026 08:34:55 -0600 Subject: [PATCH 1/2] Migrate tests to xUnit v3 for Combinatorial v2 Xunit.Combinatorial v2 requires the xUnit v3 framework. Update the framework and VSTest adapter, generate entry points for every inherited test project, and adapt lifecycle hooks and typed theory data while preserving the existing targets and coverage pipeline. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .agents/skills/testing-and-coverage/SKILL.md | 5 ++++- CONTRIBUTING.md | 6 ++++++ Directory.Packages.props | 6 +++--- StyleCop.Analyzers/Directory.Build.props | 10 ++++++++++ StyleCop.Analyzers/StyleCop.Analyzers.Internal.ruleset | 3 +++ .../HelperTests/SymbolNameHelpersUnitTests.cs | 8 +++++--- .../Helpers/UseCultureAttribute.cs | 8 +++++--- .../ReadabilityRules/SA1106UnitTests.cs | 3 +-- .../StyleCop.Analyzers.Test.csproj | 2 -- 9 files changed, 37 insertions(+), 14 deletions(-) diff --git a/.agents/skills/testing-and-coverage/SKILL.md b/.agents/skills/testing-and-coverage/SKILL.md index a899cc0a09..ba5542cac9 100644 --- a/.agents/skills/testing-and-coverage/SKILL.md +++ b/.agents/skills/testing-and-coverage/SKILL.md @@ -30,7 +30,10 @@ Check the csproj files for current versions; this table is from Oct 2026. Microsoft.CodeAnalysis.Testing 1.1.4 with the framework-neutral `DefaultVerifier`. Don't add test-framework specific verifier packages (the xUnit flavor was discontinued after 1.1.2). Assertion failures surface as `InvalidOperationException` with the library's message. -- Tests are xUnit 2 `[Fact]`/`[Theory]`. Shared data: `Helpers/CommonMemberData.cs`. Settings: pass a +- Tests are xUnit v3 `[Fact]`/`[Theory]`, with Xunit.Combinatorial v2. Every test project directly references + `xunit.v3.mtp-off` and `Microsoft.NET.Test.Sdk` through `Directory.Build.props`, generates an executable + entry point, and uses the VSTest adapter (not Microsoft.Testing.Platform). Shared data: + `Helpers/CommonMemberData.cs`. Settings: pass a `stylecop.json` string through the verifier overloads that take `settings`. ## Running tests locally diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1faebabae1..80240e1532 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -66,6 +66,12 @@ Use forward slashes in these paths when running from a Linux shell. Add `--filter "FullyQualifiedName~SA1201"` to select one rule. Each newer compiler's test project also runs the tests inherited from earlier projects. +Tests use xUnit v3 and Xunit.Combinatorial v2. Xunit.Combinatorial v2 depends on xUnit v3; +it cannot be used with the `xunit` v2 package. Every test project is an executable and directly +references `xunit.v3.mtp-off` so the v3 entry point is generated, including for projects +which inherit their tests. The MTP-off package preserves the VSTest adapter and Coverlet workflow. +The same tests continue to target `net10.0` and, on Windows, `net472`. + `.gitattributes` checks out test C# sources with CRLF on every platform so multiline source/expected-output literals match the verifier's explicit CRLF formatting option. Assertions still compare the exact output; tests for other newline sequences supply them explicitly. diff --git a/Directory.Packages.props b/Directory.Packages.props index 495b9e85c9..8d360005f8 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -33,9 +33,9 @@ - - - + + + diff --git a/StyleCop.Analyzers/Directory.Build.props b/StyleCop.Analyzers/Directory.Build.props index 2dcf44a0c1..7665944bd4 100644 --- a/StyleCop.Analyzers/Directory.Build.props +++ b/StyleCop.Analyzers/Directory.Build.props @@ -21,6 +21,16 @@ true + + Exe + + + + + + + + + + diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/HelperTests/SymbolNameHelpersUnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/HelperTests/SymbolNameHelpersUnitTests.cs index d1f0babb82..330ba92967 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/HelperTests/SymbolNameHelpersUnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/HelperTests/SymbolNameHelpersUnitTests.cs @@ -26,16 +26,18 @@ public class SymbolNameHelpersUnitTests : IAsyncLifetime private Solution testSolution; - public async Task InitializeAsync() + public async ValueTask InitializeAsync() { var compilationOptions = this.GetCompilationOptions(); this.testSolution = await CreateTestSolutionAsync(compilationOptions).ConfigureAwait(false); } - public Task DisposeAsync() +#pragma warning disable AvoidAsyncSuffix // IAsyncDisposable requires this name and returns ValueTask. + public ValueTask DisposeAsync() { - return Task.FromResult(true); + return default; } +#pragma warning restore AvoidAsyncSuffix /// /// Verify the workings of diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/Helpers/UseCultureAttribute.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/Helpers/UseCultureAttribute.cs index 30a9e70306..d3701a76a7 100755 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/Helpers/UseCultureAttribute.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/Helpers/UseCultureAttribute.cs @@ -9,7 +9,7 @@ namespace StyleCop.Analyzers.Test.Helpers using System.Globalization; using System.Reflection; using System.Threading; - using Xunit.Sdk; + using Xunit.v3; /// /// Apply this attribute to your test method to replace the @@ -83,7 +83,8 @@ public UseCultureAttribute(string culture, string uiCulture) /// and replaces them with the new cultures defined in the constructor. /// /// The method under test. - public override void Before(MethodInfo methodUnderTest) + /// The test being run. + public override void Before(MethodInfo methodUnderTest, IXunitTest test) { this.originalCulture = Thread.CurrentThread.CurrentCulture; this.originalUiCulture = Thread.CurrentThread.CurrentUICulture; @@ -102,7 +103,8 @@ public override void Before(MethodInfo methodUnderTest) /// to . /// /// The method under test. - public override void After(MethodInfo methodUnderTest) + /// The test being run. + public override void After(MethodInfo methodUnderTest, IXunitTest test) { Thread.CurrentThread.CurrentCulture = this.originalCulture; Thread.CurrentThread.CurrentUICulture = this.originalUiCulture; diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1106UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1106UnitTests.cs index 04a2358648..9f166a20db 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1106UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1106UnitTests.cs @@ -3,7 +3,6 @@ namespace StyleCop.Analyzers.Test.ReadabilityRules { - using System.Linq; using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.Testing; @@ -22,7 +21,7 @@ public static TheoryData StatementAsBlock var result = new TheoryData(); foreach (var lineEndingData in CommonData.EndOfLineSequences) { - var lineEnding = (string)lineEndingData.Single(); + var lineEnding = lineEndingData.Data; result.Add("if (true)", lineEnding); result.Add("if (true) { } else", lineEnding); result.Add("for (int i = 0; i < 10; i++)", lineEnding); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/StyleCop.Analyzers.Test.csproj b/StyleCop.Analyzers/StyleCop.Analyzers.Test/StyleCop.Analyzers.Test.csproj index 85b7f5ef51..423ed5ed42 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/StyleCop.Analyzers.Test.csproj +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/StyleCop.Analyzers.Test.csproj @@ -21,8 +21,6 @@ - - From 03a553d2dc673df5fc5d6a618dc4acbd88935270 Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Mon, 12 Oct 2026 08:45:09 -0600 Subject: [PATCH 2/2] Restore test app host permissions after artifact download GitHub Actions artifact downloads do not retain the executable bit needed by the xUnit v3 test app hosts. Restore it before running the VSTest adapter. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .github/workflows/build.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1b55b4f76b..63a2441c0f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -367,6 +367,10 @@ jobs: name: test-bin-cs${{ matrix.langVersion }}-${{ matrix.configuration }} path: StyleCop.Analyzers/${{ matrix.project }}/bin/${{ matrix.configuration }}/${{ matrix.framework }} + - name: Make test app host executable + shell: bash + run: chmod +x "StyleCop.Analyzers/${{ matrix.project }}/bin/${{ matrix.configuration }}/${{ matrix.framework }}/${{ matrix.project }}" + # The tests allocate heavily on every core; use server GC in the .NET test host. - name: Run tests env: