Skip to content

Fix #2555 and #2561: Should-BeNull pipeline and escape chars in error messages#2685

Closed
nohwnd wants to merge 1 commit intopester:mainfrom
nohwnd:pester6-fixes
Closed

Fix #2555 and #2561: Should-BeNull pipeline and escape chars in error messages#2685
nohwnd wants to merge 1 commit intopester:mainfrom
nohwnd:pester6-fixes

Conversation

@nohwnd
Copy link
Copy Markdown
Member

@nohwnd nohwnd commented Apr 3, 2026

Pester 6 Fixes (Copilot-driven)

Fixes two issues from the 6.0.0 milestone.

Fix #2555: Should-BeNull treats empty pipeline input as null

When a function returns no output and the result is piped to Should-BeNull, PowerShell sends an empty array through the pipeline. Should-BeNull now recognizes this as "no output" and treats it as null, matching user expectations.

  • Pipeline empty array: passes (void function output)
  • Explicit parameter empty array: still fails (Should-BeNull -Actual @())

Fix #2561: Escape characters visible in assertion error messages

Format-String2 now escapes control characters as Unicode control pictures so they are visible in error messages instead of being invisible or corrupting terminal output.

Character Display
NUL U+2400
BEL U+2407
BS U+2408
TAB U+2409
FF U+240C
CR U+240D
LF U+240A
ESC U+241B

Before: Expected [string] '', but got [string] '31;3;5m'.
After: Expected [string] 'hello', but got [string] 'U+241B[31m'.

Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com

…ars in error messages

pester#2555: Should-BeNull now treats empty pipeline input as $null. When a
function returns no output, PowerShell sends @() through the pipeline.
Should-BeNull recognizes this as "no output" and treats it as null,
matching user expectations. Explicit @() via parameter still fails.

pester#2561: Format-String2 now escapes control characters (NUL, BEL, BS, TAB,
FF, CR, LF, ESC) as Unicode control pictures (␀␇␈␉␌␍␊␛) so they are
visible in assertion error messages instead of being invisible or
corrupting terminal output. This is especially important for ANSI
escape sequences.
@nohwnd
Copy link
Copy Markdown
Member Author

nohwnd commented Apr 3, 2026

split into multiple prs... one fix per pr.

@nohwnd
Copy link
Copy Markdown
Member Author

nohwnd commented Apr 3, 2026

Superseded by individual PRs per review feedback. Each fix now has its own PR (#2689-#2697).

@nohwnd nohwnd closed this Apr 3, 2026
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-BeString: Doesn't handle escape character correctly in error message Should-BeNull: Strange behaviour when $null

1 participant