From 949432ad1df5c32c0dfc75c64df9c96e3a72c309 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Breu=C3=9F?= Date: Wed, 18 Nov 2026 21:44:08 +0100 Subject: [PATCH 1/2] test: compile the test projects in classic mode on the older target frameworks again Since #929 every test framework compiles with C# 15 and so in union mode, which left the classic setup and verify surface, the one every consumer on C# 14 or older gets, without a broad suite: `Mockolate.Tests` no longer even compiled with `MockolateDisableUnionParameters=true` (37 errors). `Tests/Directory.Build.props` now sets the switch for every framework except `net11.0`, so `net11.0` keeps testing union mode and `net10.0`, `net8.0` and `net48` test classic mode; the agent docs describe the split and that the switch, not the framework, decides it. Guarded as union-only: `UnionVerifyMessageTests`, the `AnyParameters()` test with matchers and predicates, and the null literal test for delegates. Rewritten to hold in both modes: the setups and verifications with more than four parameters in `DynamicMembersTests` and `DelegateTests` use matchers for every argument, and the failure messages with null arguments expect the classic description (an empty string) on the classic frameworks. Classic defects found: a null literal on a single-parameter delegate setup or verification is ambiguous (fixed on `fix/classic-delegate-verify-null-ambiguous`, whose test can then drop the guard), and on a member with more than four parameters a matcher for an `object` parameter mixed with values binds the all-values overload and is compared by equality, so the verification silently never matches. --- AGENTS.md | 2 +- Docs/agents/workflows.md | 6 +++-- Tests/Directory.Build.props | 5 ++++ Tests/Mockolate.Tests/DynamicMembersTests.cs | 10 ++++--- .../MockDelegates/DelegateTests.cs | 4 +-- .../VerifyInvokedTests.AnyParametersTests.cs | 2 ++ ...ts.MixedLiteralAndMatcherUnionModeTests.cs | 8 ++++-- .../VerifyInvokedTests.NullLiteralTests.cs | 26 ++++++++++++++++--- .../UnionVerifyMessageTests.cs | 2 ++ 9 files changed, 51 insertions(+), 14 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 48229b09c..0cdd7baba 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -4,7 +4,7 @@ Mockolate is a source-generated mocking library for .NET. Users write `IFoo.Crea ## SDK and Build -- Use the SDK pinned in `global.json` (currently .NET 11, `rollForward: latestPatch`). Tests also run on .NET 10 and .NET 8, and on .NET Framework 4.8 on Windows only. On .NET 11 the test projects compile with C# 15, so the union-typed setup surface is exercised there. +- Use the SDK pinned in `global.json` (currently .NET 11, `rollForward: latestPatch`). Tests also run on .NET 10 and .NET 8, and on .NET Framework 4.8 on Windows only. The test projects compile with C# 15 on every framework, but `Tests/Directory.Build.props` sets `MockolateDisableUnionParameters` for all except `net11.0`, so the union-typed setup surface is exercised on .NET 11 and the classic one on the others. - Build from the root with `dotnet build Mockolate.slnx`. Shared settings live in the root `Directory.Build.props` (strong naming, `MinimumRoslynVersion`), `Source/Directory.Build.props` (target frameworks, warnings as errors, AOT and trimming flags) and `Tests/Directory.Build.props` (test frameworks, TUnit, aweXpect). - Package versions belong only in `Directory.Packages.props`. `VersionOverride` is used only to pin Roslyn packages to `$(MinimumRoslynVersion)`. diff --git a/Docs/agents/workflows.md b/Docs/agents/workflows.md index 24854fa8f..c4ae8f397 100644 --- a/Docs/agents/workflows.md +++ b/Docs/agents/workflows.md @@ -32,12 +32,14 @@ Target frameworks per test project: | Project | Frameworks | |---|---| -| `Mockolate.Tests`, `Mockolate.Internal.Tests`, `Mockolate.ExampleTests` | `net11.0` (C# 15, union parameters), `net10.0`, `net8.0`, `net48` (Windows only) | +| `Mockolate.Tests`, `Mockolate.Internal.Tests`, `Mockolate.ExampleTests` | `net11.0` (union mode); `net10.0`, `net8.0` and `net48` (Windows only) in classic mode | | `Mockolate.SourceGenerators.Tests` | `net11.0`, `net10.0` (compiles against `MinimumRoslynVersion`, without the snapshot and union tests) | | `Mockolate.Analyzers.Tests` | `net11.0` | | `Build.Tests` | `net10.0` | | `Mockolate.Api.Tests` | `net8.0` | +Every framework compiles with C# 15. The setup surface is decided by `MockolateDisableUnionParameters`, which `Tests/Directory.Build.props` sets for every framework except `net11.0`, not by the framework itself. Guard tests of union-only syntax (a lambda as an argument, `AnyParameters()` after matchers, values mixed with matchers on a member with more than four parameters) with `#if NET11_0_OR_GREATER`; write tests that hold in both modes so they compile in both. Classic failure messages describe a null argument as an empty string, union ones as `null`. + A newer language feature can compile for `net10.0` and fail for `net48`; build or test `net48` too when you use one. ### Which tests to run @@ -45,7 +47,7 @@ A newer language feature can compile for `net10.0` and fail for `net48`; build o | Change in | Run | |---|---| | `Source/Mockolate` | `Mockolate.Tests`, `Mockolate.Internal.Tests`, `Mockolate.Api.Tests` | -| `Source/Mockolate.SourceGenerators` | `Mockolate.SourceGenerators.Tests`, `Mockolate.Tests` (it compiles the generated mocks) | +| `Source/Mockolate.SourceGenerators` | `Mockolate.SourceGenerators.Tests`, `Mockolate.Tests` (it compiles the generated mocks; `net11.0` for union mode and `net10.0` for classic mode) | | `Source/Mockolate.Analyzers*` | `Mockolate.Analyzers.Tests` | | Usage examples | `Mockolate.ExampleTests` | | `Pipeline/BenchmarkReport.cs` | `Build.Tests` | diff --git a/Tests/Directory.Build.props b/Tests/Directory.Build.props index 6dd97102f..8a78c9344 100644 --- a/Tests/Directory.Build.props +++ b/Tests/Directory.Build.props @@ -22,6 +22,11 @@ false + + + true + +