diff options
author | tomoya ishida <[email protected]> | 2024-10-02 12:18:29 +0900 |
---|---|---|
committer | git <[email protected]> | 2024-10-02 03:18:35 +0000 |
commit | a8a921aef3e3f5a91425e53e4faf44d032a32a97 (patch) | |
tree | f91c2347a3b4c4e935ae3f3f12cbc7a1848c51f1 | |
parent | 5edc32198895c02f014a778963eaa1297e5d618c (diff) |
[ruby/irb] Use correct binding in debug mode
(https://github.com/ruby/irb/pull/1007)
In debug command, IRB's context was using wrong binding.
Some code colorization, command detection failed because binding.local_variable returned wrong value.
https://github.com/ruby/irb/commit/68f718de21
-rw-r--r-- | lib/irb/debug/ui.rb | 2 | ||||
-rw-r--r-- | test/irb/test_debugger_integration.rb | 17 |
2 files changed, 18 insertions, 1 deletions
diff --git a/lib/irb/debug/ui.rb b/lib/irb/debug/ui.rb index 307097b8c9..7a1cd6dd16 100644 --- a/lib/irb/debug/ui.rb +++ b/lib/irb/debug/ui.rb @@ -56,7 +56,7 @@ module IRB def readline _ setup_interrupt do tc = DEBUGGER__::SESSION.instance_variable_get(:@tc) - cmd = @irb.debug_readline(tc.current_frame.binding || TOPLEVEL_BINDING) + cmd = @irb.debug_readline(tc.current_frame.eval_binding || TOPLEVEL_BINDING) case cmd when nil # when user types C-d diff --git a/test/irb/test_debugger_integration.rb b/test/irb/test_debugger_integration.rb index 8b1bddea17..45ffb2a52e 100644 --- a/test/irb/test_debugger_integration.rb +++ b/test/irb/test_debugger_integration.rb @@ -365,6 +365,23 @@ module TestIRB assert_include(output, "InputMethod: RelineInputMethod") end + def test_irb_command_can_check_local_variables + write_ruby <<~'ruby' + binding.irb + ruby + + output = run_ruby_file do + type "debug" + type 'foobar = IRB' + type "show_source foobar.start" + type "show_source = 'Foo'" + type "show_source + 'Bar'" + type "continue" + end + assert_include(output, "def start(ap_path = nil)") + assert_include(output, '"FooBar"') + end + def test_help_command_is_delegated_to_the_debugger write_ruby <<~'ruby' binding.irb |