Skip to content

Commit 4b50fc6

Browse files
st0012ko1
authored andcommitted
Fix rdbg's RUBYOPT handling logic
Fixes #715
1 parent 390b764 commit 4b50fc6

File tree

4 files changed

+33
-6
lines changed

4 files changed

+33
-6
lines changed

exe/rdbg

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ when :start
1313
start_mode = config[:remote] ? "open" : 'start'
1414
cmd = config[:command] ? ARGV.shift : (ENV['RUBY'] || RbConfig.ruby)
1515

16+
rubyopt = ENV['RUBYOPT']
1617
env = ::DEBUGGER__::Config.config_to_env_hash(config)
17-
rubyopt = env['RUBYOPT']
1818
env['RUBY_DEBUG_ADDED_RUBYOPT'] = added = "-r #{libpath}/#{start_mode}"
19-
env['RUBYOPT'] = "#{added} #{rubyopt}"
19+
env['RUBYOPT'] = "#{rubyopt} #{added}"
2020

2121
exec(env, cmd, *ARGV)
2222

lib/debug/session.rb

+4-3
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
# restore RUBYOPT
2323
if (added_opt = ENV['RUBY_DEBUG_ADDED_RUBYOPT']) &&
2424
(rubyopt = ENV['RUBYOPT']) &&
25-
rubyopt.start_with?(added_opt)
26-
ENV['RUBYOPT'] = rubyopt.delete_prefix(rubyopt)
25+
rubyopt.end_with?(added_opt)
26+
27+
ENV['RUBYOPT'] = rubyopt.delete_suffix(added_opt)
2728
ENV['RUBY_DEBUG_ADDED_RUBYOPT'] = nil
2829
end
2930

@@ -2120,7 +2121,7 @@ def self.load_rc
21202121
end
21212122

21222123
# Inspector
2123-
2124+
21242125
SHORT_INSPECT_LENGTH = 40
21252126

21262127
class LimitedPP

test/console/rdbg_option_test.rb

+25
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,31 @@
33
require_relative '../support/console_test_case'
44

55
module DEBUGGER__
6+
class RUBYOPTHandlingTest < ConsoleTestCase
7+
def program
8+
<<~RUBY
9+
1| a = 1
10+
RUBY
11+
end
12+
13+
def test_debugger_removes_rubyopt_added_by_rdbg
14+
run_rdbg(program) do
15+
type "ENV['RUBYOPT']"
16+
assert_no_line_text(/debug\/start/)
17+
type "c"
18+
end
19+
end
20+
21+
def test_debugger_respects_other_rubyopt
22+
run_rdbg(program, rubyopt: "-rreline") do
23+
type "ENV['RUBYOPT']"
24+
assert_no_line_text(/debug\/start/)
25+
assert_line_text(/-rreline/)
26+
type "c"
27+
end
28+
end
29+
end
30+
631
class DebugCommandOptionTest < ConsoleTestCase
732
def program
833
<<~RUBY

test/support/console_test_case.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,11 @@ def run_ruby program, options: nil, &test_steps
246246
end
247247
end
248248

249-
def run_rdbg program, options: nil, &test_steps
249+
def run_rdbg program, options: nil, rubyopt: nil, &test_steps
250250
prepare_test_environment(program, test_steps) do
251251
test_info = TestInfo.new(dup_scenario, 'LOCAL', /\(rdbg\)/)
252252
cmd = "#{RDBG_EXECUTABLE} #{options} -- #{temp_file_path}"
253+
cmd = "RUBYOPT=#{rubyopt} #{cmd}" if rubyopt
253254
run_test_scenario cmd, test_info
254255
end
255256
end

0 commit comments

Comments
 (0)