Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/irb/debug.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?("<internal:")
frame.realpath&.start_with?(IRB_DIR) || frame.path&.start_with?("<internal:")
end
frames
end
Expand Down Expand Up @@ -87,7 +87,7 @@ def configure_irb_for_debugger(irb)
module SkipPathHelperForIRB
def skip_internal_path?(path)
# The latter can be removed once https://github.com/ruby/debug/issues/866 is resolved
super || path.match?(IRB_DIR) || path.match?('<internal:prelude>')
super || path&.match?(IRB_DIR) || path&.match?('<internal:prelude>')
end
end

Expand Down
9 changes: 7 additions & 2 deletions test/irb/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
19 changes: 19 additions & 0 deletions test/irb/test_debugger_integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading