diff --git a/lib/irb/debug.rb b/lib/irb/debug.rb index 0225a8a50..1adeb5568 100644 --- a/lib/irb/debug.rb +++ b/lib/irb/debug.rb @@ -49,7 +49,7 @@ def setup(irb) def DEBUGGER__.capture_frames(*args) frames = capture_frames_without_irb(*args) frames.reject! do |frame| - frame.realpath&.start_with?(IRB_DIR) || frame.path.start_with?("') + super || path&.match?(IRB_DIR) || path&.match?('') end end diff --git a/test/irb/helper.rb b/test/irb/helper.rb index ead934a45..2c815bb7b 100644 --- a/test/irb/helper.rb +++ b/test/irb/helper.rb @@ -139,8 +139,13 @@ def teardown end end - def run_ruby_file(timeout: TIMEOUT_SEC, &block) - cmd = [EnvUtil.rubybin, "-I", LIB, @ruby_file.to_path] + def run_ruby_file(timeout: TIMEOUT_SEC, via_irb: false, &block) + if via_irb + irb_path = File.expand_path("../../exe/irb", __dir__) + cmd = [EnvUtil.rubybin, "-I", LIB, irb_path, @ruby_file.to_path] + else + cmd = [EnvUtil.rubybin, "-I", LIB, @ruby_file.to_path] + end tmp_dir = Dir.mktmpdir @commands = [] diff --git a/test/irb/test_debugger_integration.rb b/test/irb/test_debugger_integration.rb index e125dbf85..9c71fb1eb 100644 --- a/test/irb/test_debugger_integration.rb +++ b/test/irb/test_debugger_integration.rb @@ -123,6 +123,25 @@ def test_next assert_match(/=> 2\| puts "hello"/, output) end + def test_next_with_irb_script + # Regression test for https://github.com/ruby/irb/issues/1159 + # Running `irb file.rb` creates C frames with nil path that must be handled + write_ruby <<~'ruby' + binding.irb + puts "hello" + ruby + + output = run_ruby_file(via_irb: true) do + type "next" + type "continue" + end + + assert_not_match(/NoMethodError/, output) + assert_not_match(/undefined method.*start_with\?.*nil/, output) + + assert_match(/irb\(main\):001>/, output) + end + def test_break write_ruby <<~'RUBY' binding.irb