Skip to content

fix!: fail the collection inspections for a null subject - #1073

Merged
vbreuss merged 2 commits into
mainfrom
fix/collections-null-subject
Sep 13, 2026
Merged

vbreuss merged 2 commits into
mainfrom
fix/collections-null-subject

Conversation

@vbreuss

@vbreuss vbreuss commented Sep 13, 2026

Copy link
Copy Markdown
Member

A null subject must fail every expectation except the equality- and identity-comparisons whose expected value may itself be null. DoesNotContain is an inspection, not a comparison, so a null collection "not containing" something was a vacuous pass that silently hid real defects in user tests. The sequence, predicate and expectation overloads were all affected, on IEnumerable<T>, the non-generic IEnumerable, string[] and IAsyncEnumerable<T> alike, because seven constraint classes each serve IsEqualTo, IsContainedIn and Contains at once; they are told apart now by an explicit failsForNullSubject flag rather than by the isExpectedNull shortcut, which would have produced the right outcome for the wrong stated reason.

The string[] overload throwing a FailException about a mismatched value type was the same defect surfacing one step later: reporting success kept the chain alive, and the next node then asked a null subject for a string[].

AreAllUnique for a Nullable<ImmutableArray<string>> subject could never work — it passed string as the enumerable type, so no constraint ever matched the node and every input threw, not just null. It was also the only nullable ImmutableArray subject in the surface. Dropping the erroneous nullability makes it the string-specialised twin of the generic overload, consistent with Contains, All and Any, so ImmutableArray<string> subjects gain the string options.

@vbreuss vbreuss self-assigned this Sep 13, 2026
@vbreuss vbreuss added bug Something isn't working breaking change The changes require a new major version labels Sep 13, 2026
A `null` subject must fail every expectation except the equality- and identity-comparisons whose expected value may itself be `null`. `DoesNotContain` is an inspection, not a comparison, so a `null` collection "not containing" something was a vacuous pass that silently hid real defects in user tests. The sequence, predicate and expectation overloads were all affected, on `IEnumerable<T>`, the non-generic `IEnumerable`, `string[]` and `IAsyncEnumerable<T>` alike, because seven constraint classes each serve `IsEqualTo`, `IsContainedIn` and `Contains` at once; they are told apart now by an explicit `failsForNullSubject` flag rather than by the `isExpectedNull` shortcut, which would have produced the right outcome for the wrong stated reason.

The `string[]` overload throwing a `FailException` about a mismatched value type was the same defect surfacing one step later: reporting success kept the chain alive, and the next node then asked a `null` subject for a `string[]`.

`AreAllUnique` for a `Nullable<ImmutableArray<string>>` subject could never work — it passed `string` as the enumerable type, so no constraint ever matched the node and every input threw, not just `null`. It was also the only nullable `ImmutableArray` subject in the surface. Dropping the erroneous nullability makes it the string-specialised twin of the generic overload, consistent with `Contains`, `All` and `Any`, so `ImmutableArray<string>` subjects gain the string options.
@vbreuss
vbreuss force-pushed the fix/collections-null-subject branch from 8373a3e to 49abdc6 Compare September 13, 2026 12:38
`ThatEnumerable.AreAllUnique.ImmutableTests.cs` was a literal copy of `ThatEnumerable.AreAllUnique.Tests.cs` with its classes renamed `ImmutableArray*`, and every subject in it was still an `IEnumerable<T>`. That is how the parameterless `ImmutableArray<string?>` overload of `AreAllUnique` could be broken for every possible input while 28 tests covering it stayed green: none of them ever reached it. A survey of all 38 immutable test files found the same copy-paste in only two other classes, `IsEqualTo.ImmutableStringsTests` and `Contains.ImmutableStringCollectionTests`.

The four `WhenSubjectIsNull_ShouldFail` tests are dropped rather than converted, because an `ImmutableArray<T>` subject is a struct that cannot be `null` and so has no such overload to exercise; the same assertions already exist against `IEnumerable<T>` subjects in the non-immutable test files. A `default(ImmutableArray<T>)` subject is the meaningful analogue and remains uncovered.
@vbreuss
vbreuss enabled auto-merge (squash) September 13, 2026 12:52
@vbreuss
vbreuss disabled auto-merge September 13, 2026 13:18
@vbreuss
vbreuss merged commit 756e490 into main Sep 13, 2026
9 checks passed
@vbreuss
vbreuss deleted the fix/collections-null-subject branch September 13, 2026 13:25
@sonarqubecloud

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Sep 13, 2026 •

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/Collections/ThatAsyncEnumerable.Contains.cs 90.11% 162 8 2 10 54 40 0 164 18 276
That/Collections/ThatAsyncEnumerable.cs 81.36% 235 20 5 35 84 171 0 240 55 550
That/Collections/ThatEnumerable.AreAllUnique.cs 90.24% 74 8 0 0 20 34 0 74 8 136
That/Collections/ThatEnumerable.Contains.cs 84.24% 277 28 1 24 99 84 0 278 52 513
That/Collections/ThatEnumerable.cs 82.41% 353 17 3 59 113 267 0 356 76 812

The final mutation score is 84.18%

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

@github-actions

github-actions Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

🚀 Benchmark Results

Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.5 LTS (Noble Numbat)
AMD EPYC 7763 2.69GHz, 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 246.9 ns 1.78 ns 1.39 ns 0.0415 - 696 B
Bool_FluentAssertions 230.1 ns 2.32 ns 2.17 ns 0.0567 - 952 B
Equivalency_aweXpect 315,213.3 ns 1,123.33 ns 995.80 ns 20.0195 0.4883 335444 B
Equivalency_FluentAssertions 2,646,420.8 ns 8,959.95 ns 7,942.77 ns 289.0625 46.8750 4841651 B
Int_GreaterThan_aweXpect 267.2 ns 2.55 ns 2.38 ns 0.0515 - 864 B
Int_GreaterThan_FluentAssertions 233.2 ns 0.97 ns 0.91 ns 0.0730 - 1224 B
ItemsCount_AtLeast_aweXpect 477.9 ns 3.85 ns 3.60 ns 0.0811 - 1360 B
ItemsCount_AtLeast_FluentAssertions 470.8 ns 1.16 ns 1.09 ns 0.1197 - 2008 B
String_aweXpect 457.8 ns 1.25 ns 1.04 ns 0.0672 - 1128 B
String_FluentAssertions 1,202.2 ns 8.08 ns 7.56 ns 0.2346 - 3944 B
StringArray_aweXpect 1,892.6 ns 7.33 ns 6.86 ns 0.1564 - 2624 B
StringArray_FluentAssertions 1,268.9 ns 3.71 ns 3.10 ns 0.2480 - 4152 B
StringArrayInAnyOrder_aweXpect 2,534.2 ns 12.10 ns 10.73 ns 0.1678 - 2816 B
StringArrayInAnyOrder_FluentAssertions 27,159.5 ns 210.70 ns 197.09 ns 1.9836 0.0610 33471 B

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