[前][次][番号順一覧][スレッド一覧]

ruby-changes:61094

From: David <ko1@a...>
Date: Fri, 8 May 2020 14:14:05 +0900 (JST)
Subject: [ruby-changes:61094] 676d816ef1 (master): [rubygems/rubygems] Refactor ruby command line building for tests

https://git.ruby-lang.org/ruby.git/commit/?id=676d816ef1

From 676d816ef1fa55bae2b5020782ba47284748383b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?David=20Rodr=C3=ADguez?= <deivid.rodriguez@r...>
Date: Wed, 8 Apr 2020 21:14:27 +0200
Subject: [rubygems/rubygems] Refactor ruby command line building for tests

https://github.com/rubygems/rubygems/commit/43819b6973

diff --git a/lib/rubygems/test_case.rb b/lib/rubygems/test_case.rb
index b4d8db3..0d450ba 100644
--- a/lib/rubygems/test_case.rb
+++ b/lib/rubygems/test_case.rb
@@ -1260,6 +1260,10 @@ Also, a list: https://github.com/ruby/ruby/blob/trunk/lib/rubygems/test_case.rb#L1260
     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 6ded4ea..d64a253 100644
--- a/test/rubygems/test_gem.rb
+++ b/test/rubygems/test_gem.rb
@@ -311,7 +311,7 @@ class TestGem < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem.rb#L311
 
     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 https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem.rb#L1637
     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 https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem.rb#L1664
     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 https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem.rb#L1702
     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 3f1d069..387dff0 100644
--- a/test/rubygems/test_gem_util.rb
+++ b/test/rubygems/test_gem_util.rb
@@ -6,7 +6,7 @@ class TestGemUtil < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_util.rb#L6
 
   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 https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_util.rb#L16
   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 daf9b57..be8aa4f 100644
--- a/test/rubygems/test_kernel.rb
+++ b/test/rubygems/test_kernel.rb
@@ -98,9 +98,7 @@ class TestKernel < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_kernel.rb#L98
 
     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 6297f86..1c86a4e 100644
--- a/test/rubygems/test_require.rb
+++ b/test/rubygems/test_require.rb
@@ -391,8 +391,7 @@ class TestGemRequire < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_require.rb#L391
       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 https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_require.rb#L518
   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
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]