Skip to content
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
4 changes: 2 additions & 2 deletions exe/rdbg
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ when :start
start_mode = config[:remote] ? "open" : 'start'
cmd = config[:command] ? ARGV.shift : (ENV['RUBY'] || RbConfig.ruby)

rubyopt = ENV['RUBYOPT']
env = ::DEBUGGER__::Config.config_to_env_hash(config)
rubyopt = env['RUBYOPT']
env['RUBY_DEBUG_ADDED_RUBYOPT'] = added = "-r #{libpath}/#{start_mode}"
env['RUBYOPT'] = "#{added} #{rubyopt}"
env['RUBYOPT'] = "#{rubyopt} #{added}"

exec(env, cmd, *ARGV)

Expand Down
7 changes: 4 additions & 3 deletions lib/debug/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
# restore RUBYOPT
if (added_opt = ENV['RUBY_DEBUG_ADDED_RUBYOPT']) &&
(rubyopt = ENV['RUBYOPT']) &&
rubyopt.start_with?(added_opt)
ENV['RUBYOPT'] = rubyopt.delete_prefix(rubyopt)
rubyopt.end_with?(added_opt)

ENV['RUBYOPT'] = rubyopt.delete_suffix(added_opt)
ENV['RUBY_DEBUG_ADDED_RUBYOPT'] = nil
end

Expand Down Expand Up @@ -2120,7 +2121,7 @@ def self.load_rc
end

# Inspector

SHORT_INSPECT_LENGTH = 40

class LimitedPP
Expand Down
25 changes: 25 additions & 0 deletions test/console/rdbg_option_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,31 @@
require_relative '../support/console_test_case'

module DEBUGGER__
class RUBYOPTHandlingTest < ConsoleTestCase
def program
<<~RUBY
1| a = 1
RUBY
end

def test_debugger_removes_rubyopt_added_by_rdbg
run_rdbg(program) do
type "ENV['RUBYOPT']"
assert_no_line_text(/debug\/start/)
type "c"
end
end

def test_debugger_respects_other_rubyopt
run_rdbg(program, rubyopt: "-rreline") do
type "ENV['RUBYOPT']"
assert_no_line_text(/debug\/start/)
assert_line_text(/-rreline/)
type "c"
end
end
end

class DebugCommandOptionTest < ConsoleTestCase
def program
<<~RUBY
Expand Down
3 changes: 2 additions & 1 deletion test/support/console_test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,11 @@ def run_ruby program, options: nil, &test_steps
end
end

def run_rdbg program, options: nil, &test_steps
def run_rdbg program, options: nil, rubyopt: nil, &test_steps
prepare_test_environment(program, test_steps) do
test_info = TestInfo.new(dup_scenario, 'LOCAL', /\(rdbg\)/)
cmd = "#{RDBG_EXECUTABLE} #{options} -- #{temp_file_path}"
cmd = "RUBYOPT=#{rubyopt} #{cmd}" if rubyopt
run_test_scenario cmd, test_info
end
end
Expand Down