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

Refactor the logic of getting UI to be tested #776

Merged
merged 1 commit into from
Oct 25, 2022
Merged
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
50 changes: 27 additions & 23 deletions test/support/protocol_test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def run_protocol_scenario program, dap: true, cdp: true, &scenario
end

def req_add_breakpoint lineno, path: temp_file_path, cond: nil
case ENV['RUBY_DEBUG_TEST_UI']
case get_target_ui
when 'vscode'
@bps << [path, lineno, cond]
req_set_breakpoints_on_dap
Expand All @@ -68,7 +68,7 @@ def req_add_breakpoint lineno, path: temp_file_path, cond: nil
end

def req_delete_breakpoint bpnum
case ENV['RUBY_DEBUG_TEST_UI']
case get_target_ui
when 'vscode'
@bps.delete_at bpnum
req_set_breakpoints_on_dap
Expand All @@ -79,7 +79,7 @@ def req_delete_breakpoint bpnum
end

def req_continue
case ENV['RUBY_DEBUG_TEST_UI']
case get_target_ui
when 'vscode'
send_dap_request 'continue', threadId: 1
when 'chrome'
Expand All @@ -90,7 +90,7 @@ def req_continue
end

def req_step
case ENV['RUBY_DEBUG_TEST_UI']
case get_target_ui
when 'vscode'
send_dap_request 'stepIn', threadId: 1
when 'chrome'
Expand All @@ -101,7 +101,7 @@ def req_step
end

def req_next
case ENV['RUBY_DEBUG_TEST_UI']
case get_target_ui
when 'vscode'
send_dap_request 'next', threadId: 1
when 'chrome'
Expand All @@ -112,7 +112,7 @@ def req_next
end

def req_finish
case ENV['RUBY_DEBUG_TEST_UI']
case get_target_ui
when 'vscode'
send_dap_request 'stepOut', threadId: 1
when 'chrome'
Expand All @@ -123,7 +123,7 @@ def req_finish
end

def req_set_exception_breakpoints(breakpoints)
case ENV['RUBY_DEBUG_TEST_UI']
case get_target_ui
when 'vscode'
filter_options = breakpoints.map do |bp|
filter_option = { filterId: bp[:name] }
Expand All @@ -138,14 +138,14 @@ def req_set_exception_breakpoints(breakpoints)
end

def req_step_back
case ENV['RUBY_DEBUG_TEST_UI']
case get_target_ui
when 'vscode'
send_dap_request 'stepBack', threadId: 1
end
end

def req_terminate_debuggee
case ENV['RUBY_DEBUG_TEST_UI']
case get_target_ui
when 'vscode'
send_dap_request 'terminate'
when 'chrome'
Expand All @@ -156,7 +156,7 @@ def req_terminate_debuggee
end

def assert_reattach
case ENV['RUBY_DEBUG_TEST_UI']
case get_target_ui
when 'vscode'
req_disconnect
attach_to_dap_server
Expand All @@ -170,7 +170,7 @@ def assert_reattach
end

def assert_locals_result expected, frame_idx: 0
case ENV['RUBY_DEBUG_TEST_UI']
case get_target_ui
when 'vscode'
# get frameId
res = send_dap_request 'stackTrace',
Expand Down Expand Up @@ -228,7 +228,7 @@ def assert_locals_result expected, frame_idx: 0
end

def assert_threads_result(expected_names)
case ENV['RUBY_DEBUG_TEST_UI']
case get_target_ui
when 'vscode'
res = send_dap_request 'threads'
failure_msg = FailureMessage.new{create_protocol_message "result:\n#{JSON.pretty_generate res}."}
Expand All @@ -251,7 +251,7 @@ def assert_threads_result(expected_names)
end

def assert_hover_result expected, expression, frame_idx: 0
case ENV['RUBY_DEBUG_TEST_UI']
case get_target_ui
when 'vscode'
assert_eval_result 'hover', expression, expected, frame_idx
when 'chrome'
Expand All @@ -260,7 +260,7 @@ def assert_hover_result expected, expression, frame_idx: 0
end

def assert_repl_result expected, expression, frame_idx: 0
case ENV['RUBY_DEBUG_TEST_UI']
case get_target_ui
when 'vscode'
assert_eval_result 'repl', expression, expected, frame_idx
when 'chrome'
Expand All @@ -269,7 +269,7 @@ def assert_repl_result expected, expression, frame_idx: 0
end

def assert_watch_result expected, expression, frame_idx: 0
case ENV['RUBY_DEBUG_TEST_UI']
case get_target_ui
when 'vscode'
assert_eval_result 'watch', expression, expected, frame_idx
when 'chrome'
Expand All @@ -280,7 +280,7 @@ def assert_watch_result expected, expression, frame_idx: 0
# Not API

def execute_dap_scenario scenario
ENV['RUBY_DEBUG_TEST_UI'] = 'vscode'
ENV['RUBY_DEBUG_TESTED_UI'] = 'vscode'

@remote_info = setup_unix_domain_socket_remote_debuggee
Timeout.timeout(TIMEOUT_SEC) do
Expand All @@ -305,7 +305,7 @@ def execute_dap_scenario scenario
end

def execute_cdp_scenario scenario
ENV['RUBY_DEBUG_TEST_UI'] = 'chrome'
ENV['RUBY_DEBUG_TESTED_UI'] = 'chrome'

@remote_info = setup_tcpip_remote_debuggee
Timeout.timeout(TIMEOUT_SEC) do
Expand All @@ -330,7 +330,7 @@ def execute_cdp_scenario scenario
end

def req_disconnect
case ENV['RUBY_DEBUG_TEST_UI']
case get_target_ui
when 'vscode'
send_dap_request 'disconnect',
restart: false,
Expand Down Expand Up @@ -369,7 +369,7 @@ def req_set_breakpoints_on_dap
def close_reader
@reader_thread.raise Detach

case ENV['RUBY_DEBUG_TEST_UI']
case get_target_ui
when 'vscode'
@sock.close
when 'chrome'
Expand Down Expand Up @@ -424,7 +424,7 @@ def attach_to_cdp_server
}

def assert_eval_result context, expression, expected, frame_idx
case ENV['RUBY_DEBUG_TEST_UI']
case get_target_ui
when 'vscode'
res = send_dap_request 'stackTrace',
threadId: 1,
Expand Down Expand Up @@ -473,7 +473,7 @@ def assert_eval_result context, expression, expected, frame_idx
end

def send_request command, **kw
case ENV['RUBY_DEBUG_TEST_UI']
case get_target_ui
when 'vscode'
send type: 'request',
command: command,
Expand Down Expand Up @@ -508,7 +508,7 @@ def send_cdp_request command, **kw
end

def send **kw
case ENV['RUBY_DEBUG_TEST_UI']
case get_target_ui
when 'vscode'
kw[:seq] = @seq += 1
str = JSON.dump(kw)
Expand Down Expand Up @@ -589,6 +589,10 @@ def find_response key, target, direction
flunk create_protocol_message "TIMEOUT ERROR (#{TIMEOUT_SEC} sec) while waiting: #{key} #{target}"
end

def get_target_ui
ENV['RUBY_DEBUG_TESTED_UI']
end

# FIXME: Commonalize this method.
def recv_response
case header = @sock.gets
Expand Down Expand Up @@ -714,7 +718,7 @@ def create_protocol_message fail_msg
#{@backlog.join("\n")}
DEBUGGER_MSG

case ENV['RUBY_DEBUG_TEST_UI']
case get_target_ui
when 'vscode'
pattern = /(D|V)(<|>)(D|V)\s/
when 'chrome'
Expand Down