Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 146
Add assert locals to protocol tests#559
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
e691ab59cee8fbc2a4d71cfb057fc7f0f54File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -203,6 +203,71 @@ def assert_reattach | ||
| end | ||
| end | ||
| def assert_locals_result expected, frame_idx: 0 | ||
| case ENV['RUBY_DEBUG_TEST_UI'] | ||
| when 'vscode' | ||
| # get frameId | ||
| send_request 'stackTrace', | ||
| threadId: 1, | ||
| startFrame: 0, | ||
| levels: 20 | ||
| res = find_crt_dap_response | ||
| f_id = res.dig(:body, :stackFrames, frame_idx, :id) | ||
| # get variablesReference | ||
| send_request 'scopes', frameId: f_id | ||
| res = find_crt_dap_response | ||
st0012 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| assert_dap_response :ScopesResponse, res | ||
| locals_scope = res.dig(:body, :scopes).find { |d| d[:presentationHint] == "locals" } | ||
| locals_reference = locals_scope[:variablesReference] | ||
| # get variables | ||
| send_request 'variables', variablesReference: locals_reference | ||
| res = find_crt_dap_response | ||
st0012 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| assert_dap_response :VariablesResponse, res | ||
| expected.each do |exp| | ||
| if exp[:type] == "String" | ||
| exp[:value] = exp[:value].inspect | ||
| end | ||
| end | ||
| actual_locals = res.dig(:body, :variables).map { |loc| { name: loc[:name], value: loc[:value], type: loc[:type] } } | ||
| when 'chrome' | ||
| current_frame = @crt_frames.first | ||
| locals_scope = current_frame[:scopeChain].find { |f| f[:type] == "local" } | ||
| object_id = locals_scope.dig(:object, :objectId) | ||
| send_request "Runtime.getProperties", objectId: object_id | ||
| res = find_crt_cdp_response | ||
st0012 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| assert_cdp_response 'Runtime.getProperties', res | ||
| actual_locals = res.dig(:result, :result).map do |loc| | ||
| type = loc.dig(:value, :className) || loc.dig(:value, :type).capitalize # TODO: sync this with get_ruby_type | ||
Member 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. Oh, I noticed that this is incorrect. We can't use MemberAuthor 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. That'd be great, thank you. | ||
| { name: loc[:name], value: loc.dig(:value, :description), type: type } | ||
| end | ||
| end | ||
| failure_msg = FailureMessage.new{create_protocol_message "result:\n#{JSON.pretty_generate res}"} | ||
| actual_locals = actual_locals.sort_by { |h| h[:name] } | ||
| expected = expected.sort_by { |h| h[:name] } | ||
| expected.each_with_index do |expect, index| | ||
| actual = actual_locals[index] | ||
| assert_equal(expect[:name], actual[:name], failure_msg) | ||
| assert_equal(expect[:type], actual[:type], failure_msg) | ||
| if expect[:value].is_a?(Regexp) | ||
st0012 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| assert_match(expect[:value], actual[:value], failure_msg) | ||
| else | ||
| assert_equal(expect[:value], actual[:value], failure_msg) | ||
| end | ||
| end | ||
| end | ||
| def assert_hover_result expected, expression: nil, frame_idx: 0 | ||
| case ENV['RUBY_DEBUG_TEST_UI'] | ||
| when 'vscode' | ||
Uh oh!
There was an error while loading. Please reload this page.