diff options
author | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2022-02-02 16:57:34 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-02 16:57:34 +0900 |
commit | 6794f8cf928ab8c009b301ec49a5a81e97e6eb2f (patch) | |
tree | 63f83daf2d1d2f57d6aaee9efa01e1c91ee8b021 /test | |
parent | 69463805f0722d90a2049f43e852539b4532bf2e (diff) |
Merge pull request #5482 from hsbt/rubygems-3-3-bundler-2-3
Merge RubyGems 3.3.x and Bundler 2.3.x
Diffstat (limited to 'test')
-rw-r--r-- | test/rubygems/helper.rb | 20 | ||||
-rw-r--r-- | test/rubygems/test_gem.rb | 2 | ||||
-rw-r--r-- | test/rubygems/test_gem_command_manager.rb | 2 | ||||
-rw-r--r-- | test/rubygems/test_gem_commands_fetch_command.rb | 97 | ||||
-rw-r--r-- | test/rubygems/test_gem_commands_install_command.rb | 16 | ||||
-rw-r--r-- | test/rubygems/test_gem_commands_update_command.rb | 59 | ||||
-rw-r--r-- | test/rubygems/test_gem_installer.rb | 228 | ||||
-rw-r--r-- | test/rubygems/test_gem_package.rb | 4 | ||||
-rw-r--r-- | test/rubygems/test_gem_stream_ui.rb | 2 | ||||
-rw-r--r-- | test/rubygems/test_gem_stub_specification.rb | 16 | ||||
-rw-r--r-- | test/rubygems/test_gem_version.rb | 4 | ||||
-rw-r--r-- | test/rubygems/utilities.rb | 8 |
12 files changed, 366 insertions, 92 deletions
diff --git a/test/rubygems/helper.rb b/test/rubygems/helper.rb index f321b02e48..d97d930476 100644 --- a/test/rubygems/helper.rb +++ b/test/rubygems/helper.rb @@ -339,10 +339,10 @@ class Gem::TestCase < Test::Unit::TestCase ENV["GEM_SPEC_CACHE"] = File.join @tempdir, 'spec_cache' @orig_ruby = if ENV['RUBY'] - ruby = Gem.ruby - Gem.ruby = ENV['RUBY'] - ruby - end + ruby = Gem.ruby + Gem.ruby = ENV['RUBY'] + ruby + end @git = ENV['GIT'] || (win_platform? ? 'git.exe' : 'git') @@ -685,10 +685,10 @@ class Gem::TestCase < Test::Unit::TestCase # Load a YAML string, the psych 3 way def load_yaml(yaml) - if YAML.respond_to?(:unsafe_load) - YAML.unsafe_load(yaml) + if Psych.respond_to?(:unsafe_load) + Psych.unsafe_load(yaml) else - YAML.load(yaml) + Psych.load(yaml) end end @@ -696,10 +696,10 @@ class Gem::TestCase < Test::Unit::TestCase # Load a YAML file, the psych 3 way def load_yaml_file(file) - if YAML.respond_to?(:unsafe_load_file) - YAML.unsafe_load_file(file) + if Psych.respond_to?(:unsafe_load_file) + Psych.unsafe_load_file(file) else - YAML.load_file(file) + Psych.load_file(file) end end diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb index 970b3b70dd..cc4772a0c6 100644 --- a/test/rubygems/test_gem.rb +++ b/test/rubygems/test_gem.rb @@ -2022,6 +2022,8 @@ You may need to `bundle install` to install missing gems ENV['SOURCE_DATE_EPOCH'] = old_epoch end + private + def ruby_install_name(name) with_clean_path_to_ruby do orig_RUBY_INSTALL_NAME = RbConfig::CONFIG['ruby_install_name'] diff --git a/test/rubygems/test_gem_command_manager.rb b/test/rubygems/test_gem_command_manager.rb index c2e11d2002..ff1f955c6c 100644 --- a/test/rubygems/test_gem_command_manager.rb +++ b/test/rubygems/test_gem_command_manager.rb @@ -252,7 +252,7 @@ class TestGemCommandManager < Gem::TestCase Gem::Deprecate.skip_during do @command_manager.process_args %w[query] end - assert_equal(//, check_options[:name]) + assert_nil(check_options[:name]) assert_equal :local, check_options[:domain] assert_equal false, check_options[:details] diff --git a/test/rubygems/test_gem_commands_fetch_command.rb b/test/rubygems/test_gem_commands_fetch_command.rb index c745648d56..7d4c77afaa 100644 --- a/test/rubygems/test_gem_commands_fetch_command.rb +++ b/test/rubygems/test_gem_commands_fetch_command.rb @@ -157,4 +157,101 @@ class TestGemCommandsFetchCommand < Gem::TestCase assert_path_exist(File.join(@tempdir, a1.file_name), "#{a1.full_name} not fetched") end + + def test_execute_version_specified_by_colon + specs = spec_fetcher do |fetcher| + fetcher.gem 'a', 1 + end + + @cmd.options[:args] = %w[a:1] + + use_ui @ui do + Dir.chdir @tempdir do + @cmd.execute + end + end + + a1 = specs['a-1'] + + assert_path_exist(File.join(@tempdir, a1.file_name), + "#{a1.full_name} not fetched") + end + + def test_execute_two_version + @cmd.options[:args] = %w[a b] + @cmd.options[:version] = Gem::Requirement.new '1' + + use_ui @ui do + assert_raise Gem::MockGemUi::TermError, @ui.error do + @cmd.execute + end + end + + msg = "ERROR: Can't use --version with multiple gems. You can specify multiple gems with" \ + " version requirements using `gem fetch 'my_gem:1.0.0' 'my_other_gem:~>2.0.0'`" + + assert_empty @ui.output + assert_equal msg, @ui.error.chomp + end + + def test_execute_two_version_specified_by_colon + specs = spec_fetcher do |fetcher| + fetcher.gem 'a', 1 + fetcher.gem 'b', 1 + end + + @cmd.options[:args] = %w[a:1 b:1] + + use_ui @ui do + Dir.chdir @tempdir do + @cmd.execute + end + end + + a1 = specs['a-1'] + b1 = specs['b-1'] + + assert_path_exist(File.join(@tempdir, a1.file_name), + "#{a1.full_name} not fetched") + assert_path_exist(File.join(@tempdir, b1.file_name), + "#{b1.full_name} not fetched") + end + + def test_execute_version_nonexistent + spec_fetcher do |fetcher| + fetcher.spec 'foo', 1 + end + + @cmd.options[:args] = %w[foo:2] + + use_ui @ui do + @cmd.execute + end + + expected = <<-EXPECTED +ERROR: Could not find a valid gem 'foo' (2) in any repository +ERROR: Possible alternatives: foo + EXPECTED + + assert_equal expected, @ui.error + end + + def test_execute_nonexistent_hint_disabled + spec_fetcher do |fetcher| + fetcher.spec 'foo', 1 + end + + @cmd.options[:args] = %w[foo:2] + @cmd.options[:suggest_alternate] = false + + use_ui @ui do + @cmd.execute + end + + expected = <<-EXPECTED +ERROR: Could not find a valid gem 'foo' (2) in any repository + EXPECTED + + assert_equal expected, @ui.error + end end diff --git a/test/rubygems/test_gem_commands_install_command.rb b/test/rubygems/test_gem_commands_install_command.rb index 0365b2c408..47a97dae4b 100644 --- a/test/rubygems/test_gem_commands_install_command.rb +++ b/test/rubygems/test_gem_commands_install_command.rb @@ -277,6 +277,22 @@ ERROR: Could not find a valid gem 'bar' (= 0.5) (required by 'foo' (>= 0)) in a assert_match(/ould not find a valid gem 'nonexistent'/, @ui.error) end + def test_execute_nonexistent_force + spec_fetcher + + @cmd.options[:args] = %w[nonexistent] + @cmd.options[:force] = true + + use_ui @ui do + e = assert_raise Gem::MockGemUi::TermError do + @cmd.execute + end + assert_equal 2, e.exit_code + end + + assert_match(/ould not find a valid gem 'nonexistent'/, @ui.error) + end + def test_execute_dependency_nonexistent spec_fetcher do |fetcher| fetcher.spec 'foo', 2, 'bar' => '0.5' diff --git a/test/rubygems/test_gem_commands_update_command.rb b/test/rubygems/test_gem_commands_update_command.rb index e9264f6d14..c765e9a8df 100644 --- a/test/rubygems/test_gem_commands_update_command.rb +++ b/test/rubygems/test_gem_commands_update_command.rb @@ -106,6 +106,31 @@ class TestGemCommandsUpdateCommand < Gem::TestCase assert_empty out end + def test_execute_system_when_latest_does_not_support_your_ruby + spec_fetcher do |fetcher| + fetcher.download 'rubygems-update', 9 do |s| + s.files = %w[setup.rb] + s.required_ruby_version = '> 9' + end + end + + @cmd.options[:args] = [] + @cmd.options[:system] = true + + use_ui @ui do + @cmd.execute + end + + out = @ui.output.split "\n" + assert_equal "Updating rubygems-update", out.shift + assert_empty out + + err = @ui.error.split "\n" + assert_equal "ERROR: Error installing rubygems-update:", err.shift + assert_equal "\trubygems-update-9 requires Ruby version > 9. The current ruby version is #{Gem.ruby_version}.", err.shift + assert_empty err + end + def test_execute_system_multiple spec_fetcher do |fetcher| fetcher.download 'rubygems-update', 8 do |s| @@ -132,6 +157,40 @@ class TestGemCommandsUpdateCommand < Gem::TestCase assert_empty out end + def test_execute_system_update_installed + spec_fetcher do |fetcher| + fetcher.download 'rubygems-update', 8 do |s| + s.files = %w[setup.rb] + end + end + + @cmd.options[:args] = [] + @cmd.options[:system] = true + + @cmd.execute + + spec_fetcher do |fetcher| + fetcher.download 'rubygems-update', 9 do |s| + s.files = %w[setup.rb] + end + end + + @cmd = Gem::Commands::UpdateCommand.new + @cmd.options[:args] = [] + @cmd.options[:system] = true + + use_ui @ui do + @cmd.execute + end + + out = @ui.output.split "\n" + assert_equal "Updating rubygems-update", out.shift + assert_equal "Installing RubyGems 9", out.shift + assert_equal "RubyGems system software updated", out.shift + + assert_empty out + end + def test_execute_system_specific spec_fetcher do |fetcher| fetcher.download 'rubygems-update', 8 do |s| diff --git a/test/rubygems/test_gem_installer.rb b/test/rubygems/test_gem_installer.rb index 8874577aa8..c90fdab283 100644 --- a/test/rubygems/test_gem_installer.rb +++ b/test/rubygems/test_gem_installer.rb @@ -18,11 +18,12 @@ class TestGemInstaller < Gem::InstallerTestCase end def test_app_script_text - installer = setup_base_installer + load_relative "no" do + installer = setup_base_installer - util_make_exec @spec, '' + util_make_exec @spec, '' - expected = <<-EOF + expected = <<-EOF #!#{Gem.ruby} # # This file was generated by RubyGems. @@ -52,10 +53,11 @@ else gem "a", version load Gem.bin_path("a", "executable", version) end - EOF + EOF - wrapper = installer.app_script_text 'executable' - assert_equal expected, wrapper + wrapper = installer.app_script_text 'executable' + assert_equal expected, wrapper + end end def test_check_executable_overwrite @@ -724,17 +726,19 @@ gem 'other', version def test_generate_bin_uses_default_shebang pend "Symlinks not supported or not enabled" unless symlink_supported? - installer = setup_base_installer + load_relative 'no' do + installer = setup_base_installer - installer.wrappers = true - util_make_exec + installer.wrappers = true + util_make_exec - installer.generate_bin + installer.generate_bin - default_shebang = Gem.ruby - shebang_line = File.open("#{@gemhome}/bin/executable") {|f| f.readlines.first } - assert_match(/\A#!/, shebang_line) - assert_match(/#{default_shebang}/, shebang_line) + default_shebang = Gem.ruby + shebang_line = File.open("#{@gemhome}/bin/executable") {|f| f.readlines.first } + assert_match(/\A#!/, shebang_line) + assert_match(/#{default_shebang}/, shebang_line) + end end def test_generate_bin_with_dangling_symlink @@ -1804,13 +1808,15 @@ gem 'other', version end def test_shebang - installer = setup_base_installer + load_relative "no" do + installer = setup_base_installer - util_make_exec @spec, "#!/usr/bin/ruby" + util_make_exec @spec, "#!/usr/bin/ruby" - shebang = installer.shebang 'executable' + shebang = installer.shebang 'executable' - assert_equal "#!#{Gem.ruby}", shebang + assert_equal "#!#{Gem.ruby}", shebang + end end def test_process_options @@ -1844,42 +1850,80 @@ gem 'other', version end def test_shebang_arguments - installer = setup_base_installer + load_relative 'no' do + installer = setup_base_installer - util_make_exec @spec, "#!/usr/bin/ruby -ws" + util_make_exec @spec, "#!/usr/bin/ruby -ws" - shebang = installer.shebang 'executable' + shebang = installer.shebang 'executable' - assert_equal "#!#{Gem.ruby} -ws", shebang + assert_equal "#!#{Gem.ruby} -ws", shebang + end + end + + def test_shebang_arguments_with_load_relative + load_relative 'yes' do + installer = setup_base_installer + + util_make_exec @spec, "#!/usr/bin/ruby -ws" + + shebang = installer.shebang 'executable' + + shebang_lines = shebang.split "\n" + + assert_equal "#!/bin/sh", shebang_lines.shift + assert_includes shebang_lines, "#!#{Gem.ruby} -ws" + end end def test_shebang_empty - installer = setup_base_installer + load_relative 'no' do + installer = setup_base_installer - util_make_exec @spec, '' + util_make_exec @spec, '' - shebang = installer.shebang 'executable' - assert_equal "#!#{Gem.ruby}", shebang + shebang = installer.shebang 'executable' + assert_equal "#!#{Gem.ruby}", shebang + end end def test_shebang_env - installer = setup_base_installer + load_relative 'no' do + installer = setup_base_installer - util_make_exec @spec, "#!/usr/bin/env ruby" + util_make_exec @spec, "#!/usr/bin/env ruby" - shebang = installer.shebang 'executable' + shebang = installer.shebang 'executable' - assert_equal "#!#{Gem.ruby}", shebang + assert_equal "#!#{Gem.ruby}", shebang + end end def test_shebang_env_arguments - installer = setup_base_installer + load_relative 'no' do + installer = setup_base_installer - util_make_exec @spec, "#!/usr/bin/env ruby -ws" + util_make_exec @spec, "#!/usr/bin/env ruby -ws" - shebang = installer.shebang 'executable' + shebang = installer.shebang 'executable' - assert_equal "#!#{Gem.ruby} -ws", shebang + assert_equal "#!#{Gem.ruby} -ws", shebang + end + end + + def test_shebang_env_arguments_with_load_relative + load_relative 'yes' do + installer = setup_base_installer + + util_make_exec @spec, "#!/usr/bin/env ruby -ws" + + shebang = installer.shebang 'executable' + + shebang_lines = shebang.split "\n" + + assert_equal "#!/bin/sh", shebang_lines.shift + assert_includes shebang_lines, "#!#{Gem.ruby} -ws" + end end def test_shebang_env_shebang @@ -1897,63 +1941,120 @@ gem 'other', version end def test_shebang_nested - installer = setup_base_installer + load_relative 'no' do + installer = setup_base_installer - util_make_exec @spec, "#!/opt/local/ruby/bin/ruby" + util_make_exec @spec, "#!/opt/local/ruby/bin/ruby" - shebang = installer.shebang 'executable' + shebang = installer.shebang 'executable' - assert_equal "#!#{Gem.ruby}", shebang + assert_equal "#!#{Gem.ruby}", shebang + end end def test_shebang_nested_arguments - installer = setup_base_installer + load_relative 'no' do + installer = setup_base_installer - util_make_exec @spec, "#!/opt/local/ruby/bin/ruby -ws" + util_make_exec @spec, "#!/opt/local/ruby/bin/ruby -ws" - shebang = installer.shebang 'executable' + shebang = installer.shebang 'executable' + + assert_equal "#!#{Gem.ruby} -ws", shebang + end + end - assert_equal "#!#{Gem.ruby} -ws", shebang + def test_shebang_nested_arguments_with_load_relative + load_relative 'yes' do + installer = setup_base_installer + + util_make_exec @spec, "#!/opt/local/ruby/bin/ruby -ws" + + shebang = installer.shebang 'executable' + + shebang_lines = shebang.split "\n" + + assert_equal "#!/bin/sh", shebang_lines.shift + assert_includes shebang_lines, "#!#{Gem.ruby} -ws" + end end def test_shebang_version - installer = setup_base_installer + load_relative 'no' do + installer = setup_base_installer - util_make_exec @spec, "#!/usr/bin/ruby18" + util_make_exec @spec, "#!/usr/bin/ruby18" - shebang = installer.shebang 'executable' + shebang = installer.shebang 'executable' - assert_equal "#!#{Gem.ruby}", shebang + assert_equal "#!#{Gem.ruby}", shebang + end end def test_shebang_version_arguments - installer = setup_base_installer + load_relative 'no' do + installer = setup_base_installer - util_make_exec @spec, "#!/usr/bin/ruby18 -ws" + util_make_exec @spec, "#!/usr/bin/ruby18 -ws" - shebang = installer.shebang 'executable' + shebang = installer.shebang 'executable' + + assert_equal "#!#{Gem.ruby} -ws", shebang + end + end + + def test_shebang_version_arguments_with_load_relative + load_relative 'yes' do + installer = setup_base_installer + + util_make_exec @spec, "#!/usr/bin/ruby18 -ws" - assert_equal "#!#{Gem.ruby} -ws", shebang + shebang = installer.shebang 'executable' + + shebang_lines = shebang.split "\n" + + assert_equal "#!/bin/sh", shebang_lines.shift + assert_includes shebang_lines, "#!#{Gem.ruby} -ws" + end end def test_shebang_version_env - installer = setup_base_installer + load_relative 'no' do + installer = setup_base_installer - util_make_exec @spec, "#!/usr/bin/env ruby18" + util_make_exec @spec, "#!/usr/bin/env ruby18" - shebang = installer.shebang 'executable' + shebang = installer.shebang 'executable' - assert_equal "#!#{Gem.ruby}", shebang + assert_equal "#!#{Gem.ruby}", shebang + end end def test_shebang_version_env_arguments - installer = setup_base_installer + load_relative 'no' do + installer = setup_base_installer - util_make_exec @spec, "#!/usr/bin/env ruby18 -ws" + util_make_exec @spec, "#!/usr/bin/env ruby18 -ws" - shebang = installer.shebang 'executable' + shebang = installer.shebang 'executable' - assert_equal "#!#{Gem.ruby} -ws", shebang + assert_equal "#!#{Gem.ruby} -ws", shebang + end + end + + def test_shebang_version_env_arguments_with_load_relative + load_relative 'yes' do + installer = setup_base_installer + + util_make_exec @spec, "#!/usr/bin/env ruby18 -ws" + + shebang = installer.shebang 'executable' + + shebang_lines = shebang.split "\n" + + assert_equal "#!/bin/sh", shebang_lines.shift + assert_includes shebang_lines, "#!#{Gem.ruby} -ws" + end end def test_shebang_custom @@ -2259,6 +2360,8 @@ gem 'other', version assert_kind_of(String, installer.gem) end + private + def util_execless @spec = util_spec 'z' util_build_gem @spec @@ -2281,4 +2384,13 @@ gem 'other', version def mask 0100755 end + + def load_relative(value) + orig_LIBRUBY_RELATIVE = RbConfig::CONFIG['LIBRUBY_RELATIVE'] + RbConfig::CONFIG['LIBRUBY_RELATIVE'] = value + + yield + ensure + RbConfig::CONFIG['LIBRUBY_RELATIVE'] = orig_LIBRUBY_RELATIVE + end end diff --git a/test/rubygems/test_gem_package.rb b/test/rubygems/test_gem_package.rb index 48dcbee9f1..9172b7eef5 100644 --- a/test/rubygems/test_gem_package.rb +++ b/test/rubygems/test_gem_package.rb @@ -822,7 +822,7 @@ class TestGemPackage < Gem::Package::TarTestCase } tar.add_file 'checksums.yaml.gz', 0444 do |io| Zlib::GzipWriter.wrap io do |gz_io| - gz_io.write YAML.dump bogus_checksums + gz_io.write Psych.dump bogus_checksums end end end @@ -868,7 +868,7 @@ class TestGemPackage < Gem::Package::TarTestCase tar.add_file 'checksums.yaml.gz', 0444 do |io| Zlib::GzipWriter.wrap io do |gz_io| - gz_io.write YAML.dump checksums + gz_io.write Psych.dump checksums end end diff --git a/test/rubygems/test_gem_stream_ui.rb b/test/rubygems/test_gem_stream_ui.rb index 2071526dfa..04de6dd36a 100644 --- a/test/rubygems/test_gem_stream_ui.rb +++ b/test/rubygems/test_gem_stream_ui.rb @@ -5,7 +5,7 @@ require 'timeout' class TestGemStreamUI < Gem::TestCase # increase timeout with MJIT for --jit-wait testing - mjit_enabled = defined?(RubyVM::MJIT) ? RubyVM::MJIT.enabled? : defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled? + mjit_enabled = defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled? SHORT_TIMEOUT = (RUBY_ENGINE == "ruby" && !mjit_enabled) ? 0.1 : 1.0 module IsTty diff --git a/test/rubygems/test_gem_stub_specification.rb b/test/rubygems/test_gem_stub_specification.rb index e008391ef7..e01d5cad8c 100644 --- a/test/rubygems/test_gem_stub_specification.rb +++ b/test/rubygems/test_gem_stub_specification.rb @@ -180,22 +180,6 @@ class TestStubSpecification < Gem::TestCase assert bar.to_spec end - def test_to_spec_activated - assert @foo.to_spec.is_a?(Gem::Specification) - assert_equal "foo", @foo.to_spec.name - refute @foo.to_spec.instance_variable_get :@ignored - end - - def test_to_spec_missing_extensions - stub = stub_with_extension - - capture_output do - stub.contains_requirable_file? 'nonexistent' - end - - assert stub.to_spec.instance_variable_get :@ignored - end - def stub_with_version spec = File.join @gemhome, 'specifications', 'stub_e-2.gemspec' File.open spec, 'w' do |io| diff --git a/test/rubygems/test_gem_version.rb b/test/rubygems/test_gem_version.rb index 422e1ee86c..f8066ecbb8 100644 --- a/test/rubygems/test_gem_version.rb +++ b/test/rubygems/test_gem_version.rb @@ -154,6 +154,10 @@ class TestGemVersion < Gem::TestCase assert_equal(-1, v("5.a") <=> v("5.0.0.rc2")) assert_equal(1, v("5.x") <=> v("5.0.0.rc2")) + assert_equal(0, v("1.9.3") <=> "1.9.3") + assert_equal(1, v("1.9.3") <=> "1.9.2.99") + assert_equal(-1, v("1.9.3") <=> "1.9.3.1") + assert_nil v("1.0") <=> "whatever" end diff --git a/test/rubygems/utilities.rb b/test/rubygems/utilities.rb index 20416fe70b..613cf6c0ee 100644 --- a/test/rubygems/utilities.rb +++ b/test/rubygems/utilities.rb @@ -135,10 +135,10 @@ class Gem::FakeFetcher def download(spec, source_uri, install_dir = Gem.dir) name = File.basename spec.cache_file path = if Dir.pwd == install_dir # see fetch_command - install_dir - else - File.join install_dir, "cache" - end + install_dir + else + File.join install_dir, "cache" + end path = File.join path, name |