diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Set-Location.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Set-Location.Tests.ps1 index faff8ae43..95680dbe0 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Set-Location.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Set-Location.Tests.ps1 @@ -54,6 +54,22 @@ Describe "Set-Location" -Tags "CI" { $(Get-Location).Path | Should -BeExactly $testPath.FullName } + It "Should not use filesystem root folder if not in filesystem provider" -Skip:(!$IsWindows) { + # find filesystem root folder that doesn't exist in HKCU: + $foundFolder = $false + foreach ($folder in Get-ChildItem "${env:SystemDrive}\" -Directory) { + if (-Not (Test-Path "HKCU:\$($folder.Name)")) { + $testFolder = $folder.Name + $foundFolder = $true + break + } + } + $foundFolder | Should -BeTrue + Set-Location HKCU:\ + { Set-Location ([System.IO.Path]::DirectorySeparatorChar + $testFolder) -ErrorAction Stop } | + Should -Throw -ErrorId "PathNotFound,Microsoft.PowerShell.Commands.SetLocationCommand" + } + Context 'Set-Location with no arguments' { It 'Should go to $env:HOME when Set-Location run with no arguments from FileSystem provider' {