From ebffd3d976dc24596f550d211d3c92f66b564686 Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Fri, 16 Feb 2024 14:30:22 +0000 Subject: [PATCH] Fix `irb:rdbg` for ruby head (#876) * Update binding.irb check for Ruby head With https://github.com/ruby/ruby/pull/9605, backtrace in Ruby head now has a new format. This commit updates the check for binding.irb to work with Ruby head. * Do not include a backtick in error messages and backtraces [Feature #16495] --------- Co-authored-by: Yusuke Endoh --- lib/irb.rb | 2 +- lib/irb/cmd/debug.rb | 2 +- test/irb/test_context.rb | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/irb.rb b/lib/irb.rb index 4fa00aa16..67e03f8bc 100644 --- a/lib/irb.rb +++ b/lib/irb.rb @@ -1235,7 +1235,7 @@ def handle_exception(exc) lines.map{ |l| l + "\n" }.join } # The "" in "(irb)" may be the top level of IRB so imitate the main object. - message = message.gsub(/\(irb\):(?\d+):in `<(?top \(required\))>'/) { "(irb):#{$~[:num]}:in `
'" } + message = message.gsub(/\(irb\):(?\d+):in (?[`'])<(?top \(required\))>'/) { "(irb):#{$~[:num]}:in #{$~[:open_quote]}
'" } puts message puts 'Maybe IRB bug!' if irb_bug rescue Exception => handler_exc diff --git a/lib/irb/cmd/debug.rb b/lib/irb/cmd/debug.rb index e236084ca..f5c985f07 100644 --- a/lib/irb/cmd/debug.rb +++ b/lib/irb/cmd/debug.rb @@ -12,7 +12,7 @@ class Debug < Nop BINDING_IRB_FRAME_REGEXPS = [ '', binding.method(:irb).source_location.first, - ].map { |file| /\A#{Regexp.escape(file)}:\d+:in `irb'\z/ } + ].map { |file| /\A#{Regexp.escape(file)}:\d+:in (`|'Binding#)irb'\z/ } def execute(pre_cmds: nil, do_cmds: nil) if irb_context.with_debugger diff --git a/test/irb/test_context.rb b/test/irb/test_context.rb index 71d4aae90..059c48676 100644 --- a/test/irb/test_context.rb +++ b/test/irb/test_context.rb @@ -72,7 +72,7 @@ def test_eval_input expected_output = if RUBY_3_4 [ - :*, /\(irb\):1:in '': Foo \(RuntimeError\)\n/, + :*, /\(irb\):1:in '
': Foo \(RuntimeError\)\n/, :*, /#\n/, :*, /0$/, :*, /0$/, @@ -107,8 +107,8 @@ def test_eval_input_raise2x expected_output = if RUBY_3_4 [ - :*, /\(irb\):1:in '': Foo \(RuntimeError\)\n/, - :*, /\(irb\):2:in '': Bar \(RuntimeError\)\n/, + :*, /\(irb\):1:in '
': Foo \(RuntimeError\)\n/, + :*, /\(irb\):2:in '
': Bar \(RuntimeError\)\n/, :*, /#\n/, ] else @@ -531,7 +531,7 @@ def test_eval_input_with_exception [ :*, /\(irb\):1:in 'fuga': unhandled exception\n/, :*, /\tfrom \(irb\):1:in 'hoge'\n/, - :*, /\tfrom \(irb\):1:in ''\n/, + :*, /\tfrom \(irb\):1:in '
'\n/, :* ] elsif RUBY_VERSION < '3.0.0' && STDOUT.tty? @@ -569,7 +569,7 @@ def test_eval_input_with_invalid_byte_sequence_exception [ :*, /\(irb\):1:in 'fuga': A\\xF3B \(RuntimeError\)\n/, :*, /\tfrom \(irb\):1:in 'hoge'\n/, - :*, /\tfrom \(irb\):1:in ''\n/, + :*, /\tfrom \(irb\):1:in '
'\n/, :* ] elsif RUBY_VERSION < '3.0.0' && STDOUT.tty?