Skip to content

feat!: mark IsNotBetween as GuaranteesNotNull - #1092

Merged
vbreuss merged 1 commit into
mainfrom
feat/isnotbetween-guarantees-not-null
Sep 14, 2026
Merged

vbreuss merged 1 commit into
mainfrom
feat/isnotbetween-guarantees-not-null

Conversation

@vbreuss

@vbreuss vbreuss commented Sep 14, 2026

Copy link
Copy Markdown
Member

Every range constraint except the numeric one derives from WithNotNullValue, which forces the failure before the inversion is applied, so a null subject fails the negated form just as it fails the normal one. IsBetween said so in each of those files and IsNotBetween did not, although the two share a constraint and differ only by Invert.

ThatNumber was the exception that kept the name in the exemption list of GuaranteesNotNullTests, and it was not a deliberate one: its nullable range constraint derived from WithEqualToValue and passed the lower bound as the isExpectedNull flag, so a null subject failed or passed depending on whether the minimum happened to be null. IsNotBetween(1).And(3) passed while IsNotBetween(null).And(null) failed - the opposite of what a strict negation of IsBetween would give, and the only negated numeric expectation a null subject passed at all, next to IsNotNaN and IsNotInfinite which both fail. That base class answers a question about equality, where IsEqualTo(null) on a null subject should hold; a range has no such reading. It now derives from WithNotNullValue like the others, and the name leaves the exemption list.

The overloads taking a non-nullable subject gain nothing from the attribute, but their IsBetween twin already carries it, and marking only one half of each file would preserve the asymmetry this removes.

BREAKING CHANGE:
a null subject now fails IsNotBetween for numbers instead of passing.

@vbreuss vbreuss self-assigned this Sep 14, 2026
@vbreuss vbreuss added enhancement New feature or request breaking change The changes require a new major version labels Sep 14, 2026
@vbreuss
vbreuss enabled auto-merge (squash) September 14, 2026 09:01
@vbreuss
vbreuss force-pushed the feat/isnotbetween-guarantees-not-null branch from 17d0ef4 to e89b406 Compare September 14, 2026 09:02
@github-actions

github-actions Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Test Results

     23 files   -  27       23 suites   - 27   9m 54s ⏱️ +35s
 20 496 tests  -  34   20 494 ✅  -  34  2 💤 ±0  0 ❌ ±0 
106 163 runs   - 108  106 161 ✅  - 108  2 💤 ±0  0 ❌ ±0 

Results for commit 6aeb246. ± Comparison against base commit 6d14d7a.

This pull request removes 3233 and adds 3199 tests. Note that renamed tests count towards both.
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(message: "message010162de-e470-43e4-980e-6e1b71203e95")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(message: "message6558837a-c31c-4ddb-92fb-2b2460dbb9b4")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(message: "message66edac2a-5a10-4929-98f5-98be59a94bf6")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(message: "message6b4244af-ba10-4f93-b2d8-452655992ca5")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(message: "message98b11766-861e-43fa-a5bb-da46810e2794")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(message: "message9c942972-0c9c-492b-8c21-0aec8799023f")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "message1e42abcd-a3e5-4738-803b-419c10cbad03")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "message337959ef-e06f-4e71-9eea-005078dfef0e")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "message72a58c1a-2539-43a8-847b-381820a6fc93")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "message75008bf3-e875-40cc-adf5-1cdeac0dcd3e")
…
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(message: "message0a13fc91-cde8-4285-a324-a733bef64b84")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(message: "message2789325f-906c-429a-a621-ddf086a00e76")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(message: "message8ad9da4d-cee6-456d-ad7a-e588b8409ac6")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(message: "messageac318bc4-0d0f-419a-a462-d9f2ec0a0da5")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(message: "messagebc3d9629-ad3b-4637-8b0c-6802d54eed24")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(message: "messaged88d0d9b-3e22-44cd-b1ea-00ad9d55bc3e")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "message4547bb41-4b23-43c7-815c-45b4bc686a13")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "message4bd81678-9ac4-4757-bcb3-01170058ede7")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "message8ccb4f45-003a-48c8-9f6a-8d9ba86fff0f")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "messageb1510706-4cfd-4f3b-87e9-8a61878b20b6")
…

♻️ This comment has been updated with latest results.

@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/DateOnlys/ThatDateOnly.IsBetween.cs 100.00% 35 0 0 0 6 8 0 35 0 49
That/DateOnlys/ThatNullableDateOnly.IsBetween.cs 88.64% 39 5 0 0 6 8 0 39 5 58
That/DateTimeOffsets/ThatDateTimeOffset.IsBetween.cs 100.00% 35 0 0 0 6 8 0 35 0 49
That/DateTimeOffsets/ThatNullableDateTimeOffset.IsBetween.cs 88.64% 39 5 0 0 6 8 0 39 5 58
That/DateTimes/ThatDateTime.IsBetween.cs 100.00% 35 0 0 0 6 8 0 35 0 49
That/DateTimes/ThatNullableDateTime.IsBetween.cs 88.64% 39 5 0 0 6 8 0 39 5 58
That/Numbers/ThatNumber.IsBetween.cs 94.23% 49 3 0 0 12 16 0 49 3 80
That/TimeOnlys/ThatNullableTimeOnly.IsBetween.cs 88.64% 39 5 0 0 6 8 0 39 5 58
That/TimeOnlys/ThatTimeOnly.IsBetween.cs 100.00% 35 0 0 0 6 8 0 35 0 49
That/TimeSpans/ThatNullableTimeSpan.IsBetween.cs 88.64% 39 5 0 0 6 8 0 39 5 58
That/TimeSpans/ThatTimeSpan.IsBetween.cs 100.00% 35 0 0 0 6 8 0 35 0 49

