Add conditional to check if LastExitCode is defined
* Add broken requires statement test case * Add test case to reproduce invalid LastExitCode
This commit is contained in:
parent
35df3914d2
commit
38f799df3e
|
@ -100,7 +100,7 @@ func (p *Provisioner) defaultExecuteCommand() string {
|
|||
baseCmd := `& { if (Test-Path variable:global:ProgressPreference)` +
|
||||
`{set-variable -name variable:global:ProgressPreference -value 'SilentlyContinue'};` +
|
||||
`{set-variable -name variable:global:ErrorActionPreference -value 'Continue'};` +
|
||||
`%s. {{.Vars}};try { . '{{.Path}}' } catch { Write-Error $Error[0]; exit 1 }; exit $LastExitCode }`
|
||||
`%s. {{.Vars}};try { & '{{.Path}}' } catch { Write-Error $Error[0]; exit 1 }; if ($LastExitCode) { exit $LastExitCode }}`
|
||||
|
||||
var debugLine string
|
||||
if p.config.DebugMode != 0 {
|
||||
|
|
|
@ -44,7 +44,7 @@ func TestAccPowershellProvisioner_Invalid(t *testing.T) {
|
|||
|
||||
// This provisioner should fail with an exit code of 1. To assert the failure the fixture
|
||||
// uses the valid_exit_codes option to confirm a non-zero exit code
|
||||
testProvisioner := PowershellProvisionerAccTest{"powershell-provisioner-invalid.txt"}
|
||||
testProvisioner := PowershellProvisionerAccTest{"powershell-exit_codes-provisioner.txt"}
|
||||
acc.TestProvisionersAgainstBuilders(&testProvisioner, t)
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"type": "powershell",
|
||||
"inline": ["invalid-cmdlet"],
|
||||
"valid_exit_codes": ["1"]
|
||||
},
|
||||
{
|
||||
"type": "powershell",
|
||||
"inline": ["#Requires -Version 10.0"],
|
||||
"valid_exit_codes": ["1"]
|
||||
},
|
||||
{
|
||||
"type": "powershell",
|
||||
"script": "../../provisioner/powershell/test-fixtures/scripts/set_version_latest.ps1"
|
||||
},
|
||||
{
|
||||
"type": "powershell",
|
||||
"inline": "sc.exe start Life",
|
||||
"valid_exit_codes": ["1060"]
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
{
|
||||
"type": "powershell",
|
||||
"inline": ["invalid-cmdlet"],
|
||||
"valid_exit_codes": ["1"]
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
Set-StrictMode -Version Latest
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
function test
|
||||
{
|
||||
|
||||
$myNumbersCollection = 1..5
|
||||
|
||||
if($myNumbersCollection -contains 3)
|
||||
{
|
||||
"collection contains 3"
|
||||
}
|
||||
else
|
||||
{
|
||||
"collection doesn't contain 3"
|
||||
}
|
||||
}
|
||||
|
||||
test
|
Loading…
Reference in New Issue