Skip to content

Commit

Permalink
Add test for instance variable ordering in DAP
Browse files Browse the repository at this point in the history
PR ruby#806 sorts instance variables by name before returning them. This
commit adds a test that verifies this functionality under the DAP
protocol.
  • Loading branch information
egiurleo committed Jan 20, 2023
1 parent 3c2d1c1 commit 505a336
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
38 changes: 32 additions & 6 deletions test/protocol/variables_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require_relative "../support/protocol_test_case"

module DEBUGGER__
class DAPVariablesTest < ProtocolTestCase
class DAPGlobalVariablesTest < ProtocolTestCase
PROGRAM = <<~RUBY
1| $a = 1
2| $b = 2
Expand All @@ -18,19 +18,19 @@ def test_eval_evaluates_global_variables
globals = gather_variables(type: "globals")

# User defined globals
assert_includes(globals, { name: "$a", value: "1", type: "Integer" })
assert_includes(globals, { name: "$b", value: "2", type: "Integer" })
assert_includes(globals, { name: "$a", value: "1", type: "Integer", variablesReference: 0 })
assert_includes(globals, { name: "$b", value: "2", type: "Integer", variablesReference: 0 })

# Ruby defined globals
assert_includes(globals, { name: "$VERBOSE", value: "false", type: "FalseClass" })
assert_includes(globals, { name: "$stdout", value: "#<IO:<STDOUT>>", type: "IO" })
assert_includes(globals, { name: "$VERBOSE", value: "false", type: "FalseClass", variablesReference: 0 })
assert_includes(globals, { name: "$stdout", value: "#<IO:<STDOUT>>", type: "IO", variablesReference: 0 })

req_terminate_debuggee
end
end
end

class CDPVariablesTest < ProtocolTestCase
class CDPGlobalVariablesTest < ProtocolTestCase
PROGRAM = <<~RUBY
1| $a = 1
2| $b = 2
Expand All @@ -56,4 +56,30 @@ def test_eval_evaluates_global_variables
end
end
end

class DAPInstanceVariableTest < ProtocolTestCase
PROGRAM = <<~RUBY
1| @a = 1
2| @c = 3
3| @b = 2
4| __LINE__
RUBY

def test_ordering_instance_variables
run_protocol_scenario PROGRAM, cdp: false do
req_add_breakpoint 4
req_continue

locals = gather_variables

variables_reference = locals.find { |local| local[:name] == "%self" }[:variablesReference]
res = send_dap_request 'variables', variablesReference: variables_reference

instance_vars = res.dig(:body, :variables)
assert_equal instance_vars.map { |var| var[:name] }, ["#class", "@a", "@b", "@c"]

req_terminate_debuggee
end
end
end
end
3 changes: 1 addition & 2 deletions test/support/protocol_test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def gather_variables(frame_idx: 0, type: "locals")

# get variables
res = send_dap_request 'variables', variablesReference: locals_reference
res.dig(:body, :variables).map { |loc| { name: loc[:name], value: loc[:value], type: loc[:type] } }
res.dig(:body, :variables).map { |loc| { name: loc[:name], value: loc[:value], type: loc[:type], variablesReference: loc[:variablesReference] } }
when 'chrome'
current_frame = @crt_frames.first
locals_scope = current_frame[:scopeChain].find { |f| f[:type] == type }
Expand Down Expand Up @@ -1073,4 +1073,3 @@ def parse_ k, v
end
end
end

0 comments on commit 505a336

Please sign in to comment.