summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorHiroshi SHIBATA <hsbt@ruby-lang.org>2021-08-18 19:37:11 +0900
committernagachika <nagachika@ruby-lang.org>2021-08-19 15:46:40 +0900
commit37f824377fce1bb0fb3ae94f858e2b9417b67b56 (patch)
tree262faa7f44212747afc4b694b0c67165d3f288ca /test
parent41a28637807bef9b15c404c93a778aaa6266ace7 (diff)
Merge RubyGems 3.2.26 and Bundler 2.2.26
Diffstat (limited to 'test')
-rw-r--r--test/rubygems/helper.rb6
-rw-r--r--test/rubygems/test_gem.rb324
-rw-r--r--test/rubygems/test_gem_installer.rb2
-rw-r--r--test/rubygems/test_rubygems.rb44
4 files changed, 240 insertions, 136 deletions
diff --git a/test/rubygems/helper.rb b/test/rubygems/helper.rb
index c3befb535f..fd2763db41 100644
--- a/test/rubygems/helper.rb
+++ b/test/rubygems/helper.rb
@@ -1297,7 +1297,11 @@ Also, a list:
end
def ruby_with_rubygems_in_load_path
- [Gem.ruby, "-I", File.expand_path("../../lib", __dir__)]
+ [Gem.ruby, "-I", rubygems_path]
+ end
+
+ def rubygems_path
+ $LOAD_PATH.find{|p| p == File.dirname($LOADED_FEATURES.find{|f| f.end_with?("/rubygems.rb") }) }
end
def with_clean_path_to_ruby
diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb
index 79ea89e2fa..da154dac75 100644
--- a/test/rubygems/test_gem.rb
+++ b/test/rubygems/test_gem.rb
@@ -19,7 +19,6 @@ class TestGem < Gem::TestCase
common_installer_setup
- ENV.delete 'RUBYGEMS_GEMDEPS'
@additional = %w[a b].map {|d| File.join @tempdir, d }
util_remove_interrupt_command
@@ -540,7 +539,6 @@ class TestGem < Gem::TestCase
s.executables = []
end
install_specs spec
- # Should not find a-10's non-abin (bug)
assert_equal @abin_path, Gem.bin_path('a', 'abin')
end
@@ -664,22 +662,22 @@ class TestGem < Gem::TestCase
end
def test_self_use_gemdeps
- rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] = ENV['RUBYGEMS_GEMDEPS'], '-'
+ with_rubygems_gemdeps('-') do
+ FileUtils.mkdir_p 'detect/a/b'
+ FileUtils.mkdir_p 'detect/a/Isolate'
- FileUtils.mkdir_p 'detect/a/b'
- FileUtils.mkdir_p 'detect/a/Isolate'
+ FileUtils.touch 'detect/Isolate'
- FileUtils.touch 'detect/Isolate'
+ begin
+ Dir.chdir 'detect/a/b'
- begin
- Dir.chdir 'detect/a/b'
+ Gem.use_gemdeps
- assert_equal add_bundler_full_name([]), Gem.use_gemdeps.map(&:full_name)
- ensure
- Dir.chdir @tempdir
+ assert_equal add_bundler_full_name([]), loaded_spec_names
+ ensure
+ Dir.chdir @tempdir
+ end
end
- ensure
- ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps
end
def test_self_dir
@@ -1580,6 +1578,31 @@ class TestGem < Gem::TestCase
assert_equal %w[plugin], PLUGINS_LOADED
end
+ def test_load_user_installed_plugins
+ plugin_path = File.join "lib", "rubygems_plugin.rb"
+
+ Dir.chdir @tempdir do
+ FileUtils.mkdir_p 'lib'
+ File.open plugin_path, "w" do |fp|
+ fp.puts "class TestGem; PLUGINS_LOADED << 'plugin'; end"
+ end
+
+ foo = util_spec 'foo', '1' do |s|
+ s.files << plugin_path
+ end
+
+ install_gem_user foo
+ end
+
+ Gem.paths = { "GEM_PATH" => [Gem.dir, Gem.user_dir].join(File::PATH_SEPARATOR) }
+
+ gem 'foo'
+
+ Gem.load_plugins
+
+ assert_equal %w[plugin], PLUGINS_LOADED
+ end
+
def test_load_env_plugins
with_plugin('load') { Gem.load_env_plugins }
assert_equal :loaded, TEST_PLUGIN_LOAD rescue nil
@@ -1689,11 +1712,11 @@ class TestGem < Gem::TestCase
f.puts "gem 'c'"
end
- ENV['RUBYGEMS_GEMDEPS'] = path
-
- Gem.use_gemdeps
+ with_rubygems_gemdeps(path) do
+ Gem.use_gemdeps
- assert_equal add_bundler_full_name(%W[a-1 b-1 c-1]), loaded_spec_names
+ assert_equal add_bundler_full_name(%W[a-1 b-1 c-1]), loaded_spec_names
+ end
end
def test_auto_activation_of_used_gemdeps_file
@@ -1711,10 +1734,13 @@ class TestGem < Gem::TestCase
f.puts "gem 'c'"
end
- ENV['RUBYGEMS_GEMDEPS'] = "-"
+ with_rubygems_gemdeps("-") do
+ expected_specs = [a, b, util_spec("bundler", Bundler::VERSION), c].compact.map(&:full_name)
+
+ Gem.use_gemdeps
- expected_specs = [a, b, util_spec("bundler", Bundler::VERSION), c].compact
- assert_equal expected_specs, Gem.use_gemdeps.sort_by {|s| s.name }
+ assert_equal expected_specs, loaded_spec_names
+ end
end
BUNDLER_LIB_PATH = File.expand_path $LOAD_PATH.find {|lp| File.file?(File.join(lp, "bundler.rb")) }
@@ -1726,10 +1752,18 @@ class TestGem < Gem::TestCase
names
end
- def test_looks_for_gemdeps_files_automatically_on_start
+ def test_looks_for_gemdeps_files_automatically_from_binstubs
pend "Requiring bundler messes things up" if Gem.java_platform?
- a = util_spec "a", "1", nil, "lib/a.rb"
+ a = util_spec "a", "1" do |s|
+ s.executables = %w[foo]
+ s.bindir = "exe"
+ end
+
+ write_file File.join(@tempdir, 'exe', 'foo') do |fp|
+ fp.puts "puts Gem.loaded_specs.values.map(&:full_name).sort"
+ end
+
b = util_spec "b", "1", nil, "lib/b.rb"
c = util_spec "c", "1", nil, "lib/c.rb"
@@ -1741,31 +1775,44 @@ class TestGem < Gem::TestCase
install_gem c, :install_dir => path
ENV['GEM_PATH'] = path
- ENV['RUBYGEMS_GEMDEPS'] = "-"
- path = File.join @tempdir, "gem.deps.rb"
- cmd = [*ruby_with_rubygems_in_load_path,
- "-I#{BUNDLER_LIB_PATH}"]
- cmd << "-eputs Gem.loaded_specs.values.map(&:full_name).sort"
+ with_rubygems_gemdeps("-") do
+ new_PATH = [File.join(path, "bin"), ENV["PATH"]].join(File::PATH_SEPARATOR)
+ new_RUBYOPT = "-I#{rubygems_path} -I#{BUNDLER_LIB_PATH}"
- File.open path, "w" do |f|
- f.puts "gem 'a'"
- end
- out0 = IO.popen(cmd, &:read).split(/\n/)
+ path = File.join @tempdir, "gem.deps.rb"
- File.open path, "a" do |f|
- f.puts "gem 'b'"
- f.puts "gem 'c'"
- end
- out = IO.popen(cmd, &:read).split(/\n/)
+ File.open path, "w" do |f|
+ f.puts "gem 'a'"
+ end
+ out0 = with_path_and_rubyopt(new_PATH, new_RUBYOPT) do
+ IO.popen("foo", &:read).split(/\n/)
+ end
+
+ File.open path, "a" do |f|
+ f.puts "gem 'b'"
+ f.puts "gem 'c'"
+ end
+ out = with_path_and_rubyopt(new_PATH, new_RUBYOPT) do
+ IO.popen("foo", &:read).split(/\n/)
+ end
- assert_equal ["b-1", "c-1"], out - out0
+ assert_equal ["b-1", "c-1"], out - out0
+ end
end
- def test_looks_for_gemdeps_files_automatically_on_start_in_parent_dir
+ def test_looks_for_gemdeps_files_automatically_from_binstubs_in_parent_dir
pend "Requiring bundler messes things up" if Gem.java_platform?
- a = util_spec "a", "1", nil, "lib/a.rb"
+ a = util_spec "a", "1" do |s|
+ s.executables = %w[foo]
+ s.bindir = "exe"
+ end
+
+ write_file File.join(@tempdir, 'exe', 'foo') do |fp|
+ fp.puts "puts Gem.loaded_specs.values.map(&:full_name).sort"
+ end
+
b = util_spec "b", "1", nil, "lib/b.rb"
c = util_spec "c", "1", nil, "lib/c.rb"
@@ -1777,29 +1824,34 @@ class TestGem < Gem::TestCase
install_gem c, :install_dir => path
ENV['GEM_PATH'] = path
- ENV['RUBYGEMS_GEMDEPS'] = "-"
- Dir.mkdir "sub1"
+ with_rubygems_gemdeps("-") do
+ Dir.mkdir "sub1"
- path = File.join @tempdir, "gem.deps.rb"
- cmd = [*ruby_with_rubygems_in_load_path, "-Csub1",
- "-I#{BUNDLER_LIB_PATH}"]
- cmd << "-eputs Gem.loaded_specs.values.map(&:full_name).sort"
+ new_PATH = [File.join(path, "bin"), ENV["PATH"]].join(File::PATH_SEPARATOR)
+ new_RUBYOPT = "-I#{rubygems_path} -I#{BUNDLER_LIB_PATH}"
- File.open path, "w" do |f|
- f.puts "gem 'a'"
- end
- out0 = IO.popen(cmd, &:read).split(/\n/)
+ path = File.join @tempdir, "gem.deps.rb"
- File.open path, "a" do |f|
- f.puts "gem 'b'"
- f.puts "gem 'c'"
- end
- out = IO.popen(cmd, &:read).split(/\n/)
+ File.open path, "w" do |f|
+ f.puts "gem 'a'"
+ end
+ out0 = with_path_and_rubyopt(new_PATH, new_RUBYOPT) do
+ IO.popen("foo", :chdir => "sub1", &:read).split(/\n/)
+ end
+
+ File.open path, "a" do |f|
+ f.puts "gem 'b'"
+ f.puts "gem 'c'"
+ end
+ out = with_path_and_rubyopt(new_PATH, new_RUBYOPT) do
+ IO.popen("foo", :chdir => "sub1", &:read).split(/\n/)
+ end
- Dir.rmdir "sub1"
+ Dir.rmdir "sub1"
- assert_equal ["b-1", "c-1"], out - out0
+ assert_equal ["b-1", "c-1"], out - out0
+ end
end
def test_register_default_spec
@@ -1863,21 +1915,19 @@ class TestGem < Gem::TestCase
end
def test_use_gemdeps_ENV
- rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] = ENV['RUBYGEMS_GEMDEPS'], nil
-
- spec = util_spec 'a', 1
+ with_rubygems_gemdeps(nil) do
+ spec = util_spec 'a', 1
- refute spec.activated?
+ refute spec.activated?
- File.open 'gem.deps.rb', 'w' do |io|
- io.write 'gem "a"'
- end
+ File.open 'gem.deps.rb', 'w' do |io|
+ io.write 'gem "a"'
+ end
- Gem.use_gemdeps
+ Gem.use_gemdeps
- refute spec.activated?
- ensure
- ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps
+ refute spec.activated?
+ end
end
def test_use_gemdeps_argument_missing
@@ -1890,110 +1940,96 @@ class TestGem < Gem::TestCase
end
def test_use_gemdeps_argument_missing_match_ENV
- rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] =
- ENV['RUBYGEMS_GEMDEPS'], 'gem.deps.rb'
+ with_rubygems_gemdeps('gem.deps.rb') do
+ e = assert_raise ArgumentError do
+ Gem.use_gemdeps 'gem.deps.rb'
+ end
- e = assert_raise ArgumentError do
- Gem.use_gemdeps 'gem.deps.rb'
+ assert_equal 'Unable to find gem dependencies file at gem.deps.rb',
+ e.message
end
-
- assert_equal 'Unable to find gem dependencies file at gem.deps.rb',
- e.message
- ensure
- ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps
end
def test_use_gemdeps_automatic
- rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] = ENV['RUBYGEMS_GEMDEPS'], '-'
-
- spec = util_spec 'a', 1
- install_specs spec
- spec = Gem::Specification.find {|s| s == spec }
+ with_rubygems_gemdeps('-') do
+ spec = util_spec 'a', 1
+ install_specs spec
+ spec = Gem::Specification.find {|s| s == spec }
- refute spec.activated?
+ refute spec.activated?
- File.open 'Gemfile', 'w' do |io|
- io.write 'gem "a"'
- end
+ File.open 'Gemfile', 'w' do |io|
+ io.write 'gem "a"'
+ end
- Gem.use_gemdeps
+ Gem.use_gemdeps
- assert_equal add_bundler_full_name(%W[a-1]), loaded_spec_names
- ensure
- ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps
+ assert_equal add_bundler_full_name(%W[a-1]), loaded_spec_names
+ end
end
def test_use_gemdeps_automatic_missing
- rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] = ENV['RUBYGEMS_GEMDEPS'], '-'
+ with_rubygems_gemdeps('-') do
+ Gem.use_gemdeps
- Gem.use_gemdeps
-
- assert true # count
- ensure
- ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps
+ assert true # count
+ end
end
def test_use_gemdeps_disabled
- rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] = ENV['RUBYGEMS_GEMDEPS'], ''
+ with_rubygems_gemdeps('') do
+ spec = util_spec 'a', 1
- spec = util_spec 'a', 1
+ refute spec.activated?
- refute spec.activated?
-
- File.open 'gem.deps.rb', 'w' do |io|
- io.write 'gem "a"'
- end
+ File.open 'gem.deps.rb', 'w' do |io|
+ io.write 'gem "a"'
+ end
- Gem.use_gemdeps
+ Gem.use_gemdeps
- refute spec.activated?
- ensure
- ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps
+ refute spec.activated?
+ end
end
def test_use_gemdeps_missing_gem
- rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] = ENV['RUBYGEMS_GEMDEPS'], 'x'
-
- File.open 'x', 'w' do |io|
- io.write 'gem "a"'
- end
+ with_rubygems_gemdeps('x') do
+ File.open 'x', 'w' do |io|
+ io.write 'gem "a"'
+ end
- expected = <<-EXPECTED
+ expected = <<-EXPECTED
Could not find gem 'a' in locally installed gems.
-The source does not contain any versions of 'a'
-You may need to `gem install -g` to install missing gems
+You may need to `bundle install` to install missing gems
- EXPECTED
+ EXPECTED
- Gem::Deprecate.skip_during do
- actual_stdout, actual_stderr = capture_output do
- Gem.use_gemdeps
+ Gem::Deprecate.skip_during do
+ actual_stdout, actual_stderr = capture_output do
+ Gem.use_gemdeps
+ end
+ assert_empty actual_stdout
+ assert_equal(expected, actual_stderr)
end
- assert_empty actual_stdout
- assert_equal(expected, actual_stderr)
end
- ensure
- ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps
end
def test_use_gemdeps_specific
- rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] = ENV['RUBYGEMS_GEMDEPS'], 'x'
+ with_rubygems_gemdeps('x') do
+ spec = util_spec 'a', 1
+ install_specs spec
- spec = util_spec 'a', 1
- install_specs spec
-
- spec = Gem::Specification.find {|s| s == spec }
- refute spec.activated?
+ spec = Gem::Specification.find {|s| s == spec }
+ refute spec.activated?
- File.open 'x', 'w' do |io|
- io.write 'gem "a"'
- end
+ File.open 'x', 'w' do |io|
+ io.write 'gem "a"'
+ end
- Gem.use_gemdeps
+ Gem.use_gemdeps
- assert_equal add_bundler_full_name(%W[a-1]), loaded_spec_names
- ensure
- ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps
+ assert_equal add_bundler_full_name(%W[a-1]), loaded_spec_names
+ end
end
def test_operating_system_defaults
@@ -2111,4 +2147,22 @@ You may need to `gem install -g` to install missing gems
def util_cache_dir
File.join Gem.dir, "cache"
end
+
+ def with_path_and_rubyopt(path_value, rubyopt_value)
+ path, ENV['PATH'] = ENV['PATH'], path_value
+ rubyopt, ENV['RUBYOPT'] = ENV['RUBYOPT'], rubyopt_value
+
+ yield
+ ensure
+ ENV['PATH'] = path
+ ENV['RUBYOPT'] = rubyopt
+ end
+
+ def with_rubygems_gemdeps(value)
+ rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] = ENV['RUBYGEMS_GEMDEPS'], value
+
+ yield
+ ensure
+ ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps
+ end
end
diff --git a/test/rubygems/test_gem_installer.rb b/test/rubygems/test_gem_installer.rb
index a2b390d639..988f14146d 100644
--- a/test/rubygems/test_gem_installer.rb
+++ b/test/rubygems/test_gem_installer.rb
@@ -33,6 +33,8 @@ class TestGemInstaller < Gem::InstallerTestCase
require 'rubygems'
+Gem.use_gemdeps
+
version = \">= 0.a\"
str = ARGV.first
diff --git a/test/rubygems/test_rubygems.rb b/test/rubygems/test_rubygems.rb
new file mode 100644
index 0000000000..493b9fdf4a
--- /dev/null
+++ b/test/rubygems/test_rubygems.rb
@@ -0,0 +1,44 @@
+require_relative 'helper'
+
+class GemTest < Gem::TestCase
+ def test_rubygems_normal_behaviour
+ _ = Gem::Util.popen(*ruby_with_rubygems_in_load_path, '-e', "'require \"rubygems\"'", {:err => [:child, :out]}).strip
+ assert $?.success?
+ end
+
+ def test_operating_system_other_exceptions
+ pend "does not apply to truffleruby" if RUBY_ENGINE == 'truffleruby'
+
+ path = util_install_operating_system_rb <<-RUBY
+ intentionally_not_implemented_method
+ RUBY
+
+ output = Gem::Util.popen(*ruby_with_rubygems_and_fake_operating_system_in_load_path(path), '-e', "'require \"rubygems\"'", {:err => [:child, :out]}).strip
+ assert !$?.success?
+ assert_includes output, "undefined local variable or method `intentionally_not_implemented_method'"
+ assert_includes output, "Loading the rubygems/defaults/operating_system.rb file caused an error. " \
+ "This file is owned by your OS, not by rubygems upstream. " \
+ "Please find out which OS package this file belongs to and follow the guidelines from your OS to report " \
+ "the problem and ask for help."
+ end
+
+ private
+
+ def util_install_operating_system_rb(content)
+ dir_lib = Dir.mktmpdir("test_operating_system_lib", @tempdir)
+ dir_lib_arg = File.join dir_lib
+
+ dir_lib_rubygems_defaults_arg = File.join dir_lib_arg, "lib", "rubygems", "defaults"
+ FileUtils.mkdir_p dir_lib_rubygems_defaults_arg
+
+ operating_system_rb = File.join dir_lib_rubygems_defaults_arg, "operating_system.rb"
+
+ File.open(operating_system_rb, 'w') {|f| f.write content }
+
+ File.join dir_lib_arg, "lib"
+ end
+
+ def ruby_with_rubygems_and_fake_operating_system_in_load_path(operating_system_path)
+ [Gem.ruby, "-I", operating_system_path, "-I" , $LOAD_PATH.find{|p| p == File.dirname($LOADED_FEATURES.find{|f| f.end_with?("/rubygems.rb") }) }]
+ end
+end