Skip to content

Clean up the test harness - #1369

Merged
meziantou merged 12 commits into
mainfrom
feature/codefixtest-behaviors-flags-600516
Sep 1, 2026
Merged

meziantou merged 12 commits into
mainfrom
feature/codefixtest-behaviors-flags-600516

Conversation

@meziantou

Copy link
Copy Markdown
Owner

What changed

Analyzer

  • MA0060 (DoNotIgnoreReturnValueAnalyzer) now declares a single descriptor. ReturnValueRule and OutParameterRule shared the MA0060 id, which forced every test of that rule to use MarkupOptions.UseFirstDescriptor. They are merged into one Rule with messageFormat: "{0}" (the pattern already used by OptimizeStringBuilderUsageAnalyzer and others), and the message is composed at the report site. The reported messages are unchanged, suffix included:
    • The return value of 'X' should be used (+ : <Message> from [DoNotIgnore])
    • The out parameter 'x' of 'M' should not be discarded (+ : <Message>)

Tests

  • Removed the redundant CodeFixTestBehaviors.FixOne | CodeFixTestBehaviors.SkipFixAllCheck pairs. The two flags are orthogonal and the pairing is valid, but only 7 of the 13 sites needed a flag at all: 4 tests in AvoidUnusedInternalTypesAnalyzerTests keep SkipFixAllCheck (the fix removes the file's only type, so the harness cannot compare a state with no document) and 3 in OptimizeStringBuilderUsageAnalyzerTests keep FixOne (the fix reveals another diagnostic). Each removal was verified by re-running the affected classes.
  • DoNotIgnoreReturnValueAnalyzerTests drops UseFirstDescriptor and, now that the message is assertable, pins both message shapes with {|#0:…|} + WithMessage(...).
  • All package references go through named extension methods on ReferenceAssemblies with an optional version — AddSerilog(), AddSqlite(), AddEntityFrameworkCore(), AddNewtonsoftJson(), AddMoq(), … — instead of inline AddPackages([new PackageIdentity(...)]). Default versions are the latest stable ones (MSTest 4.3.3, NUnit 4.6.1, xUnit v3 4.0.0, EF Core 10.0.11, Serilog 4.4.0, YamlDotNet 18.1.0, …); a test that needs a specific version passes it.
  • Renamed AddXUnitApi → AddXunit (now xUnit v3), AddMSTestApi → AddMSTest, AddNUnitApi → AddNUnit. Added AddXunitV2 for the test that asserts the pre-Xunit.TestContext behavior. Removed AddSystemTextJson and AddSystemCollectionsImmutable, which only existed because a few tests compiled against an older target framework.
  • DoNotUseBlockingCallInAsyncContextAnalyzer_AsyncContextTests no longer pins netstandard2.1 for the whole class (it dated back to needing ValueTask in 2020). Only ProcessWaitForExit_NET5 depended on it and now pins Net50 explicitly, matching its name and its ProcessWaitForExit_NET6 counterpart.
  • The 6 UseStringComparerAnalyzerTests immutable-collection tests no longer target net48 + a System.Collections.Immutable package; nothing in them is framework specific.

Build / CI

  • paths-ignore of the push trigger now includes tests/**, so a push to main touching only tests does not run the workflow and does not publish a package. Pull requests still run the full matrix.
  • Bumped Meziantou.NET.Sdk, .Test and .Web to 1.0.161.
  • Documented why Microsoft.Bcl.AsyncInterfaces must stay: the suppressor tests Assembly.LoadFrom the IDE code-style analyzers, which need it in the output folder.

Notes for reviewers

  • Two test snippets had to be adapted to the newer test frameworks: MSTest 4 cannot infer T for AreEqual(null, true), and NUnit 4 moved Assert.AreEqual to ClassicAssert (which MA0003 does not exempt), so the snippet is now Assert.That(true, Is.True) — still a boolean literal on NUnit.Framework.Assert, so it exercises the same exemption. Assert.That(null, Is.Null) was rejected because it is ambiguous under Roslyn 4.8.
  • DbContext_Add moved off Net60 because EF Core 10 does not support net6.0.
  • global.json was updated despite the AGENTS.md rule, at the maintainer's request.

Validation

Full test suite passes on every supported Roslyn version: 4.8 (3748), 4.14 (3775), 5.0 (3803), 5.6 (3827), 5.9 (3860) — 0 failures. dotnet build is clean and dotnet run --project src/DocumentationGenerator reports no documentation change.

@meziantou meziantou changed the title Merge the MA0060 descriptors and clean up the test harness Clean up the test harness Sep 1, 2026
@meziantou
meziantou merged commit 112b9c8 into main Sep 1, 2026
13 checks passed
@meziantou
meziantou deleted the feature/codefixtest-behaviors-flags-600516 branch September 1, 2026 00:25
This was referenced Sep 24, 2026
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