The final mutation score is 93.74%

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 14, 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.59GHz, 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 254.9 ns 2.22 ns 1.86 ns 0.0415 - 696 B
Bool_FluentAssertions 256.4 ns 7.89 ns 7.38 ns 0.0567 - 952 B
Equivalency_aweXpect 383,905.0 ns 2,308.33 ns 2,159.21 ns 32.2266 1.4648 542085 B
Equivalency_FluentAssertions 2,591,981.0 ns 14,734.26 ns 13,061.54 ns 289.0625 46.8750 4841651 B
Int_GreaterThan_aweXpect 271.7 ns 8.19 ns 7.66 ns 0.0515 - 864 B
Int_GreaterThan_FluentAssertions 251.5 ns 1.80 ns 1.41 ns 0.0730 - 1224 B
ItemsCount_AtLeast_aweXpect 469.4 ns 2.80 ns 2.34 ns 0.0811 - 1360 B
ItemsCount_AtLeast_FluentAssertions 496.5 ns 4.46 ns 3.96 ns 0.1192 - 2008 B
String_aweXpect 452.4 ns 2.54 ns 2.25 ns 0.0672 - 1128 B
String_FluentAssertions 1,212.7 ns 47.12 ns 44.08 ns 0.2346 - 3944 B
StringArray_aweXpect 1,845.8 ns 8.35 ns 7.41 ns 0.1564 - 2624 B
StringArray_FluentAssertions 1,315.9 ns 8.17 ns 6.82 ns 0.2480 - 4152 B
StringArrayInAnyOrder_aweXpect 2,459.3 ns 9.31 ns 8.71 ns 0.1678 - 2816 B
StringArrayInAnyOrder_FluentAssertions 26,869.0 ns 87.11 ns 81.48 ns 1.9836 0.0610 33471 B

Every range constraint except the numeric one derives from `WithNotNullValue`, which forces the failure before the inversion is applied, so a null subject fails the negated form just as it fails the normal one. `IsBetween` said so in each of those files and `IsNotBetween` did not, although the two share a constraint and differ only by `Invert`.

`ThatNumber` was the exception that kept the name in the exemption list of `GuaranteesNotNullTests`, and it was not a deliberate one: its nullable range constraint derived from `WithEqualToValue` and passed the lower bound as the `isExpectedNull` flag, so a null subject failed or passed depending on whether the minimum happened to be null. `IsNotBetween(1).And(3)` passed while `IsNotBetween(null).And(null)` failed - the opposite of what a strict negation of `IsBetween` would give, and the only negated numeric expectation a null subject passed at all, next to `IsNotNaN` and `IsNotInfinite` which both fail. That base class answers a question about equality, where `IsEqualTo(null)` on a null subject should hold; a range has no such reading. It now derives from `WithNotNullValue` like the others, and the name leaves the exemption list.

The overloads taking a non-nullable subject gain nothing from the attribute, but their `IsBetween` twin already carries it, and marking only one half of each file would preserve the asymmetry this removes.

**BREAKING CHANGE:**
a null subject now fails `IsNotBetween` for numbers instead of passing.
@vbreuss
vbreuss force-pushed the feat/isnotbetween-guarantees-not-null branch from e89b406 to 6aeb246 Compare September 14, 2026 11:20
@sonarqubecloud

Copy link
Copy Markdown

@vbreuss
vbreuss merged commit fd00414 into main Sep 14, 2026
14 checks passed
@vbreuss
vbreuss deleted the feat/isnotbetween-guarantees-not-null branch September 14, 2026 11:30
github-actions Bot added a commit that referenced this pull request Sep 14, 2026
github-actions Bot added a commit that referenced this pull request Sep 14, 2026
vbreuss added a commit that referenced this pull request Sep 14, 2026
… anything

The attribute has one mechanical effect: `IsNotNullSuppressor` reads it and drops a CS8600, CS8602, CS8604 or CS8629 on the subject. A subject that cannot be `null` - `ImmutableArray<T>`, `TimeSpan`, `DateTime`, `bool`, a `TNumber` constrained to `struct`, or a concrete `float`/`double` overload - never raises one, so 226 of the 769 markings did nothing.

They were also invisible to the sweep, which skips a subject it cannot make `null`, so they were neither invoked nor verified. At nearly a third of all markings that dilutes the signal, and it shifts how the attribute reads: from a suppression directive into documentation that an expectation rejects `null`. That drift is how a marking reaches a reference type it does not hold for, and there the cost is a real CS8602 dropped in a user's code.

`EveryMarkedExpectation_ShouldHaveASubjectThatCanBeNull` now rejects such a marking, which makes the rule self-enforcing. It asks about the subject rather than the receiver, because a receiver like `ThatSubject<T>` is a struct that wraps a subject which can be `null` - `Is` and `IsExactly` are marked for exactly that reason. The non-nullable `IsNotBetween` overloads that #1092 marked to keep each file symmetrical are covered by it too.
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 enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant