Skip to content

Commit c0caf1c

Browse files
sunblazest0012
authored andcommitted
[ruby/irb] Load history when starting a direct debug session
(ruby/irb#1046) * Load history when starting a direct debug session When starting a debug session directly with RUBY_DEBUG_IRB_CONSOLE=1 and `require 'debug'; debugger`, IRB's history wasn't loaded. This commit ensures history is loaded in this case by calling `load_history` when configuring IRB for the debugger. Fixes ruby/irb#975 * Update test/irb/test_history.rb * Update lib/irb/debug.rb --------- ruby/irb@7f851b5353 Co-authored-by: Stan Lo <[email protected]>
1 parent 300be2b commit c0caf1c

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

lib/irb/debug.rb

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ def configure_irb_for_debugger(irb)
8181
IRB.instance_variable_set(:@debugger_irb, irb)
8282
irb.context.with_debugger = true
8383
irb.context.irb_name += ":rdbg"
84+
irb.context.io.load_history if irb.context.io.class < HistorySavingAbility
8485
end
8586

8687
module SkipPathHelperForIRB

test/irb/test_history.rb

+30
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,36 @@ def foo
488488
HISTORY
489489
end
490490

491+
def test_direct_debug_session_loads_history
492+
@envs['RUBY_DEBUG_IRB_CONSOLE'] = "1"
493+
write_history <<~HISTORY
494+
old_history_1
495+
old_history_2
496+
old_history_3
497+
HISTORY
498+
499+
write_ruby <<~'RUBY'
500+
require 'debug'
501+
debugger
502+
binding.irb # needed to satisfy run_ruby_file
503+
RUBY
504+
505+
output = run_ruby_file do
506+
type "history"
507+
type "puts 'foo'"
508+
type "history"
509+
type "exit!"
510+
end
511+
512+
assert_include(output, "irb:rdbg(main):002") # assert that we're in an irb:rdbg session
513+
assert_include(output, "5: history")
514+
assert_include(output, "4: puts 'foo'")
515+
assert_include(output, "3: history")
516+
assert_include(output, "2: old_history_3")
517+
assert_include(output, "1: old_history_2")
518+
assert_include(output, "0: old_history_1")
519+
end
520+
491521
private
492522

493523
def write_history(history)

0 commit comments

Comments
 (0)