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
43819b6973
This commit is contained in:
parent
1635394347
commit
676d816ef1
Notes:
git
2020-05-08 14:14:26 +09:00
5 changed files with 15 additions and 17 deletions
|
@ -1260,6 +1260,10 @@ Also, a list:
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def ruby_with_rubygems_in_load_path
|
||||||
|
[Gem.ruby, "-I", File.expand_path("..", __dir__)]
|
||||||
|
end
|
||||||
|
|
||||||
def with_clean_path_to_ruby
|
def with_clean_path_to_ruby
|
||||||
orig_ruby = Gem.ruby
|
orig_ruby = Gem.ruby
|
||||||
|
|
||||||
|
|
|
@ -311,7 +311,7 @@ class TestGem < Gem::TestCase
|
||||||
|
|
||||||
output, status = Open3.capture2e(
|
output, status = Open3.capture2e(
|
||||||
{ "GEM_HOME" => Gem.paths.home, "DEBUG_RESOLVER" => "1" },
|
{ "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
|
assert status.success?, output
|
||||||
|
@ -1637,7 +1637,6 @@ class TestGem < Gem::TestCase
|
||||||
assert_equal expected_specs, Gem.use_gemdeps.sort_by { |s| s.name }
|
assert_equal expected_specs, Gem.use_gemdeps.sort_by { |s| s.name }
|
||||||
end
|
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_LIB_PATH = File.expand_path $LOAD_PATH.find {|lp| File.file?(File.join(lp, "bundler.rb")) }
|
||||||
BUNDLER_FULL_NAME = "bundler-#{Bundler::VERSION}".freeze
|
BUNDLER_FULL_NAME = "bundler-#{Bundler::VERSION}".freeze
|
||||||
|
|
||||||
|
@ -1665,7 +1664,7 @@ class TestGem < Gem::TestCase
|
||||||
ENV['RUBYGEMS_GEMDEPS'] = "-"
|
ENV['RUBYGEMS_GEMDEPS'] = "-"
|
||||||
|
|
||||||
path = File.join @tempdir, "gem.deps.rb"
|
path = File.join @tempdir, "gem.deps.rb"
|
||||||
cmd = [Gem.ruby, "-I#{LIB_PATH}",
|
cmd = [*ruby_with_rubygems_in_load_path,
|
||||||
"-I#{BUNDLER_LIB_PATH}"]
|
"-I#{BUNDLER_LIB_PATH}"]
|
||||||
cmd << "-eputs Gem.loaded_specs.values.map(&:full_name).sort"
|
cmd << "-eputs Gem.loaded_specs.values.map(&:full_name).sort"
|
||||||
|
|
||||||
|
@ -1703,7 +1702,7 @@ class TestGem < Gem::TestCase
|
||||||
Dir.mkdir "sub1"
|
Dir.mkdir "sub1"
|
||||||
|
|
||||||
path = File.join @tempdir, "gem.deps.rb"
|
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}"]
|
"-I#{BUNDLER_LIB_PATH}"]
|
||||||
cmd << "-eputs Gem.loaded_specs.values.map(&:full_name).sort"
|
cmd << "-eputs Gem.loaded_specs.values.map(&:full_name).sort"
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ class TestGemUtil < Gem::TestCase
|
||||||
|
|
||||||
def test_class_popen
|
def test_class_popen
|
||||||
skip "popen with a block does not behave well on jruby" if Gem.java_platform?
|
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
|
assert_raises Errno::ECHILD do
|
||||||
Process.wait(-1)
|
Process.wait(-1)
|
||||||
|
@ -16,7 +16,7 @@ class TestGemUtil < Gem::TestCase
|
||||||
def test_silent_system
|
def test_silent_system
|
||||||
skip if Gem.java_platform?
|
skip if Gem.java_platform?
|
||||||
assert_silent do
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -98,9 +98,7 @@ class TestKernel < Gem::TestCase
|
||||||
|
|
||||||
output, _ = Open3.capture2e(
|
output, _ = Open3.capture2e(
|
||||||
{ "GEM_HOME" => Gem.paths.home },
|
{ "GEM_HOME" => Gem.paths.home },
|
||||||
Gem.ruby,
|
*ruby_with_rubygems_in_load_path,
|
||||||
"-I",
|
|
||||||
File.expand_path("../../lib", __dir__),
|
|
||||||
"-r",
|
"-r",
|
||||||
"./activate.rb"
|
"./activate.rb"
|
||||||
)
|
)
|
||||||
|
|
|
@ -391,8 +391,7 @@ class TestGemRequire < Gem::TestCase
|
||||||
require "json"
|
require "json"
|
||||||
puts Gem.loaded_specs["json"]
|
puts Gem.loaded_specs["json"]
|
||||||
RUBY
|
RUBY
|
||||||
rubygems_libdir = File.expand_path('../../../lib', __FILE__)
|
output = Gem::Util.popen(*ruby_with_rubygems_in_load_path, "-e", cmd).strip
|
||||||
output = Gem::Util.popen(Gem.ruby, "-I#{rubygems_libdir}", "-e", cmd).strip
|
|
||||||
refute_empty output
|
refute_empty output
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -519,31 +518,29 @@ class TestGemRequire < Gem::TestCase
|
||||||
if RUBY_VERSION >= "2.5"
|
if RUBY_VERSION >= "2.5"
|
||||||
["", "Kernel."].each do |prefix|
|
["", "Kernel."].each do |prefix|
|
||||||
define_method "test_no_kernel_require_in_#{prefix.tr(".", "_")}warn_with_uplevel" do
|
define_method "test_no_kernel_require_in_#{prefix.tr(".", "_")}warn_with_uplevel" do
|
||||||
lib = File.realpath("../../../lib", __FILE__)
|
|
||||||
Dir.mktmpdir("warn_test") do |dir|
|
Dir.mktmpdir("warn_test") do |dir|
|
||||||
File.write(dir + "/sub.rb", "#{prefix}warn 'uplevel', 'test', uplevel: 1\n")
|
File.write(dir + "/sub.rb", "#{prefix}warn 'uplevel', 'test', uplevel: 1\n")
|
||||||
File.write(dir + "/main.rb", "require 'sub'\n")
|
File.write(dir + "/main.rb", "require 'sub'\n")
|
||||||
_, err = capture_subprocess_io do
|
_, 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
|
end
|
||||||
assert_match(/main\.rb:1: warning: uplevel\ntest\n$/, err)
|
assert_match(/main\.rb:1: warning: uplevel\ntest\n$/, err)
|
||||||
_, err = capture_subprocess_io do
|
_, 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
|
end
|
||||||
assert_match(/main\.rb:1: warning: uplevel\ntest\n$/, err)
|
assert_match(/main\.rb:1: warning: uplevel\ntest\n$/, err)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
define_method "test_no_other_behavioral_changes_with_#{prefix.tr(".", "_")}warn" do
|
define_method "test_no_other_behavioral_changes_with_#{prefix.tr(".", "_")}warn" do
|
||||||
lib = File.realpath("../../../lib", __FILE__)
|
|
||||||
Dir.mktmpdir("warn_test") do |dir|
|
Dir.mktmpdir("warn_test") do |dir|
|
||||||
File.write(dir + "/main.rb", "#{prefix}warn({x:1}, {y:2}, [])\n")
|
File.write(dir + "/main.rb", "#{prefix}warn({x:1}, {y:2}, [])\n")
|
||||||
_, err = capture_subprocess_io do
|
_, 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
|
end
|
||||||
assert_match(/{:x=>1}\n{:y=>2}\n$/, err)
|
assert_match(/{:x=>1}\n{:y=>2}\n$/, err)
|
||||||
_, err = capture_subprocess_io do
|
_, 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
|
end
|
||||||
assert_match(/{:x=>1}\n{:y=>2}\n$/, err)
|
assert_match(/{:x=>1}\n{:y=>2}\n$/, err)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue