Skip to content

fix!: reject an empty needle in the params overloads of StartsWith and EndsWith - #1076

Merged
vbreuss merged 1 commit into
mainfrom
fix/startswith-endswith-params-validation
Sep 13, 2026
Merged

vbreuss merged 1 commit into
mainfrom
fix/startswith-endswith-params-validation

Conversation

@vbreuss

@vbreuss vbreuss commented Sep 13, 2026

Copy link
Copy Markdown
Member

#1069 rejected a null or empty argument for Contains, StartsWith and EndsWith, but only on the overloads taking an IEnumerable<TItem>: their params twins kept a null-only guard, so EndsWith(emptyCollection) threw while EndsWith() asserted nothing at all and passed for any subject. That left one expectation contradicting itself depending on which overload the caller happened to bind to, which is the worst version of the inconsistency to ship in a major.

All 28 params overloads across StartsWith, EndsWith, DoesNotStartWith and DoesNotEndWith now use the same ThrowIfNullOrEmpty guard as their siblings, so the exception type and the message no longer depend on the overload either. The eight redundant ArgumentNullException.ThrowIfNull calls sitting directly after ThrowIfNullOrEmpty on the asynchronous non-params overloads have been dropped as dead, and using System; with them.

Several WhenSubjectIsNull_ShouldFail tests reached the null subject through an empty needle, so they were asserting the subject's behaviour by way of the argument that now throws; they were given a real needle rather than a suppression, and the tests that pinned the old empty-needle behaviour now pin the exception. The argument-null tests asserted only a parameter name, which is why the differing message went unnoticed, so they pin the message now too.

