summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorHiroshi SHIBATA <hsbt@ruby-lang.org>2022-04-11 19:45:23 +0900
committernagachika <nagachika@ruby-lang.org>2022-04-12 14:07:25 +0900
commit48be8051ef26dd93e714846d94a2c3794c5b101b (patch)
tree0bae4db96d8723fafd9ad45b8e92467ed11022d2 /test
parente73165c4cd3876435040100b8acab6ffc84f8fa8 (diff)
Merge RubyGems-3.2.33
Diffstat (limited to 'test')
-rw-r--r--test/rubygems/test_gem_command_manager.rb12
-rw-r--r--test/rubygems/test_gem_commands_setup_command.rb17
-rw-r--r--test/rubygems/test_gem_installer.rb42
-rw-r--r--test/rubygems/test_require.rb30
4 files changed, 70 insertions, 31 deletions
diff --git a/test/rubygems/test_gem_command_manager.rb b/test/rubygems/test_gem_command_manager.rb
index 6225576367..ee71fc7c18 100644
--- a/test/rubygems/test_gem_command_manager.rb
+++ b/test/rubygems/test_gem_command_manager.rb
@@ -36,6 +36,18 @@ class TestGemCommandManager < Gem::TestCase
assert_kind_of Gem::Commands::InstallCommand, command
end
+ def test_find_login_alias_command
+ command = @command_manager.find_command 'login'
+
+ assert_kind_of Gem::Commands::SigninCommand, command
+ end
+
+ def test_find_logout_alias_comamnd
+ command = @command_manager.find_command 'logout'
+
+ assert_kind_of Gem::Commands::SignoutCommand, command
+ end
+
def test_find_command_ambiguous_exact
ins_command = Class.new
Gem::Commands.send :const_set, :InsCommand, ins_command
diff --git a/test/rubygems/test_gem_commands_setup_command.rb b/test/rubygems/test_gem_commands_setup_command.rb
index 50f99bc419..5cf94a1dc9 100644
--- a/test/rubygems/test_gem_commands_setup_command.rb
+++ b/test/rubygems/test_gem_commands_setup_command.rb
@@ -156,6 +156,21 @@ class TestGemCommandsSetupCommand < Gem::TestCase
assert_match %r{\A#!\s*#{bin_env}#{ruby_exec}}, File.read(gem_bin_path)
end
+ def test_destdir_flag_does_not_try_to_write_to_the_default_gem_home
+ FileUtils.chmod "-w", File.join(@gemhome, "plugins")
+
+ destdir = File.join(@tempdir, 'foo')
+
+ @cmd.options[:destdir] = destdir
+ @cmd.execute
+
+ spec = Gem::Specification.load("bundler/bundler.gemspec")
+
+ spec.executables.each do |e|
+ assert_path_exist File.join destdir, @gemhome.gsub(/^[a-zA-Z]:/, ''), 'gems', spec.full_name, spec.bindir, e
+ end
+ end
+
def test_files_in
assert_equal %w[rubygems.rb rubygems/requirement.rb rubygems/ssl_certs/rubygems.org/foo.pem],
@cmd.files_in('lib').sort
@@ -245,6 +260,8 @@ class TestGemCommandsSetupCommand < Gem::TestCase
def test_install_default_bundler_gem_with_destdir_flag
@cmd.extend FileUtils
+ FileUtils.chmod "-w", @gemhome
+
destdir = File.join(@tempdir, 'foo')
bin_dir = File.join(destdir, 'bin')
diff --git a/test/rubygems/test_gem_installer.rb b/test/rubygems/test_gem_installer.rb
index 988f14146d..dae2b070d5 100644
--- a/test/rubygems/test_gem_installer.rb
+++ b/test/rubygems/test_gem_installer.rb
@@ -288,6 +288,33 @@ gem 'other', version
"(SyntaxError)", e.message
end
+ def test_ensure_no_race_conditions_between_installing_and_loading_gemspecs
+ a, a_gem = util_gem 'a', 2
+
+ Gem::Installer.at(a_gem).install
+
+ t1 = Thread.new do
+ 5.times do
+ Gem::Installer.at(a_gem).install
+ sleep 0.1
+ end
+ end
+
+ t2 = Thread.new do
+ _, err = capture_output do
+ 20.times do
+ Gem::Specification.load(a.spec_file)
+ Gem::Specification.send(:clear_load_cache)
+ end
+ end
+
+ assert_empty err
+ end
+
+ t1.join
+ t2.join
+ end
+
def test_ensure_loadable_spec_security_policy
pend 'openssl is missing' unless Gem::HAVE_OPENSSL
@@ -948,7 +975,6 @@ gem 'other', version
Gem.pre_install do
assert_path_not_exist cache_file, 'cache file must not exist yet'
- assert_path_not_exist spec_file, 'spec file must not exist yet'
true
end
@@ -956,13 +982,11 @@ gem 'other', version
assert_path_exist gemdir, 'gem install dir must exist'
assert_path_exist rakefile, 'gem executable must exist'
assert_path_not_exist stub_exe, 'gem executable must not exist'
- assert_path_not_exist spec_file, 'spec file must not exist yet'
true
end
Gem.post_install do
assert_path_exist cache_file, 'cache file must exist'
- assert_path_exist spec_file, 'spec file must exist'
end
@newspec = nil
@@ -1237,7 +1261,11 @@ gem 'other', version
end
def test_install_post_build_false
- installer = setup_base_installer
+ @spec = util_spec 'a'
+
+ util_build_gem @spec
+
+ installer = util_installer @spec, @gemhome
Gem.post_build do
false
@@ -1279,7 +1307,11 @@ gem 'other', version
end
def test_install_pre_install_false
- installer = setup_base_installer
+ @spec = util_spec 'a'
+
+ util_build_gem @spec
+
+ installer = util_installer @spec, @gemhome
Gem.pre_install do
false
diff --git a/test/rubygems/test_require.rb b/test/rubygems/test_require.rb
index 4d0301742e..56774116a9 100644
--- a/test/rubygems/test_require.rb
+++ b/test/rubygems/test_require.rb
@@ -24,16 +24,6 @@ class TestGemRequire < Gem::TestCase
end
end
- def setup
- super
-
- @old_loaded_features = $LOADED_FEATURES.dup
- assert_raise LoadError do
- require 'test_gem_require_a'
- end
- $LOADED_FEATURES.replace @old_loaded_features
- end
-
def assert_require(path)
assert require(path), "'#{path}' was already required"
end
@@ -88,8 +78,6 @@ class TestGemRequire < Gem::TestCase
FileUtils.mkdir_p File.dirname c_rb
File.open(c_rb, 'w') {|f| f.write "class Object; HELLO = 'world' end" }
- lp = $LOAD_PATH.dup
-
# Pretend to provide a commandline argument that overrides a file in gem b
$LOAD_PATH.unshift dash_i_arg
@@ -98,7 +86,6 @@ class TestGemRequire < Gem::TestCase
assert_equal "world", ::Object::HELLO
assert_equal %w[a-1 b-1], loaded_spec_names
ensure
- $LOAD_PATH.replace lp
Object.send :remove_const, :HELLO if Object.const_defined? :HELLO
end
@@ -132,8 +119,6 @@ class TestGemRequire < Gem::TestCase
assert_require 'test_gem_require_a'
- lp = $LOAD_PATH.dup
-
# Pretend to provide a commandline argument that overrides a file in gem b
$LOAD_PATH.unshift dash_i_arg
@@ -142,7 +127,6 @@ class TestGemRequire < Gem::TestCase
assert_equal "world", ::Object::HELLO
assert_equal %w[a-1 b-1], loaded_spec_names
ensure
- $LOAD_PATH.replace lp
Object.send :remove_const, :HELLO if Object.const_defined? :HELLO
end
@@ -153,16 +137,10 @@ class TestGemRequire < Gem::TestCase
dash_i_ext_arg = util_install_extension_file('a')
dash_i_lib_arg = util_install_ruby_file('a')
- lp = $LOAD_PATH.dup
-
- begin
- $LOAD_PATH.unshift dash_i_lib_arg
- $LOAD_PATH.unshift dash_i_ext_arg
- assert_require 'a'
- assert_match(/a\.rb$/, $LOADED_FEATURES.last)
- ensure
- $LOAD_PATH.replace lp
- end
+ $LOAD_PATH.unshift dash_i_lib_arg
+ $LOAD_PATH.unshift dash_i_ext_arg
+ assert_require 'a'
+ assert_match(/a\.rb$/, $LOADED_FEATURES.last)
end
def test_concurrent_require