* lib/rubygems: Import RubyGems from master as of commit b165260

* test/rubygems:  ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42124 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
drbrain 2013-07-22 22:46:50 +00:00
Родитель 66cc0fa4ab
Коммит 4c2304f000
34 изменённых файлов: 1169 добавлений и 597 удалений

Просмотреть файл

@ -1,3 +1,8 @@
Tue Jul 23 07:44:59 2013 Eric Hodel <drbrain@segment7.net>
* lib/rubygems: Import RubyGems from master as of commit b165260
* test/rubygems: ditto.
Tue Jul 23 07:14:31 2013 Tanaka Akira <akr@fsij.org>
* bignum.c (bary_mulsub_1xN): New function.

Просмотреть файл

@ -446,18 +446,48 @@ module Gem
# $LOAD_PATH for files as well as gems.
#
# Note that find_files will return all files even if they are from different
# versions of the same gem.
# versions of the same gem. See also find_latest_files
def self.find_files(glob, check_load_path=true)
files = []
if check_load_path
files = $LOAD_PATH.map { |load_path|
files = find_files_from_load_path glob if check_load_path
files.concat Gem::Specification.map { |spec|
spec.matches_for_glob("#{glob}#{Gem.suffix_pattern}")
}.flatten
# $LOAD_PATH might contain duplicate entries or reference
# the spec dirs directly, so we prune.
files.uniq! if check_load_path
return files
end
def self.find_files_from_load_path glob # :nodoc:
$LOAD_PATH.map { |load_path|
Dir["#{File.expand_path glob, load_path}#{Gem.suffix_pattern}"]
}.flatten.select { |file| File.file? file.untaint }
end
files.concat Gem::Specification.map { |spec|
##
# Returns a list of paths matching +glob+ from the latest gems that can be
# used by a gem to pick up features from other gems. For example:
#
# Gem.find_latest_files('rdoc/discover').each do |path| load path end
#
# if +check_load_path+ is true (the default), then find_latest_files also
# searches $LOAD_PATH for files as well as gems.
#
# Unlike find_files, find_latest_files will return only files from the
# latest version of a gem.
def self.find_latest_files(glob, check_load_path=true)
files = []
files = find_files_from_load_path glob if check_load_path
files.concat Gem::Specification.latest_specs(true).map { |spec|
spec.matches_for_glob("#{glob}#{Gem.suffix_pattern}")
}.flatten
@ -947,7 +977,7 @@ module Gem
##
# Load +plugins+ as Ruby files
def self.load_plugin_files(plugins)
def self.load_plugin_files plugins # :nodoc:
plugins.each do |plugin|
# Skip older versions of the GemCutter plugin: Its commands are in
@ -965,10 +995,16 @@ module Gem
end
##
# Find all 'rubygems_plugin' files in installed gems and load them
# Find the 'rubygems_plugin' files in the latest installed gems and load
# them
def self.load_plugins
# Remove this env var by at least 3.0
if ENV['RUBYGEMS_LOAD_ALL_PLUGINS']
load_plugin_files find_files('rubygems_plugin', false)
else
load_plugin_files find_latest_files('rubygems_plugin', false)
end
end
##

Просмотреть файл

@ -33,6 +33,39 @@ class Gem::CommandManager
include Gem::UserInteraction
BUILTIN_COMMANDS = [ # :nodoc:
:build,
:cert,
:check,
:cleanup,
:contents,
:dependency,
:environment,
:fetch,
:generate_index,
:help,
:install,
:list,
:lock,
:mirror,
:outdated,
:owner,
:pristine,
:push,
:query,
:rdoc,
:search,
:server,
:sources,
:specification,
:stale,
:uninstall,
:unpack,
:update,
:which,
:yank,
]
##
# Return the authoritative instance of the command manager.
@ -61,36 +94,10 @@ class Gem::CommandManager
def initialize
require 'timeout'
@commands = {}
register_command :build
register_command :cert
register_command :check
register_command :cleanup
register_command :contents
register_command :dependency
register_command :environment
register_command :fetch
register_command :generate_index
register_command :help
register_command :install
register_command :list
register_command :lock
register_command :mirror
register_command :outdated
register_command :owner
register_command :pristine
register_command :push
register_command :query
register_command :rdoc
register_command :search
register_command :server
register_command :sources
register_command :specification
register_command :stale
register_command :uninstall
register_command :unpack
register_command :update
register_command :which
register_command :yank
BUILTIN_COMMANDS.each do |name|
register_command name
end
end
##
@ -132,14 +139,6 @@ class Gem::CommandManager
alert_error "While executing gem ... (#{ex.class})\n #{ex.to_s}"
ui.backtrace ex
if Gem.configuration.really_verbose and \
ex.kind_of?(Gem::Exception) and ex.source_exception
e = ex.source_exception
ui.errs.puts "Because of: (#{e.class})\n #{e.to_s}"
ui.backtrace e
end
terminate_interaction(1)
rescue Interrupt
alert_error "Interrupted"
@ -147,8 +146,6 @@ class Gem::CommandManager
end
def process_args(args, build_args=nil)
args = args.to_str.split(/\s+/) if args.respond_to?(:to_str)
if args.empty? then
say Gem::Command::HELP
terminate_interaction 1

Просмотреть файл

@ -85,44 +85,52 @@ class Gem::Commands::CertCommand < Gem::Command
end
end
def execute
options[:add].each do |certificate|
def add_certificate certificate # :nodoc:
Gem::Security.trust_dir.trust_cert certificate
say "Added '#{certificate.subject}'"
end
options[:remove].each do |filter|
certificates_matching filter do |certificate, path|
FileUtils.rm path
say "Removed '#{certificate.subject}'"
def execute
options[:add].each do |certificate|
add_certificate certificate
end
options[:remove].each do |filter|
remove_certificates_matching filter
end
options[:list].each do |filter|
certificates_matching filter do |certificate, _|
# this could probably be formatted more gracefully
say certificate.subject.to_s
end
list_certificates_matching filter
end
options[:build].each do |name|
build name
end
unless options[:sign].empty? then
load_default_cert unless options[:issuer_cert]
load_default_key unless options[:key]
end
options[:sign].each do |cert_file|
sign cert_file
end
sign_certificates unless options[:sign].empty?
end
def build name
if options[:key]
key = options[:key]
key, key_path = build_key
cert_path = build_cert name, key
say "Certificate: #{cert_path}"
if key_path
say "Private Key: #{key_path}"
say "Don't forget to move the key file to somewhere private!"
end
end
def build_cert name, key # :nodoc:
cert = Gem::Security.create_cert_email name, key
Gem::Security.write cert, "gem-public_cert.pem"
end
def build_key # :nodoc:
if options[:key] then
options[:key]
else
passphrase = ask_for_password 'Passphrase for your Private Key:'
say "\n"
@ -135,16 +143,8 @@ class Gem::Commands::CertCommand < Gem::Command
key = Gem::Security.create_key
key_path = Gem::Security.write key, "gem-private_key.pem", 0600, passphrase
end
cert = Gem::Security.create_cert_email name, key
cert_path = Gem::Security.write cert, "gem-public_cert.pem"
say "Certificate: #{cert_path}"
if key_path
say "Private Key: #{key_path}"
say "Don't forget to move the key file to somewhere private!"
return key, key_path
end
end
@ -200,6 +200,13 @@ For further reading on signing gems see `ri Gem::Security`.
EOF
end
def list_certificates_matching filter # :nodoc:
certificates_matching filter do |certificate, _|
# this could probably be formatted more gracefully
say certificate.subject.to_s
end
end
def load_default_cert
cert_file = File.join Gem.default_cert_path
cert = File.read cert_file
@ -233,6 +240,18 @@ For further reading on signing gems see `ri Gem::Security`.
terminate_interaction 1
end
def load_defaults # :nodoc:
load_default_cert unless options[:issuer_cert]
load_default_key unless options[:key]
end
def remove_certificates_matching filter # :nodoc:
certificates_matching filter do |certificate, path|
FileUtils.rm path
say "Removed '#{certificate.subject}'"
end
end
def sign cert_file
cert = File.read cert_file
cert = OpenSSL::X509::Certificate.new cert
@ -247,5 +266,13 @@ For further reading on signing gems see `ri Gem::Security`.
Gem::Security.write cert, cert_file, permissions
end
def sign_certificates # :nodoc:
load_defaults unless options[:sign].empty?
options[:sign].each do |cert_file|
sign cert_file
end
end
end if defined?(OpenSSL::SSL)

Просмотреть файл

@ -31,6 +31,10 @@ class Gem::Commands::ContentsCommand < Gem::Command
"Don't include installed path prefix") do |prefix, options|
options[:prefix] = prefix
end
@path_kind = nil
@spec_dirs = nil
@version = nil
end
def arguments # :nodoc:
@ -46,43 +50,40 @@ class Gem::Commands::ContentsCommand < Gem::Command
end
def execute
version = options[:version] || Gem::Requirement.default
@version = options[:version] || Gem::Requirement.default
@spec_dirs = specification_directories
@path_kind = path_description @spec_dirs
spec_dirs = options[:specdirs].map do |i|
[i, File.join(i, "specifications")]
end.flatten
names = gem_names
path_kind = if spec_dirs.empty? then
spec_dirs = Gem::Specification.dirs
"default gem paths"
names.each do |name|
found = gem_contents name
terminate_interaction 1 unless found or names.length > 1
end
end
def files_in spec
if spec.default_gem? then
files_in_default_gem spec
else
"specified path"
files_in_gem spec
end
end
gem_names = if options[:all] then
Gem::Specification.map(&:name)
else
get_all_gem_names
def files_in_gem spec
gem_path = spec.full_gem_path
extra = "/{#{spec.require_paths.join ','}}" if options[:lib_only]
glob = "#{gem_path}#{extra}/**/*"
prefix_re = /#{Regexp.escape(gem_path)}\//
Dir[glob].map do |file|
[gem_path, file.sub(prefix_re, "")]
end
end
gem_names.each do |name|
# HACK: find_by_name fails for some reason... ARGH
# How many places must we embed our resolve logic?
spec = Gem::Specification.find_all_by_name(name, version).last
unless spec then
say "Unable to find gem '#{name}' in #{path_kind}"
if Gem.configuration.verbose then
say "\nDirectories searched:"
spec_dirs.sort.each { |dir| say dir }
end
terminate_interaction 1 if gem_names.length == 1
end
if spec.default_gem?
files = spec.files.sort.map do |file|
def files_in_default_gem spec
spec.files.sort.map do |file|
case file
when /\A#{spec.bindir}\//
[Gem::ConfigMap[:bindir], $POSTMATCH]
@ -92,27 +93,69 @@ class Gem::Commands::ContentsCommand < Gem::Command
[Gem::ConfigMap[:rubylibdir], file]
end
end
end
def gem_contents name
spec = spec_for name
return false unless spec
files = files_in spec
show_files files
true
end
def gem_names # :nodoc:
if options[:all] then
Gem::Specification.map(&:name)
else
gem_path = spec.full_gem_path
extra = "/{#{spec.require_paths.join ','}}" if options[:lib_only]
glob = "#{gem_path}#{extra}/**/*"
prefix_re = /#{Regexp.escape(gem_path)}\//
files = Dir[glob].map do |file|
[gem_path, file.sub(prefix_re, "")]
get_all_gem_names
end
end
def path_description spec_dirs # :nodoc:
if spec_dirs.empty? then
spec_dirs = Gem::Specification.dirs
"default gem paths"
else
"specified path"
end
end
def show_files files
files.sort.each do |prefix, basename|
absolute_path = File.join(prefix, basename)
next if File.directory? absolute_path
if options[:prefix]
if options[:prefix] then
say absolute_path
else
say basename
end
end
end
def spec_for name
spec = Gem::Specification.find_all_by_name(name, @version).last
return spec if spec
say "Unable to find gem '#{name}' in #{@path_kind}"
if Gem.configuration.verbose then
say "\nDirectories searched:"
@spec_dirs.sort.each { |dir| say dir }
end
return nil
end
def specification_directories # :nodoc:
options[:specdirs].map do |i|
[i, File.join(i, "specifications")]
end.flatten
end
end

Просмотреть файл

@ -42,67 +42,55 @@ class Gem::Commands::DependencyCommand < Gem::Command
"#{program_name} GEMNAME"
end
def execute
if options[:reverse_dependencies] and remote? and not local? then
alert_error 'Only reverse dependencies for local gems are supported.'
terminate_interaction 1
def fetch_remote_specs dependency # :nodoc:
fetcher = Gem::SpecFetcher.fetcher
ss, = fetcher.spec_for_dependency dependency
ss.map { |spec, _| spec }
end
options[:args] << '' if options[:args].empty?
pattern = if options[:args].length == 1 and
options[:args].first =~ /\A\/(.*)\/(i)?\z/m then
flags = $2 ? Regexp::IGNORECASE : nil
Regexp.new $1, flags
else
/\A#{Regexp.union(*options[:args])}/
end
# TODO: deprecate for real damnit
dependency = Gem::Deprecate.skip_during {
Gem::Dependency.new pattern, options[:version]
}
dependency.prerelease = options[:prerelease]
def fetch_specs dependency # :nodoc:
specs = []
specs.concat dependency.matching_specs if local?
specs.concat fetch_remote_specs dependency if remote?
if remote? and not options[:reverse_dependencies] then
fetcher = Gem::SpecFetcher.fetcher
ensure_specs specs
ss, _ = fetcher.spec_for_dependency dependency
ss.each { |s,o| specs << s }
specs.uniq.sort
end
if specs.empty? then
patterns = options[:args].join ','
say "No gems found matching #{patterns} (#{options[:version]})" if
Gem.configuration.verbose
def gem_dependency args, version, prerelease # :nodoc:
args << '' if args.empty?
terminate_interaction 1
pattern = if args.length == 1 and args.first =~ /\A\/(.*)\/(i)?\z/m then
flags = $2 ? Regexp::IGNORECASE : nil
Regexp.new $1, flags
else
/\A#{Regexp.union(*args)}/
end
specs = specs.uniq.sort
dependency = Gem::Deprecate.skip_during {
Gem::Dependency.new pattern, version
}
reverse = Hash.new { |h, k| h[k] = [] }
dependency.prerelease = prerelease
if options[:reverse_dependencies] then
dependency
end
def display_pipe specs # :nodoc:
specs.each do |spec|
reverse[spec.full_name] = find_reverse_dependencies spec
end
end
if options[:pipe_format] then
specs.each do |spec|
unless spec.dependencies.empty?
unless spec.dependencies.empty? then
spec.dependencies.sort_by { |dep| dep.name }.each do |dep|
say "#{dep.name} --version '#{dep.requirement}'"
end
end
end
else
end
def display_readable specs, reverse # :nodoc:
response = ''
specs.each do |spec|
@ -118,9 +106,42 @@ class Gem::Commands::DependencyCommand < Gem::Command
say response
end
def execute
ensure_local_only_reverse_dependencies
dependency =
gem_dependency options[:args], options[:version], options[:prerelease]
specs = fetch_specs dependency
reverse = reverse_dependencies specs
if options[:pipe_format] then
display_pipe specs
else
display_readable specs, reverse
end
end
def print_dependencies(spec, level = 0)
def ensure_local_only_reverse_dependencies # :nodoc:
if options[:reverse_dependencies] and remote? and not local? then
alert_error 'Only reverse dependencies for local gems are supported.'
terminate_interaction 1
end
end
def ensure_specs specs # :nodoc:
return unless specs.empty?
patterns = options[:args].join ','
say "No gems found matching #{patterns} (#{options[:version]})" if
Gem.configuration.verbose
terminate_interaction 1
end
def print_dependencies(spec, level = 0) # :nodoc:
response = ''
response << ' ' * level + "Gem #{spec.full_name}\n"
unless spec.dependencies.empty? then
@ -131,10 +152,30 @@ class Gem::Commands::DependencyCommand < Gem::Command
response
end
def remote_specs dependency # :nodoc:
fetcher = Gem::SpecFetcher.fetcher
ss, _ = fetcher.spec_for_dependency dependency
ss.map { |s,o| s }
end
def reverse_dependencies specs # :nodoc:
reverse = Hash.new { |h, k| h[k] = [] }
return reverse unless options[:reverse_dependencies]
specs.each do |spec|
reverse[spec.full_name] = find_reverse_dependencies spec
end
reverse
end
##
# Returns an Array of [specification, dep] that are satisfied by +spec+.
def find_reverse_dependencies(spec)
def find_reverse_dependencies spec # :nodoc:
result = []
Gem::Specification.each do |sp|

Просмотреть файл

@ -69,20 +69,36 @@ lib/rubygems/defaults/operating_system.rb
def execute
out = ''
arg = options[:args][0]
out <<
case arg
when /^packageversion/ then
out << Gem::RubyGemsPackageVersion
Gem::RubyGemsPackageVersion
when /^version/ then
out << Gem::VERSION
Gem::VERSION
when /^gemdir/, /^gemhome/, /^home/, /^GEM_HOME/ then
out << Gem.dir
Gem.dir
when /^gempath/, /^path/, /^GEM_PATH/ then
out << Gem.path.join(File::PATH_SEPARATOR)
Gem.path.join(File::PATH_SEPARATOR)
when /^remotesources/ then
out << Gem.sources.to_a.join("\n")
Gem.sources.to_a.join("\n")
when /^platform/ then
out << Gem.platforms.join(File::PATH_SEPARATOR)
Gem.platforms.join(File::PATH_SEPARATOR)
when nil then
show_environment
else
raise Gem::CommandLineError, "Unknown environment option [#{arg}]"
end
say out
true
end
def add_path out, path
path.each do |component|
out << " - #{component}\n"
end
end
def show_environment # :nodoc:
out = "RubyGems Environment:\n"
out << " - RUBYGEMS VERSION: #{Gem::VERSION}\n"
@ -129,17 +145,7 @@ lib/rubygems/defaults/operating_system.rb
shell_path = ENV['PATH'].split(File::PATH_SEPARATOR)
add_path out, shell_path
else
raise Gem::CommandLineError, "Unknown environment option [#{arg}]"
end
say out
true
end
def add_path out, path
path.each do |component|
out << " - #{component}\n"
end
out
end
end

Просмотреть файл

@ -94,6 +94,8 @@ platform.
def initialize
super 'help', "Provide help on the 'gem' command"
@command_manager = Gem::CommandManager.instance
end
def arguments # :nodoc:
@ -110,24 +112,46 @@ platform.
end
def execute
command_manager = Gem::CommandManager.instance
arg = options[:args][0]
if begins? "commands", arg then
show_commands
elsif begins? "options", arg then
say Gem::Command::HELP
elsif begins? "examples", arg then
say EXAMPLES
elsif begins? "platforms", arg then
say PLATFORMS
elsif options[:help] then
show_help
elsif arg then
show_command_help arg
else
say Gem::Command::HELP
end
end
def show_commands # :nodoc:
out = []
out << "GEM commands are:"
out << nil
margin_width = 4
desc_width = command_manager.command_names.map { |n| n.size }.max + 4
desc_width = @command_manager.command_names.map { |n| n.size }.max + 4
summary_width = 80 - margin_width - desc_width
wrap_indent = ' ' * (margin_width + desc_width)
format = "#{' ' * margin_width}%-#{desc_width}s%s"
command_manager.command_names.each do |cmd_name|
command = command_manager[cmd_name]
@command_manager.command_names.each do |cmd_name|
command = @command_manager[cmd_name]
summary =
if command then
@ -150,39 +174,31 @@ platform.
out << "e.g. 'gem i rake' is short for 'gem install rake'."
say out.join("\n")
end
elsif begins? "options", arg then
say Gem::Command::HELP
def show_command_help command_name # :nodoc:
command_name = command_name.downcase
elsif begins? "examples", arg then
say EXAMPLES
possibilities = @command_manager.find_command_possibilities command_name
elsif begins? "platforms", arg then
say PLATFORMS
if possibilities.size == 1 then
command = @command_manager[possibilities.first]
command.invoke("--help")
elsif possibilities.size > 1 then
alert_warning "Ambiguous command #{command_name} (#{possibilities.join(', ')})"
else
alert_warning "Unknown command #{command_name}. Try: gem help commands"
end
end
elsif options[:help] then
command = command_manager[options[:help]]
if command
def show_help # :nodoc:
command = @command_manager[options[:help]]
if command then
# help with provided command
command.invoke("--help")
else
alert_error "Unknown command #{options[:help]}. Try 'gem help commands'"
end
elsif arg then
possibilities = command_manager.find_command_possibilities(arg.downcase)
if possibilities.size == 1
command = command_manager[possibilities.first]
command.invoke("--help")
elsif possibilities.size > 1
alert_warning "Ambiguous command #{arg} (#{possibilities.join(', ')})"
else
alert_warning "Unknown command #{arg}. Try gem help commands"
end
else
say Gem::Command::HELP
end
end
end

Просмотреть файл

@ -113,7 +113,44 @@ to write the specification by hand. For example:
"#{program_name} GEMNAME [GEMNAME ...] [options] -- --build-flags"
end
def install_from_gemdeps(gf)
def check_install_dir # :nodoc:
if options[:install_dir] and options[:user_install] then
alert_error "Use --install-dir or --user-install but not both"
terminate_interaction 1
end
end
def check_version # :nodoc:
if options[:version] != Gem::Requirement.default and
get_all_gem_names.size > 1 then
alert_error "Can't use --version w/ multiple gems. Use name:ver instead."
terminate_interaction 1
end
end
def execute
if gf = options[:gemdeps] then
install_from_gemdeps gf
return
end
@installed_specs = []
ENV.delete 'GEM_PATH' if options[:install_dir].nil? and RUBY_VERSION > '1.9'
check_install_dir
check_version
load_hooks
exit_code = install_gems
show_installed
raise Gem::SystemExitException, exit_code
end
def install_from_gemdeps gf # :nodoc:
require 'rubygems/request_set'
rs = Gem::RequestSet.new
rs.load_gemdeps gf
@ -135,58 +172,26 @@ to write the specification by hand. For example:
raise Gem::SystemExitException, 0
end
def execute
if gf = options[:gemdeps] then
install_from_gemdeps gf
return
end
@installed_specs = []
ENV.delete 'GEM_PATH' if options[:install_dir].nil? and RUBY_VERSION > '1.9'
if options[:install_dir] and options[:user_install]
alert_error "Use --install-dir or --user-install but not both"
terminate_interaction 1
def install_gem name, version # :nodoc:
return if options[:conservative] and
not Gem::Dependency.new(name, version).matching_specs.empty?
inst = Gem::DependencyInstaller.new options
inst.install name, Gem::Requirement.create(version)
@installed_specs.push(*inst.installed_gems)
show_install_errors inst.errors
end
def install_gems # :nodoc:
exit_code = 0
if options[:version] != Gem::Requirement.default &&
get_all_gem_names.size > 1 then
alert_error "Can't use --version w/ multiple gems. Use name:ver instead."
terminate_interaction 1
end
# load post-install hooks appropriate to options
if options[:install_as_default]
require 'rubygems/install_default_message'
else
require 'rubygems/install_message'
end
require 'rubygems/rdoc'
get_all_gem_names_and_versions.each do |gem_name, gem_version|
gem_version ||= options[:version]
begin
next if options[:conservative] and
not Gem::Dependency.new(gem_name, gem_version).matching_specs.empty?
inst = Gem::DependencyInstaller.new options
inst.install gem_name, Gem::Requirement.create(gem_version)
@installed_specs.push(*inst.installed_gems)
next unless errs = inst.errors
errs.each do |x|
next unless Gem::SourceFetchProblem === x
msg = "Unable to pull data from '#{x.source.uri}': #{x.error.message}"
alert_warning msg
end
install_gem gem_name, gem_version
rescue Gem::InstallError => e
alert_error "Error installing #{gem_name}:\n\t#{e.message}"
exit_code |= 1
@ -197,13 +202,39 @@ to write the specification by hand. For example:
end
end
unless @installed_specs.empty? then
exit_code
end
##
# Loads post-install hooks
def load_hooks # :nodoc:
if options[:install_as_default]
require 'rubygems/install_default_message'
else
require 'rubygems/install_message'
end
require 'rubygems/rdoc'
end
def show_install_errors errors # :nodoc:
return unless errors
errors.each do |x|
return unless Gem::SourceFetchProblem === x
msg = "Unable to pull data from '#{x.source.uri}': #{x.error.message}"
alert_warning msg
end
end
def show_installed # :nodoc:
return if @installed_specs.empty?
gems = @installed_specs.length == 1 ? 'gem' : 'gems'
say "#{@installed_specs.length} #{gems} installed"
end
raise Gem::SystemExitException, exit_code
end
end

Просмотреть файл

@ -14,7 +14,7 @@ class Gem::Commands::QueryCommand < Gem::Command
summary = 'Query gem information in local or remote repositories')
super name, summary,
:name => //, :domain => :local, :details => false, :versions => true,
:installed => false, :version => Gem::Requirement.default
:installed => nil, :version => Gem::Requirement.default
add_option('-i', '--[no-]installed',
'Check for installed gem') do |value, options|
@ -67,16 +67,21 @@ class Gem::Commands::QueryCommand < Gem::Command
name = options[:name]
prerelease = options[:prerelease]
if options[:installed] then
unless options[:installed].nil? then
if name.source.empty? then
alert_error "You must specify a gem name"
exit_code |= 4
elsif installed? name, options[:version] then
else
installed = installed? name, options[:version]
installed = !installed unless options[:installed]
if installed then
say "true"
else
say "false"
exit_code |= 1
end
end
terminate_interaction exit_code
end

