From 676d816ef1fa55bae2b5020782ba47284748383b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Wed, 8 Apr 2020 21:14:27 +0200 Subject: [PATCH] [rubygems/rubygems] Refactor ruby command line building for tests https://github.com/rubygems/rubygems/commit/43819b6973 --- lib/rubygems/test_case.rb | 4 ++++ test/rubygems/test_gem.rb | 7 +++---- test/rubygems/test_gem_util.rb | 4 ++-- test/rubygems/test_kernel.rb | 4 +--- test/rubygems/test_require.rb | 13 +++++-------- 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/lib/rubygems/test_case.rb b/lib/rubygems/test_case.rb index b4d8db317c..0d450ba023 100644 --- a/lib/rubygems/test_case.rb +++ b/lib/rubygems/test_case.rb @@ -1260,6 +1260,10 @@ Also, a list: end end + def ruby_with_rubygems_in_load_path + [Gem.ruby, "-I", File.expand_path("..", __dir__)] + end + def with_clean_path_to_ruby orig_ruby = Gem.ruby diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb index 6ded4ea678..d64a253bbc 100644 --- a/test/rubygems/test_gem.rb +++ b/test/rubygems/test_gem.rb @@ -311,7 +311,7 @@ class TestGem < Gem::TestCase output, status = Open3.capture2e( { "GEM_HOME" => Gem.paths.home, "DEBUG_RESOLVER" => "1" }, - Gem.ruby, "-I", File.expand_path("../../lib", __dir__), "-e", "\"Gem.activate_bin_path('a', 'exec', '>= 0')\"" + *ruby_with_rubygems_in_load_path, "-e", "\"Gem.activate_bin_path('a', 'exec', '>= 0')\"" ) assert status.success?, output @@ -1637,7 +1637,6 @@ class TestGem < Gem::TestCase assert_equal expected_specs, Gem.use_gemdeps.sort_by { |s| s.name } end - LIB_PATH = File.expand_path "../../../lib", __FILE__ BUNDLER_LIB_PATH = File.expand_path $LOAD_PATH.find {|lp| File.file?(File.join(lp, "bundler.rb")) } BUNDLER_FULL_NAME = "bundler-#{Bundler::VERSION}".freeze @@ -1665,7 +1664,7 @@ class TestGem < Gem::TestCase ENV['RUBYGEMS_GEMDEPS'] = "-" path = File.join @tempdir, "gem.deps.rb" - cmd = [Gem.ruby, "-I#{LIB_PATH}", + cmd = [*ruby_with_rubygems_in_load_path, "-I#{BUNDLER_LIB_PATH}"] cmd << "-eputs Gem.loaded_specs.values.map(&:full_name).sort" @@ -1703,7 +1702,7 @@ class TestGem < Gem::TestCase Dir.mkdir "sub1" path = File.join @tempdir, "gem.deps.rb" - cmd = [Gem.ruby, "-Csub1", "-I#{LIB_PATH}", + cmd = [*ruby_with_rubygems_in_load_path, "-Csub1", "-I#{BUNDLER_LIB_PATH}"] cmd << "-eputs Gem.loaded_specs.values.map(&:full_name).sort" diff --git a/test/rubygems/test_gem_util.rb b/test/rubygems/test_gem_util.rb index 3f1d069a20..387dff0d8a 100644 --- a/test/rubygems/test_gem_util.rb +++ b/test/rubygems/test_gem_util.rb @@ -6,7 +6,7 @@ class TestGemUtil < Gem::TestCase def test_class_popen skip "popen with a block does not behave well on jruby" if Gem.java_platform? - assert_equal "0\n", Gem::Util.popen(Gem.ruby, '-I', File.expand_path('../../../lib', __FILE__), '-e', 'p 0') + assert_equal "0\n", Gem::Util.popen(*ruby_with_rubygems_in_load_path, '-e', 'p 0') assert_raises Errno::ECHILD do Process.wait(-1) @@ -16,7 +16,7 @@ class TestGemUtil < Gem::TestCase def test_silent_system skip if Gem.java_platform? assert_silent do - Gem::Util.silent_system Gem.ruby, '-I', File.expand_path('../../../lib', __FILE__), '-e', 'puts "hello"; warn "hello"' + Gem::Util.silent_system(*ruby_with_rubygems_in_load_path, '-e', 'puts "hello"; warn "hello"') end end diff --git a/test/rubygems/test_kernel.rb b/test/rubygems/test_kernel.rb index daf9b57d7c..be8aa4f512 100644 --- a/test/rubygems/test_kernel.rb +++ b/test/rubygems/test_kernel.rb @@ -98,9 +98,7 @@ class TestKernel < Gem::TestCase output, _ = Open3.capture2e( { "GEM_HOME" => Gem.paths.home }, - Gem.ruby, - "-I", - File.expand_path("../../lib", __dir__), + *ruby_with_rubygems_in_load_path, "-r", "./activate.rb" ) diff --git a/test/rubygems/test_require.rb b/test/rubygems/test_require.rb index 6297f86fb4..1c86a4ed66 100644 --- a/test/rubygems/test_require.rb +++ b/test/rubygems/test_require.rb @@ -391,8 +391,7 @@ class TestGemRequire < Gem::TestCase require "json" puts Gem.loaded_specs["json"] RUBY - rubygems_libdir = File.expand_path('../../../lib', __FILE__) - output = Gem::Util.popen(Gem.ruby, "-I#{rubygems_libdir}", "-e", cmd).strip + output = Gem::Util.popen(*ruby_with_rubygems_in_load_path, "-e", cmd).strip refute_empty output end @@ -519,31 +518,29 @@ class TestGemRequire < Gem::TestCase if RUBY_VERSION >= "2.5" ["", "Kernel."].each do |prefix| define_method "test_no_kernel_require_in_#{prefix.tr(".", "_")}warn_with_uplevel" do - lib = File.realpath("../../../lib", __FILE__) Dir.mktmpdir("warn_test") do |dir| File.write(dir + "/sub.rb", "#{prefix}warn 'uplevel', 'test', uplevel: 1\n") File.write(dir + "/main.rb", "require 'sub'\n") _, err = capture_subprocess_io do - system(Gem.ruby, "-w", "--disable=gems", "-I", lib, "-C", dir, "-I.", "main.rb") + system(*ruby_with_rubygems_in_load_path, "-w", "--disable=gems", "-C", dir, "-I.", "main.rb") end assert_match(/main\.rb:1: warning: uplevel\ntest\n$/, err) _, err = capture_subprocess_io do - system(Gem.ruby, "-w", "--enable=gems", "-I", lib, "-C", dir, "-I.", "main.rb") + system(*ruby_with_rubygems_in_load_path, "-w", "--enable=gems", "-C", dir, "-I.", "main.rb") end assert_match(/main\.rb:1: warning: uplevel\ntest\n$/, err) end end define_method "test_no_other_behavioral_changes_with_#{prefix.tr(".", "_")}warn" do - lib = File.realpath("../../../lib", __FILE__) Dir.mktmpdir("warn_test") do |dir| File.write(dir + "/main.rb", "#{prefix}warn({x:1}, {y:2}, [])\n") _, err = capture_subprocess_io do - system(Gem.ruby, "-w", "--disable=gems", "-I", lib, "-C", dir, "main.rb") + system(*ruby_with_rubygems_in_load_path, "-w", "--disable=gems", "-C", dir, "main.rb") end assert_match(/{:x=>1}\n{:y=>2}\n$/, err) _, err = capture_subprocess_io do - system(Gem.ruby, "-w", "--enable=gems", "-I", lib, "-C", dir, "main.rb") + system(*ruby_with_rubygems_in_load_path, "-w", "--enable=gems", "-C", dir, "main.rb") end assert_match(/{:x=>1}\n{:y=>2}\n$/, err) end