Skip to content

Commit 35c09fe

Browse files
committed
Improve RUBYOPT's handling in tests
When debugging the issue related to ruby/irb#919, I noticed that debugger tests don't respect the IRB version I specified in the Gemfile. This is because console tests force override the RUBYOPT env, which will remove the `-rbundler/setup` injected by bundler. Further more, if tests use `run_rdbg` with the `rubyopt` option, the RUBYOPT will be overridden yet again. So in this commit I did 2 improvements: 1. `run_rdbg` should append instead of override RUBYOPT 2. If tests are executed with bundler, we also run the debugger in PTY process with bundler by appending `-rbundler/setup` to RUBYOPT
1 parent 0b77e82 commit 35c09fe

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

test/support/console_test_case.rb

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ def debug_code(program, remote: true, verbose: false, &test_steps)
120120
end
121121

122122
def run_test_scenario cmd, test_info, verbose: false
123-
PTY.spawn({ "HOME" => pty_home_dir }, cmd) do |read, write, pid|
123+
env = { "HOME" => pty_home_dir }
124+
125+
PTY.spawn(env, cmd) do |read, write, pid|
124126
test_info.backlog = []
125127
test_info.last_backlog = []
126128
begin
@@ -225,7 +227,12 @@ def prepare_test_environment(program, test_steps, &block)
225227
@scenario = []
226228
test_steps.call
227229
@scenario.freeze
228-
inject_lib_to_load_path
230+
231+
ENV['RUBYOPT'] = "-I #{__dir__}/../../lib"
232+
233+
if ENV.key?('BUNDLE_GEMFILE')
234+
ENV["RUBYOPT"] += " -rbundler/setup"
235+
end
229236

230237
block.call
231238

@@ -283,7 +290,7 @@ def run_rdbg program, options: nil, rubyopt: nil, &test_steps
283290
prepare_test_environment(program, test_steps) do
284291
test_info = TestInfo.new(dup_scenario, 'LOCAL', /\(rdbg\)/)
285292
cmd = "#{RDBG_EXECUTABLE} #{options} -- #{temp_file_path}"
286-
cmd = "RUBYOPT=#{rubyopt} #{cmd}" if rubyopt
293+
ENV["RUBYOPT"] += " #{rubyopt}" if rubyopt
287294
run_test_scenario cmd, test_info
288295
end
289296
end
@@ -301,10 +308,6 @@ def new_thread &block
301308
end
302309
end
303310

304-
def inject_lib_to_load_path
305-
ENV['RUBYOPT'] = "-I #{__dir__}/../../lib"
306-
end
307-
308311
def assert_empty_queue test_info, exception: nil
309312
message = "Expected all commands/assertions to be executed. Still have #{test_info.queue.length} left."
310313
if exception

0 commit comments

Comments
 (0)