[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
This commit is contained in:
tomoya ishida 2024-10-02 12:18:29 +09:00 committed by git
parent 5edc321988
commit a8a921aef3
2 changed files with 18 additions and 1 deletions

View File

@ -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

View File

@ -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