Repository navigation
fix!: fail the collection inspections for a null subject - #1073
Merged
Merged
Conversation
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
force-pushed
the
fix/collections-null-subject
branch
from
September 13, 2026 12:38
8373a3e to
49abdc6
Compare
`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
enabled auto-merge (squash)
September 13, 2026 12:52
vbreuss
disabled auto-merge
September 13, 2026 13:18
|
Contributor
👽 Mutation ResultsaweXpectDetails
The final mutation score is 84.18%Coverage Thresholds: high:80 low:60 break:0aweXpect.CoreDetails
The final mutation score is NaN%Coverage Thresholds: high:80 low:60 break:0 |
Contributor
🚀 Benchmark ResultsDetails
|
github-actions Bot
added a commit
that referenced
this pull request
Sep 13, 2026
…or a `null` subject (#1073) by Valentin Breuß
github-actions Bot
added a commit
that referenced
this pull request
Sep 13, 2026
…or a `null` subject (#1073) by Valentin Breuß
This was referenced Oct 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



A
nullsubject must fail every expectation except the equality- and identity-comparisons whose expected value may itself benull.DoesNotContainis an inspection, not a comparison, so anullcollection "not containing" something was a vacuous pass that silently hid real defects in user tests. The sequence, predicate and expectation overloads were all affected, onIEnumerable<T>, the non-genericIEnumerable,string[]andIAsyncEnumerable<T>alike, because seven constraint classes each serveIsEqualTo,IsContainedInandContainsat once; they are told apart now by an explicitfailsForNullSubjectflag rather than by theisExpectedNullshortcut, which would have produced the right outcome for the wrong stated reason.The
string[]overload throwing aFailExceptionabout a mismatched value type was the same defect surfacing one step later: reporting success kept the chain alive, and the next node then asked anullsubject for astring[].AreAllUniquefor aNullable<ImmutableArray<string>>subject could never work — it passedstringas the enumerable type, so no constraint ever matched the node and every input threw, not justnull. It was also the only nullableImmutableArraysubject in the surface. Dropping the erroneous nullability makes it the string-specialised twin of the generic overload, consistent withContains,AllandAny, soImmutableArray<string>subjects gain the string options.