Просмотреть файл

@ -7,6 +7,8 @@ class Gem::Commands::SearchCommand < Gem::Commands::QueryCommand
super 'search', 'Display all gems whose name contains STRING'
remove_option '--name-matches'
defaults[:domain] = :remote
end
def arguments # :nodoc:

Просмотреть файл

@ -37,46 +37,8 @@ class Gem::Commands::SourcesCommand < Gem::Command
add_proxy_option
end
def defaults_str
'--list'
end
def execute
options[:list] = !(options[:add] ||
options[:clear_all] ||
options[:remove] ||
options[:update])
if options[:clear_all] then
path = Gem.spec_cache_dir
FileUtils.rm_rf path
unless File.exist? path then
say "*** Removed specs cache ***"
else
unless File.writable? path then
say "*** Unable to remove source cache (write protected) ***"
else
say "*** Unable to remove source cache ***"
end
terminate_interaction 1
end
end
if source_uri = options[:add] then
uri = URI source_uri
if uri.scheme and uri.scheme.downcase == 'http' and
uri.host.downcase == 'rubygems.org' then
question = <<-QUESTION.chomp
https://rubygems.org is recommended for security over #{uri}
Do you want to add this insecure source?
QUESTION
terminate_interaction 1 unless ask_yes_no question
end
def add_source source_uri # :nodoc:
check_rubygems_https source_uri
source = Gem::Source.new source_uri
@ -99,9 +61,74 @@ Do you want to add this insecure source?
end
end
if options[:remove] then
source_uri = options[:remove]
def check_rubygems_https source_uri # :nodoc:
uri = URI source_uri
if uri.scheme and uri.scheme.downcase == 'http' and
uri.host.downcase == 'rubygems.org' then
question = <<-QUESTION.chomp
https://rubygems.org is recommended for security over #{uri}
Do you want to add this insecure source?
QUESTION
terminate_interaction 1 unless ask_yes_no question
end
end
def clear_all # :nodoc:
path = Gem.spec_cache_dir
FileUtils.rm_rf path
unless File.exist? path then
say "*** Removed specs cache ***"
else
unless File.writable? path then
say "*** Unable to remove source cache (write protected) ***"
else
say "*** Unable to remove source cache ***"
end
terminate_interaction 1
end
end
def defaults_str # :nodoc:
'--list'
end
def list # :nodoc:
say "*** CURRENT SOURCES ***"
say
Gem.sources.each do |src|
say src
end
end
def list? # :nodoc:
!(options[:list] ||
options[:add] ||
options[:clear_all] ||
options[:remove] ||
options[:update])
end
def execute
clear_all if options[:clear_all]
source_uri = options[:add]
add_source source_uri if source_uri
source_uri = options[:remove]
remove_source source_uri if source_uri
update if options[:update]
list if list?
end
def remove_source source_uri # :nodoc:
unless Gem.sources.include? source_uri then
say "source #{source_uri} not present in cache"
else
@ -112,7 +139,7 @@ Do you want to add this insecure source?
end
end
if options[:update] then
def update # :nodoc:
Gem.sources.each_source do |src|
src.load_specs :released
src.load_specs :latest
@ -121,19 +148,7 @@ Do you want to add this insecure source?
say "source cache successfully updated"
end
if options[:list] then
say "*** CURRENT SOURCES ***"
say
Gem.sources.each do |src|
say src
end
end
end
private
def remove_cache_file(desc, path)
def remove_cache_file desc, path # :nodoc:
FileUtils.rm_rf path
if not File.exist?(path) then

