Skip to content

Retarget C# 6/7 tests to net472 and update Microsoft.CodeAnalysis.Testing to 1.1.4 - #4190

Merged
AArnott merged 4 commits into
masterfrom
test-net472-testing-1.1.4
Oct 9, 2026
Merged

AArnott merged 4 commits into
masterfrom
test-net472-testing-1.1.4

Conversation

@AArnott

@AArnott AArnott commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #4189.

Changes

  • Retarget the .NET Framework test assemblies to net472

    • StyleCop.Analyzers.Test (C# 6, Roslyn 1.3.2): net452 → net472
    • StyleCop.Analyzers.Test.CSharp7: net46 → net472
    • CI already runs these assemblies on the runner's .NET Framework 4.8. The net452 ItemGroup (Microsoft.VisualStudio.Composition, System.ValueTuple, NuGet.Frameworks 5.9.3) is removed: net472 has System.ValueTuple in the box, and the testing library now brings Microsoft.VisualStudio.Composition and NuGet 7.0.3 on its own.
    • In .github/workflows/build.yml, the matrix framework values and the test-bin artifact paths for C# 6 and C# 7 now use net472. No other scripts or docs referenced net452 or net46.
  • Update Microsoft.CodeAnalysis.Testing to 1.1.4, the latest version and the first stable one with ReferenceAssemblies.Net.Net90 (9.0.0) and Net100 (10.0.1).

    • The C# 6 project is the only one that references the testing package; the C# 7–15 projects get it through their ProjectReference, so all test projects use the same version.
    • No older version is needed for Roslyn 1.3.2: 1.1.4 only requires Microsoft.CodeAnalysis.CSharp.Workspaces >= 1.0.1.
    • Microsoft.CodeAnalysis.CSharp.CodeFix.Testing.XUnit and Microsoft.CodeAnalysis.Testing.Verifiers.XUnit were discontinued after 1.1.2, and Verifiers.XUnit 1.1.2 pins Analyzer.Testing to exactly [1.1.2]. The project now references Microsoft.CodeAnalysis.CSharp.CodeFix.Testing 1.1.4 instead.
    • The project now uses the library's framework-neutral DefaultVerifier everywhere XUnitVerifier was used: StyleCopCodeFixVerifier, StyleCopDiagnosticVerifier, CustomDiagnosticVerifier, AnalyzerConfigurationUnitTests and DiagnosticVerifierTests. Version 1.1.4 has no overloads without a verifier type argument (CSharpCodeFixTest<TAnalyzer, TCodeFix, TVerifier>, CSharpCodeFixVerifier<…, TVerifier>, CodeFixTest<TVerifier>), so the argument stays and is set to DefaultVerifier.
    • Test expectation updates in DiagnosticVerifierTests: the same failure conditions and key message content are still checked; only the xUnit-specific parts changed.
      • All 14 failure tests now use Assert.ThrowsAsync<InvalidOperationException>, the exact type DefaultVerifier throws, instead of Assert.ThrowsAnyAsync<XunitException>. Every StartsWith/Contains check on the message is unchanged.
      • TestUnexpectedLocationForProjectDiagnosticAsync still compares the full message exactly: the context, "Expected a project diagnostic with no location", and the expected and actual diagnostic, including the actual span (7,33). Only xUnit's trailing Assert.Equal() Failure / Expected: None / Actual: SourceFile(...) dump is gone, because the default verifier doesn't produce it. A side effect is that this test now also passes on Linux; before, the hard-coded character offsets depended on line endings.
  • Use the built-in reference assemblies: GenericAnalyzerTest now uses ReferenceAssemblies.Net.Net90 / Net100 in place of the hand-built ones from Match C# 13+ test reference assemblies to the language version #4189, and the CreateNetReferenceAssemblies helper is removed.

    • The three .NET Framework 4.7.2 coverage tests from Match C# 13+ test reference assemblies to the language version #4189 are kept as they were: SA1000 allows ref struct, SA1116 params collections, and SA1003 field keyword.
    • The default reference assemblies for C# 6 and C# 7 tests (NetFramework.Net452 / Net46) are unchanged. They set which framework the test source compiles against, not where the test assembly runs.
  • Two dependency fixes found in CI:

    • Removed the NuGet.Frameworks 6.3.4 pin from StyleCop.Analyzers.Test.CSharp8. It was there to raise the version above the old net452 5.9.3. Now the testing library brings 7.0.3 on net472, so the pin caused an NU1605 downgrade error.
    • StyleCop.Analyzers.Test now references NuGet.Resolver 7.0.3 directly for net472. Analyzer.Testing 1.1.4 references NuGet.* without compile assets, so binding-redirect generation never saw System.Text.Json 8.0.5's reference to Microsoft.Bcl.AsyncInterfaces 8.0.0.0. In the C# 14/15 projects, Roslyn 5.x deploys AsyncInterfaces 9.0/10.0, so downloading Microsoft.NETCore.App.Ref 10.0.1 failed with a FileLoadException and the xunit run hung until the job timed out. With the direct reference, the redirects are generated: 9.0.0.0 for C# 14 and 10.0.0.1 for C# 15.

StyleCopTester still targets net46. It is a developer tool, not a test project, so this PR leaves it alone.

Validation

  • On Linux (net6.0), the C# 14 suite has exactly the same failures as master (the known CRLF/Linux baseline of 296). C# 6 has the same failures minus one: TestUnexpectedLocationForProjectDiagnosticAsync now passes, giving 318 instead of 319. There are no new failures. C# 14 inherits the C# 13 tests, so it covers both Net90 and Net100.

  • On Linux, net472 builds of every test project (via -p:OS=Windows_NT) succeed.

  • CI on 015e102 is fully green: 25 of 25 checks, including all 10 Windows test jobs, which run the net472 binaries, and Merge code coverage. Test totals in the Debug jobs match master, all with 0 failed and 0 skipped:

    C# 6 7 8 9 10 11 12 13 14 15
    Tests 7135 7519 7742 8278 9015 9094 9307 9412 9529 9544

…ting to 1.1.4

- StyleCop.Analyzers.Test: net452 -> net472; StyleCop.Analyzers.Test.CSharp7: net46 -> net472
- Replace Microsoft.CodeAnalysis.CSharp.CodeFix.Testing.XUnit 1.1.2-beta1.23509.1 with
  Microsoft.CodeAnalysis.CSharp.CodeFix.Testing 1.1.4 (the .XUnit packages were discontinued after 1.1.2)
- Add a local port of XUnitVerifier so failures keep xUnit exception types and messages
- Use the built-in ReferenceAssemblies.Net.Net90/Net100 instead of hand-built ones
- Update CI test matrix frameworks and test-bin artifact paths
The testing library 1.1.4 brings NuGet.Frameworks 7.0.3 on net472, so the pin
now causes an NU1605 downgrade error.
…r NuGet's dependencies

Microsoft.CodeAnalysis.Analyzer.Testing 1.1.4 references NuGet.* without compile
assets, so RAR never saw System.Text.Json 8.0.5's reference to
Microsoft.Bcl.AsyncInterfaces 8.0.0.0. In the C# 14/15 test projects Roslyn 5.x
deploys a newer Microsoft.Bcl.AsyncInterfaces with no redirect, so downloading
Microsoft.NETCore.App.Ref failed with FileLoadException and the xunit run hung.
@codecov

codecov Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.51%. Comparing base (4d4b682) to head (015e102).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4190      +/-   ##
==========================================
- Coverage   97.51%   97.51%   -0.01%     
==========================================
  Files        1239     1239              
  Lines      132797   132787      -10     
  Branches     4288     4288              
==========================================
- Hits       129502   129492      -10     
  Misses       2154     2154              
  Partials     1141     1141              
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@AArnott
AArnott marked this pull request as ready for review October 9, 2026 04:27
Remove the local port of XUnitVerifier and its exception types; the
Microsoft.CodeAnalysis.Testing.Verifiers.XUnit package was discontinued and the
framework-neutral DefaultVerifier is the supported replacement. Version 1.1.4
still requires the TVerifier type argument on CSharpCodeFixTest/CSharpCodeFixVerifier/
CodeFixTest, so it is now DefaultVerifier everywhere.

DiagnosticVerifierTests now expects InvalidOperationException (the exact type
DefaultVerifier throws) instead of any XunitException, and the full-message
check for an unexpected location on a project diagnostic no longer includes
xUnit's trailing 'Assert.Equal() Failure' location dump.
@AArnott
AArnott merged commit 918eaf2 into master Oct 9, 2026
25 checks passed
@AArnott
AArnott deleted the test-net472-testing-1.1.4 branch October 9, 2026 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant