From abcf12af5733cde47c3c67dbc1cec403631469e2 Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Mon, 21 Aug 2023 12:34:42 +0100 Subject: [PATCH 1/2] Avoid overriding user's irb_name setting in debugger integration Instead of always setting `irb_name` to `irb:rdbg`, it should respect the user's setting and only append `:rdbg` to it. --- lib/irb/debug.rb | 2 +- test/irb/test_debug_cmd.rb | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/irb/debug.rb b/lib/irb/debug.rb index dab9d1846..f72282299 100644 --- a/lib/irb/debug.rb +++ b/lib/irb/debug.rb @@ -73,7 +73,7 @@ def configure_irb_for_debugger(irb) require 'irb/debug/ui' IRB.instance_variable_set(:@debugger_irb, irb) irb.context.with_debugger = true - irb.context.irb_name = "irb:rdbg" + irb.context.irb_name += ":rdbg" end def binding_irb? diff --git a/test/irb/test_debug_cmd.rb b/test/irb/test_debug_cmd.rb index c4e4a04fd..0731f84ed 100644 --- a/test/irb/test_debug_cmd.rb +++ b/test/irb/test_debug_cmd.rb @@ -289,6 +289,30 @@ def test_prompt_line_number_continues assert_match(/irb:rdbg\(main\):005> next/, output) end + def test_prompt_irb_name_is_kept + @irbrc = Tempfile.new('irbrc') + @irbrc.write <<~RUBY + IRB.conf[:IRB_NAME] = "foo" + RUBY + @irbrc.close + @envs['IRBRC'] = @irbrc.path + + write_ruby <<~'ruby' + binding.irb + puts "Hello" + ruby + + output = run_ruby_file do + type "next" + type "continue" + end + + assert_match(/foo\(main\):001> next/, output) + assert_match(/foo:rdbg\(main\):002> continue/, output) + ensure + @irbrc&.unlink + end + def test_irb_commands_are_available_after_moving_around_with_the_debugger write_ruby <<~'ruby' class Foo From 9bd6dfc2d5fcb787cd68a1a16300dcdcfded24b2 Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Mon, 21 Aug 2023 13:06:53 +0100 Subject: [PATCH 2/2] Introduce write_rc test helper --- test/irb/helper.rb | 19 +++++++++++++++++-- test/irb/test_debug_cmd.rb | 7 +------ test/irb/test_history.rb | 5 +---- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/test/irb/helper.rb b/test/irb/helper.rb index e281b8e2f..122eb607f 100644 --- a/test/irb/helper.rb +++ b/test/irb/helper.rb @@ -83,6 +83,9 @@ class IntegrationTestCase < TestCase TIMEOUT_SEC = 3 def setup + @envs = {} + @tmpfiles = [] + unless defined?(PTY) omit "Integration tests require PTY." end @@ -90,8 +93,12 @@ def setup if ruby_core? omit "This test works only under ruby/irb" end + end - @envs = {} + def teardown + @tmpfiles.each do |tmpfile| + File.unlink(tmpfile) + end end def run_ruby_file(&block) @@ -133,7 +140,6 @@ def run_ruby_file(&block) MSG assert_block(message) { false } ensure - File.unlink(@ruby_file) if @ruby_file FileUtils.remove_entry tmp_dir end @@ -180,8 +186,17 @@ def type(command) def write_ruby(program) @ruby_file = Tempfile.create(%w{irb- .rb}) + @tmpfiles << @ruby_file @ruby_file.write(program) @ruby_file.close end + + def write_rc(content) + @irbrc = Tempfile.new('irbrc') + @tmpfiles << @irbrc + @irbrc.write(content) + @irbrc.close + @envs['IRBRC'] = @irbrc.path + end end end diff --git a/test/irb/test_debug_cmd.rb b/test/irb/test_debug_cmd.rb index 0731f84ed..a99f7a943 100644 --- a/test/irb/test_debug_cmd.rb +++ b/test/irb/test_debug_cmd.rb @@ -290,12 +290,9 @@ def test_prompt_line_number_continues end def test_prompt_irb_name_is_kept - @irbrc = Tempfile.new('irbrc') - @irbrc.write <<~RUBY + write_rc <<~RUBY IRB.conf[:IRB_NAME] = "foo" RUBY - @irbrc.close - @envs['IRBRC'] = @irbrc.path write_ruby <<~'ruby' binding.irb @@ -309,8 +306,6 @@ def test_prompt_irb_name_is_kept assert_match(/foo\(main\):001> next/, output) assert_match(/foo:rdbg\(main\):002> continue/, output) - ensure - @irbrc&.unlink end def test_irb_commands_are_available_after_moving_around_with_the_debugger diff --git a/test/irb/test_history.rb b/test/irb/test_history.rb index 9bf146609..15628e66e 100644 --- a/test/irb/test_history.rb +++ b/test/irb/test_history.rb @@ -326,12 +326,9 @@ def write_history(history) @history_file = Tempfile.new('irb_history') @history_file.write(history) @history_file.close - @irbrc = Tempfile.new('irbrc') - @irbrc.write <<~RUBY + write_rc <<~RUBY IRB.conf[:HISTORY_FILE] = "#{@history_file.path}" RUBY - @irbrc.close - @envs['IRBRC'] = @irbrc.path end end end