Skip to content

fix: fail instead of silently succeeding when equivalency finds no members - #1051

Merged
vbreuss merged 1 commit into
mainfrom
fix/equivalency-zero-member-guard
Sep 12, 2026
Merged

vbreuss merged 1 commit into
mainfrom
fix/equivalency-zero-member-guard

Conversation

@vbreuss

@vbreuss vbreuss commented Sep 12, 2026 •

Copy link
Copy Markdown
Member

IsEquivalentTo walked the public fields and properties of the expected type. When that walk yielded no members at all and both sides had the same type, the comparison returned true without verifying anything, so the assertion passed unconditionally.

Zero members is now treated as an error, consistent with the existing behaviour for mismatching types, which already reported a failure in that case. Throwing rather than failing keeps the result correct under negation: a comparison that verifies nothing is neither equivalent nor not equivalent.

The guard is skipped when the caller excluded every member explicitly via IncludeMembers.None for both fields and properties, since comparing nothing is then an explicit choice.

Generic_For_IgnoringMember_ShouldSetOptionForType relied on the old behaviour: MemberToIgnore.ByName keeps its state in a private field, so the element comparison verified nothing and the test passed even with a completely different expected member name. It now uses the same It.Is<MemberToIgnore[]>().That.HasCount(1) form as the four sibling tests in that file; the member name itself remains covered by the ToString() assertion below it.

Tests live in aweXpect.Core.Tests because it references aweXpect.Core by project in every configuration, whereas aweXpect.Tests compiles against the released aweXpect.Core package outside Debug and could not observe this change. Front-end IsEquivalentTo tests can follow once Core is released.

…mbers

`IsEquivalentTo` walked the public fields and properties of the expected
type. When that walk yielded no members at all and both sides had the same
type, the comparison returned `true` without verifying anything, so the
assertion passed unconditionally.

Zero members is now treated as an error, consistent with the existing
behaviour for mismatching types, which already reported a failure in that
case. Throwing rather than failing keeps the result correct under negation:
a comparison that verifies nothing is neither equivalent nor not equivalent.

The guard is skipped when the caller excluded every member explicitly via
`IncludeMembers.None` for both fields and properties, since comparing
nothing is then an explicit choice.

This also covers types whose members were removed by the trimmer, which is
the failure mode that makes equivalency unsafe under Native AOT.

`Generic_For_IgnoringMember_ShouldSetOptionForType` relied on the old
behaviour: `MemberToIgnore.ByName` keeps its state in a private field, so
the element comparison verified nothing and the test passed even with a
completely different expected member name. It now uses the same
`It.Is<MemberToIgnore[]>().That.HasCount(1)` form as the four sibling tests
in that file; the member name itself remains covered by the `ToString()`
assertion below it.

Tests live in `aweXpect.Core.Tests` because it references `aweXpect.Core` by
project in every configuration, whereas `aweXpect.Tests` compiles against the
released `aweXpect.Core` package outside `Debug` and could not observe this
change. Front-end `IsEquivalentTo` tests can follow once Core is released.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@vbreuss vbreuss self-assigned this Sep 12, 2026
Copilot AI lite review requested due to automatic review settings September 12, 2026 18:25
@vbreuss vbreuss added the bug Something isn't working label Sep 12, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@vbreuss
vbreuss enabled auto-merge (squash) September 12, 2026 18:25
@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

Test Results

     23 files   - 27       23 suites   - 27   11m 17s ⏱️ +18s
 20 241 tests  - 34   20 239 ✅  - 34  2 💤 ±0  0 ❌ ±0 
104 687 runs   - 78  104 685 ✅  - 78  2 💤 ±0  0 ❌ ±0 

Results for commit b66031a. ± Comparison against base commit ae28ac8.

