From 574e8527101fe341fd6a3019f8a3ae996d1db5dd Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Fri, 24 Aug 2012 16:50:05 +0100 Subject: [PATCH] foreman run should exit with the same code as its command --- lib/foreman/cli.rb | 1 + spec/foreman/cli_spec.rb | 5 +++++ spec/spec_helper.rb | 6 ++++++ 3 files changed, 12 insertions(+) diff --git a/lib/foreman/cli.rb b/lib/foreman/cli.rb index f64940a..ed67df8 100644 --- a/lib/foreman/cli.rb +++ b/lib/foreman/cli.rb @@ -86,6 +86,7 @@ class Foreman::CLI < Thor end end Process.wait(pid) + exit $?.exitstatus end desc "version", "Display Foreman gem version" diff --git a/spec/foreman/cli_spec.rb b/spec/foreman/cli_spec.rb index 6246b41..595da0e 100644 --- a/spec/foreman/cli_spec.rb +++ b/spec/foreman/cli_spec.rb @@ -72,6 +72,11 @@ describe "Foreman::CLI", :fakefs do it "includes the environment" do forked_foreman("run #{resource_path("bin/env FOO")} -e #{resource_path(".env")}").should == "bar\n" end + + it "exits with the same exit code as the command" do + fork_and_get_exitstatus("run echo 1").should == 0 + fork_and_get_exitstatus("run date 'invalid_date'").should == 1 + end end describe "version" do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 419ddc9..9c0628c 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -58,6 +58,12 @@ def fork_and_capture(&blk) end end +def fork_and_get_exitstatus(args) + pid = Process.spawn("bundle exec bin/foreman #{args}", :out => "/dev/null", :err => "/dev/null") + Process.wait(pid) + $?.exitstatus +end + def mock_exit(&block) block.should raise_error(SystemExit) end