diff options
author | hsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-11-28 03:08:14 +0000 |
---|---|---|
committer | hsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-11-28 03:08:14 +0000 |
commit | 5dbc6583c93621a7e992163bd27991bd3d3d9378 (patch) | |
tree | 93d60f32d81d9ee58b538586f44acccbbc27c230 | |
parent | b52761e4f71326099374515e494b1667b2bbf84b (diff) |
Merge rubygems upstream from https://github.com/rubygems/rubygems/commit/2c499655f29070c809dfea9f5fda6fac6850e62e
https://github.com/rubygems/rubygems/pull/2493
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66065 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | lib/rubygems/commands/install_command.rb | 2 | ||||
-rw-r--r-- | lib/rubygems/commands/pristine_command.rb | 5 | ||||
-rw-r--r-- | lib/rubygems/commands/uninstall_command.rb | 21 | ||||
-rw-r--r-- | lib/rubygems/installer.rb | 10 | ||||
-rw-r--r-- | lib/rubygems/specification.rb | 10 | ||||
-rw-r--r-- | test/rubygems/test_gem_commands_install_command.rb | 38 | ||||
-rw-r--r-- | test/rubygems/test_gem_commands_pristine_command.rb | 24 | ||||
-rw-r--r-- | test/rubygems/test_gem_commands_uninstall_command.rb | 59 | ||||
-rw-r--r-- | test/rubygems/test_gem_installer.rb | 10 | ||||
-rw-r--r-- | test/rubygems/test_gem_package.rb | 6 | ||||
-rw-r--r-- | test/rubygems/test_gem_specification.rb | 12 |
11 files changed, 119 insertions, 78 deletions
diff --git a/lib/rubygems/commands/install_command.rb b/lib/rubygems/commands/install_command.rb index fca14681ee..776b58651f 100644 --- a/lib/rubygems/commands/install_command.rb +++ b/lib/rubygems/commands/install_command.rb @@ -142,7 +142,7 @@ You can use `i` command instead of `install`. if options[:version] != Gem::Requirement.default and get_all_gem_names.size > 1 alert_error "Can't use --version with multiple gems. You can specify multiple gems with" \ - " version requirments using `gem install 'my_gem:1.0.0' 'my_other_gem:~>2.0.0'`" + " version requirements using `gem install 'my_gem:1.0.0' 'my_other_gem:~>2.0.0'`" terminate_interaction 1 end end diff --git a/lib/rubygems/commands/pristine_command.rb b/lib/rubygems/commands/pristine_command.rb index b686d8341d..41decde856 100644 --- a/lib/rubygems/commands/pristine_command.rb +++ b/lib/rubygems/commands/pristine_command.rb @@ -129,11 +129,6 @@ extensions will be restored. end end - if spec.bundled_gem_in_old_ruby? - say "Skipped #{spec.full_name}, it is bundled with old Ruby" - next - end - unless spec.extensions.empty? or options[:extensions] or options[:only_executables] say "Skipped #{spec.full_name}, it needs to compile an extension" next diff --git a/lib/rubygems/commands/uninstall_command.rb b/lib/rubygems/commands/uninstall_command.rb index 3f975ce3bc..9de0ea722b 100644 --- a/lib/rubygems/commands/uninstall_command.rb +++ b/lib/rubygems/commands/uninstall_command.rb @@ -114,7 +114,18 @@ that is a dependency of an existing gem. You can use the "#{program_name} GEMNAME [GEMNAME ...]" end + def check_version # :nodoc: + if options[:version] != Gem::Requirement.default and + get_all_gem_names.size > 1 + alert_error "Can't use --version with multiple gems. You can specify multiple gems with" \ + " version requirements using `gem uninstall 'my_gem:1.0.0' 'my_other_gem:~>2.0.0'`" + terminate_interaction 1 + end + end + def execute + check_version + if options[:all] and not options[:args].empty? uninstall_specific elsif options[:all] @@ -138,8 +149,9 @@ that is a dependency of an existing gem. You can use the def uninstall_specific deplist = Gem::DependencyList.new - get_all_gem_names.uniq.each do |name| - gem_specs = Gem::Specification.find_all_by_name(name) + get_all_gem_names_and_versions.each do |name, version| + requirement = Array(version || options[:version]) + gem_specs = Gem::Specification.find_all_by_name(name, *requirement) say("Gem '#{name}' is not installed") if gem_specs.empty? gem_specs.each do |spec| deplist.add spec @@ -148,8 +160,9 @@ that is a dependency of an existing gem. You can use the deps = deplist.strongly_connected_components.flatten.reverse - deps.map(&:name).uniq.each do |gem_name| - uninstall_gem(gem_name) + deps.each do |dep| + options[:version] = dep.version + uninstall_gem(dep.name) end end diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb index 3c2a2ac3c2..b1f83174bd 100644 --- a/lib/rubygems/installer.rb +++ b/lib/rubygems/installer.rb @@ -749,11 +749,11 @@ require 'rubygems' version = "#{Gem::Requirement.default}.a" -if ARGV.first - str = ARGV.first - str = str.dup.force_encoding("BINARY") - if str =~ /\\A_(.*)_\\z/ and Gem::Version.correct?($1) - version = $1 +str = ARGV.first +if str + str = str.b[/\\A_(.*)_\\z/, 1] + if str and Gem::Version.correct?(str) + version = str ARGV.shift end end diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb index 4721bfc415..7eaa509d2b 100644 --- a/lib/rubygems/specification.rb +++ b/lib/rubygems/specification.rb @@ -1661,16 +1661,6 @@ class Gem::Specification < Gem::BasicSpecification end ## - # Used to detect if the gem is bundled in older version of Ruby, but not - # detectable as default gem (see BasicSpecification#default_gem?). - - def bundled_gem_in_old_ruby? - !default_gem? && - RUBY_VERSION < "2.0.0" && - summary == "This #{name} is bundled with Ruby" - end - - ## # Returns the full path to the cache directory containing this # spec's cached gem. diff --git a/test/rubygems/test_gem_commands_install_command.rb b/test/rubygems/test_gem_commands_install_command.rb index b024c77c70..0976a31b50 100644 --- a/test/rubygems/test_gem_commands_install_command.rb +++ b/test/rubygems/test_gem_commands_install_command.rb @@ -393,6 +393,23 @@ ERROR: Possible alternatives: non_existent_with_hint assert_equal %w[a-2.a], @cmd.installed_specs.map { |spec| spec.full_name } end + def test_execute_with_version_specified_by_colon + spec_fetcher do |fetcher| + fetcher.download 'a', 1 + fetcher.download 'a', 2 + end + + @cmd.options[:args] = %w[a:1] + + use_ui @ui do + assert_raises Gem::MockGemUi::SystemExitException, @ui.error do + @cmd.execute + end + end + + assert_equal %w[a-1], @cmd.installed_specs.map { |spec| spec.full_name } + end + def test_execute_prerelease_skipped_when_non_pre_available spec_fetcher do |fetcher| fetcher.gem 'a', '2.pre' @@ -649,12 +666,31 @@ ERROR: Possible alternatives: non_existent_with_hint assert_empty @cmd.installed_specs msg = "ERROR: Can't use --version with multiple gems. You can specify multiple gems with" \ - " version requirments using `gem install 'my_gem:1.0.0' 'my_other_gem:~>2.0.0'`" + " version requirements using `gem install '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 + spec_fetcher do |fetcher| + fetcher.gem 'a', 1 + fetcher.gem 'a', 2 + fetcher.gem 'b', 1 + fetcher.gem 'b', 2 + end + + @cmd.options[:args] = %w[a:1 b:1] + + use_ui @ui do + assert_raises Gem::MockGemUi::SystemExitException, @ui.error do + @cmd.execute + end + end + + assert_equal %w[a-1 b-1], @cmd.installed_specs.map { |spec| spec.full_name } + end + def test_execute_conservative spec_fetcher do |fetcher| fetcher.download 'b', 2 diff --git a/test/rubygems/test_gem_commands_pristine_command.rb b/test/rubygems/test_gem_commands_pristine_command.rb index 5d7a267974..e4aa8d8656 100644 --- a/test/rubygems/test_gem_commands_pristine_command.rb +++ b/test/rubygems/test_gem_commands_pristine_command.rb @@ -505,30 +505,6 @@ class TestGemCommandsPristineCommand < Gem::TestCase assert_empty(@ui.error) end - def test_execute_bundled_gem_on_old_rubies - util_set_RUBY_VERSION '1.9.3', 551 - - spec = util_spec 'bigdecimal', '1.1.0' do |s| - s.summary = "This bigdecimal is bundled with Ruby" - end - install_specs spec - - @cmd.options[:args] = %w[bigdecimal] - - use_ui @ui do - @cmd.execute - end - - assert_equal([ - "Restoring gems to pristine condition...", - "Skipped bigdecimal-1.1.0, it is bundled with old Ruby" - ], @ui.output.split("\n")) - - assert_empty @ui.error - ensure - util_restore_RUBY_VERSION - end - def test_handle_options @cmd.handle_options %w[] diff --git a/test/rubygems/test_gem_commands_uninstall_command.rb b/test/rubygems/test_gem_commands_uninstall_command.rb index f62f4277ed..407d2451a6 100644 --- a/test/rubygems/test_gem_commands_uninstall_command.rb +++ b/test/rubygems/test_gem_commands_uninstall_command.rb @@ -151,12 +151,14 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase assert_match(/Successfully uninstalled/, output) end - def test_execute_with_force_leaves_executable + def test_execute_with_version_leaves_non_matching_versions ui = Gem::MockGemUi.new util_make_gems util_setup_gem ui + assert_equal 3, Gem::Specification.find_all_by_name('a').length + @cmd.options[:version] = '1' @cmd.options[:force] = true @cmd.options[:args] = ['a'] @@ -165,17 +167,43 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase @cmd.execute end - assert !Gem::Specification.all_names.include?('a') + assert_equal 2, Gem::Specification.find_all_by_name('a').length + assert File.exist? File.join(@gemhome, 'bin', 'executable') end - def test_execute_with_force_uninstalls_all_versions + def test_execute_with_version_specified_as_colon ui = Gem::MockGemUi.new "y\n" util_make_gems util_setup_gem ui - assert Gem::Specification.find_all_by_name('a').length > 1 + assert_equal 3, Gem::Specification.find_all_by_name('a').length + + @cmd.options[:force] = true + @cmd.options[:args] = ['a:1'] + + use_ui ui do + @cmd.execute + end + + assert_equal 2, Gem::Specification.find_all_by_name('a').length + + assert File.exist? File.join(@gemhome, 'bin', 'executable') + end + + def test_execute_with_force_and_without_version_uninstalls_everything + ui = Gem::MockGemUi.new "y\n" + + a_1, = util_gem 'a', 1 + install_gem a_1 + + a_3a, = util_gem 'a', '3.a' + install_gem a_3a + + util_setup_gem ui + + assert_equal 3, Gem::Specification.find_all_by_name('a').length @cmd.options[:force] = true @cmd.options[:args] = ['a'] @@ -184,7 +212,9 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase @cmd.execute end - refute_includes Gem::Specification.all_names, 'a' + assert_empty Gem::Specification.find_all_by_name('a') + assert_match "Removing executable", ui.output + refute File.exist? @executable end def test_execute_with_force_ignores_dependencies @@ -261,6 +291,25 @@ WARNING: Use your OS package manager to uninstall vendor gems assert_match expected, @ui.error end + def test_execute_two_version + @cmd.options[:args] = %w[a b] + @cmd.options[:version] = Gem::Requirement.new("> 1") + + use_ui @ui do + e = assert_raises Gem::MockGemUi::TermError do + @cmd.execute + end + + assert_equal 1, e.exit_code + end + + msg = "ERROR: Can't use --version with multiple gems. You can specify multiple gems with" \ + " version requirements using `gem uninstall 'my_gem:1.0.0' 'my_other_gem:~>2.0.0'`" + + assert_empty @ui.output + assert_equal msg, @ui.error.lines.last.chomp + end + def test_handle_options_vendor_missing orig_vendordir = RbConfig::CONFIG['vendordir'] RbConfig::CONFIG.delete 'vendordir' diff --git a/test/rubygems/test_gem_installer.rb b/test/rubygems/test_gem_installer.rb index 4004df2a39..23c153d69b 100644 --- a/test/rubygems/test_gem_installer.rb +++ b/test/rubygems/test_gem_installer.rb @@ -53,11 +53,11 @@ require 'rubygems' version = \">= 0.a\" -if ARGV.first - str = ARGV.first - str = str.dup.force_encoding("BINARY") - if str =~ /\\A_(.*)_\\z/ and Gem::Version.correct?($1) - version = $1 +str = ARGV.first +if str + str = str.b[/\\A_(.*)_\\z/, 1] + if str and Gem::Version.correct?(str) + version = str ARGV.shift end end diff --git a/test/rubygems/test_gem_package.rb b/test/rubygems/test_gem_package.rb index 813a829403..b868fe237c 100644 --- a/test/rubygems/test_gem_package.rb +++ b/test/rubygems/test_gem_package.rb @@ -150,8 +150,6 @@ class TestGemPackage < Gem::Package::TarTestCase end def test_add_files_symlink - skip 'symlink not supported' if Gem.win_platform? && RUBY_VERSION < '2.3' - spec = Gem::Specification.new spec.files = %w[lib/code.rb lib/code_sym.rb] @@ -472,8 +470,6 @@ class TestGemPackage < Gem::Package::TarTestCase end def test_extract_tar_gz_symlink_relative_path - skip 'symlink not supported' if Gem.win_platform? && RUBY_VERSION < '2.3' - package = Gem::Package.new @gem tgz_io = util_tar_gz do |tar| @@ -501,8 +497,6 @@ class TestGemPackage < Gem::Package::TarTestCase end def test_extract_symlink_parent - skip 'symlink not supported' if Gem.win_platform? && RUBY_VERSION < '2.3' - package = Gem::Package.new @gem tgz_io = util_tar_gz do |tar| diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb index 821fa93311..4fbb1e73e0 100644 --- a/test/rubygems/test_gem_specification.rb +++ b/test/rubygems/test_gem_specification.rb @@ -3724,18 +3724,6 @@ end assert_equal ["default-2.0.0.0"], Gem::Specification.map(&:full_name) end - def test_detect_bundled_gem_in_old_ruby - util_set_RUBY_VERSION '1.9.3', 551 - - spec = util_spec 'bigdecimal', '1.1.0' do |s| - s.summary = "This bigdecimal is bundled with Ruby" - end - - assert spec.bundled_gem_in_old_ruby? - ensure - util_restore_RUBY_VERSION - end - def util_setup_deps @gem = util_spec "awesome", "1.0" do |awesome| awesome.add_runtime_dependency "bonobo", [] |