Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .agents/skills/testing-and-coverage/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
<PackageVersion Include="System.Text.RegularExpressions" Version="4.3.1" />
<PackageVersion Include="TunnelVisionLabs.LanguageTypes.SourceGenerator" Version="0.1.20-beta" />
<PackageVersion Include="TunnelVisionLabs.ReferenceAssemblyAnnotator" Version="1.0.0-alpha.160" />
<PackageVersion Include="xunit" Version="2.4.2" />
<PackageVersion Include="Xunit.Combinatorial" Version="1.7.31" />
<PackageVersion Include="xunit.v3.mtp-off" Version="4.0.2" />
<PackageVersion Include="Xunit.Combinatorial" Version="2.1.43" />
<PackageVersion Include="xunit.runner.visualstudio" Version="4.0.1" />
</ItemGroup>

Expand Down
11 changes: 10 additions & 1 deletion StyleCop.Analyzers/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,23 @@

<ItemGroup Condition="$([System.String]::Copy('$(MSBuildProjectName)').StartsWith('StyleCop.Analyzers.Test.CSharp'))">
<PackageReference Include="DiffPlex" PrivateAssets="all" />
<PackageReference Include="Microsoft.NET.Test.Sdk" PrivateAssets="all" />
</ItemGroup>

<PropertyGroup Condition="'$(BuildingInsideVisualStudio)' != 'true'">
<!-- Ideally this is always enabled, but that tends to hurt developer productivity -->
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<PropertyGroup Condition="$(MSBuildProjectName.StartsWith('StyleCop.Analyzers.Test'))">
<OutputType>Exe</OutputType>
</PropertyGroup>

<ItemGroup Condition="$(MSBuildProjectName.StartsWith('StyleCop.Analyzers.Test'))">
<!-- Each inherited test project needs the v3 entry point; keep the existing VSTest/coverlet pipeline. -->
<PackageReference Include="Microsoft.NET.Test.Sdk" PrivateAssets="all" />
<PackageReference Include="xunit.v3.mtp-off" />
</ItemGroup>

<PropertyGroup>
<!--
Debug builds used Windows PDBs for OpenCover, which is no longer used. Coverlet rewrites Windows PDBs through the
Expand Down
3 changes: 3 additions & 0 deletions StyleCop.Analyzers/StyleCop.Analyzers.Internal.ruleset
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
</Rules>
<Rules AnalyzerId="xunit.analyzers" RuleNamespace="xunit.analyzers">
<Rule Id="xUnit1004" Action="Info" />
<!-- Preserve the shared verifier's ConfigureAwait(false) and explicit CancellationToken.None conventions. -->
<Rule Id="xUnit1030" Action="None" />
<Rule Id="xUnit1051" Action="None" />
</Rules>
<Rules AnalyzerId="Microsoft.CodeAnalysis.Analyzers" RuleNamespace="Microsoft.CodeAnalysis.Analyzers">
<Rule Id="RS1001" Action="None" /> <!-- Missing diagnostic analyzer attribute -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

/// <summary>
/// Verify the workings of <see cref="SymbolNameHelpers.ToQualifiedString(ISymbol, NameSyntax)"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace StyleCop.Analyzers.Test.Helpers
using System.Globalization;
using System.Reflection;
using System.Threading;
using Xunit.Sdk;
using Xunit.v3;

/// <summary>
/// Apply this attribute to your test method to replace the
Expand Down Expand Up @@ -83,7 +83,8 @@ public UseCultureAttribute(string culture, string uiCulture)
/// and replaces them with the new cultures defined in the constructor.
/// </summary>
/// <param name="methodUnderTest">The method under test.</param>
public override void Before(MethodInfo methodUnderTest)
/// <param name="test">The test being run.</param>
public override void Before(MethodInfo methodUnderTest, IXunitTest test)
{
this.originalCulture = Thread.CurrentThread.CurrentCulture;
this.originalUiCulture = Thread.CurrentThread.CurrentUICulture;
Expand All @@ -102,7 +103,8 @@ public override void Before(MethodInfo methodUnderTest)
/// <see cref="CultureInfo.CurrentUICulture" /> to <see cref="Thread.CurrentPrincipal" />.
/// </summary>
/// <param name="methodUnderTest">The method under test.</param>
public override void After(MethodInfo methodUnderTest)
/// <param name="test">The test being run.</param>
public override void After(MethodInfo methodUnderTest, IXunitTest test)
{
Thread.CurrentThread.CurrentCulture = this.originalCulture;
Thread.CurrentThread.CurrentUICulture = this.originalUiCulture;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

namespace StyleCop.Analyzers.Test.ReadabilityRules
{
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Testing;
Expand All @@ -22,7 +21,7 @@ public static TheoryData<string, string> StatementAsBlock
var result = new TheoryData<string, string>();
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" VersionOverride="1.3.2" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="xunit" />
<PackageReference Include="Xunit.Combinatorial" />
<PackageReference Include="xunit.runner.visualstudio" PrivateAssets="all" />
</ItemGroup>
Expand Down
Loading