Use shortpath instead of multiple quotes in Get-Item test relying on node (#18250)

This commit is contained in:
Steve Lee
2022-10-14 08:10:52 +05:00
committed by GitHub
parent 1228ebc1f5
commit 19ea81f6be
@@ -191,16 +191,21 @@ Describe "Get-Item environment provider on Windows with accidental case-variant
if (-not (Get-Command -ErrorAction Ignore node.exe)) {
Write-Warning "Test skipped, because prerequisite Node.js is not installed."
} else {
$valDirect, $valGetItem, $unused = node.exe -pe @"
$fso = New-Object -ComObject Scripting.FileSystemObject
$shortPath = $fso.GetFile("$PSHOME\pwsh.exe").ShortPath.Replace('\', '/')
$script = @"
env = {}
env.testVar = process.env.testVar // include the original case variant with its original value.
env.TESTVAR = 'b' // redefine with a case variant name and different value
// Note: Which value will win is not deterministic(!); what matters, however, is that both
// $env:testvar and Get-Item env:testvar report the same value.
// `$env:testvar and Get-Item env:testvar report the same value.
// The nondeterministic behavior makes it hard to prove that the values are *always* the
// same, however.
require('child_process').execSync(\"\\\"$($PSHOME -replace '\\', '/')/pwsh.exe\\\" -noprofile -command `$env:testvar, (Get-Item env:testvar).Value\", { env: env }).toString()
require('child_process').execSync('$shortPath -noprofile -command `$env:testvar, (Get-Item env:testvar).Value', { env: env }).toString()
"@
$valDirect, $valGetItem, $unused = node.exe -pe $script
$LASTEXITCODE | Should -Be 0
$valDirect | Should -Not -BeNullOrEmpty
$valGetItem | Should -BeExactly $valDirect
}
}