Skip to content

Improve error message for array comparison in Should -Be#2699

Open
yezhi0 wants to merge 2 commits into
pester:mainfrom
yezhi0:main
Open

Improve error message for array comparison in Should -Be#2699
yezhi0 wants to merge 2 commits into
pester:mainfrom
yezhi0:main

Conversation

@yezhi0

@yezhi0 yezhi0 commented Apr 21, 2026

Copy link
Copy Markdown

This PR improves the error message when Should -Be compares two arrays that differ in length or type, but appear identical due to unrolling.

Changes:

  • Add detection for collection length and type differences.
  • Show a clear message with expected and actual lengths and types.
  • Preserve existing behavior for string comparisons.

Fixes #1154

yezhi0 added 2 commits April 21, 2026 23:21
Show collection length and type when array comparison fails due to
different lengths or types, addressing confusing error messages
where both sides appeared identical.

Related: pester#1154

@nohwnd nohwnd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

provide tests for the change you are making

# This looks odd; it's to unroll single-element arrays so the "-is [string]" expression works properly.
$ActualValue = $($ActualValue)
$ExpectedValue = $($ExpectedValue)
# 获取类型和长度信息

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can we get english comments

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Should -Be gives confusing error message comparing arrays that are not enumerated.

2 participants