Skip to content

Commit f6b1680

Browse files
Add test for sh full command echo on error exit
1 parent 5e01167 commit f6b1680

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

test/test_rake_file_utils.rb

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,49 @@ def test_sh_show_command
287287
assert_equal expected_cmd, show_cmd
288288
end
289289

290+
def test_sh_if_a_command_exits_with_error_status_its_full_output_is_printed
291+
verbose false do
292+
standard_output = 'Some output'
293+
standard_error = 'Some error'
294+
shell_command = "ruby -e\"puts '#{standard_output}';STDERR.puts '#{standard_error}';exit false\""
295+
actual_both = capture_subprocess_io do
296+
begin
297+
sh shell_command
298+
rescue
299+
else
300+
flunk
301+
end
302+
end
303+
actual = actual_both.join
304+
assert_match standard_output, actual
305+
assert_match standard_error, actual
306+
end
307+
end
308+
309+
def test_sh_if_a_command_exits_with_error_status_sh_echoes_it_fully
310+
verbose true do
311+
assert_echoes_fully
312+
end
313+
verbose false do
314+
assert_echoes_fully
315+
end
316+
end
317+
318+
def assert_echoes_fully
319+
long_string = '1234567890' * 10
320+
shell_command = "ruby -e\"'#{long_string}';exit false\""
321+
capture_subprocess_io do
322+
begin
323+
sh shell_command
324+
rescue => ex
325+
assert_match 'Command failed with status', ex.message
326+
assert_match shell_command, ex.message
327+
else
328+
flunk
329+
end
330+
end
331+
end
332+
290333
def test_ruby_with_multiple_arguments
291334
skip if jruby9? # https://github.com/jruby/jruby/issues/3653
292335

0 commit comments

Comments
 (0)