diff options
author | Jay Mundrawala <jdmundrawala@gmail.com> | 2015-01-26 10:31:01 -0600 |
---|---|---|
committer | Jay Mundrawala <jdmundrawala@gmail.com> | 2015-01-26 10:31:01 -0600 |
commit | 65031fc65172a99c301177c62963c3dff528fac3 (patch) | |
tree | f70e1645d56f6d8f925510219d453b69e8c9fba8 | |
parent | 9467b30cc1690f566f083d1710fd0436adb8b67b (diff) | |
parent | 56e047311b35efe99df84b7544f255712423cd0c (diff) | |
download | chef-65031fc65172a99c301177c62963c3dff528fac3.tar.gz |
Merge pull request #2774 from chef/jdm/powershell-2348
Fix up powershell script
-rw-r--r-- | lib/chef/provider/powershell_script.rb | 4 | ||||
-rw-r--r-- | spec/functional/resource/powershell_spec.rb | 15 |
2 files changed, 17 insertions, 2 deletions
diff --git a/lib/chef/provider/powershell_script.rb b/lib/chef/provider/powershell_script.rb index 96955f73b6..8c79b384e9 100644 --- a/lib/chef/provider/powershell_script.rb +++ b/lib/chef/provider/powershell_script.rb @@ -24,8 +24,8 @@ class Chef protected EXIT_STATUS_EXCEPTION_HANDLER = "\ntrap [Exception] {write-error -exception ($_.Exception.Message);exit 1}".freeze - EXIT_STATUS_NORMALIZATION_SCRIPT = "\nif ($? -ne $true) { if ( $LASTEXITCODE -ne 0) {exit $LASTEXITCODE} else { exit 1 }}".freeze - EXIT_STATUS_RESET_SCRIPT = "\n$LASTEXITCODE=0".freeze + EXIT_STATUS_NORMALIZATION_SCRIPT = "\nif ($? -ne $true) { if ( $LASTEXITCODE ) {exit $LASTEXITCODE} else { exit 1 }}".freeze + EXIT_STATUS_RESET_SCRIPT = "\n$global:LASTEXITCODE=$null".freeze # Process exit codes are strange with PowerShell. Unless you # explicitly call exit in Powershell, the powershell.exe diff --git a/spec/functional/resource/powershell_spec.rb b/spec/functional/resource/powershell_spec.rb index 033f34e256..1b3ac844e0 100644 --- a/spec/functional/resource/powershell_spec.rb +++ b/spec/functional/resource/powershell_spec.rb @@ -56,6 +56,21 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do resource.run_action(:run) end + it "returns the -27 for a powershell script that exits with -27" do + file = Tempfile.new(['foo', '.ps1']) + begin + file.write "exit -27" + file.close + resource.code(". \"#{file.path}\"") + resource.returns(-27) + resource.run_action(:run) + ensure + file.close + file.unlink + end + end + + it "returns the process exit code" do resource.code(arbitrary_nonzero_process_exit_code_content) resource.returns(arbitrary_nonzero_process_exit_code) |