1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[rubygems/rubygems] Refactor ruby command line building for tests

https://github.com/rubygems/rubygems/commit/43819b6973
This commit is contained in:
David Rodríguez 2020-04-08 21:14:27 +02:00 committed by Hiroshi SHIBATA
parent 1635394347
commit 676d816ef1
Notes: git 2020-05-08 14:14:26 +09:00
5 changed files with 15 additions and 17 deletions

View file

@ -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

View file

@ -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"

View file

@ -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

View file

@ -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"
)

View file

@ -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