mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Use shortpath instead of multiple quotes in Get-Item test relying on node (#18250)
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user