From 19ea81f6be73bc3590f62525346256b70a96252f Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Thu, 13 Oct 2022 20:10:52 -0700 Subject: [PATCH] Use shortpath instead of multiple quotes in `Get-Item` test relying on node (#18250) --- .../Get-Item.Tests.ps1 | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Item.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Item.Tests.ps1 index 4efc250e0d..bb70185505 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Item.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Item.Tests.ps1 @@ -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 } }