Skip to content

Commit

Permalink
Display an accurate message when the test fails
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ono-max committed Nov 28, 2022
1 parent 0caebcc commit 525442a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
19 changes: 16 additions & 3 deletions test/support/console_test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,23 @@ def run_test_scenario cmd, test_info
check_error(/DEBUGGEE Exception/, test_info)
assert_empty_queue test_info
end

if r = test_info.remote_info
assert_program_finish test_info, r.pid, :debuggee
end

assert_program_finish test_info, pid, :debugger
# result of `gets` return this exception in some platform
# https://github.com/ruby/ruby/blob/master/ext/pty/pty.c#L729-L736
rescue Errno::EIO => e
check_error(/DEBUGGEE Exception/, test_info)
assert_empty_queue test_info, exception: e
if r = test_info.remote_info
assert_program_finish test_info, r.pid, :debuggee
end

assert_program_finish test_info, pid, :debugger
# result of `gets` return this exception in some platform
rescue Timeout::Error
assert_block(create_message("TIMEOUT ERROR (#{TIMEOUT_SEC} sec)", test_info)) { false }
ensure
Expand All @@ -189,13 +201,14 @@ def run_test_scenario cmd, test_info
read.close
write.close
kill_safely pid, :debugger, test_info
if name = test_info.failed_process
assert_block(create_message("Expected the #{name} program to finish", test_info)) { false }
end
end
end
end

def assert_program_finish test_info, pid, name
assert_block(create_message("Expected the #{name} program to finish", test_info)) { wait_pid pid, TIMEOUT_SEC }
end

def prepare_test_environment(program, test_steps, &block)
ENV['RUBY_DEBUG_NO_COLOR'] = 'true'
ENV['RUBY_DEBUG_TEST_UI'] = 'terminal'
Expand Down
2 changes: 2 additions & 0 deletions test/support/test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ def wait_pid pid, sec
end

false
rescue Errno::ECHILD
true
end

def kill_safely pid, name, test_info
Expand Down
4 changes: 2 additions & 2 deletions test/support/test_case_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ def steps
end

def test_the_test_fails_when_debuggee_on_unix_domain_socket_mode_doesnt_exist_after_scenarios
assert_raise_message(/Expected the remote program to finish/) do
assert_raise_message(/Expected the debuggee program to finish/) do
prepare_test_environment(program, steps) do
debug_code_on_unix_domain_socket()
end
end
end

def test_the_test_fails_when_debuggee_on_tcpip_mode_doesnt_exist_after_scenarios
assert_raise_message(/Expected the remote program to finish/) do
assert_raise_message(/Expected the debuggee program to finish/) do
prepare_test_environment(program, steps) do
debug_code_on_tcpip()
end
Expand Down

0 comments on commit 525442a

Please sign in to comment.