Skip to content

Commit 19ea81f

Browse files
authored
Use shortpath instead of multiple quotes in Get-Item test relying on node (PowerShell#18250)
1 parent 1228ebc commit 19ea81f

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

test/powershell/Modules/Microsoft.PowerShell.Management/Get-Item.Tests.ps1

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,16 +191,21 @@ Describe "Get-Item environment provider on Windows with accidental case-variant
191191
if (-not (Get-Command -ErrorAction Ignore node.exe)) {
192192
Write-Warning "Test skipped, because prerequisite Node.js is not installed."
193193
} else {
194-
$valDirect, $valGetItem, $unused = node.exe -pe @"
194+
$fso = New-Object -ComObject Scripting.FileSystemObject
195+
$shortPath = $fso.GetFile("$PSHOME\pwsh.exe").ShortPath.Replace('\', '/')
196+
$script = @"
195197
env = {}
196198
env.testVar = process.env.testVar // include the original case variant with its original value.
197199
env.TESTVAR = 'b' // redefine with a case variant name and different value
198200
// Note: Which value will win is not deterministic(!); what matters, however, is that both
199-
// $env:testvar and Get-Item env:testvar report the same value.
201+
// `$env:testvar and Get-Item env:testvar report the same value.
200202
// The nondeterministic behavior makes it hard to prove that the values are *always* the
201203
// same, however.
202-
require('child_process').execSync(\"\\\"$($PSHOME -replace '\\', '/')/pwsh.exe\\\" -noprofile -command `$env:testvar, (Get-Item env:testvar).Value\", { env: env }).toString()
204+
require('child_process').execSync('$shortPath -noprofile -command `$env:testvar, (Get-Item env:testvar).Value', { env: env }).toString()
203205
"@
206+
$valDirect, $valGetItem, $unused = node.exe -pe $script
207+
$LASTEXITCODE | Should -Be 0
208+
$valDirect | Should -Not -BeNullOrEmpty
204209
$valGetItem | Should -BeExactly $valDirect
205210
}
206211
}

0 commit comments

Comments
 (0)