From 35c09fe76ffbcaefea3f5cd218d4b0f3df88e374 Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Thu, 11 Apr 2024 12:58:42 +0100 Subject: [PATCH] Improve RUBYOPT's handling in tests When debugging the issue related to https://github.com/ruby/irb/pull/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 --- test/support/console_test_case.rb | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/test/support/console_test_case.rb b/test/support/console_test_case.rb index f7e62fb4b..04e6b2eac 100644 --- a/test/support/console_test_case.rb +++ b/test/support/console_test_case.rb @@ -120,7 +120,9 @@ def debug_code(program, remote: true, verbose: false, &test_steps) end def run_test_scenario cmd, test_info, verbose: false - PTY.spawn({ "HOME" => pty_home_dir }, cmd) do |read, write, pid| + env = { "HOME" => pty_home_dir } + + PTY.spawn(env, cmd) do |read, write, pid| test_info.backlog = [] test_info.last_backlog = [] begin @@ -225,7 +227,12 @@ def prepare_test_environment(program, test_steps, &block) @scenario = [] test_steps.call @scenario.freeze - inject_lib_to_load_path + + ENV['RUBYOPT'] = "-I #{__dir__}/../../lib" + + if ENV.key?('BUNDLE_GEMFILE') + ENV["RUBYOPT"] += " -rbundler/setup" + end block.call @@ -283,7 +290,7 @@ 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 + ENV["RUBYOPT"] += " #{rubyopt}" if rubyopt run_test_scenario cmd, test_info end end @@ -301,10 +308,6 @@ def new_thread &block end end - def inject_lib_to_load_path - ENV['RUBYOPT'] = "-I #{__dir__}/../../lib" - end - def assert_empty_queue test_info, exception: nil message = "Expected all commands/assertions to be executed. Still have #{test_info.queue.length} left." if exception