Skip to content

Commit 0157758

Browse files
authored
Merge pull request #147 from MarkDBlackwell/mdb/sh-full-echo-on-error
Sh fully echoes commands which error exit
2 parents 236cda9 + 64eaba2 commit 0157758

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

lib/rake/file_utils.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ def sh(*cmd, &block)
6060

6161
def create_shell_runner(cmd) # :nodoc:
6262
show_command = sh_show_command cmd
63-
show_command = show_command[0, 42] + "..." unless $trace
64-
6563
lambda do |ok, status|
6664
ok or
6765
fail "Command failed with status (#{status.exitstatus}): " +

test/test_rake_file_utils.rb

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,49 @@ def test_sh_show_command
313313
assert_equal expected_cmd, show_cmd
314314
end
315315

316+
def test_sh_if_a_command_exits_with_error_status_its_full_output_is_printed
317+
verbose false do
318+
standard_output = 'Some output'
319+
standard_error = 'Some error'
320+
shell_command = "ruby -e\"puts '#{standard_output}';STDERR.puts '#{standard_error}';exit false\""
321+
actual_both = capture_subprocess_io do
322+
begin
323+
sh shell_command
324+
rescue
325+
else
326+
flunk
327+
end
328+
end
329+
actual = actual_both.join
330+
assert_match standard_output, actual
331+
assert_match standard_error, actual
332+
end
333+
end
334+
335+
def test_sh_if_a_command_exits_with_error_status_sh_echoes_it_fully
336+
verbose true do
337+
assert_echoes_fully
338+
end
339+
verbose false do
340+
assert_echoes_fully
341+
end
342+
end
343+
344+
def assert_echoes_fully
345+
long_string = '1234567890' * 10
346+
shell_command = "ruby -e\"'#{long_string}';exit false\""
347+
capture_subprocess_io do
348+
begin
349+
sh shell_command
350+
rescue => ex
351+
assert_match 'Command failed with status', ex.message
352+
assert_match shell_command, ex.message
353+
else
354+
flunk
355+
end
356+
end
357+
end
358+
316359
def test_ruby_with_multiple_arguments
317360
skip if jruby9? # https://github.com/jruby/jruby/issues/3653
318361

0 commit comments

Comments
 (0)