mirror of
https://github.com/hashicorp/packer.git
synced 2026-02-03 20:39:29 -05:00
Merge pull request #13539 from MBradbury/powershell-test-lastexitcode
Check LASTEXITCODE is set before checking its value
This commit is contained in:
commit
74cc342e44
2 changed files with 2 additions and 2 deletions
|
|
@ -55,7 +55,7 @@ const wrapPowershellString string = `
|
|||
$exitCode = 1
|
||||
}
|
||||
|
||||
if ($LASTEXITCODE -ne $null -and $LASTEXITCODE -ne 0) {
|
||||
if ((Test-Path variable:global:LASTEXITCODE) -and $LASTEXITCODE -ne $null -and $LASTEXITCODE -ne 0) {
|
||||
$exitCode = $LASTEXITCODE
|
||||
}
|
||||
exit $exitCode
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ func TestProvisionerPrepare_extractScript(t *testing.T) {
|
|||
|
||||
// File contents should contain 2 lines concatenated by newlines: foo\nbar
|
||||
readFile, err := os.ReadFile(file)
|
||||
expectedContents := "if (Test-Path variable:global:ProgressPreference) {\n set-variable -name variable:global:ProgressPreference -value 'SilentlyContinue'\n }\n \n $exitCode = 0\n try {\n $env:PACKER_BUILDER_TYPE=\"\"; $env:PACKER_BUILD_NAME=\"\"; \n foo\n bar\n \n $exitCode = 0\n } catch {\n Write-Error \"An error occurred: $_\"\n $exitCode = 1\n }\n \n if ($LASTEXITCODE -ne $null -and $LASTEXITCODE -ne 0) {\n $exitCode = $LASTEXITCODE\n }\n exit $exitCode"
|
||||
expectedContents := "if (Test-Path variable:global:ProgressPreference) {\n set-variable -name variable:global:ProgressPreference -value 'SilentlyContinue'\n }\n \n $exitCode = 0\n try {\n $env:PACKER_BUILDER_TYPE=\"\"; $env:PACKER_BUILD_NAME=\"\"; \n foo\n bar\n \n $exitCode = 0\n } catch {\n Write-Error \"An error occurred: $_\"\n $exitCode = 1\n }\n \n if ((Test-Path variable:global:LASTEXITCODE) -and $LASTEXITCODE -ne $null -and $LASTEXITCODE -ne 0) {\n $exitCode = $LASTEXITCODE\n }\n exit $exitCode"
|
||||
normalizedExpectedContent := normalizeWhiteSpace(expectedContents)
|
||||
if err != nil {
|
||||
t.Fatalf("Should not be error: %s", err)
|
||||
|
|
|
|||
Loading…
Reference in a new issue