Просмотреть файл

@ -1,6 +1,7 @@
require 'rubygems/command'
require 'rubygems/version_option'
require 'rubygems/uninstaller'
require 'fileutils'
##
# Gem uninstaller command line tool
@ -14,7 +15,7 @@ class Gem::Commands::UninstallCommand < Gem::Command
def initialize
super 'uninstall', 'Uninstall gems from the local repository',
:version => Gem::Requirement.default, :user_install => true,
:check_dev => false
:install_dir => Gem.dir, :check_dev => false
add_option('-a', '--[no-]all',
'Uninstall all matching versions'
@ -92,8 +93,31 @@ class Gem::Commands::UninstallCommand < Gem::Command
end
def execute
# REFACTOR: stolen from cleanup_command
if options[:all] and not options[:args].empty? then
alert_error 'Gem names and --all may not be used together'
terminate_interaction 1
elsif options[:all] then
uninstall_all
else
uninstall_specific
end
end
def uninstall_all
install_dir = options[:install_dir]
dirs_to_be_emptied = Dir[File.join(install_dir, '*')]
dirs_to_be_emptied.delete_if { |dir| dir.end_with? 'build_info' }
dirs_to_be_emptied.each do |dir|
FileUtils.rm_rf Dir[File.join(dir, '*')]
end
alert("Successfully uninstalled all gems in #{install_dir}")
end
def uninstall_specific
deplist = Gem::DependencyList.new
get_all_gem_names.uniq.each do |name|
Gem::Specification.find_all_by_name(name).each do |spec|
deplist.add spec

Просмотреть файл

@ -56,23 +56,33 @@ class Gem::Commands::UpdateCommand < Gem::Command
"#{program_name} GEMNAME [GEMNAME ...]"
end
def check_latest_rubygems version # :nodoc:
if Gem.rubygems_version == version then
say "Latest version currently installed. Aborting."
terminate_interaction
end
options[:user_install] = false
end
def check_update_arguments # :nodoc:
unless options[:args].empty? then
alert_error "Gem names are not allowed with the --system option"
terminate_interaction 1
end
end
def execute
hig = {}
if options[:system] then
update_rubygems
return
else
end
say "Updating installed gems"
hig = {} # highest installed gems
Gem::Specification.each do |spec|
if hig[spec.name].nil? or hig[spec.name].version < spec.version then
hig[spec.name] = spec
end
end
end
hig = highest_installed_gems
gems_to_update = which_to_update hig, options[:args].uniq
@ -85,6 +95,92 @@ class Gem::Commands::UpdateCommand < Gem::Command
end
end
def fetch_remote_gems spec # :nodoc:
dependency = Gem::Dependency.new spec.name, "> #{spec.version}"
dependency.prerelease = options[:prerelease]
fetcher = Gem::SpecFetcher.fetcher
spec_tuples, _ = fetcher.search_for_dependency dependency
spec_tuples
end
def highest_installed_gems # :nodoc:
hig = {} # highest installed gems
Gem::Specification.each do |spec|
if hig[spec.name].nil? or hig[spec.name].version < spec.version then
hig[spec.name] = spec
end
end
hig
end
def highest_remote_version spec # :nodoc:
spec_tuples = fetch_remote_gems spec
matching_gems = spec_tuples.select do |g,_|
g.name == spec.name and g.match_platform?
end
highest_remote_gem = matching_gems.sort_by { |g,_| g.version }.last
highest_remote_gem ||= [Gem::NameTuple.null]
highest_remote_gem.first.version
end
def install_rubygems version # :nodoc:
args = update_rubygems_arguments
update_dir = File.join Gem.dir, 'gems', "rubygems-update-#{version}"
Dir.chdir update_dir do
say "Installing RubyGems #{version}"
# Make sure old rubygems isn't loaded
old = ENV["RUBYOPT"]
ENV.delete("RUBYOPT") if old
installed = system Gem.ruby, 'setup.rb', *args
say "RubyGems system software updated" if installed
ENV["RUBYOPT"] = old if old
end
end
def rubygems_target_version
version = options[:system]
update_latest = version == true
if update_latest then
version = Gem::Version.new Gem::VERSION
requirement = Gem::Requirement.new ">= #{Gem::VERSION}"
else
version = Gem::Version.new version
requirement = Gem::Requirement.new version
end
rubygems_update = Gem::Specification.new
rubygems_update.name = 'rubygems-update'
rubygems_update.version = version
hig = {
'rubygems-update' => rubygems_update
}
gems_to_update = which_to_update hig, options[:args], :system
_, up_ver = gems_to_update.first
target = if update_latest then
up_ver
else
version
end
return target, requirement
end
def update_gem name, version = Gem::Requirement.default
return if @updated.any? { |spec| spec.name == name }
@ -118,74 +214,28 @@ class Gem::Commands::UpdateCommand < Gem::Command
# Update RubyGems software to the latest version.
def update_rubygems
unless options[:args].empty? then
alert_error "Gem names are not allowed with the --system option"
terminate_interaction 1
end
check_update_arguments
options[:user_install] = false
version, requirement = rubygems_target_version
# TODO: rename version and other variable name conflicts
# TODO: get rid of all this indirection on name and other BS
check_latest_rubygems version
version = options[:system]
if version == true then
version = Gem::Version.new Gem::VERSION
requirement = Gem::Requirement.new ">= #{Gem::VERSION}"
else
version = Gem::Version.new version
requirement = Gem::Requirement.new version
end
rubygems_update = Gem::Specification.new
rubygems_update.name = 'rubygems-update'
rubygems_update.version = version
hig = {
'rubygems-update' => rubygems_update
}
gems_to_update = which_to_update hig, options[:args], :system
name, up_ver = gems_to_update.first
current_ver = Gem.rubygems_version
target = if options[:system] == true then
up_ver
else
version
end
if current_ver == target then
# if options[:system] != true and version == current_ver then
say "Latest version currently installed. Aborting."
terminate_interaction
end
update_gem name, target
update_gem 'rubygems-update', version
installed_gems = Gem::Specification.find_all_by_name 'rubygems-update', requirement
version = installed_gems.last.version
install_rubygems version
end
def update_rubygems_arguments # :nodoc:
args = []
args << '--prefix' << Gem.prefix if Gem.prefix
# TODO use --document for >= 1.9 , --no-rdoc --no-ri < 1.9
args << '--no-rdoc' unless options[:document].include? 'rdoc'
args << '--no-ri' unless options[:document].include? 'ri'
args << '--no-format-executable' if options[:no_format_executable]
update_dir = File.join Gem.dir, 'gems', "rubygems-update-#{version}"
Dir.chdir update_dir do
say "Installing RubyGems #{version}"
setup_cmd = "#{Gem.ruby} setup.rb #{args.join ' '}"
# Make sure old rubygems isn't loaded
old = ENV["RUBYOPT"]
ENV.delete("RUBYOPT") if old
installed = system setup_cmd
say "RubyGems system software updated" if installed
ENV["RUBYOPT"] = old if old
end
args
end
def which_to_update highest_installed_gems, gem_names, system = false
@ -195,21 +245,7 @@ class Gem::Commands::UpdateCommand < Gem::Command
next if not gem_names.empty? and
gem_names.all? { |name| /#{name}/ !~ l_spec.name }
dependency = Gem::Dependency.new l_spec.name, "> #{l_spec.version}"
dependency.prerelease = options[:prerelease]
fetcher = Gem::SpecFetcher.fetcher
spec_tuples, _ = fetcher.search_for_dependency dependency
matching_gems = spec_tuples.select do |g,_|
g.name == l_name and g.match_platform?
end
highest_remote_gem = matching_gems.sort_by { |g,_| g.version }.last
highest_remote_gem ||= [Gem::NameTuple.null]
highest_remote_ver = highest_remote_gem.first.version
highest_remote_ver = highest_remote_version l_spec
if system or (l_spec.version < highest_remote_ver) then
result << [l_spec.name, [l_spec.version, highest_remote_ver].max]

Просмотреть файл

@ -7,7 +7,13 @@
# Base exception class for RubyGems. All exception raised by RubyGems are a
# subclass of this one.
class Gem::Exception < RuntimeError
attr_accessor :source_exception
##
#--
# TODO: remove in RubyGems 3, nobody sets this
attr_accessor :source_exception # :nodoc:
end
class Gem::CommandLineError < Gem::Exception; end

Просмотреть файл

@ -23,11 +23,13 @@ class Gem::Ext::Builder
make_program = (/mswin/ =~ RUBY_PLATFORM) ? 'nmake' : 'make'
end
destdir = '"DESTDIR=%s"' % ENV['DESTDIR'] if RUBY_VERSION > '2.0'
['', 'install'].each do |target|
# Pass DESTDIR via command line to override what's in MAKEFLAGS
cmd = [
make_program,
'"DESTDIR=%s"' % ENV['DESTDIR'],
destdir,
target
].join(' ').rstrip
run(cmd, results, "make #{target}".rstrip)

Просмотреть файл

@ -39,6 +39,7 @@ class Gem::Ext::ExtConfBuilder < Gem::Ext::Builder
run cmd, results
ENV["DESTDIR"] = nil
ENV["RUBYOPT"] = rubyopt
siteconf.unlink
make dest_path, results
@ -49,14 +50,14 @@ class Gem::Ext::ExtConfBuilder < Gem::Ext::Builder
destent.exist? or File.rename(ent.path, destent.path)
end
end
results
ensure
ENV["RUBYOPT"] = rubyopt
ENV["DESTDIR"] = destdir
end
end
t.unlink if t
t.unlink if t and t.path
results
ensure
FileUtils.rm_rf tmp_dest if tmp_dest
end

Просмотреть файл

@ -36,6 +36,8 @@ class Gem::PathSupport
@spec_cache_dir =
env["GEM_SPEC_CACHE"] || ENV["GEM_SPEC_CACHE"] ||
Gem.default_spec_cache_dir
@spec_cache_dir = @spec_cache_dir.dup.untaint
end
private

Просмотреть файл

@ -324,7 +324,11 @@ class Gem::RemoteFetcher
# connections to reduce connect overhead.
def request(uri, request_class, last_modified = nil)
Gem::Request.new(uri, request_class, last_modified, @proxy).fetch
request = Gem::Request.new uri, request_class, last_modified, @proxy
request.fetch do |req|
yield req if block_given?
end
end
def https?(uri)

Просмотреть файл

@ -1,4 +1,5 @@
require 'net/http'
require 'thread'
require 'time'
require 'rubygems/user_interaction'
@ -14,6 +15,7 @@ class Gem::Request
@last_modified = last_modified
@requests = Hash.new 0
@connections = {}
@connections_mutex = Mutex.new
@user_agent = user_agent
@proxy_uri =
@ -82,8 +84,11 @@ class Gem::Request
end
connection_id = [Thread.current.object_id, *net_http_args].join ':'
connection = @connections_mutex.synchronize do
@connections[connection_id] ||= Net::HTTP.new(*net_http_args)
connection = @connections[connection_id]
@connections[connection_id]
end
if https?(uri) and not connection.started? then
configure_connection_for_https(connection)

Просмотреть файл

@ -74,6 +74,12 @@ class Gem::SpecFetcher
list, errors = available_specs(type)
list.each do |source, specs|
if dependency.name.is_a?(String) && specs.respond_to?(:bsearch)
start_index = (0 ... specs.length).bsearch{ |i| specs[i].name >= dependency.name }
end_index = (0 ... specs.length).bsearch{ |i| specs[i].name > dependency.name }
specs = specs[start_index ... end_index] if start_index && end_index
end
found[source] = specs.select do |tup|
if dependency.match?(tup)
if matching_platform and !Gem::Platform.match(tup.platform)
@ -214,15 +220,15 @@ class Gem::SpecFetcher
def tuples_for(source, type, gracefully_ignore=false)
cache = @caches[type]
if gracefully_ignore
tuples =
begin
cache[source.uri] ||= source.load_specs(type)
rescue Gem::RemoteFetcher::FetchError
raise unless gracefully_ignore
[]
end
else
cache[source.uri] ||= source.load_specs(type)
end
tuples.sort_by { |tup| tup.name }
end
end

Просмотреть файл

@ -954,7 +954,7 @@ class Gem::Specification < Gem::BasicSpecification
result.map(&:last).map(&:values).flatten.reject { |spec|
minimum = native[spec.name]
minimum && spec.version < minimum
}
}.sort_by{ |tup| tup.name }
end
##
@ -1853,11 +1853,6 @@ class Gem::Specification < Gem::BasicSpecification
end
end
# Prevent ruby hitting spec.method_missing when [[spec]].flatten is called
def to_ary # :nodoc:
nil
end
##
# Normalize the list of files so that:
# * All file lists have redundancies removed.
@ -2008,6 +2003,10 @@ class Gem::Specification < Gem::BasicSpecification
@requirements = Array req
end
def respond_to_missing? m, include_private = false # :nodoc:
false
end
##
# Returns the full path to this spec's ri directory.

Просмотреть файл

@ -6,6 +6,13 @@ module Gem
# :nodoc:
PREFIX = "# stub: "
OPEN_MODE = # :nodoc:
if Object.const_defined? :Encoding then
'r:UTF-8:-'
else
'r'
end
# :nodoc:
class StubLine
attr_reader :parts
@ -96,7 +103,7 @@ module Gem
def data
unless @data
File.open(filename, "r:UTF-8:-") do |file|
open filename, OPEN_MODE do |file|
begin
file.readline # discard encoding line
stubline = file.readline.chomp

Просмотреть файл

@ -13,8 +13,13 @@ end
class TestGem < Gem::TestCase
PLUGINS_LOADED = []
def setup
super
PLUGINS_LOADED.clear
common_installer_setup
ENV.delete 'RUBYGEMS_GEMDEPS'
@ -345,9 +350,7 @@ class TestGem < Gem::TestCase
spec
}
# HACK should be Gem.refresh
Gem.searcher = nil
Gem::Specification.reset
Gem.refresh
expected = [
File.expand_path('test/rubygems/sff/discover.rb', @@project_dir),
@ -361,6 +364,37 @@ class TestGem < Gem::TestCase
assert_equal cwd, $LOAD_PATH.shift
end
def test_self_find_latest_files
cwd = File.expand_path("test/rubygems", @@project_dir)
$LOAD_PATH.unshift cwd
discover_path = File.join 'lib', 'sff', 'discover.rb'
_, foo2 = %w(1 2).map { |version|
spec = quick_gem 'sff', version do |s|
s.files << discover_path
end
write_file(File.join 'gems', spec.full_name, discover_path) do |fp|
fp.puts "# #{spec.full_name}"
end
spec
}
Gem.refresh
expected = [
File.expand_path('test/rubygems/sff/discover.rb', @@project_dir),
File.join(foo2.full_gem_path, discover_path),
]
assert_equal expected, Gem.find_latest_files('sff/discover')
assert_equal expected, Gem.find_latest_files('sff/**.rb'), '[ruby-core:31730]'
ensure
assert_equal cwd, $LOAD_PATH.shift
end
def test_self_latest_spec_for
a1 = quick_spec 'a', 1
a2 = quick_spec 'a', 2
@ -883,14 +917,20 @@ class TestGem < Gem::TestCase
Dir.chdir @tempdir do
FileUtils.mkdir_p 'lib'
File.open plugin_path, "w" do |fp|
fp.puts "class TestGem; TEST_SPEC_PLUGIN_LOAD = :loaded; end"
fp.puts "class TestGem; PLUGINS_LOADED << 'plugin'; end"
end
foo = quick_spec 'foo', '1' do |s|
foo1 = quick_spec 'foo', '1' do |s|
s.files << plugin_path
end
install_gem foo
install_gem foo1
foo2 = quick_spec 'foo', '2' do |s|
s.files << plugin_path
end
install_gem foo2
end
Gem.searcher = nil
@ -900,7 +940,7 @@ class TestGem < Gem::TestCase
Gem.load_plugins
assert_equal :loaded, TEST_SPEC_PLUGIN_LOAD
assert_equal %w[plugin], PLUGINS_LOADED
end
def test_load_env_plugins

Просмотреть файл

@ -58,7 +58,7 @@ class TestGemCommandManager < Gem::TestCase
use_ui @ui do
assert_raises Gem::MockGemUi::TermError do
@command_manager.run 'interrupt'
@command_manager.run %w[interrupt]
end
assert_equal '', ui.output
assert_equal "ERROR: Interrupted\n", ui.error
@ -75,7 +75,7 @@ class TestGemCommandManager < Gem::TestCase
@command_manager.register_command :crash
use_ui @ui do
assert_raises Gem::MockGemUi::TermError do
@command_manager.run 'crash'
@command_manager.run %w[crash]
end
assert_equal '', ui.output
err = ui.error.split("\n").first
@ -89,7 +89,7 @@ class TestGemCommandManager < Gem::TestCase
def test_process_args_bad_arg
use_ui @ui do
assert_raises Gem::MockGemUi::TermError do
@command_manager.process_args("--bad-arg")
@command_manager.process_args %w[--bad-arg]
end
end
@ -107,7 +107,7 @@ class TestGemCommandManager < Gem::TestCase
end
#check defaults
@command_manager.process_args("install")
@command_manager.process_args %w[install]
assert_equal %w[ri], check_options[:document].sort
assert_equal false, check_options[:force]
assert_equal :both, check_options[:domain]
@ -118,8 +118,10 @@ class TestGemCommandManager < Gem::TestCase
#check settings
check_options = nil
@command_manager.process_args(
"install --force --local --rdoc --install-dir . --version 3.0 --no-wrapper --bindir . ")
@command_manager.process_args %w[
install --force --local --rdoc --install-dir .
--version 3.0 --no-wrapper --bindir .
]
assert_equal %w[rdoc ri], check_options[:document].sort
assert_equal true, check_options[:force]
assert_equal :local, check_options[:domain]
@ -130,17 +132,17 @@ class TestGemCommandManager < Gem::TestCase
#check remote domain
check_options = nil
@command_manager.process_args("install --remote")
@command_manager.process_args %w[install --remote]
assert_equal :remote, check_options[:domain]
#check both domain
check_options = nil
@command_manager.process_args("install --both")
@command_manager.process_args %w[install --both]
assert_equal :both, check_options[:domain]
#check both domain
check_options = nil
@command_manager.process_args("install --both")
@command_manager.process_args %w[install --both]
assert_equal :both, check_options[:domain]
end
end
@ -155,12 +157,12 @@ class TestGemCommandManager < Gem::TestCase
end
#check defaults
@command_manager.process_args("uninstall")
@command_manager.process_args %w[uninstall]
assert_equal Gem::Requirement.default, check_options[:version]
#check settings
check_options = nil
@command_manager.process_args("uninstall foobar --version 3.0")
@command_manager.process_args %w[uninstall foobar --version 3.0]
assert_equal "foobar", check_options[:args].first
assert_equal Gem::Requirement.new('3.0'), check_options[:version]
end
@ -175,12 +177,12 @@ class TestGemCommandManager < Gem::TestCase
end
#check defaults
@command_manager.process_args("check")
@command_manager.process_args %w[check]
assert_equal true, check_options[:alien]
#check settings
check_options = nil
@command_manager.process_args("check foobar --alien")
@command_manager.process_args %w[check foobar --alien]
assert_equal true, check_options[:alien]
end
@ -194,12 +196,12 @@ class TestGemCommandManager < Gem::TestCase
end
#check defaults
@command_manager.process_args("build")
@command_manager.process_args %w[build]
#NOTE: Currently no defaults
#check settings
check_options = nil
@command_manager.process_args("build foobar.rb")
@command_manager.process_args %w[build foobar.rb]
assert_equal 'foobar.rb', check_options[:args].first
end
@ -213,26 +215,26 @@ class TestGemCommandManager < Gem::TestCase
end
#check defaults
@command_manager.process_args("query")
@command_manager.process_args %w[query]
assert_equal(//, check_options[:name])
assert_equal :local, check_options[:domain]
assert_equal false, check_options[:details]
#check settings
check_options = nil
@command_manager.process_args("query --name foobar --local --details")
@command_manager.process_args %w[query --name foobar --local --details]
assert_equal(/foobar/i, check_options[:name])
assert_equal :local, check_options[:domain]
assert_equal true, check_options[:details]
#remote domain
check_options = nil
@command_manager.process_args("query --remote")
@command_manager.process_args %w[query --remote]
assert_equal :remote, check_options[:domain]
#both (local/remote) domains
check_options = nil
@command_manager.process_args("query --both")
@command_manager.process_args %w[query --both]
assert_equal :both, check_options[:domain]
end
@ -246,12 +248,12 @@ class TestGemCommandManager < Gem::TestCase
end
#check defaults
@command_manager.process_args("update")
@command_manager.process_args %w[update]
assert_includes check_options[:document], 'rdoc'
#check settings
check_options = nil
@command_manager.process_args("update --force --rdoc --install-dir .")
@command_manager.process_args %w[update --force --rdoc --install-dir .]
assert_includes check_options[:document], 'ri'
assert_equal true, check_options[:force]
assert_equal Dir.pwd, check_options[:install_dir]

Просмотреть файл

@ -91,6 +91,34 @@ class TestGemCommandsContentsCommand < Gem::TestCase
assert_equal "", @ui.error
end
def test_execute_missing_single
@cmd.options[:args] = %w[foo]
assert_raises Gem::MockGemUi::TermError do
use_ui @ui do
@cmd.execute
end
end
assert_match "Unable to find gem 'foo'", @ui.output
assert_empty @ui.error
end
def test_execute_missing_multiple
@cmd.options[:args] = %w[foo bar]
gem 'foo'
use_ui @ui do
@cmd.execute
end
assert_match "lib/foo.rb", @ui.output
assert_match "Unable to find gem 'bar'", @ui.output
assert_empty @ui.error
end
def test_execute_multiple
@cmd.options[:args] = %w[foo bar]

Просмотреть файл

@ -18,7 +18,7 @@ class TestGemCommandsHelpCommand < Gem::TestCase
def test_gem_help_bad
util_gem 'bad' do |out, err|
assert_equal('', out)
assert_match(/Unknown command bad. Try gem help commands\n/, err)
assert_match "Unknown command bad", err
end
end

Просмотреть файл

@ -104,9 +104,9 @@ class TestGemCommandsPristineCommand < Gem::TestCase
assert_path_exists gem_exec
if win_platform?
assert_match /\A#!\s*ruby/, File.read(gem_exec)
assert_match %r%\A#!\s*ruby%, File.read(gem_exec)
else
assert_match /\A#!\s*\/usr\/bin\/env ruby/, File.read(gem_exec)
assert_match %r%\A#!\s*/usr/bin/env ruby%, File.read(gem_exec)
end
end

Просмотреть файл

@ -195,6 +195,34 @@ pl (1)
assert_equal '', @ui.error
end
def test_execute_installed_inverse
@cmd.handle_options %w[-n a --no-installed]
e = assert_raises Gem::MockGemUi::TermError do
use_ui @ui do
@cmd.execute
end
end
assert_equal "false\n", @ui.output
assert_equal '', @ui.error
assert_equal 1, e.exit_code
end
def test_execute_installed_inverse_not_installed
@cmd.handle_options %w[-n not_installed --no-installed]
assert_raises Gem::MockGemUi::SystemExitException do
use_ui @ui do
@cmd.execute
end
end
assert_equal "true\n", @ui.output
assert_equal '', @ui.error
end
def test_execute_installed_no_name
@cmd.handle_options %w[--installed]

Просмотреть файл

@ -0,0 +1,17 @@
require 'rubygems/test_case'
require 'rubygems/commands/search_command'
class TestGemCommandsSearchCommand < Gem::TestCase
def setup
super
@cmd = Gem::Commands::SearchCommand.new
end
def test_initialize
assert_equal :remote, @cmd.defaults[:domain]
end
end

Просмотреть файл

@ -16,6 +16,20 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
@executable = File.join(@gemhome, 'bin', 'executable')
end
def test_execute_all_gem_names
@cmd.options[:args] = %w[a b]
@cmd.options[:all] = true
assert_raises Gem::MockGemUi::TermError do
use_ui @ui do
@cmd.execute
end
end
assert_equal "ERROR: Gem names and --all may not be used together\n",
@ui.error
end
def test_execute_dependency_order
c = quick_gem 'c' do |spec|
spec.add_dependency 'a'
@ -43,6 +57,7 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
def test_execute_removes_executable
ui = Gem::MockGemUi.new
util_setup_gem ui
build_rake_in do
@ -175,5 +190,23 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
assert Gem::Specification.find_all_by_name('x').length == 0
end
def test_execute_all
ui = Gem::MockGemUi.new "y\n"
util_make_gems
util_setup_gem ui
assert Gem::Specification.find_all_by_name('a').length > 1
@cmd.options[:all] = true
@cmd.options[:args] = []
use_ui ui do
@cmd.execute
end
refute_includes Gem::Specification.all_names, 'a'
end
end

Просмотреть файл

@ -0,0 +1,58 @@
require 'rubygems/test_case'
require 'rubygems/ext'
class TestGemExtBuilder < Gem::TestCase
def setup
super
@ext = File.join @tempdir, 'ext'
@dest_path = File.join @tempdir, 'prefix'
FileUtils.mkdir_p @ext
FileUtils.mkdir_p @dest_path
@orig_DESTDIR = ENV['DESTDIR']
end
def teardown
ENV['DESTDIR'] = @orig_DESTDIR
super
end
def test_class_make
ENV['DESTDIR'] = 'destination'
results = []
Dir.chdir @ext do
open 'Makefile', 'w' do |io|
io.puts <<-MAKEFILE
all:
\t@#{Gem.ruby} -e "puts %Q{all: \#{ENV['DESTDIR']}}"
install:
\t@#{Gem.ruby} -e "puts %Q{install: \#{ENV['DESTDIR']}}"
MAKEFILE
end
Gem::Ext::Builder.make @dest_path, results
end
results = results.join "\n"
if RUBY_VERSION > '2.0' then
assert_match %r%"DESTDIR=#{ENV['DESTDIR']}"$%, results
assert_match %r%"DESTDIR=#{ENV['DESTDIR']}" install$%, results
else
refute_match %r%"DESTDIR=#{ENV['DESTDIR']}"$%, results
refute_match %r%"DESTDIR=#{ENV['DESTDIR']}" install$%, results
end
assert_match %r%^all: destination$%, results
assert_match %r%^install: destination$%, results
end
end

Просмотреть файл

@ -27,7 +27,10 @@ class TestGemExtExtConfBuilder < Gem::TestCase
output = []
Dir.chdir @ext do
result =
Gem::Ext::ExtConfBuilder.build 'extconf.rb', nil, @dest_path, output
assert_same result, output
end
assert_match(/^#{Gem.ruby} extconf.rb/, output[0])
@ -108,6 +111,42 @@ checking for main\(\) in .*?nonexistent/m, error.message)
assert_equal("#{Gem.ruby} extconf.rb", output[0])
end
def test_class_build_unconventional
if vc_windows? && !nmake_found?
skip("test_class_build skipped - nmake not found")
end
File.open File.join(@ext, 'extconf.rb'), 'w' do |extconf|
extconf.puts <<-'EXTCONF'
include RbConfig
ruby_exe = "#{CONFIG['RUBY_INSTALL_NAME']}#{CONFIG['EXEEXT']}"
ruby = File.join CONFIG['bindir'], ruby_exe
open 'Makefile', 'w' do |io|
io.write <<-Makefile
all: ruby
install: ruby
ruby:
\t#{ruby} -e0
Makefile
end
EXTCONF
end
output = []
Dir.chdir @ext do
Gem::Ext::ExtConfBuilder.build 'extconf.rb', nil, @dest_path, output
end
assert_contains_make_command '', output[2]
assert_contains_make_command 'install', output[4]
assert_empty Dir.glob(File.join(@ext, 'siteconf*.rb'))
end
def test_class_make
if vc_windows? && !nmake_found?
skip("test_class_make skipped - nmake not found")

Просмотреть файл

@ -580,6 +580,17 @@ gems:
end
end
def test_request_block
fetcher = Gem::RemoteFetcher.new nil
assert_throws :block_called do
fetcher.request URI('http://example'), Net::HTTP::Get do |req|
assert_kind_of Net::HTTPGenericRequest, req
throw :block_called
end
end
end
def test_yaml_error_on_size
use_ui @ui do
self.class.enable_yaml = false