Skip to content

fix!: fail a null subject for the negated form of an expectation - #1094

Merged
vbreuss merged 1 commit into
mainfrom
fix/null-subject-under-negation
Sep 14, 2026
Merged

vbreuss merged 1 commit into
mainfrom
fix/null-subject-under-negation

Conversation

@vbreuss

@vbreuss vbreuss commented Sep 14, 2026

Copy link
Copy Markdown
Member

DoesNotComplyWith negates an expectation, and a constraint that reports a null subject as a failure from its own IsMetBy has that failure flipped into a success - so That(nullList).DoesNotComplyWith(x => x.HasItem(1)) passed, asserting that a collection which does not exist definitely has no such item. A null subject means the question is unanswerable, and inverting unanswerable gives unanswerable, not true. ConstraintResult.WithNotNullValue<T> already decides before the inversion is applied, which is why the 372 expectations built on it were right and these 45 were not.

The ordering comparisons on a nullable number used the equality null policy, under which a null operand is legitimate. That reading belongs to IsEqualTo, not to IsGreaterThan - the same argument that moved IsNotBetween off WithEqualToValue, because neither a range nor an ordering has a null reading.

The sweep only ever invoked the positive form, which is how this survived. GuaranteesNotNullTests now invokes every expectation through DoesNotComplyWith as well, and derives that axis' exemption rather than listing it: the negated form of an exempt expectation is exempt too, so IsNotNull negated is IsNull. Exempt stays the single source of truth for both axes.

Five nested expectations are recorded as awaiting a core release. Their outer constraints already fail correctly on their own; only the composite does not, because the negation is applied by MappingNode, which cannot tell a subject that was ruled out as null from an expectation that was merely unmet.

BREAKING CHANGE:
a null subject now fails the negated form of every expectation that inspects it, and Implies reports it was <null> instead of it did not.

`DoesNotComplyWith` negates an expectation, and a constraint that reports a null subject as a failure from its own `IsMetBy` has that failure flipped into a success - so `That(nullList).DoesNotComplyWith(x => x.HasItem(1))` passed, asserting that a collection which does not exist definitely has no such item. A null subject means the question is unanswerable, and inverting unanswerable gives unanswerable, not true. `ConstraintResult.WithNotNullValue<T>` already decides before the inversion is applied, which is why the 372 expectations built on it were right and these 45 were not.

The ordering comparisons on a nullable number used the equality null policy, under which a null operand is legitimate. That reading belongs to `IsEqualTo`, not to `IsGreaterThan` - the same argument that moved `IsNotBetween` off `WithEqualToValue`, because neither a range nor an ordering has a null reading.

The sweep only ever invoked the positive form, which is how this survived. `GuaranteesNotNullTests` now invokes every expectation through `DoesNotComplyWith` as well, and derives that axis' exemption rather than listing it: the negated form of an exempt expectation is exempt too, so `IsNotNull` negated is `IsNull`. `Exempt` stays the single source of truth for both axes.

Five nested expectations are recorded as awaiting a core release. Their outer constraints already fail correctly on their own; only the composite does not, because the negation is applied by `MappingNode`, which cannot tell a subject that was ruled out as null from an expectation that was merely unmet.

**BREAKING CHANGE:**
a null subject now fails the negated form of every expectation that inspects it, and `Implies` reports `it was <null>` instead of `it did not`.
@vbreuss vbreuss self-assigned this Sep 14, 2026
@vbreuss vbreuss added bug Something isn't working breaking change The changes require a new major version labels Sep 14, 2026
@vbreuss
vbreuss marked this pull request as ready for review September 14, 2026 13:20
@vbreuss
vbreuss enabled auto-merge (squash) September 14, 2026 13:21
@vbreuss
vbreuss disabled auto-merge September 14, 2026 13:27
@vbreuss
vbreuss merged commit 48275fc into main Sep 14, 2026
10 checks passed
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
30.6% Duplication on New Code (required ≤ 30%)

See analysis details on SonarQube Cloud

