-
Notifications
You must be signed in to change notification settings - Fork 137
Add assert_threads_result
helper and threads test
#607
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../support/test_case' | ||
|
||
module DEBUGGER__ | ||
class ThreadsTest < TestCase | ||
PROGRAM = <<~RUBY | ||
1| def foo | ||
2| Thread.new { sleep 30 } | ||
3| end | ||
4| | ||
5| foo | ||
6| sleep 0.1 # make sure the thread stops | ||
7| binding.b | ||
RUBY | ||
|
||
def test_reponse_returns_correct_threads_info | ||
run_protocol_scenario PROGRAM, cdp: false do | ||
req_continue | ||
|
||
assert_threads_result( | ||
[ | ||
/\.rb:\d:in `<main>'/, | ||
/\.rb:\d:in `block in foo'/ | ||
] | ||
) | ||
|
||
req_terminate_debuggee | ||
end | ||
end | ||
end | ||
end | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -230,6 +230,29 @@ def assert_locals_result expected, frame_idx: 0 | |
end | ||
end | ||
|
||
def assert_threads_result(expected_names) | ||
case ENV['RUBY_DEBUG_TEST_UI'] | ||
when 'vscode' | ||
res = send_dap_request 'threads' | ||
failure_msg = FailureMessage.new{create_protocol_message "result:\n#{JSON.pretty_generate res}."} | ||
|
||
threads = res.dig(:body, :threads) | ||
|
||
assert_equal expected_names.count, threads.count, failure_msg | ||
|
||
thread_names = threads.map { |t| t[:name] } | ||
|
||
expected_names.each do |expected| | ||
thread_names.reject! do |name| | ||
name.match?(expected) | ||
end | ||
end | ||
|
||
failure_msg = FailureMessage.new{create_protocol_message "result:\n#{JSON.pretty_generate res}.\nExpect all thread names to be matched. Unmatched threads:"} | ||
assert_equal [], thread_names, failure_msg | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
end | ||
end | ||
|
||
def assert_hover_result expected, expression: nil, frame_idx: 0 | ||
case ENV['RUBY_DEBUG_TEST_UI'] | ||
when 'vscode' | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use
assert_match
method in this case, could you tell me the reason why you implemented so?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you think we can use it here? Remember, the order of threads info is not guaranteed. So we don't know which one will match.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, that's right. My bad 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries 😉
Do other changes look good to you?