Skip to content

Commit

Permalink
Merge pull request #147 from MarkDBlackwell/mdb/sh-full-echo-on-error
Browse files Browse the repository at this point in the history
Sh fully echoes commands which error exit
  • Loading branch information
hsbt authored Aug 12, 2022
2 parents 236cda9 + 64eaba2 commit 0157758
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
2 changes: 0 additions & 2 deletions lib/rake/file_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ def sh(*cmd, &block)

def create_shell_runner(cmd) # :nodoc:
show_command = sh_show_command cmd
show_command = show_command[0, 42] + "..." unless $trace

lambda do |ok, status|
ok or
fail "Command failed with status (#{status.exitstatus}): " +
Expand Down
43 changes: 43 additions & 0 deletions test/test_rake_file_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,49 @@ def test_sh_show_command
assert_equal expected_cmd, show_cmd
end

def test_sh_if_a_command_exits_with_error_status_its_full_output_is_printed
verbose false do
standard_output = 'Some output'
standard_error = 'Some error'
shell_command = "ruby -e\"puts '#{standard_output}';STDERR.puts '#{standard_error}';exit false\""
actual_both = capture_subprocess_io do
begin
sh shell_command
rescue
else
flunk
end
end
actual = actual_both.join
assert_match standard_output, actual
assert_match standard_error, actual
end
end

def test_sh_if_a_command_exits_with_error_status_sh_echoes_it_fully
verbose true do
assert_echoes_fully
end
verbose false do
assert_echoes_fully
end
end

def assert_echoes_fully
long_string = '1234567890' * 10
shell_command = "ruby -e\"'#{long_string}';exit false\""
capture_subprocess_io do
begin
sh shell_command
rescue => ex
assert_match 'Command failed with status', ex.message
assert_match shell_command, ex.message
else
flunk
end
end
end

def test_ruby_with_multiple_arguments
skip if jruby9? # https://github.com/jruby/jruby/issues/3653

Expand Down

0 comments on commit 0157758

Please sign in to comment.