Skip to content

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

Closed
nohwnd wants to merge 1 commit into
pester:mainfrom
nohwnd:fix-2555-shouldbenull
Closed

Fix #2555: Should-BeNull treats empty pipeline input as null#2689
nohwnd wants to merge 1 commit into
pester:mainfrom
nohwnd:fix-2555-shouldbenull

Conversation

@nohwnd

@nohwnd nohwnd commented Apr 3, 2026

Copy link
Copy Markdown
Member

Fix #2555

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.

  • Pipeline empty array: passes (void function output)
  • Explicit parameter empty array: still fails

Copilot-generated fix.

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

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.

- Pipeline empty array: passes (void function output)
- Explicit parameter empty array: still fails

Copilot-generated fix.

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

nohwnd commented Jun 12, 2026

Copy link
Copy Markdown
Member Author

Superseded by PR 2708, which fixes the same issue at the right layer: Collect-Input -UnrollInput now returns $null when the pipeline collected no items, so @() | Should-BeNull (and Should-Be -Expected $null, Should-NotBeNull, …) all do the right thing.

With #2708 merged, the patch on Should-BeNull.ps1 here is dead code, and the two tests added in this PR are already covered (plus more cases for @($null), ,$null, multi-item arrays) on main. Closing.

@nohwnd nohwnd closed this Jun 12, 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-BeNull: Strange behaviour when $null

1 participant