github-actions Bot added a commit that referenced this pull request Sep 14, 2026
…ed form of an expectation (#1094) by Valentin Breuß
github-actions Bot added a commit that referenced this pull request Sep 14, 2026
…ed form of an expectation (#1094) by Valentin Breuß
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Benchmark Results

Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.5 LTS (Noble Numbat)
AMD EPYC 7763 2.45GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.303
[Host] : .NET 8.0.31 (8.0.31, 8.0.3126.42015), X64 RyuJIT x86-64-v3

Job=InProcess Toolchain=InProcessEmitToolchain IterationCount=15
LaunchCount=1 WarmupCount=10

Method Mean Error StdDev Gen0 Gen1 Allocated
Bool_aweXpect 274.1 ns 3.69 ns 3.45 ns 0.0415 - 696 B
Bool_FluentAssertions 275.9 ns 2.96 ns 2.63 ns 0.0567 - 952 B
Equivalency_aweXpect 400,478.1 ns 1,046.27 ns 927.49 ns 32.2266 1.4648 542085 B
Equivalency_FluentAssertions 2,828,692.7 ns 15,597.57 ns 14,589.98 ns 289.0625 46.8750 4841651 B
Int_GreaterThan_aweXpect 291.4 ns 0.95 ns 0.89 ns 0.0515 - 864 B
Int_GreaterThan_FluentAssertions 298.2 ns 3.61 ns 3.37 ns 0.0730 - 1224 B
ItemsCount_AtLeast_aweXpect 507.7 ns 1.52 ns 1.42 ns 0.0811 - 1360 B
ItemsCount_AtLeast_FluentAssertions 551.0 ns 2.13 ns 2.00 ns 0.1192 - 2008 B
String_aweXpect 497.3 ns 2.01 ns 1.68 ns 0.0668 - 1128 B
String_FluentAssertions 1,384.9 ns 6.87 ns 6.43 ns 0.2346 - 3944 B
StringArray_aweXpect 1,938.9 ns 3.16 ns 2.80 ns 0.1564 - 2624 B
StringArray_FluentAssertions 1,455.6 ns 8.96 ns 7.94 ns 0.2480 - 4152 B
StringArrayInAnyOrder_aweXpect 2,602.2 ns 7.74 ns 6.86 ns 0.1678 - 2816 B
StringArrayInAnyOrder_FluentAssertions 28,005.3 ns 31.93 ns 26.66 ns 1.9836 0.0610 33471 B

@github-actions

Copy link
Copy Markdown
Contributor

👽 Mutation Results

Mutation testing badge

aweXpect

Details
File Score Killed Survived Timeout No Coverage Ignored Compile Errors Runtime Errors Total Detected Total Undetected Total Mutants
That/Booleans/ThatNullableBool.Implies.cs 100.00% 18 0 0 0 5 6 0 18 0 29
That/Collections/ThatAsyncEnumerable.Contains.cs 81.91% 152 24 2 10 54 40 0 154 34 282
That/Collections/ThatAsyncEnumerable.HasItem.cs 78.89% 65 16 6 3 29 36 0 71 19 155
That/Collections/ThatAsyncEnumerable.HasItemThat.cs 66.67% 34 10 0 7 17 16 0 34 17 84
That/Collections/ThatEnumerable.Contains.cs 77.19% 264 54 0 24 99 84 0 264 78 525
That/Collections/ThatEnumerable.HasItem.cs 81.01% 139 27 6 7 60 80 0 145 34 319
That/Collections/ThatEnumerable.HasItemThat.cs 82.50% 66 12 0 2 22 30 0 66 14 132
That/Numbers/ThatNumber.IsGreaterThan.cs 86.21% 25 4 0 0 8 12 0 25 4 49
That/Numbers/ThatNumber.IsGreaterThanOrEqualTo.cs 86.21% 25 4 0 0 8 12 0 25 4 49
That/Numbers/ThatNumber.IsLessThan.cs 86.21% 25 4 0 0 8 12 0 25 4 49
That/Numbers/ThatNumber.IsLessThanOrEqualTo.cs 86.21% 25 4 0 0 8 12 0 25 4 49
That/Numbers/ThatNumber.IsNegative.cs 100.00% 16 0 0 0 4 8 0 16 0 28
That/Numbers/ThatNumber.IsPositive.cs 100.00% 16 0 0 0 4 8 0 16 0 28
That/Recording/ThatEventRecording.cs 94.00% 47 3 0 0 15 26 0 47 3 91
That/Strings/ThatString.Contains.cs 93.90% 77 2 0 3 22 24 0 77 5 128

The final mutation score is 82.08%

Coverage Thresholds: high:80 low:60 break:0

aweXpect.Core

Details
File Score Killed Survived Timeout No Coverage Ignored Compile Errors Runtime Errors Total Detected Total Undetected Total Mutants

The final mutation score is NaN%

Coverage Thresholds: high:80 low:60 break:0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change The changes require a new major version bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant