Skip to content

Commit

Permalink
foreman run should exit with the same code as its command
Browse files Browse the repository at this point in the history
  • Loading branch information
Omar Khan committed Aug 24, 2012
1 parent 68f098c commit 574e852
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/foreman/cli.rb
Expand Up @@ -86,6 +86,7 @@ def run(*args)
end
end
Process.wait(pid)
exit $?.exitstatus
end

desc "version", "Display Foreman gem version"
Expand Down
5 changes: 5 additions & 0 deletions spec/foreman/cli_spec.rb
Expand Up @@ -72,6 +72,11 @@
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
Expand Down
6 changes: 6 additions & 0 deletions spec/spec_helper.rb
Expand Up @@ -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
Expand Down

0 comments on commit 574e852

Please sign in to comment.