Skip to content

fix: correct error message for prefix/suffix of empty strings#791

Merged
vbreuss merged 3 commits intomainfrom
topic/fix-prefix-suffix-for-emtpy-strings
Sep 17, 2025
Merged

fix: correct error message for prefix/suffix of empty strings#791
vbreuss merged 3 commits intomainfrom
topic/fix-prefix-suffix-for-emtpy-strings

Conversation

@vbreuss
Copy link
Copy Markdown
Member

@vbreuss vbreuss commented Sep 17, 2025

This PR fixes error message formatting for string prefix and suffix assertions when dealing with empty strings. The changes ensure that empty strings are properly handled in error messages to avoid displaying confusing contextual information.

Key changes:

  • Updates error message logic to use string.IsNullOrEmpty() instead of null-only checks
  • Adds conditional context display to prevent showing "Actual" context for null/empty strings
  • Includes test coverage for empty string scenarios in both StartsWith and EndsWith assertions

@vbreuss vbreuss self-assigned this Sep 17, 2025
@vbreuss vbreuss added the bug Something isn't working label Sep 17, 2025
Copilot AI review requested due to automatic review settings September 17, 2025 18:29
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes error message formatting for string prefix and suffix assertions when dealing with empty strings. The changes ensure that empty strings are properly handled in error messages to avoid displaying confusing contextual information.

  • Updates error message logic to use string.IsNullOrEmpty() instead of null-only checks
  • Adds conditional context display to prevent showing "Actual" context for null/whitespace strings
  • Includes test coverage for empty string scenarios in both StartsWith and EndsWith assertions

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
ThatString.StartsWith.Tests.cs Adds test case for empty string input to verify proper error message formatting
ThatString.EndsWith.Tests.cs Adds test case for empty string input to verify proper error message formatting
ThatString.IsEqualTo.cs Conditionally adds "Actual" context only for non-null/non-whitespace strings
StringEqualityOptions.SuffixMatchType.cs Updates null check to include empty strings for better error message handling
StringEqualityOptions.PrefixMatchType.cs Updates null check to include empty strings for better error message handling

Comment thread Source/aweXpect/That/Strings/ThatString.IsEqualTo.cs Outdated
@vbreuss vbreuss enabled auto-merge (squash) September 17, 2025 18:34
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Sep 17, 2025

🚀 Benchmark Results

Details

BenchmarkDotNet v0.14.0, Ubuntu 24.04.3 LTS (Noble Numbat)
AMD EPYC 7763, 1 CPU, 4 logical and 2 physical cores
.NET SDK 8.0.414
[Host] : .NET 8.0.20 (8.0.2025.41914), X64 RyuJIT AVX2

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

Method Mean Error StdDev Gen0 Gen1 Allocated
Bool_aweXpect 206.6 ns 0.90 ns 0.75 ns 0.0300 - 504 B
Bool_FluentAssertions 240.8 ns 0.69 ns 0.61 ns 0.0567 - 952 B
Bool_TUnit 859.1 ns 3.32 ns 3.11 ns 0.1431 - 2408 B
Equivalency_aweXpect 312,041.0 ns 1,126.42 ns 940.61 ns 20.0195 0.9766 335556 B
Equivalency_FluentAssertions 2,201,947.5 ns 4,083.46 ns 3,409.87 ns 273.4375 46.8750 4584416 B
Equivalency_TUnit 662,501.5 ns 1,310.68 ns 1,161.89 ns 51.7578 2.9297 880545 B
Int_GreaterThan_aweXpect 243.3 ns 0.64 ns 0.60 ns 0.0486 - 816 B
Int_GreaterThan_FluentAssertions 240.4 ns 1.34 ns 1.26 ns 0.0730 - 1224 B
Int_GreaterThan_TUnit 1,180.6 ns 3.11 ns 2.91 ns 0.1774 - 2984 B
ItemsCount_AtLeast_aweXpect 471.4 ns 1.51 ns 1.34 ns 0.0868 - 1464 B
ItemsCount_AtLeast_FluentAssertions 476.2 ns 2.25 ns 2.10 ns 0.1197 - 2008 B
ItemsCount_AtLeast_TUnit 23,403.8 ns 38.48 ns 35.99 ns 1.6174 - 27480 B
String_aweXpect 458.8 ns 0.93 ns 0.77 ns 0.0734 - 1232 B
String_FluentAssertions 453.9 ns 0.65 ns 0.51 ns 0.1292 - 2168 B
String_TUnit 1,180.4 ns 5.70 ns 5.05 ns 0.1831 - 3072 B
StringArray_aweXpect 1,912.0 ns 5.40 ns 4.79 ns 0.1717 - 2888 B
StringArray_FluentAssertions 1,260.9 ns 6.31 ns 5.90 ns 0.2480 - 4152 B
StringArray_TUnit 3,186.4 ns 5.59 ns 5.22 ns 0.3128 - 5296 B
StringArrayInAnyOrder_aweXpect 2,431.3 ns 5.44 ns 4.82 ns 0.1831 - 3080 B
StringArrayInAnyOrder_FluentAssertions 147,656.1 ns 1,137.55 ns 1,008.41 ns 3.4180 - 63787 B
StringArrayInAnyOrder_TUnit 3,746.1 ns 15.47 ns 14.47 ns 0.3853 - 6488 B

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Sep 17, 2025

