Show the differing index when Should -Be compares arrays#2748
Merged
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
nohwnd
commented
Jun 26, 2026
| It "Keeps the plain message for collections of equal length" { | ||
| ShouldBeFailureMessage (1, 2, 3) (1, 2, 4) | Verify-Equal "Expected @(1, 2, 4), but got @(1, 2, 3)." | ||
| It "Outputs the differing index for collections of equal length" { | ||
| ShouldBeFailureMessage (1, 2, 3) (1, 2, 4) | Verify-Equal "Expected collections to be the same, but they were different.`nCollection lengths are both 3.`nCollections differ at index 2.`nExpected: 4`nBut was: 3" |
Member
Author
There was a problem hiding this comment.
-
format with newlines so we can read it (don't forget the normalize the output so it compares on linux as well, plenty examples around)
-
we no longer get to see the content of the array, not good.
Member
Author
There was a problem hiding this comment.
Done in 5a1d6fe - the message now shows the full collections (like the string diff does) plus the index, so the array contents are back. Joined with
so it compares the same on Linux.
Showing only the differing element dropped the array contents. Show the whole collection like the string diff does and keep the index callout. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Fix #1990
When two arrays have the same length but a different value, the failure now points at the first differing index. It prints the expected and actual element at that index, and keeps the existing length mismatch and scalar messages unchanged. Added regression tests for
Should -BeandShould -BeExactly.