Skip to content

Commit ebffd3d

Browse files
st0012mame
andauthored
Fix irb:rdbg for ruby head (#876)
* Update binding.irb check for Ruby head With ruby/ruby#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 <mame@ruby-lang.org>
1 parent 9359d4b commit ebffd3d

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

lib/irb.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1235,7 +1235,7 @@ def handle_exception(exc)
12351235
lines.map{ |l| l + "\n" }.join
12361236
}
12371237
# The "<top (required)>" in "(irb)" may be the top level of IRB so imitate the main object.
1238-
message = message.gsub(/\(irb\):(?<num>\d+):in `<(?<frame>top \(required\))>'/) { "(irb):#{$~[:num]}:in `<main>'" }
1238+
message = message.gsub(/\(irb\):(?<num>\d+):in (?<open_quote>[`'])<(?<frame>top \(required\))>'/) { "(irb):#{$~[:num]}:in #{$~[:open_quote]}<main>'" }
12391239
puts message
12401240
puts 'Maybe IRB bug!' if irb_bug
12411241
rescue Exception => handler_exc

lib/irb/cmd/debug.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Debug < Nop
1212
BINDING_IRB_FRAME_REGEXPS = [
1313
'<internal:prelude>',
1414
binding.method(:irb).source_location.first,
15-
].map { |file| /\A#{Regexp.escape(file)}:\d+:in `irb'\z/ }
15+
].map { |file| /\A#{Regexp.escape(file)}:\d+:in (`|'Binding#)irb'\z/ }
1616

1717
def execute(pre_cmds: nil, do_cmds: nil)
1818
if irb_context.with_debugger

test/irb/test_context.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def test_eval_input
7272
expected_output =
7373
if RUBY_3_4
7474
[
75-
:*, /\(irb\):1:in '<top \(required\)>': Foo \(RuntimeError\)\n/,
75+
:*, /\(irb\):1:in '<main>': Foo \(RuntimeError\)\n/,
7676
:*, /#<RuntimeError: Foo>\n/,
7777
:*, /0$/,
7878
:*, /0$/,
@@ -107,8 +107,8 @@ def test_eval_input_raise2x
107107
expected_output =
108108
if RUBY_3_4
109109
[
110-
:*, /\(irb\):1:in '<top \(required\)>': Foo \(RuntimeError\)\n/,
111-
:*, /\(irb\):2:in '<top \(required\)>': Bar \(RuntimeError\)\n/,
110+
:*, /\(irb\):1:in '<main>': Foo \(RuntimeError\)\n/,
111+
:*, /\(irb\):2:in '<main>': Bar \(RuntimeError\)\n/,
112112
:*, /#<RuntimeError: Bar>\n/,
113113
]
114114
else
@@ -531,7 +531,7 @@ def test_eval_input_with_exception
531531
[
532532
:*, /\(irb\):1:in 'fuga': unhandled exception\n/,
533533
:*, /\tfrom \(irb\):1:in 'hoge'\n/,
534-
:*, /\tfrom \(irb\):1:in '<top \(required\)>'\n/,
534+
:*, /\tfrom \(irb\):1:in '<main>'\n/,
535535
:*
536536
]
537537
elsif RUBY_VERSION < '3.0.0' && STDOUT.tty?
@@ -569,7 +569,7 @@ def test_eval_input_with_invalid_byte_sequence_exception
569569
[
570570
:*, /\(irb\):1:in 'fuga': A\\xF3B \(RuntimeError\)\n/,
571571
:*, /\tfrom \(irb\):1:in 'hoge'\n/,
572-
:*, /\tfrom \(irb\):1:in '<top \(required\)>'\n/,
572+
:*, /\tfrom \(irb\):1:in '<main>'\n/,
573573
:*
574574
]
575575
elsif RUBY_VERSION < '3.0.0' && STDOUT.tty?

0 commit comments

Comments
 (0)