1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Merge rubygems upstream from 2c499655f2

https://github.com/rubygems/rubygems/pull/2493

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66065 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
hsbt 2018-11-28 03:08:14 +00:00
parent b52761e4f7
commit 5dbc6583c9
11 changed files with 119 additions and 78 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -1660,16 +1660,6 @@ class Gem::Specification < Gem::BasicSpecification
File.join build_info_dir, "#{full_name}.info"
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.

View file

@ -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

View file

@ -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[]

View file

@ -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'

View file

@ -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

View file

@ -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|

View file

@ -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", []