@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
…` and `EndsWith`

#1069 rejected a `null` or empty argument for `Contains`, `StartsWith` and `EndsWith`, but only on the overloads taking an `IEnumerable<TItem>`: their `params` twins kept a null-only guard, so `EndsWith(emptyCollection)` threw while `EndsWith()` asserted nothing at all and passed for any subject. That left one expectation contradicting itself depending on which overload the caller happened to bind to, which is the worst version of the inconsistency to ship in a major.

All 28 `params` overloads across `StartsWith`, `EndsWith`, `DoesNotStartWith` and `DoesNotEndWith` now use the same `ThrowIfNullOrEmpty` guard as their siblings, so the exception type and the message no longer depend on the overload either. The eight redundant `ArgumentNullException.ThrowIfNull` calls sitting directly after `ThrowIfNullOrEmpty` on the asynchronous non-`params` overloads have been dropped as dead, and `using System;` with them.

Several `WhenSubjectIsNull_ShouldFail` tests reached the null subject through an empty needle, so they were asserting the subject's behaviour by way of the argument that now throws; they were given a real needle rather than a suppression, and the tests that pinned the old empty-needle behaviour now pin the exception. The argument-null tests asserted only a parameter name, which is why the differing message went unnoticed, so they pin the message now too.
@vbreuss
vbreuss force-pushed the fix/startswith-endswith-params-validation branch from c12a91c to ddaf2f3 Compare September 13, 2026 14:12
@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 9V74 3.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-v4

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

Method Mean Error StdDev Gen0 Gen1 Allocated
Bool_aweXpect 194.7 ns 1.93 ns 1.80 ns 0.0415 - 696 B
Bool_FluentAssertions 207.1 ns 2.21 ns 1.96 ns 0.0567 - 952 B
Equivalency_aweXpect 230,918.5 ns 2,431.68 ns 2,274.59 ns 20.0195 0.9766 335442 B
Equivalency_FluentAssertions 1,793,076.1 ns 26,357.46 ns 24,654.78 ns 289.0625 50.7813 4841647 B
Int_GreaterThan_aweXpect 200.3 ns 2.85 ns 2.66 ns 0.0515 - 864 B
Int_GreaterThan_FluentAssertions 212.4 ns 1.28 ns 1.19 ns 0.0730 - 1224 B
ItemsCount_AtLeast_aweXpect 361.1 ns 6.98 ns 6.52 ns 0.0811 - 1360 B
ItemsCount_AtLeast_FluentAssertions 406.9 ns 5.02 ns 4.70 ns 0.1197 - 2008 B
String_aweXpect 379.8 ns 3.62 ns 3.21 ns 0.0672 - 1128 B
String_FluentAssertions 933.1 ns 13.49 ns 12.62 ns 0.2356 0.0010 3944 B
StringArray_aweXpect 1,470.6 ns 7.02 ns 6.56 ns 0.1564 - 2624 B
StringArray_FluentAssertions 1,091.9 ns 6.98 ns 6.53 ns 0.2480 - 4152 B
StringArrayInAnyOrder_aweXpect 1,927.2 ns 7.83 ns 6.94 ns 0.1678 - 2816 B
StringArrayInAnyOrder_FluentAssertions 15,632.7 ns 199.09 ns 186.23 ns 1.9836 0.0610 33471 B

@github-actions

Copy link
Copy Markdown
Contributor

Test Results

     23 files   -  27       23 suites   - 27   10m 9s ⏱️ + 1m 41s
 20 702 tests  -  33   20 700 ✅  -  33  2 💤 ±0  0 ❌ ±0 
107 762 runs   - 108  107 760 ✅  - 108  2 💤 ±0  0 ❌ ±0 

Results for commit ddaf2f3. ± Comparison against base commit 9547e82.

This pull request removes 3257 and adds 3224 tests. Note that renamed tests count towards both.
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(message: "message20787f66-87fc-464a-b114-9679cb122a15")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(message: "message4090f256-aa50-41c1-b29f-3ba61cc199b2")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(message: "message4ce5475c-d38f-4053-a8cc-9ba6e0a0c87f")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(message: "message5a716b95-e212-4307-b0a2-34534c3c5726")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(message: "message7f96ae4e-bb58-4053-abfc-bf339f2c8133")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(message: "messagea49195fa-f21a-48cd-80f9-a24de12aacdb")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "message0d00dfaf-338d-4e4a-9b12-1464ea8cf936")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "message2d199ec9-a165-4935-983a-363b2fd775c0")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "message8ff4b0f4-9979-480f-a470-5d4bab910792")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "messagea5c72c17-2255-4dbb-ae3a-b8157c522fe3")
…
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(message: "message22eb542a-3068-424b-a54f-c6676cb42302")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(message: "message5585a0c9-de80-4434-99ea-1ccdb6b60e84")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(message: "message5b4ad457-ebf2-4b29-8dec-f609b870bbb1")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(message: "message795d94cc-8cf1-4d15-b58b-db1ccc49a87b")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(message: "messagec8b3ab0b-657a-4379-80c5-0858c6534ae4")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(message: "messageca497591-a590-406a-ac9f-1f414cb6f55f")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "message02a9d997-88ec-4121-a7cd-3de8e86b9199")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "message19edf386-1404-4b51-8fc1-4d47fc2a33e2")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "message76a13f3b-9dfa-4543-bf44-2b6d80769488")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "messaged46a36e1-724e-45a2-9d81-fd391001d47e")
…

@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/Collections/ThatAsyncEnumerable.EndsWith.cs 90.48% 57 0 0 6 24 24 0 57 6 111
That/Collections/ThatAsyncEnumerable.StartsWith.cs 89.29% 50 0 0 6 22 23 0 50 6 101
That/Collections/ThatEnumerable.EndsWith.cs 88.98% 113 4 0 10 40 46 0 113 14 213
That/Collections/ThatEnumerable.StartsWith.cs 87.61% 99 4 0 10 38 44 0 99 14 195

The final mutation score is 88.86%

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

@sonarqubecloud

Copy link
Copy Markdown

@vbreuss
vbreuss merged commit 6870b4c into main Sep 13, 2026
13 checks passed
@vbreuss
vbreuss deleted the fix/startswith-endswith-params-validation branch September 13, 2026 14:28
github-actions Bot added a commit that referenced this pull request Sep 13, 2026
…rams` overloads of `StartsWith` and `EndsWith` (#1076) by Valentin Breuß
github-actions Bot added a commit that referenced this pull request Sep 13, 2026
…rams` overloads of `StartsWith` and `EndsWith` (#1076) by Valentin Breuß
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