Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display an accurate message when the test fails #842

Merged
merged 2 commits into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion test/support/assertions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def program

def test_the_helper_takes_a_string_expectation_and_escape_it
assert_raise_message(/Expected to include `"foobar\\\\?/) do
debug_code(program, remote: false) do
debug_code(program) do
assert_line_text("foobar?")
end
end
Expand Down Expand Up @@ -49,6 +49,30 @@ def test_the_helper_raises_an_error_with_invalid_expectation
end
end
end

def test_the_test_fails_when_debuggee_on_unix_domain_socket_mode_doesnt_exist_after_scenarios
assert_raise_message(/Expected to include `"foobar\\\\?/) 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 to include `"foobar\\\\?/) do
prepare_test_environment(program, steps) do
debug_code_on_tcpip()
end
end
end

private

def steps
Proc.new{
assert_line_text("foobar?")
}
end
end
end

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