Skip to content

refactor!: accept a null subject on the non-generic collection expectations - #1096

Merged
vbreuss merged 1 commit into
mainfrom
refactor/nullable-non-generic-enumerable-subject
Sep 14, 2026
Merged

vbreuss merged 1 commit into
mainfrom
refactor/nullable-non-generic-enumerable-subject

Conversation

@vbreuss

@vbreuss vbreuss commented Sep 14, 2026

Copy link
Copy Markdown
Member

Every other reference-type subject is annotated nullable - IEnumerable<TItem> 48 of 48, string 29 of 29, Version 14 of 14, Exception 11 of 11 - but the non-generic IEnumerable overloads were annotated non-nullable in 31 of 32 places, HasItem being the lone exception. Asserting on a nullable variable through one of them therefore produced a CS8620 at the call site while the identical assertion on the generic overload produced nothing.

The warning was misleading rather than protective: the annotation is invisible at runtime, so these overloads were always swept by GuaranteesNotNullTests and always failed a null subject with it was <null> like everything else. Telling callers not to pass null contradicts the rule that a null subject is an ordinary input which fails cleanly.

Widening a parameter of the covariant IThat<out T> cannot invalidate an existing caller, so this removes warnings without introducing any.

@vbreuss vbreuss self-assigned this Sep 14, 2026
@vbreuss vbreuss added the breaking change The changes require a new major version label Sep 14, 2026
@vbreuss
vbreuss added this pull request to stack #1098 September 14, 2026 13:25
@vbreuss
vbreuss removed this pull request from stack #1098 September 14, 2026 13:25
@vbreuss
vbreuss added this pull request to stack #1099 September 14, 2026 13:26
@vbreuss
vbreuss removed this pull request from stack #1099 September 14, 2026 13:29
@vbreuss
vbreuss added this pull request to stack #1101 September 14, 2026 13:32
@vbreuss
vbreuss force-pushed the refactor/nullable-non-generic-enumerable-subject branch from d223b19 to f3c42fc Compare September 14, 2026 13:34
@github-actions

Copy link
Copy Markdown
Contributor

Test Results

     23 files  ±0       23 suites  ±0   11m 14s ⏱️ + 1m 50s
 20 492 tests  - 5   20 490 ✅  - 5  2 💤 ±0  0 ❌ ±0 
106 169 runs  ±0  106 167 ✅ ±0  2 💤 ±0  0 ❌ ±0 

Results for commit f3c42fc. ± Comparison against base commit c8f3dc5.

@github-actions

github-actions Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

🚀 Benchmark Results

Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.5 LTS (Noble Numbat)
Intel Xeon Platinum 8370C CPU 2.80GHz, 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-v4

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

Method Mean Error StdDev Gen0 Gen1 Allocated
Bool_aweXpect 276.1 ns 1.87 ns 1.66 ns 0.0277 - 696 B
Bool_FluentAssertions 295.7 ns 4.37 ns 3.87 ns 0.0377 - 952 B
Equivalency_aweXpect 388,345.6 ns 1,416.36 ns 1,324.87 ns 21.4844 0.9766 542084 B
Equivalency_FluentAssertions 2,427,493.1 ns 11,625.17 ns 10,874.19 ns 191.4063 35.1563 4841631 B
Int_GreaterThan_aweXpect 293.5 ns 2.81 ns 2.63 ns 0.0343 - 864 B
Int_GreaterThan_FluentAssertions 313.9 ns 4.15 ns 3.88 ns 0.0486 - 1224 B
ItemsCount_AtLeast_aweXpect 517.5 ns 3.59 ns 3.36 ns 0.0534 - 1360 B
ItemsCount_AtLeast_FluentAssertions 564.5 ns 5.61 ns 5.24 ns 0.0792 - 2008 B
String_aweXpect 495.9 ns 1.71 ns 1.52 ns 0.0448 - 1128 B
String_FluentAssertions 1,428.6 ns 8.49 ns 7.09 ns 0.1564 - 3944 B
StringArray_aweXpect 1,840.5 ns 7.21 ns 6.74 ns 0.1030 - 2624 B
StringArray_FluentAssertions 1,513.4 ns 8.18 ns 7.65 ns 0.1640 - 4152 B
StringArrayInAnyOrder_aweXpect 2,352.6 ns 13.51 ns 12.63 ns 0.1106 - 2816 B
StringArrayInAnyOrder_FluentAssertions 24,421.7 ns 113.13 ns 105.82 ns 1.3123 0.0305 33468 B

@github-actions

github-actions Bot commented Sep 14, 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

The final mutation score is NaN%

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

Base automatically changed from docs/null-rule-for-extension-authors to main September 14, 2026 14:26
…ations

Every other reference-type subject is annotated nullable - `IEnumerable<TItem>` 48 of 48, `string` 29 of 29, `Version` 14 of 14, `Exception` 11 of 11 - but the non-generic `IEnumerable` overloads were annotated non-nullable in 31 of 32 places, `HasItem` being the lone exception. Asserting on a nullable variable through one of them therefore produced a CS8620 at the call site while the identical assertion on the generic overload produced nothing.

The warning was misleading rather than protective: the annotation is invisible at runtime, so these overloads were always swept by `GuaranteesNotNullTests` and always failed a null subject with `it was <null>` like everything else. Telling callers not to pass null contradicts the rule that a null subject is an ordinary input which fails cleanly.

Widening a parameter of the covariant `IThat<out T>` cannot invalidate an existing caller, so this removes warnings without introducing any.
@vbreuss
vbreuss force-pushed the refactor/nullable-non-generic-enumerable-subject branch from f3c42fc to 24a97c0 Compare September 14, 2026 14:26
@vbreuss
vbreuss merged commit dbd64a1 into main Sep 14, 2026
9 of 10 checks passed
@vbreuss
vbreuss deleted the refactor/nullable-non-generic-enumerable-subject branch September 14, 2026 14:27
@sonarqubecloud

Copy link
Copy Markdown

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant