From 7112c6a1c15b26eebf0c020dfee7abd30eebde2d Mon Sep 17 00:00:00 2001 From: hsbt Date: Tue, 6 Feb 2018 02:58:35 +0000 Subject: Merge RubyGems-2.7.5 from upstream. Please see its details: http://blog.rubygems.org/2018/02/06/2.7.5-released.html git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62244 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/rubygems/test_gem.rb | 16 +++--- test/rubygems/test_gem_commands_cleanup_command.rb | 2 +- test/rubygems/test_gem_commands_install_command.rb | 2 +- test/rubygems/test_gem_commands_push_command.rb | 10 ++-- test/rubygems/test_gem_commands_setup_command.rb | 59 ++++++++++++++-------- .../test_gem_commands_uninstall_command.rb | 4 +- test/rubygems/test_gem_dependency_installer.rb | 2 +- test/rubygems/test_gem_doctor.rb | 4 +- test/rubygems/test_gem_ext_builder.rb | 12 ++--- test/rubygems/test_gem_gemcutter_utilities.rb | 8 +-- test/rubygems/test_gem_indexer.rb | 3 +- test/rubygems/test_gem_install_update_options.rb | 2 +- test/rubygems/test_gem_installer.rb | 6 +-- test/rubygems/test_gem_package.rb | 30 +++++------ test/rubygems/test_gem_package_old.rb | 2 +- test/rubygems/test_gem_rdoc.rb | 4 +- test/rubygems/test_gem_remote_fetcher.rb | 2 +- test/rubygems/test_gem_request_set.rb | 14 ++--- test/rubygems/test_gem_request_set_lockfile.rb | 8 +-- .../test_gem_request_set_lockfile_parser.rb | 2 +- .../test_gem_request_set_lockfile_tokenizer.rb | 2 +- .../test_gem_resolver_git_specification.rb | 2 +- test/rubygems/test_gem_server.rb | 8 +-- test/rubygems/test_gem_source.rb | 6 +-- test/rubygems/test_gem_source_git.rb | 2 +- test/rubygems/test_gem_specification.rb | 36 ++++++------- test/rubygems/test_gem_stub_specification.rb | 14 ++--- test/rubygems/test_gem_util.rb | 24 ++++++++- test/rubygems/test_gem_version.rb | 11 ++++ test/rubygems/test_require.rb | 14 ++--- 30 files changed, 182 insertions(+), 129 deletions(-) (limited to 'test/rubygems') diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb index bd4c91d96d..183771f0f3 100644 --- a/test/rubygems/test_gem.rb +++ b/test/rubygems/test_gem.rb @@ -463,7 +463,7 @@ class TestGem < Gem::TestCase assert File.directory?(util_cache_dir) end - unless win_platform? || Process.uid == 0 then # only for FS that support write protection + unless win_platform? || Process.uid.zero? then # only for FS that support write protection def test_self_ensure_gem_directories_write_protected gemdir = File.join @tempdir, "egd" FileUtils.rm_r gemdir rescue nil @@ -775,7 +775,7 @@ class TestGem < Gem::TestCase end def test_self_read_binary - open 'test', 'w' do |io| + File.open 'test', 'w' do |io| io.write "\xCF\x80" end @@ -1642,7 +1642,7 @@ class TestGem < Gem::TestCase spec = Gem::Specification.find { |s| s == spec } refute spec.activated? - open gem_deps_file, 'w' do |io| + File.open gem_deps_file, 'w' do |io| io.write 'gem "a"' end @@ -1661,7 +1661,7 @@ class TestGem < Gem::TestCase refute spec.activated? - open 'gem.deps.rb', 'w' do |io| + File.open 'gem.deps.rb', 'w' do |io| io.write 'gem "a"' end @@ -1705,7 +1705,7 @@ class TestGem < Gem::TestCase refute spec.activated? - open 'Gemfile', 'w' do |io| + File.open 'Gemfile', 'w' do |io| io.write 'gem "a"' end @@ -1734,7 +1734,7 @@ class TestGem < Gem::TestCase refute spec.activated? - open 'gem.deps.rb', 'w' do |io| + File.open 'gem.deps.rb', 'w' do |io| io.write 'gem "a"' end @@ -1749,7 +1749,7 @@ class TestGem < Gem::TestCase skip 'Insecure operation - read' if RUBY_VERSION <= "1.8.7" rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] = ENV['RUBYGEMS_GEMDEPS'], 'x' - open 'x', 'w' do |io| + File.open 'x', 'w' do |io| io.write 'gem "a"' end @@ -1790,7 +1790,7 @@ You may need to `gem install -g` to install missing gems spec = Gem::Specification.find { |s| s == spec } refute spec.activated? - open 'x', 'w' do |io| + File.open 'x', 'w' do |io| io.write 'gem "a"' end diff --git a/test/rubygems/test_gem_commands_cleanup_command.rb b/test/rubygems/test_gem_commands_cleanup_command.rb index a222659ead..60d208fcc0 100644 --- a/test/rubygems/test_gem_commands_cleanup_command.rb +++ b/test/rubygems/test_gem_commands_cleanup_command.rb @@ -158,7 +158,7 @@ class TestGemCommandsCleanupCommand < Gem::TestCase assert_path_exists @a_1_1.gem_dir ensure FileUtils.chmod 0755, @gemhome - end unless win_platform? || Process.uid == 0 + end unless win_platform? || Process.uid.zero? def test_execute_dry_run @cmd.options[:args] = %w[a] diff --git a/test/rubygems/test_gem_commands_install_command.rb b/test/rubygems/test_gem_commands_install_command.rb index fefc5c7059..822d40e3f3 100644 --- a/test/rubygems/test_gem_commands_install_command.rb +++ b/test/rubygems/test_gem_commands_install_command.rb @@ -131,7 +131,7 @@ class TestGemCommandsInstallCommand < Gem::TestCase def test_execute_no_user_install skip 'skipped on MS Windows (chmod has no effect)' if win_platform? - skip 'skipped in root privilege' if Process.uid == 0 + skip 'skipped in root privilege' if Process.uid.zero? specs = spec_fetcher do |fetcher| fetcher.gem 'a', 2 diff --git a/test/rubygems/test_gem_commands_push_command.rb b/test/rubygems/test_gem_commands_push_command.rb index b888a741f0..1c5dbfe23e 100644 --- a/test/rubygems/test_gem_commands_push_command.rb +++ b/test/rubygems/test_gem_commands_push_command.rb @@ -132,7 +132,7 @@ class TestGemCommandsPushCommand < Gem::TestCase } FileUtils.mkdir_p File.dirname Gem.configuration.credentials_path - open Gem.configuration.credentials_path, 'w' do |f| + File.open Gem.configuration.credentials_path, 'w' do |f| f.write keys.to_yaml end Gem.configuration.load_api_keys @@ -166,7 +166,7 @@ class TestGemCommandsPushCommand < Gem::TestCase } FileUtils.mkdir_p File.dirname Gem.configuration.credentials_path - open Gem.configuration.credentials_path, 'w' do |f| + File.open Gem.configuration.credentials_path, 'w' do |f| f.write keys.to_yaml end Gem.configuration.load_api_keys @@ -193,7 +193,7 @@ class TestGemCommandsPushCommand < Gem::TestCase } FileUtils.mkdir_p File.dirname Gem.configuration.credentials_path - open Gem.configuration.credentials_path, 'w' do |f| + File.open Gem.configuration.credentials_path, 'w' do |f| f.write keys.to_yaml end Gem.configuration.load_api_keys @@ -235,7 +235,7 @@ class TestGemCommandsPushCommand < Gem::TestCase } FileUtils.mkdir_p File.dirname Gem.configuration.credentials_path - open Gem.configuration.credentials_path, 'w' do |f| + File.open Gem.configuration.credentials_path, 'w' do |f| f.write keys.to_yaml end Gem.configuration.load_api_keys @@ -266,7 +266,7 @@ class TestGemCommandsPushCommand < Gem::TestCase } FileUtils.mkdir_p File.dirname Gem.configuration.credentials_path - open Gem.configuration.credentials_path, 'w' do |f| + File.open Gem.configuration.credentials_path, 'w' do |f| f.write keys.to_yaml end Gem.configuration.load_api_keys diff --git a/test/rubygems/test_gem_commands_setup_command.rb b/test/rubygems/test_gem_commands_setup_command.rb index 2136edb1be..9fdf428501 100644 --- a/test/rubygems/test_gem_commands_setup_command.rb +++ b/test/rubygems/test_gem_commands_setup_command.rb @@ -6,6 +6,8 @@ require 'rubygems/commands/setup_command' class TestGemCommandsSetupCommand < Gem::TestCase + BUNDLER_VERS = `gem list -e bundler`[/([^() ]+)\)\Z/, 1] || "1.16.1" + def setup super @@ -16,27 +18,27 @@ class TestGemCommandsSetupCommand < Gem::TestCase FileUtils.mkdir_p 'bin' FileUtils.mkdir_p 'lib/rubygems/ssl_certs/rubygems.org' - open 'bin/gem', 'w' do |io| io.puts '# gem' end - open 'lib/rubygems.rb', 'w' do |io| io.puts '# rubygems.rb' end - open 'lib/rubygems/test_case.rb', 'w' do |io| io.puts '# test_case.rb' end - open 'lib/rubygems/ssl_certs/rubygems.org/foo.pem', 'w' do |io| io.puts 'PEM' end + File.open 'bin/gem', 'w' do |io| io.puts '# gem' end + File.open 'lib/rubygems.rb', 'w' do |io| io.puts '# rubygems.rb' end + File.open 'lib/rubygems/test_case.rb', 'w' do |io| io.puts '# test_case.rb' end + File.open 'lib/rubygems/ssl_certs/rubygems.org/foo.pem', 'w' do |io| io.puts 'PEM' end FileUtils.mkdir_p 'bundler/exe' FileUtils.mkdir_p 'bundler/lib/bundler' - open 'bundler/exe/bundle', 'w' do |io| io.puts '# bundle' end - open 'bundler/lib/bundler.rb', 'w' do |io| io.puts '# bundler.rb' end - open 'bundler/lib/bundler/b.rb', 'w' do |io| io.puts '# b.rb' end + File.open 'bundler/exe/bundle', 'w' do |io| io.puts '# bundle' end + File.open 'bundler/lib/bundler.rb', 'w' do |io| io.puts '# bundler.rb' end + File.open 'bundler/lib/bundler/b.rb', 'w' do |io| io.puts '# b.rb' end FileUtils.mkdir_p 'default/gems' gemspec = Gem::Specification.new gemspec.name = "bundler" - gemspec.version = "1.16.0" + gemspec.version = BUNDLER_VERS gemspec.bindir = "exe" gemspec.executables = ["bundle"] - open 'bundler/bundler.gemspec', 'w' do |io| + File.open 'bundler/bundler.gemspec', 'w' do |io| io.puts gemspec.to_ruby end @@ -46,6 +48,11 @@ class TestGemCommandsSetupCommand < Gem::TestCase end FileUtils.mkdir_p File.join(Gem.default_dir, "specifications") + + open(File.join(Gem.default_dir, "specifications", "bundler-#{BUNDLER_VERS}.gemspec"), 'w') do |io| + io.puts "# bundler-#{BUNDLER_VERS}" + end + open(File.join(Gem.default_dir, "specifications", "bundler-audit-1.0.0.gemspec"), 'w') do |io| io.puts '# bundler-audit' end @@ -134,13 +141,25 @@ class TestGemCommandsSetupCommand < Gem::TestCase default_dir = Gem::Specification.default_specifications_dir + # expect to remove other versions of bundler gemspecs on default specification directory. refute_path_exists File.join(default_dir, "bundler-1.15.4.gemspec") - refute_path_exists 'default/gems/bundler-1.15.4' - - assert_path_exists File.join(default_dir, "bundler-1.16.0.gemspec") - assert_path_exists 'default/gems/bundler-1.16.0' + assert_path_exists File.join(default_dir, "bundler-#{BUNDLER_VERS}.gemspec") + # expect to not remove bundler-* gemspecs. assert_path_exists File.join(Gem.default_dir, "specifications", "bundler-audit-1.0.0.gemspec") + + # expect to remove normal gem that was same version. because it's promoted default gems. + refute_path_exists File.join(Gem.default_dir, "specifications", "bundler-#{BUNDLER_VERS}.gemspec") + + # expect to install default gems. It location was `site_ruby` directory on real world. + assert_path_exists "default/gems/bundler-#{BUNDLER_VERS}" + + # expect to not remove other versions of bundler on `site_ruby` + assert_path_exists 'default/gems/bundler-1.15.4' + + # TODO: We need to assert to remove same version of bundler on gem_dir directory(It's not site_ruby dir) + + # expect to not remove bundler-* direcotyr. assert_path_exists 'default/gems/bundler-audit-1.0.0' end if Gem::USE_BUNDLER_FOR_GEMDEPS @@ -162,14 +181,14 @@ class TestGemCommandsSetupCommand < Gem::TestCase FileUtils.mkdir_p lib_rubygems_defaults FileUtils.mkdir_p lib_bundler - open securerandom_rb, 'w' do |io| io.puts '# securerandom.rb' end + File.open securerandom_rb, 'w' do |io| io.puts '# securerandom.rb' end - open old_builder_rb, 'w' do |io| io.puts '# builder.rb' end - open old_format_rb, 'w' do |io| io.puts '# format.rb' end - open old_bundler_c_rb, 'w' do |io| io.puts '# c.rb' end + File.open old_builder_rb, 'w' do |io| io.puts '# builder.rb' end + File.open old_format_rb, 'w' do |io| io.puts '# format.rb' end + File.open old_bundler_c_rb, 'w' do |io| io.puts '# c.rb' end - open engine_defaults_rb, 'w' do |io| io.puts '# jruby.rb' end - open os_defaults_rb, 'w' do |io| io.puts '# operating_system.rb' end + File.open engine_defaults_rb, 'w' do |io| io.puts '# jruby.rb' end + File.open os_defaults_rb, 'w' do |io| io.puts '# operating_system.rb' end @cmd.remove_old_lib_files lib @@ -191,7 +210,7 @@ class TestGemCommandsSetupCommand < Gem::TestCase @cmd.options[:previous_version] = Gem::Version.new '2.0.2' - open 'History.txt', 'w' do |io| + File.open 'History.txt', 'w' do |io| io.puts <<-History_txt # coding: UTF-8 diff --git a/test/rubygems/test_gem_commands_uninstall_command.rb b/test/rubygems/test_gem_commands_uninstall_command.rb index 2097ca7d43..2fdff706e7 100644 --- a/test/rubygems/test_gem_commands_uninstall_command.rb +++ b/test/rubygems/test_gem_commands_uninstall_command.rb @@ -92,7 +92,7 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase # Evil hack to prevent false removal success FileUtils.rm_f @executable - open @executable, "wb+" do |f| f.puts "binary" end + File.open @executable, "wb+" do |f| f.puts "binary" end @cmd.options[:executables] = true @cmd.options[:args] = [@spec.name] @@ -204,7 +204,7 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase end assert Gem::Specification.find_all_by_name('dep_x').length > 0 - assert Gem::Specification.find_all_by_name('x').length == 0 + assert Gem::Specification.find_all_by_name('x').length.zero? end def test_execute_all diff --git a/test/rubygems/test_gem_dependency_installer.rb b/test/rubygems/test_gem_dependency_installer.rb index e55cc75682..3d76291668 100644 --- a/test/rubygems/test_gem_dependency_installer.rb +++ b/test/rubygems/test_gem_dependency_installer.rb @@ -424,7 +424,7 @@ class TestGemDependencyInstaller < Gem::TestCase extconf_rb = File.join @gemhome, 'gems', 'e-1', 'extconf.rb' FileUtils.mkdir_p File.dirname extconf_rb - open extconf_rb, 'w' do |io| + File.open extconf_rb, 'w' do |io| io.write <<-EXTCONF_RB require 'mkmf' create_makefile 'e' diff --git a/test/rubygems/test_gem_doctor.rb b/test/rubygems/test_gem_doctor.rb index 39b8a11692..8db65d70ce 100644 --- a/test/rubygems/test_gem_doctor.rb +++ b/test/rubygems/test_gem_doctor.rb @@ -24,7 +24,7 @@ class TestGemDoctor < Gem::TestCase FileUtils.rm b.spec_file - open c.spec_file, 'w' do |io| + File.open c.spec_file, 'w' do |io| io.write 'this will raise an exception when evaluated.' end @@ -77,7 +77,7 @@ Removed directory gems/c-2 FileUtils.rm b.spec_file - open c.spec_file, 'w' do |io| + File.open c.spec_file, 'w' do |io| io.write 'this will raise an exception when evaluated.' end diff --git a/test/rubygems/test_gem_ext_builder.rb b/test/rubygems/test_gem_ext_builder.rb index d142ef28da..3dabd3e350 100644 --- a/test/rubygems/test_gem_ext_builder.rb +++ b/test/rubygems/test_gem_ext_builder.rb @@ -32,7 +32,7 @@ class TestGemExtBuilder < Gem::TestCase results = [] Dir.chdir @ext do - open 'Makefile', 'w' do |io| + File.open 'Makefile', 'w' do |io| io.puts <<-MAKEFILE all: \t@#{Gem.ruby} -e "puts %Q{all: \#{ENV['DESTDIR']}}" @@ -72,7 +72,7 @@ install: results = [] Dir.chdir @ext do - open 'Makefile', 'w' do |io| + File.open 'Makefile', 'w' do |io| io.puts <<-MAKEFILE all: \t@#{Gem.ruby} -e "puts %Q{all: \#{ENV['DESTDIR']}}" @@ -107,7 +107,7 @@ install: extconf_rb = File.join ext_dir, 'extconf.rb' - open extconf_rb, 'w' do |f| + File.open extconf_rb, 'w' do |f| f.write <<-'RUBY' require 'mkmf' @@ -168,7 +168,7 @@ install: extconf_rb = File.join ext_dir, 'extconf.rb' - open extconf_rb, 'w' do |f| + File.open extconf_rb, 'w' do |f| f.write <<-'RUBY' require 'mkmf' @@ -290,7 +290,7 @@ install: FileUtils.mkdir_p @spec.gem_dir - open File.join(@spec.gem_dir, "extconf.rb"), "w" do |f| + File.open File.join(@spec.gem_dir, "extconf.rb"), "w" do |f| f.write <<-'RUBY' puts "IN EXTCONF" extconf_args = File.join File.dirname(__FILE__), 'extconf_args' @@ -323,7 +323,7 @@ install: build_info_file = File.join build_info_dir, "#{@spec.full_name}.info" - open build_info_file, 'w' do |io| + File.open build_info_file, 'w' do |io| io.puts '--with-foo-dir=/nonexistent' end diff --git a/test/rubygems/test_gem_gemcutter_utilities.rb b/test/rubygems/test_gem_gemcutter_utilities.rb index c3f9a7ea18..286d59a787 100644 --- a/test/rubygems/test_gem_gemcutter_utilities.rb +++ b/test/rubygems/test_gem_gemcutter_utilities.rb @@ -31,7 +31,7 @@ class TestGemGemcutterUtilities < Gem::TestCase FileUtils.mkdir_p File.dirname Gem.configuration.credentials_path - open Gem.configuration.credentials_path, 'w' do |f| + File.open Gem.configuration.credentials_path, 'w' do |f| f.write keys.to_yaml end @@ -46,7 +46,7 @@ class TestGemGemcutterUtilities < Gem::TestCase keys = { :rubygems_api_key => 'KEY' } FileUtils.mkdir_p File.dirname Gem.configuration.credentials_path - open Gem.configuration.credentials_path, 'w' do |f| + File.open Gem.configuration.credentials_path, 'w' do |f| f.write keys.to_yaml end @@ -59,7 +59,7 @@ class TestGemGemcutterUtilities < Gem::TestCase keys = { :rubygems_api_key => 'KEY', :other => 'OTHER' } FileUtils.mkdir_p File.dirname Gem.configuration.credentials_path - open Gem.configuration.credentials_path, 'w' do |f| + File.open Gem.configuration.credentials_path, 'w' do |f| f.write keys.to_yaml end @@ -163,7 +163,7 @@ class TestGemGemcutterUtilities < Gem::TestCase other_api_key = 'f46dbb18bb6a9c97cdc61b5b85c186a17403cdcbf' FileUtils.mkdir_p File.dirname(Gem.configuration.credentials_path) - open Gem.configuration.credentials_path, 'w' do |f| + File.open Gem.configuration.credentials_path, 'w' do |f| f.write Hash[:other_api_key, other_api_key].to_yaml end util_sign_in [api_key, 200, 'OK'] diff --git a/test/rubygems/test_gem_indexer.rb b/test/rubygems/test_gem_indexer.rb index a4a966e8de..5a9075e676 100644 --- a/test/rubygems/test_gem_indexer.rb +++ b/test/rubygems/test_gem_indexer.rb @@ -39,8 +39,7 @@ class TestGemIndexer < Gem::TestCase def test_initialize assert_equal @tempdir, @indexer.dest_directory - assert_equal File.join(Dir.tmpdir, "gem_generate_index_#{$$}"), - @indexer.directory + assert_match %r{#{Dir.mktmpdir('gem_generate_index').match(/.*-/)}}, @indexer.directory indexer = Gem::Indexer.new @tempdir assert indexer.build_modern diff --git a/test/rubygems/test_gem_install_update_options.rb b/test/rubygems/test_gem_install_update_options.rb index 69a2b61041..371e408d27 100644 --- a/test/rubygems/test_gem_install_update_options.rb +++ b/test/rubygems/test_gem_install_update_options.rb @@ -141,7 +141,7 @@ class TestGemInstallUpdateOptions < Gem::InstallerTestCase def test_user_install_disabled_read_only if win_platform? skip('test_user_install_disabled_read_only test skipped on MS Windows') - elsif Process.uid == 0 + elsif Process.uid.zero? skip('test_user_install_disabled_read_only test skipped in root privilege') else @cmd.handle_options %w[--no-user-install] diff --git a/test/rubygems/test_gem_installer.rb b/test/rubygems/test_gem_installer.rb index 63acc3d130..93b0482407 100644 --- a/test/rubygems/test_gem_installer.rb +++ b/test/rubygems/test_gem_installer.rb @@ -140,7 +140,7 @@ end s.require_path = 'lib' end - open File.join(util_inst_bindir, 'executable'), 'w' do |io| + File.open File.join(util_inst_bindir, 'executable'), 'w' do |io| io.write <<-EXEC #!/usr/local/bin/ruby # @@ -437,7 +437,7 @@ gem 'other', version if win_platform? skip('test_generate_bin_script_no_perms skipped on MS Windows') - elsif Process.uid == 0 + elsif Process.uid.zero? skip('test_generate_bin_script_no_perms skipped in root privilege') else FileUtils.chmod 0000, util_inst_bindir @@ -531,7 +531,7 @@ gem 'other', version if win_platform? skip('test_generate_bin_symlink_no_perms skipped on MS Windows') - elsif Process.uid == 0 + elsif Process.uid.zero? skip('test_user_install_disabled_read_only test skipped in root privilege') else FileUtils.chmod 0000, util_inst_bindir diff --git a/test/rubygems/test_gem_package.rb b/test/rubygems/test_gem_package.rb index cec1981c4c..936df60522 100644 --- a/test/rubygems/test_gem_package.rb +++ b/test/rubygems/test_gem_package.rb @@ -24,7 +24,7 @@ class TestGemPackage < Gem::Package::TarTestCase end def test_class_new_old_format - open 'old_format.gem', 'wb' do |io| + File.open 'old_format.gem', 'wb' do |io| io.write SIMPLE_GEM end @@ -45,7 +45,7 @@ class TestGemPackage < Gem::Package::TarTestCase FileUtils.mkdir 'lib' - open 'lib/code.rb', 'w' do |io| + File.open 'lib/code.rb', 'w' do |io| io.write '# lib/code.rb' end @@ -110,8 +110,8 @@ class TestGemPackage < Gem::Package::TarTestCase FileUtils.mkdir_p 'lib/empty' - open 'lib/code.rb', 'w' do |io| io.write '# lib/code.rb' end - open 'lib/extra.rb', 'w' do |io| io.write '# lib/extra.rb' end + File.open 'lib/code.rb', 'w' do |io| io.write '# lib/code.rb' end + File.open 'lib/extra.rb', 'w' do |io| io.write '# lib/extra.rb' end package = Gem::Package.new 'bogus.gem' package.spec = spec @@ -140,7 +140,7 @@ class TestGemPackage < Gem::Package::TarTestCase spec.files = %w[lib/code.rb lib/code_sym.rb] FileUtils.mkdir_p 'lib' - open 'lib/code.rb', 'w' do |io| io.write '# lib/code.rb' end + File.open 'lib/code.rb', 'w' do |io| io.write '# lib/code.rb' end # NOTE: 'code.rb' is correct, because it's relative to lib/code_sym.rb File.symlink('code.rb', 'lib/code_sym.rb') @@ -179,7 +179,7 @@ class TestGemPackage < Gem::Package::TarTestCase FileUtils.mkdir 'lib' - open 'lib/code.rb', 'w' do |io| + File.open 'lib/code.rb', 'w' do |io| io.write '# lib/code.rb' end @@ -218,7 +218,7 @@ class TestGemPackage < Gem::Package::TarTestCase FileUtils.mkdir 'lib' - open 'lib/code.rb', 'w' do |io| + File.open 'lib/code.rb', 'w' do |io| io.write '# lib/code.rb' end @@ -261,7 +261,7 @@ class TestGemPackage < Gem::Package::TarTestCase FileUtils.mkdir 'lib' - open 'lib/code.rb', 'w' do |io| + File.open 'lib/code.rb', 'w' do |io| io.write '# lib/code.rb' end @@ -311,7 +311,7 @@ class TestGemPackage < Gem::Package::TarTestCase FileUtils.mkdir 'lib' - open 'lib/code.rb', 'w' do |io| + File.open 'lib/code.rb', 'w' do |io| io.write '# lib/code.rb' end @@ -348,7 +348,7 @@ class TestGemPackage < Gem::Package::TarTestCase FileUtils.mkdir 'lib' - open 'lib/code.rb', 'w' do |io| + File.open 'lib/code.rb', 'w' do |io| io.write '# lib/code.rb' end @@ -408,7 +408,7 @@ class TestGemPackage < Gem::Package::TarTestCase end end - open 'empty.gem', 'wb' do |io| + File.open 'empty.gem', 'wb' do |io| io.write gem.string end @@ -620,7 +620,7 @@ class TestGemPackage < Gem::Package::TarTestCase end end - open 'mismatch.gem', 'wb' do |io| + File.open 'mismatch.gem', 'wb' do |io| io.write gem.string end @@ -670,7 +670,7 @@ class TestGemPackage < Gem::Package::TarTestCase end end - open 'data_checksum_missing.gem', 'wb' do |io| + File.open 'data_checksum_missing.gem', 'wb' do |io| io.write gem.string end @@ -773,7 +773,7 @@ class TestGemPackage < Gem::Package::TarTestCase FileUtils.mkdir 'lib' FileUtils.touch 'lib/code.rb' - open @gem, 'wb' do |gem_io| + File.open @gem, 'wb' do |gem_io| Gem::Package::TarWriter.new gem_io do |gem| build.add_metadata gem build.add_contents gem @@ -804,7 +804,7 @@ class TestGemPackage < Gem::Package::TarTestCase end def test_verify_truncate - open 'bad.gem', 'wb' do |io| + File.open 'bad.gem', 'wb' do |io| io.write File.read(@gem, 1024) # don't care about newlines end diff --git a/test/rubygems/test_gem_package_old.rb b/test/rubygems/test_gem_package_old.rb index c15475b0c7..604981b3c1 100644 --- a/test/rubygems/test_gem_package_old.rb +++ b/test/rubygems/test_gem_package_old.rb @@ -7,7 +7,7 @@ class TestGemPackageOld < Gem::TestCase def setup super - open 'old_format.gem', 'wb' do |io| + File.open 'old_format.gem', 'wb' do |io| io.write SIMPLE_GEM end diff --git a/test/rubygems/test_gem_rdoc.rb b/test/rubygems/test_gem_rdoc.rb index 3961a8e3f9..0355883cb3 100644 --- a/test/rubygems/test_gem_rdoc.rb +++ b/test/rubygems/test_gem_rdoc.rb @@ -223,7 +223,7 @@ class TestGemRDoc < Gem::TestCase def test_remove_unwritable skip 'chmod not supported' if Gem.win_platform? - skip 'skipped in root privilege' if Process.uid == 0 + skip 'skipped in root privilege' if Process.uid.zero? FileUtils.mkdir_p @a.base_dir FileUtils.chmod 0, @a.base_dir @@ -252,7 +252,7 @@ class TestGemRDoc < Gem::TestCase def test_setup_unwritable skip 'chmod not supported' if Gem.win_platform? - skip 'skipped in root privilege' if Process.uid == 0 + skip 'skipped in root privilege' if Process.uid.zero? FileUtils.mkdir_p @a.doc_dir FileUtils.chmod 0, @a.doc_dir diff --git a/test/rubygems/test_gem_remote_fetcher.rb b/test/rubygems/test_gem_remote_fetcher.rb index fc51b06f1b..20e34e84e1 100644 --- a/test/rubygems/test_gem_remote_fetcher.rb +++ b/test/rubygems/test_gem_remote_fetcher.rb @@ -431,7 +431,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg== assert File.exist?(a1_cache_gem) end - unless win_platform? || Process.uid == 0 # File.chmod doesn't work + unless win_platform? || Process.uid.zero? # File.chmod doesn't work def test_download_local_read_only FileUtils.mv @a1_gem, @tempdir local_path = File.join @tempdir, @a1.file_name diff --git a/test/rubygems/test_gem_request_set.rb b/test/rubygems/test_gem_request_set.rb index 3a48827481..5dc6c1518d 100644 --- a/test/rubygems/test_gem_request_set.rb +++ b/test/rubygems/test_gem_request_set.rb @@ -52,7 +52,7 @@ class TestGemRequestSet < Gem::TestCase rs = Gem::RequestSet.new installed = [] - open 'gem.deps.rb', 'w' do |io| + File.open 'gem.deps.rb', 'w' do |io| io.puts 'gem "a"' io.flush @@ -78,7 +78,7 @@ class TestGemRequestSet < Gem::TestCase rs = Gem::RequestSet.new - open 'gem.deps.rb', 'w' do |io| + File.open 'gem.deps.rb', 'w' do |io| io.puts 'gem "a"' io.flush @@ -104,7 +104,7 @@ Gems to install: rs = Gem::RequestSet.new installed = [] - open 'gem.deps.rb', 'w' do |io| + File.open 'gem.deps.rb', 'w' do |io| io.puts 'gem "a"' end @@ -128,7 +128,7 @@ Gems to install: rs = Gem::RequestSet.new - open 'gem.deps.rb', 'w' do |io| + File.open 'gem.deps.rb', 'w' do |io| io.puts 'gem "a"' io.flush @@ -150,7 +150,7 @@ Gems to install: rs = Gem::RequestSet.new installed = [] - open 'gem.deps.rb.lock', 'w' do |io| + File.open 'gem.deps.rb.lock', 'w' do |io| io.puts <<-LOCKFILE GEM remote: #{@gem_repo} @@ -167,7 +167,7 @@ DEPENDENCIES LOCKFILE end - open 'gem.deps.rb', 'w' do |io| + File.open 'gem.deps.rb', 'w' do |io| io.puts 'gem "b"' end @@ -190,7 +190,7 @@ DEPENDENCIES rs = Gem::RequestSet.new installed = [] - open 'gem.deps.rb', 'w' do |io| + File.open 'gem.deps.rb', 'w' do |io| io.puts <<-GEM_DEPS gem "a" ruby "0" diff --git a/test/rubygems/test_gem_request_set_lockfile.rb b/test/rubygems/test_gem_request_set_lockfile.rb index 908f97303e..7460b7efad 100644 --- a/test/rubygems/test_gem_request_set_lockfile.rb +++ b/test/rubygems/test_gem_request_set_lockfile.rb @@ -31,7 +31,7 @@ class TestGemRequestSetLockfile < Gem::TestCase def write_lockfile lockfile @lock_file = File.expand_path "#{@gem_deps_file}.lock" - open @lock_file, 'w' do |io| + File.open @lock_file, 'w' do |io| io.write lockfile end end @@ -387,7 +387,7 @@ DEPENDENCIES s.add_dependency 'c', '~> 1.0' end - open 'b.gemspec', 'w' do |io| + File.open 'b.gemspec', 'w' do |io| io.write b.to_ruby end @@ -400,7 +400,7 @@ DEPENDENCIES Dir.chdir 'c' do c = Gem::Specification.new 'c', 1 - open 'c.gemspec', 'w' do |io| + File.open 'c.gemspec', 'w' do |io| io.write c.to_ruby end @@ -455,7 +455,7 @@ DEPENDENCIES gem_deps_lock_file = "#{@gem_deps_file}.lock" - open gem_deps_lock_file, 'w' do |io| + File.open gem_deps_lock_file, 'w' do |io| io.write 'hello' end diff --git a/test/rubygems/test_gem_request_set_lockfile_parser.rb b/test/rubygems/test_gem_request_set_lockfile_parser.rb index 9946c522d9..f3517da43a 100644 --- a/test/rubygems/test_gem_request_set_lockfile_parser.rb +++ b/test/rubygems/test_gem_request_set_lockfile_parser.rb @@ -536,7 +536,7 @@ DEPENDENCIES end def write_lockfile lockfile - open @lock_file, 'w' do |io| + File.open @lock_file, 'w' do |io| io.write lockfile end end diff --git a/test/rubygems/test_gem_request_set_lockfile_tokenizer.rb b/test/rubygems/test_gem_request_set_lockfile_tokenizer.rb index ab506a14e6..f4aba6d94a 100644 --- a/test/rubygems/test_gem_request_set_lockfile_tokenizer.rb +++ b/test/rubygems/test_gem_request_set_lockfile_tokenizer.rb @@ -295,7 +295,7 @@ GEM end def write_lockfile lockfile - open @lock_file, 'w' do |io| + File.open @lock_file, 'w' do |io| io.write lockfile end end diff --git a/test/rubygems/test_gem_resolver_git_specification.rb b/test/rubygems/test_gem_resolver_git_specification.rb index 9e8e2c5715..211757eb20 100644 --- a/test/rubygems/test_gem_resolver_git_specification.rb +++ b/test/rubygems/test_gem_resolver_git_specification.rb @@ -70,7 +70,7 @@ class TestGemResolverGitSpecification < Gem::TestCase Dir.chdir 'git/a' do FileUtils.mkdir_p 'ext/lib' - open 'ext/extconf.rb', 'w' do |io| + File.open 'ext/extconf.rb', 'w' do |io| io.puts 'require "mkmf"' io.puts 'create_makefile "a"' end diff --git a/test/rubygems/test_gem_server.rb b/test/rubygems/test_gem_server.rb index 6fe02e480f..b5c025e694 100644 --- a/test/rubygems/test_gem_server.rb +++ b/test/rubygems/test_gem_server.rb @@ -100,7 +100,7 @@ class TestGemServer < Gem::TestCase specs_dir = File.join dir, 'specifications' FileUtils.mkdir_p specs_dir - open File.join(specs_dir, spec.spec_name), 'w' do |io| + File.open File.join(specs_dir, spec.spec_name), 'w' do |io| io.write spec.to_ruby end @@ -198,7 +198,7 @@ class TestGemServer < Gem::TestCase FileUtils.mkdir_p specs_dir - open File.join(specs_dir, spec.spec_name), 'w' do |io| + File.open File.join(specs_dir, spec.spec_name), 'w' do |io| io.write spec.to_ruby end @@ -339,7 +339,7 @@ class TestGemServer < Gem::TestCase specs_dir = File.join dir, 'specifications' FileUtils.mkdir_p specs_dir - open File.join(specs_dir, spec.spec_name), 'w' do |io| + File.open File.join(specs_dir, spec.spec_name), 'w' do |io| io.write spec.to_ruby end @@ -378,7 +378,7 @@ class TestGemServer < Gem::TestCase specs_dir = File.join dir, 'specifications' FileUtils.mkdir_p specs_dir - open File.join(specs_dir, spec.spec_name), 'w' do |io| + File.open File.join(specs_dir, spec.spec_name), 'w' do |io| io.write spec.to_ruby end diff --git a/test/rubygems/test_gem_source.rb b/test/rubygems/test_gem_source.rb index 4a93e222f8..8805a9b404 100644 --- a/test/rubygems/test_gem_source.rb +++ b/test/rubygems/test_gem_source.rb @@ -110,7 +110,7 @@ class TestGemSource < Gem::TestCase cache_file = File.join cache_dir, a1.spec_name - open cache_file, 'wb' do |io| + File.open cache_file, 'wb' do |io| Marshal.dump a1, io end @@ -163,7 +163,7 @@ class TestGemSource < Gem::TestCase cache_file = File.join cache_dir, "latest_specs.#{Gem.marshal_version}" - open cache_file, 'wb' do |io| + File.open cache_file, 'wb' do |io| Marshal.dump latest_specs, io end @@ -187,7 +187,7 @@ class TestGemSource < Gem::TestCase cache_file = File.join cache_dir, "latest_specs.#{Gem.marshal_version}" - open cache_file, 'wb' do |io| + File.open cache_file, 'wb' do |io| # Setup invalid data in the cache: io.write Marshal.dump(latest_specs)[0, 10] end diff --git a/test/rubygems/test_gem_source_git.rb b/test/rubygems/test_gem_source_git.rb index 0e13a11e7e..8f5d3ee745 100644 --- a/test/rubygems/test_gem_source_git.rb +++ b/test/rubygems/test_gem_source_git.rb @@ -229,7 +229,7 @@ class TestGemSourceGit < Gem::TestCase Dir.chdir 'b' do b = Gem::Specification.new 'b', 1 - open 'b.gemspec', 'w' do |io| + File.open 'b.gemspec', 'w' do |io| io.write b.to_ruby end diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb index 7bfeb48d3c..b1087c9f59 100644 --- a/test/rubygems/test_gem_specification.rb +++ b/test/rubygems/test_gem_specification.rb @@ -922,7 +922,7 @@ dependencies: [] end def test_self_load_relative - open 'a-2.gemspec', 'w' do |io| + File.open 'a-2.gemspec', 'w' do |io| io.write @a2.to_ruby_for_cache end @@ -1114,7 +1114,7 @@ dependencies: [] end def test_self_remove_spec_removed - open @a1.spec_file, 'w' do |io| + File.open @a1.spec_file, 'w' do |io| io.write @a1.to_ruby end @@ -1366,13 +1366,13 @@ dependencies: [] assert_empty @ext.build_args - open @ext.build_info_file, 'w' do |io| + File.open @ext.build_info_file, 'w' do |io| io.puts end assert_empty @ext.build_args - open @ext.build_info_file, 'w' do |io| + File.open @ext.build_info_file, 'w' do |io| io.puts '--with-foo-dir=wherever' end @@ -1388,9 +1388,9 @@ dependencies: [] extconf_rb = File.join @ext.gem_dir, @ext.extensions.first FileUtils.mkdir_p File.dirname extconf_rb - open extconf_rb, 'w' do |f| + File.open extconf_rb, 'w' do |f| f.write <<-'RUBY' - open 'Makefile', 'w' do |f| + File.open 'Makefile', 'w' do |f| f.puts "clean:\n\techo clean" f.puts "default:\n\techo built" f.puts "install:\n\techo installed" @@ -1438,9 +1438,9 @@ dependencies: [] extconf_rb = File.join spec.gem_dir, spec.extensions.first FileUtils.mkdir_p File.dirname extconf_rb - open extconf_rb, 'w' do |f| + File.open extconf_rb, 'w' do |f| f.write <<-'RUBY' - open 'Makefile', 'w' do |f| + File.open 'Makefile', 'w' do |f| f.puts "default:\n\techo built" f.puts "install:\n\techo installed" end @@ -1464,7 +1464,7 @@ dependencies: [] def test_build_extensions_extensions_dir_unwritable skip 'chmod not supported' if Gem.win_platform? - skip 'skipped in root privilege' if Process.uid == 0 + skip 'skipped in root privilege' if Process.uid.zero? ext_spec @@ -1473,9 +1473,9 @@ dependencies: [] extconf_rb = File.join @ext.gem_dir, @ext.extensions.first FileUtils.mkdir_p File.dirname extconf_rb - open extconf_rb, 'w' do |f| + File.open extconf_rb, 'w' do |f| f.write <<-'RUBY' - open 'Makefile', 'w' do |f| + File.open 'Makefile', 'w' do |f| f.puts "clean:\n\techo clean" f.puts "default:\n\techo built" f.puts "install:\n\techo installed" @@ -1490,7 +1490,7 @@ dependencies: [] @ext.build_extensions refute_path_exists @ext.extension_dir ensure - unless ($DEBUG or win_platform? or Process.uid == 0) then + unless ($DEBUG or win_platform? or Process.uid.zero?) then FileUtils.chmod 0755, File.join(@ext.base_dir, 'extensions') FileUtils.chmod 0755, @ext.base_dir end @@ -1506,9 +1506,9 @@ dependencies: [] extconf_rb = File.join @ext.gem_dir, @ext.extensions.first FileUtils.mkdir_p File.dirname extconf_rb - open extconf_rb, 'w' do |f| + File.open extconf_rb, 'w' do |f| f.write <<-'RUBY' - open 'Makefile', 'w' do |f| + File.open 'Makefile', 'w' do |f| f.puts "clean:\n\techo clean" f.puts "default:\n\techo built" f.puts "install:\n\techo installed" @@ -1555,9 +1555,9 @@ dependencies: [] extconf_rb = File.join @ext.gem_dir, @ext.extensions.first FileUtils.mkdir_p File.dirname extconf_rb - open extconf_rb, 'w' do |f| + File.open extconf_rb, 'w' do |f| f.write <<-'RUBY' - open 'Makefile', 'w' do |f| + File.open 'Makefile', 'w' do |f| f.puts "clean:\n\techo clean" f.puts "default:\n\techo built" f.puts "install:\n\techo installed" @@ -3422,9 +3422,9 @@ end extconf_rb = File.join @ext.gem_dir, @ext.extensions.first FileUtils.mkdir_p File.dirname extconf_rb - open extconf_rb, 'w' do |f| + File.open extconf_rb, 'w' do |f| f.write <<-'RUBY' - open 'Makefile', 'w' do |f| + File.open 'Makefile', 'w' do |f| f.puts "clean:\n\techo clean" f.puts "default:\n\techo built" f.puts "install:\n\techo installed" diff --git a/test/rubygems/test_gem_stub_specification.rb b/test/rubygems/test_gem_stub_specification.rb index 43680265c7..f9a3a236c0 100644 --- a/test/rubygems/test_gem_stub_specification.rb +++ b/test/rubygems/test_gem_stub_specification.rb @@ -127,9 +127,9 @@ class TestStubSpecification < Gem::TestCase extconf_rb = File.join s.gem_dir, s.extensions.first FileUtils.mkdir_p File.dirname extconf_rb - open extconf_rb, 'w' do |f| + File.open extconf_rb, 'w' do |f| f.write <<-'RUBY' - open 'Makefile', 'w' do |f| + File.open 'Makefile', 'w' do |f| f.puts "clean:\n\techo clean" f.puts "default:\n\techo built" f.puts "install:\n\techo installed" @@ -149,7 +149,7 @@ class TestStubSpecification < Gem::TestCase spec = new_default_spec 'default', 1 spec.extensions << 'extconf.rb' - open spec.loaded_from, 'w' do |io| + File.open spec.loaded_from, 'w' do |io| io.write spec.to_ruby_for_cache end @@ -198,7 +198,7 @@ class TestStubSpecification < Gem::TestCase def stub_with_version spec = File.join @gemhome, 'specifications', 'stub_e-2.gemspec' - open spec, 'w' do |io| + File.open spec, 'w' do |io| io.write <<-STUB # -*- encoding: utf-8 -*- # stub: stub_v 2 ruby lib @@ -221,7 +221,7 @@ end def stub_without_version spec = File.join @gemhome, 'specifications', 'stub-2.gemspec' - open spec, 'w' do |io| + File.open spec, 'w' do |io| io.write <<-STUB # -*- encoding: utf-8 -*- # stub: stub_v ruby lib @@ -245,7 +245,7 @@ end def stub_with_extension spec = File.join @gemhome, 'specifications', 'stub_e-2.gemspec' - open spec, 'w' do |io| + File.open spec, 'w' do |io| io.write <<-STUB # -*- encoding: utf-8 -*- # stub: stub_e 2 ruby lib @@ -271,7 +271,7 @@ end def stub_without_extension spec = File.join @gemhome, 'specifications', 'stub-2.gemspec' - open spec, 'w' do |io| + File.open spec, 'w' do |io| io.write <<-STUB # -*- encoding: utf-8 -*- # stub: stub 2 ruby lib diff --git a/test/rubygems/test_gem_util.rb b/test/rubygems/test_gem_util.rb index dc85d25586..80dbff4b9e 100644 --- a/test/rubygems/test_gem_util.rb +++ b/test/rubygems/test_gem_util.rb @@ -5,7 +5,7 @@ require 'rubygems/util' class TestGemUtil < Gem::TestCase def test_class_popen - skip "MJIT executes process and it's caught by Process.wait(-1)" if RubyVM::MJIT.enabled? + skip "MJIT executes process and it's caught by Process.wait(-1)" if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled? assert_equal "0\n", Gem::Util.popen(Gem.ruby, '-e', 'p 0') assert_raises Errno::ECHILD do @@ -30,6 +30,28 @@ class TestGemUtil < Gem::TestCase loop { break if enum.next.nil? } # exhaust the enumerator end + def test_traverse_parents_does_not_crash_on_permissions_error + skip 'skipped on MS Windows (chmod has no effect)' if win_platform? + + FileUtils.mkdir_p 'd/e/f' + # remove 'execute' permission from "e" directory and make it + # impossible to cd into it and its children + FileUtils.chmod(0666, 'd/e') + + paths = Gem::Util.traverse_parents('d/e/f').to_a + + assert_equal File.join(@tempdir, 'd'), paths[0] + assert_equal @tempdir, paths[1] + # File.expand_path with macOS returns `/private` prefix. + if RUBY_PLATFORM !~ /darwin/ + assert_equal Dir.tmpdir, paths[2] + assert_equal '/', paths[3] + end + ensure + # restore default permissions, allow the directory to be removed + FileUtils.chmod(0775, 'd/e') unless win_platform? + end + def test_linked_list_find list = [1,2,3,4,5].inject(Gem::List.new(0)) { |m,o| Gem::List.new o, m diff --git a/test/rubygems/test_gem_version.rb b/test/rubygems/test_gem_version.rb index 56c818663e..792ad5f084 100644 --- a/test/rubygems/test_gem_version.rb +++ b/test/rubygems/test_gem_version.rb @@ -2,6 +2,8 @@ require 'rubygems/test_case' require "rubygems/version" +require "minitest/benchmark" + class TestGemVersion < Gem::TestCase class V < ::Gem::Version @@ -102,6 +104,15 @@ class TestGemVersion < Gem::TestCase end end + def bench_anchored_version_pattern + assert_performance_linear 0.5 do |count| + version_string = count.times.map {|i| "0" * i.succ }.join(".") << "." + version_string =~ Gem::Version::ANCHORED_VERSION_PATTERN + end + rescue RegexpError + skip "It fails to allocate the memory for regex pattern of Gem::Version::ANCHORED_VERSION_PATTERN" + end + def test_empty_version ["", " ", " "].each do |empty| assert_equal "0", Gem::Version.new(empty).version diff --git a/test/rubygems/test_require.rb b/test/rubygems/test_require.rb index a106fc21a6..e292ce226d 100644 --- a/test/rubygems/test_require.rb +++ b/test/rubygems/test_require.rb @@ -70,10 +70,12 @@ class TestGemRequire < Gem::TestCase def create_sync_thread Thread.new do - yield - ensure - FILE_ENTERED_LATCH.release - FILE_EXIT_LATCH.await + begin + yield + ensure + FILE_ENTERED_LATCH.release + FILE_EXIT_LATCH.await + end end end @@ -100,8 +102,8 @@ class TestGemRequire < Gem::TestCase assert t1.join, "thread 1 should exit" assert t2.join, "thread 2 should exit" ensure - Object.send :remove_const, :FILE_ENTERED_LATCH - Object.send :remove_const, :FILE_EXIT_LATCH + Object.send :remove_const, :FILE_ENTERED_LATCH if Object.const_defined? :FILE_ENTERED_LATCH + Object.send :remove_const, :FILE_EXIT_LATCH if Object.const_defined? :FILE_EXIT_LATCH end def test_require_is_not_lazy_with_exact_req -- cgit v1.2.3