{{ message }}
Include original index in extraneous item failure messages#3203
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR improves BeEquivalentTo failure diagnostics for collection equivalency by including the original index of extraneous (subject-only) items in the assertion failure message (Fixes #985), making it easier to locate where collections diverge.
Changes:
- Wrap subjects in
IndexedItem<object>so original indices survive the matching pipeline through to reporting. - Update ordered equivalency strategies to operate on
List<IndexedItem<object>>and compare via.Item. - Extend/adjust specs and release notes to cover and document the improved failure messages.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
Test Results 37 files ± 0 37 suites ±0 2m 47s ⏱️ -1s Results for commit 6059560. ± Comparison against base commit fb42954. This pull request removes 10 and adds 10 tests. Note that renamed tests count towards both.♻️ This comment has been updated with latest results. |
Coverage Report for CI Build 25427286962Coverage decreased (-0.002%) to 97.14%Details
Uncovered Changes
Coverage RegressionsNo coverage regressions found. Coverage Stats💛 - Coveralls |
f29c4ec to
3fc7825
Compare
jnyrup
requested changes
May 5, 2026
jnyrup
approved these changes
May 6, 2026
When BeEquivalentTo fails because the subject collection has more items
than expected, the error message now includes the original index of each
extraneous item to help diagnose where collections diverge.
Before:
found one extraneous item Customer { Age = 16, ... }
After:
found one extraneous item at index 1 Customer { Age = 16, ... }
For multiple extra items:
found extraneous items {Customer { Age = 16, ... } (at index 1), ...}
Fixes #985
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Escape { and } in Formatter.ToString output before embedding into
the FailWith format string, preventing string.Format from treating
object dumps like 'Customer { Age = 16 }' as format placeholders
- Pass a single item (not a 1-element list) as the {1} argument
whenever remainingSubjects.Count == 1, matching the previous
behavior for the 'both missing and extra' fallback path
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Multi-item: 'found extraneous items: A (at index 3), B (at index 96)'
instead of 'found extraneous items {A (at index 3), B (at index 96)}'
- Single-item: 'found one extraneous item at index 1: X'
instead of 'found one extraneous item at index 1 X'
- Fix TestBeEquivalent to be a proper test with a throw assertion
and a descriptive name
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…lidator.cs Co-authored-by: Jonas Nyrup <jnyrup@users.noreply.github.com>
Without escaping curly braces in the formatted items string, string.Format throws a FormatException, causing a **WARNING** fallback instead of the actual failure message. The existing test didn't catch this because the WARNING still contained the expected text from the raw format string. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Jonas Nyrup <jnyrup@users.noreply.github.com>
…lidator.cs Co-authored-by: Jonas Nyrup <jnyrup@users.noreply.github.com>
510afe6 to
ad34005
Compare
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced May 12, 2026
This was referenced Jun 29, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Fixes #985.
When
BeEquivalentTofails because the subject collection has more items than expected, the error message now includes the original index of each extraneous item, making it easier to diagnose where collections diverge.Before
After
Single extra item:
Multiple extra items:
Implementation
EnumerableEquivalencyValidator: subjects are now wrapped inList<IndexedItem<object>>so original indices survive through the matching pipeline to the reporting stage.StrictlyOrderedEquivalencyStrategy/LooselyOrderedEquivalencyStrategy: updated to passList<IndexedItem<object>>instead ofList<object>for subjects; raw objects are accessed via.Item.at index N:. When both missing and extra items exist, the compact fallback format is used to avoid expensive per-item formatting.Customer { Age = 16 }) are escaped before embedding into theFailWithformat string to preventstring.Formattreating them as placeholders.