Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In SystemCommand, fix success? and exit_status #7895

Merged
merged 2 commits into from
Dec 8, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/cask/system_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ def self.run(executable, options={})
raw_stderr.close_read

# Ruby 1.8 sets $?. Ruby 1.9+ has raw_wait_thr, and does not set $?.
processed_exit_status = raw_wait_thr.nil? ? $? : raw_wait_thr.value
processed_status = raw_wait_thr.nil? ? $? : raw_wait_thr.value

_assert_success(processed_exit_status, command, processed_stdout) if options[:must_succeed]
_assert_success(processed_status, command, processed_stdout) if options[:must_succeed]

Cask::SystemCommand::Result.new(command, processed_stdout, processed_stderr, processed_exit_status)
Cask::SystemCommand::Result.new(command, processed_stdout, processed_stderr, processed_status.exitstatus)
end

def self.run!(command, options={})
Expand Down
62 changes: 62 additions & 0 deletions test/cask/system_command_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
require 'test_helper'

describe Cask::SystemCommand do
describe "when the exit code is 0" do
result = nil

before do
command = '/usr/bin/true'
options = {
:must_succeed => false
}
result = Cask::SystemCommand.run(command, options)
end

it "says the command was successful" do
result.success?.must_equal(true)
end

it "says the exit status is 0" do
result.exit_status.must_equal(0)
end
end

describe "when the exit code is 1" do
before do
# See: https://bugs.ruby-lang.org/issues/1287
skip("Ruby 1.8.7 doesn't see exit statuses") if TestHelper.ruby18?
end

describe "and the command must succeed" do
it "throws an error" do
lambda {
command = '/usr/bin/false'
options = {
:must_succeed => true
}
result = Cask::SystemCommand.run(command, options)
}.must_raise(CaskCommandFailedError)
end
end

describe "and the command does not have to succeed" do
result = nil

before do
command = '/usr/bin/false'
options = {
:must_succeed => false
}
result = Cask::SystemCommand.run(command, options)
end

it "says the command failed" do
result.success?.must_equal(false)
end

it "says the exit status is 1" do
result.exit_status.must_equal(1)
end
end
end
end
3 changes: 1 addition & 2 deletions test/syntax_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@

# Reason for this hack is unknown. Travis appears to freeze,
# but only in one section of the build matrix.
skip if ENV.key?('TRAVIS_JOB_ID') and
RUBY_VERSION.match(%r{^1\.8})
skip if ENV.key?('TRAVIS_JOB_ID') and TestHelper.ruby18?

args = flags + [ '--', file ]
shutup do
Expand Down
4 changes: 4 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ def self.install_without_artifacts(cask)
end
end
end

def self.ruby18?
RUBY_VERSION.match(%r{^1\.8})
end
end

require 'support/fake_fetcher'
Expand Down