👽 Mutation Results

Mutation testing badge

aweXpect

Details
File Score Killed Survived Timeout No Coverage Ignored Compile Errors Total Detected Total Undetected Total Mutants
That/Strings/ThatString.IsEqualTo.cs 92.86% 13 1 0 0 2 4 13 1 20

The final mutation score is 92.86%

Coverage Thresholds: high:80 low:60 break:0

aweXpect.Core

Details
File Score Killed Survived Timeout No Coverage Ignored Compile Errors Total Detected Total Undetected Total Mutants
Options/StringEqualityOptions.PrefixMatchType.cs 93.10% 54 3 0 1 15 8 54 4 81
Options/StringEqualityOptions.SuffixMatchType.cs 63.08% 41 3 0 21 16 8 41 24 89

The final mutation score is 77.24%

Coverage Thresholds: high:80 low:60 break:0

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Sep 17, 2025

@vbreuss vbreuss disabled auto-merge September 17, 2025 18:48
@github-actions
Copy link
Copy Markdown
Contributor

Test Results

    14 files   - 24      14 suites   - 24   5m 21s ⏱️ + 1m 8s
17 866 tests  - 25  17 861 ✅  - 27   5 💤 +2  0 ❌ ±0 
50 265 runs   - 66  50 254 ✅  - 72  11 💤 +6  0 ❌ ±0 

Results for commit 5774d8e. ± Comparison against base commit 07fdc9d.

This pull request removes 1561 and adds 1536 tests. Note that renamed tests count towards both.
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "message2e332be1-fb2b-4ab2-a33f-d5307b9873a4")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "message4e5364d5-ea0f-4699-ba6a-22689cd09a59")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "messagea65ddd09-b7d2-4610-b7f0-d28956466ed8")
aweXpect.Core.Tests.Core.Exceptions.SkipExceptionTests ‑ Message_ShouldBeSet(message: "message14908bee-2734-461c-a07e-ab917e98e25f")
aweXpect.Core.Tests.Core.Exceptions.SkipExceptionTests ‑ Message_ShouldBeSet(message: "message1c325cc8-772f-4886-aa5f-07e0a5b0b507")
aweXpect.Core.Tests.Core.Exceptions.SkipExceptionTests ‑ Message_ShouldBeSet(message: "message91bc7459-4c26-443e-b02a-87715cfa71e3")
aweXpect.Core.Tests.FailTests ‑ Test_ShouldThrowException(reason: "reasona614ed03-a56f-4ef6-8194-8c03655d2827")
aweXpect.Core.Tests.FailTests ‑ Test_ShouldThrowException(reason: "reasond7dffcb9-e767-4880-a019-c77b22d9835e")
aweXpect.Core.Tests.FailTests ‑ Test_ShouldThrowException(reason: "reasonf66aba6c-d6b6-4a75-b77f-3922938379b8")
aweXpect.Core.Tests.FailTests ‑ Unless_ShouldThrowException(condition: False, reason: "reason2e652783-6734-42e2-a80e-7b49a66e3fff")
…
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "message52d363a6-6646-407b-b63c-14b1f0fc8d90")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "message5be68e6d-71c3-44f3-80b0-5333da0ed271")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "messagef8801964-0dc3-4dba-8268-5de1ed9acf27")
aweXpect.Core.Tests.Core.Exceptions.SkipExceptionTests ‑ Message_ShouldBeSet(message: "message26290210-c51e-44e1-a3a5-8f4e7974e941")
aweXpect.Core.Tests.Core.Exceptions.SkipExceptionTests ‑ Message_ShouldBeSet(message: "messageaa204ca2-b0c8-49fa-9bac-1cce2485e9b9")
aweXpect.Core.Tests.Core.Exceptions.SkipExceptionTests ‑ Message_ShouldBeSet(message: "messageb5949639-8b8a-4689-a837-bb787d06f834")
aweXpect.Core.Tests.FailTests ‑ Test_ShouldThrowException(reason: "reason57078382-df5f-4844-bc21-d9cf38d2752b")
aweXpect.Core.Tests.FailTests ‑ Test_ShouldThrowException(reason: "reasonac2e3446-85b7-4aaf-9db5-107be5856182")
aweXpect.Core.Tests.FailTests ‑ Test_ShouldThrowException(reason: "reasond21c6764-7c24-4418-a56a-fc28642658ee")
aweXpect.Core.Tests.FailTests ‑ Unless_ShouldThrowException(condition: False, reason: "reason6cc91d87-a5ac-4b92-afd4-1eeee6815fcd")
…

@vbreuss vbreuss merged commit 05fb28b into main Sep 17, 2025
13 checks passed
@vbreuss vbreuss deleted the topic/fix-prefix-suffix-for-emtpy-strings branch September 17, 2025 18:48
github-actions Bot added a commit that referenced this pull request Sep 17, 2025
github-actions Bot added a commit that referenced this pull request Sep 17, 2025
@github-actions
Copy link
Copy Markdown
Contributor

This is addressed in release v2.25.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working state: released The issue is released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants