Skip to content

Commit abfc353

Browse files
committed
Add assert_threads_result helper and threads test
1 parent 32eba51 commit abfc353

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

test/protocol/threads_test.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../support/test_case'
4+
5+
module DEBUGGER__
6+
class ThreadsTest < TestCase
7+
PROGRAM = <<~RUBY
8+
1| def foo
9+
2| Thread.new { sleep 30 }
10+
3| end
11+
4|
12+
5| foo
13+
6| sleep 0.1 # make sure the thread stops
14+
7| binding.b
15+
RUBY
16+
17+
def test_reponse_returns_correct_threads_info
18+
run_protocol_scenario PROGRAM do
19+
req_continue
20+
21+
assert_threads_result(
22+
[
23+
/\.rb:6:in `<main>'/,
24+
/\.rb:2:in `block in foo'/
25+
]
26+
)
27+
28+
req_terminate_debuggee
29+
end
30+
end
31+
end
32+
end
33+

test/support/protocol_utils.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,24 @@ def assert_locals_result expected, frame_idx: 0
268268
end
269269
end
270270

271+
def assert_threads_result(expected_names)
272+
case ENV['RUBY_DEBUG_TEST_UI']
273+
when 'vscode'
274+
send_request 'threads'
275+
res = find_crt_dap_response
276+
assert_dap_response :ThreadsResponse, res
277+
278+
threads = res.dig(:body, :threads)
279+
failure_msg = FailureMessage.new{create_protocol_message "result:\n#{JSON.pretty_generate res}"}
280+
281+
assert_equal expected_names.count, threads.count, failure_msg
282+
283+
expected_names.each_with_index do |expected, index|
284+
assert_match expected, threads[index][:name], failure_msg
285+
end
286+
end
287+
end
288+
271289
def assert_hover_result expected, expression: nil, frame_idx: 0
272290
case ENV['RUBY_DEBUG_TEST_UI']
273291
when 'vscode'

0 commit comments

Comments
 (0)