Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid overriding user's irb_name setting in debugger integration #688

Merged
merged 2 commits into from
Aug 21, 2023
Merged
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
2 changes: 1 addition & 1 deletion lib/irb/debug.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
19 changes: 17 additions & 2 deletions test/irb/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,22 @@ class IntegrationTestCase < TestCase
TIMEOUT_SEC = 3

def setup
@envs = {}
@tmpfiles = []

unless defined?(PTY)
omit "Integration tests require PTY."
end

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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
19 changes: 19 additions & 0 deletions test/irb/test_debug_cmd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,25 @@ def test_prompt_line_number_continues
assert_match(/irb:rdbg\(main\):005> next/, output)
end

def test_prompt_irb_name_is_kept
write_rc <<~RUBY
IRB.conf[:IRB_NAME] = "foo"
RUBY

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)
end

def test_irb_commands_are_available_after_moving_around_with_the_debugger
write_ruby <<~'ruby'
class Foo
Expand Down
5 changes: 1 addition & 4 deletions test/irb/test_history.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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