This pull request removes 3229 and adds 3195 tests. Note that renamed tests count towards both.
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(message: "message00997c52-8830-4137-ae11-50e0bf5e6767")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(message: "message692ff591-588b-4b76-a969-7e543bf099ea")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(message: "messagebc01e15b-b878-4d9d-a319-d7710bb6f951")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(message: "messagedf60878f-e826-49f9-b9d7-ac605fdde978")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(message: "messagee1d86dc9-a486-4fb5-b3bf-0e204bd7eee4")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(message: "messagee498d9d4-b065-423c-9a47-6dcef9004142")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "message0765b29c-e338-4812-9ad3-5889af60b855")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "message10c6ba77-1b76-4025-8aeb-089b351c21b1")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "message31d939ba-0154-440a-aacf-4954ae7d019e")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "message879e54e8-9a3b-4564-a135-4328c1f3f907")
…
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(message: "message61655fb3-b93f-4cb2-951a-6464f5568a1e")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(message: "message8467dc2c-d020-47e0-8186-3733cc4aabc1")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(message: "message9cfba023-897c-48e5-a0b2-0961ac9ec4ce")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(message: "messagea90397c6-da86-4e76-b751-3fc189450460")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(message: "messaged0403762-4a99-46b7-aab0-e9d52bbcfe3d")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(message: "messagefa8e19e4-057a-43da-9994-09f60c83ff17")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "message068a9d61-618b-4d38-bdf7-562c6c0643fa")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "message268633a5-88a3-43fb-bf88-ccf5991ff43a")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "message2ac45acf-6562-40cb-8c65-836f6807c05d")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "message47efc354-9c39-4ef4-b79e-42ca64022540")
…

@vbreuss
vbreuss merged commit f2c58ef into main Sep 12, 2026
14 checks passed
@vbreuss
vbreuss deleted the fix/equivalency-zero-member-guard branch September 12, 2026 18:33
github-actions Bot added a commit that referenced this pull request Sep 12, 2026
…g when equivalency finds no members (#1051) by Valentin Breuß
github-actions Bot added a commit that referenced this pull request Sep 12, 2026
…g when equivalency finds no members (#1051) by Valentin Breuß
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Benchmark Results

Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.5 LTS (Noble Numbat)
AMD EPYC 7763 2.68GHz, 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 278.9 ns 0.68 ns 0.53 ns 0.0415 - 696 B
Bool_FluentAssertions 266.5 ns 3.54 ns 3.14 ns 0.0567 - 952 B
Equivalency_aweXpect 329,346.5 ns 1,366.64 ns 1,211.49 ns 20.0195 0.4883 335444 B
Equivalency_FluentAssertions 2,751,291.9 ns 7,152.95 ns 6,340.90 ns 289.0625 46.8750 4841651 B
Int_GreaterThan_aweXpect 291.9 ns 2.17 ns 2.03 ns 0.0515 - 864 B
Int_GreaterThan_FluentAssertions 279.0 ns 5.46 ns 5.11 ns 0.0730 - 1224 B
ItemsCount_AtLeast_aweXpect 543.0 ns 7.36 ns 6.89 ns 0.0811 - 1360 B
ItemsCount_AtLeast_FluentAssertions 500.6 ns 7.00 ns 5.85 ns 0.1192 - 2008 B
String_aweXpect 488.8 ns 7.66 ns 7.17 ns 0.0668 - 1128 B
String_FluentAssertions 1,257.3 ns 23.45 ns 21.93 ns 0.2346 - 3944 B
StringArray_aweXpect 2,013.8 ns 15.83 ns 14.81 ns 0.1564 - 2624 B
StringArray_FluentAssertions 1,402.2 ns 26.37 ns 24.66 ns 0.2480 - 4152 B
StringArrayInAnyOrder_aweXpect 2,616.7 ns 11.48 ns 10.18 ns 0.1678 - 2816 B
StringArrayInAnyOrder_FluentAssertions 26,962.9 ns 162.37 ns 143.93 ns 1.9836 0.0610 33471 B

@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

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
Equivalency/EquivalencyComparison.Compare.cs 86.67% 208 14 0 18 54 37 0 208 32 331

The final mutation score is 86.67%

Coverage Thresholds: high:80 low:60 break: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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants