Skip to content

Fix #2628 and #2474: LiteralPath for Should -Exist and DirectoryInfo display loop#2686

Closed
nohwnd wants to merge 1 commit intopester:mainfrom
nohwnd:fix-assertions
Closed

Fix #2628 and #2474: LiteralPath for Should -Exist and DirectoryInfo display loop#2686
nohwnd wants to merge 1 commit intopester:mainfrom
nohwnd:fix-assertions

Conversation

@nohwnd
Copy link
Copy Markdown
Member

@nohwnd nohwnd commented Apr 3, 2026

Pester 6 Fixes (Copilot-generated)

Fix #2628: Should -Exist uses -LiteralPath

Changed Test-Path to Test-Path -LiteralPath so paths with wildcard characters like [ and ] are found correctly.

Fix #2474: DirectoryInfo/FileInfo infinite loop prevention

Added System.IO.DirectoryInfo and System.IO.FileInfo to the display property map in Get-DisplayProperty2 to prevent infinite recursion from circular Root/Directory properties.

All 2154 tests pass locally.

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

…rectoryInfo display loop

pester#2628: Should -Exist now uses Test-Path -LiteralPath instead of
Test-Path so paths with wildcard characters ([ ]) work correctly.

pester#2474: Added DirectoryInfo and FileInfo to the display property map
in Get-DisplayProperty2 to prevent infinite recursion from circular
Root/Directory properties.

Copilot-generated fix.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment on lines -14 to -16
It 'works for path with escaped [ ] characters' {
It 'works for path with literal [ ] characters' {
New-Item -Path "TestDrive:\[test].txt" -ItemType File | Out-Null
"TestDrive:\``[test``].txt" | Should -Exist
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

revert this and follow the design, the default behavior of Should -Exist has to remain the same ( a thin wrapper over Test-Path) and additional -LiteralPath parameter for specifying escaped path, following the semantics of Test-Path

@nohwnd
Copy link
Copy Markdown
Member Author

nohwnd commented Apr 3, 2026

Fix for Fix #2474: DirectoryInfo/FileInfo infinite loop prevention is good, but split to its own 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

1 participant