Skip to content

Commit a9fa12f

Browse files
committed
Display an accurate message when the test fails
Currently, the message when the test fails is overridden by a test that checks if the remote debuggee is terminated. For example, when `assert_line_text` method is failed, the message should be `Expected to include ~ in ~`, but it will be overridden and the message will be `Expected the remote program to finish ~`. We should not assert in ensure block to prevent the problem.
1 parent 0caebcc commit a9fa12f

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

test/support/console_test_case.rb

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,23 @@ def run_test_scenario cmd, test_info
176176
check_error(/DEBUGGEE Exception/, test_info)
177177
assert_empty_queue test_info
178178
end
179+
180+
if r = test_info.remote_info
181+
assert_program_finish test_info, r.pid, :debuggee
182+
end
183+
184+
assert_program_finish test_info, pid, :debugger
179185
# result of `gets` return this exception in some platform
180186
# https://github.com/ruby/ruby/blob/master/ext/pty/pty.c#L729-L736
181187
rescue Errno::EIO => e
182188
check_error(/DEBUGGEE Exception/, test_info)
183189
assert_empty_queue test_info, exception: e
190+
if r = test_info.remote_info
191+
assert_program_finish test_info, r.pid, :debuggee
192+
end
193+
194+
assert_program_finish test_info, pid, :debugger
195+
# result of `gets` return this exception in some platform
184196
rescue Timeout::Error
185197
assert_block(create_message("TIMEOUT ERROR (#{TIMEOUT_SEC} sec)", test_info)) { false }
186198
ensure
@@ -189,13 +201,16 @@ def run_test_scenario cmd, test_info
189201
read.close
190202
write.close
191203
kill_safely pid, :debugger, test_info
192-
if name = test_info.failed_process
193-
assert_block(create_message("Expected the #{name} program to finish", test_info)) { false }
194-
end
195204
end
196205
end
197206
end
198207

208+
def assert_program_finish test_info, pid, name
209+
unless wait_pid pid, TIMEOUT_SEC
210+
assert_block(create_message("Expected the #{name} program to finish", test_info)) { false }
211+
end
212+
end
213+
199214
def prepare_test_environment(program, test_steps, &block)
200215
ENV['RUBY_DEBUG_NO_COLOR'] = 'true'
201216
ENV['RUBY_DEBUG_TEST_UI'] = 'terminal'

test/support/test_case.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ def wait_pid pid, sec
118118
end
119119

120120
false
121+
rescue Errno::ECHILD
122+
true
121123
end
122124

123125
def kill_safely pid, name, test_info

test/support/test_case_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ def steps
6161
end
6262

6363
def test_the_test_fails_when_debuggee_on_unix_domain_socket_mode_doesnt_exist_after_scenarios
64-
assert_raise_message(/Expected the remote program to finish/) do
64+
assert_raise_message(/Expected the debuggee program to finish/) do
6565
prepare_test_environment(program, steps) do
6666
debug_code_on_unix_domain_socket()
6767
end
6868
end
6969
end
7070

7171
def test_the_test_fails_when_debuggee_on_tcpip_mode_doesnt_exist_after_scenarios
72-
assert_raise_message(/Expected the remote program to finish/) do
72+
assert_raise_message(/Expected the debuggee program to finish/) do
7373
prepare_test_environment(program, steps) do
7474
debug_code_on_tcpip()
7575
end

0 commit comments

Comments
 (0)