Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Test-Path: Return $false when given an empty or $null -Path/-LiteralPath value #8080
Test-Path is expected to be almost exclusively a True/False response cmdlet, and the cases where it may error or return an unexpected result are a few too many at present (see above issues). This PR allows
PS> Test-Path ' ' False PS> Test-Path '' False PS> Test-Path @() False
PS> Test-Path $null PS> Test-Path $null, $null
These are non-terminating errors.
A small handful of tests predicated on Test-Path failing in these cases have been updated to simply transform the error into terminating via -ErrorAction, as it appears that the important part of the test was not Test-Path itself, but throwing a terminating error in specific code strictures.
Tests for the additional behaviours have also been added.
Added non-terminating errors for the following cases, per PowerShell committee recommendation:
Docs issue: MicrosoftDocs/PowerShell-Docs#3165
We'll get a non-terminating error per the recommendation. In terms of output this will effectively be treated as
Would explicitly outputting