summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorryan <ryan@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-01 03:45:05 +0000
committerryan <ryan@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-01 03:45:05 +0000
commitd22130922e7842226d38d59680e4bbb48a28a5f0 ()
tree39594d3a14641dd5488a99a5e633239296fa5742
parent4752539e3f3e563d559732c52424206bd6f12dbd (diff)
Import rubygems 1.8.5 (released @ 137c80f)
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31885 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--lib/rubygems.rb444
-rw-r--r--lib/rubygems/builder.rb13
-rw-r--r--lib/rubygems/command.rb10
-rw-r--r--lib/rubygems/command_manager.rb18
-rw-r--r--lib/rubygems/commands/build_command.rb24
-rw-r--r--lib/rubygems/commands/cert_command.rb2
-rw-r--r--lib/rubygems/commands/cleanup_command.rb29
-rw-r--r--lib/rubygems/commands/contents_command.rb31
-rw-r--r--lib/rubygems/commands/dependency_command.rb68
-rw-r--r--lib/rubygems/commands/fetch_command.rb11
-rw-r--r--lib/rubygems/commands/install_command.rb3
-rw-r--r--lib/rubygems/commands/lock_command.rb8
-rw-r--r--lib/rubygems/commands/outdated_command.rb8
-rw-r--r--lib/rubygems/commands/pristine_command.rb50
-rw-r--r--lib/rubygems/commands/query_command.rb15
-rw-r--r--lib/rubygems/commands/server_command.rb2
-rw-r--r--lib/rubygems/commands/setup_command.rb2
-rw-r--r--lib/rubygems/commands/specification_command.rb31
-rw-r--r--lib/rubygems/commands/stale_command.rb3
-rw-r--r--lib/rubygems/commands/unpack_command.rb60
-rw-r--r--lib/rubygems/commands/update_command.rb40
-rw-r--r--lib/rubygems/commands/which_command.rb14
-rw-r--r--lib/rubygems/config_file.rb16
-rw-r--r--lib/rubygems/custom_require.rb11
-rw-r--r--lib/rubygems/defaults.rb44
-rw-r--r--lib/rubygems/dependency.rb52
-rw-r--r--lib/rubygems/dependency_installer.rb78
-rw-r--r--lib/rubygems/dependency_list.rb29
-rw-r--r--lib/rubygems/deprecate.rb74
-rw-r--r--lib/rubygems/doc_manager.rb21
-rw-r--r--lib/rubygems/ext/builder.rb2
-rw-r--r--lib/rubygems/ext/rake_builder.rb4
-rw-r--r--lib/rubygems/gem_path_searcher.rb26
-rw-r--r--lib/rubygems/gem_runner.rb4
-rw-r--r--lib/rubygems/indexer.rb238
-rw-r--r--lib/rubygems/installer.rb209
-rw-r--r--lib/rubygems/installer_test_case.rb58
-rw-r--r--lib/rubygems/local_remote_options.rb4
-rw-r--r--lib/rubygems/mock_gem_ui.rb14
-rw-r--r--lib/rubygems/package.rb28
-rw-r--r--lib/rubygems/package/tar_input.rb12
-rw-r--r--lib/rubygems/package/tar_writer.rb2
-rw-r--r--lib/rubygems/package_task.rb2
-rw-r--r--lib/rubygems/path_support.rb78
-rw-r--r--lib/rubygems/platform.rb14
-rw-r--r--lib/rubygems/remote_fetcher.rb114
-rw-r--r--lib/rubygems/requirement.rb12
-rw-r--r--lib/rubygems/security.rb2
-rw-r--r--lib/rubygems/server.rb134
-rw-r--r--lib/rubygems/source_index.rb172
-rw-r--r--lib/rubygems/spec_fetcher.rb17
-rw-r--r--lib/rubygems/specification.rb2467
-rw-r--r--lib/rubygems/test_case.rb188
-rw-r--r--lib/rubygems/test_utilities.rb7
-rw-r--r--lib/rubygems/text.rb2
-rw-r--r--lib/rubygems/uninstaller.rb89
-rw-r--r--lib/rubygems/user_interaction.rb58
-rw-r--r--test/rubygems/functional.rb98
-rw-r--r--test/rubygems/test_gem.rb277
-rw-r--r--test/rubygems/test_gem_builder.rb19
-rw-r--r--test/rubygems/test_gem_command_manager.rb2
-rw-r--r--test/rubygems/test_gem_commands_build_command.rb34
-rw-r--r--test/rubygems/test_gem_commands_cleanup_command.rb57
-rw-r--r--test/rubygems/test_gem_commands_contents_command.rb49
-rw-r--r--test/rubygems/test_gem_commands_dependency_command.rb29
-rw-r--r--test/rubygems/test_gem_commands_fetch_command.rb9
-rw-r--r--test/rubygems/test_gem_commands_help_command.rb64
-rw-r--r--test/rubygems/test_gem_commands_install_command.rb49
-rw-r--r--test/rubygems/test_gem_commands_list_command.rb5
-rw-r--r--test/rubygems/test_gem_commands_outdated_command.rb19
-rw-r--r--test/rubygems/test_gem_commands_pristine_command.rb115
-rw-r--r--test/rubygems/test_gem_commands_push_command.rb2
-rw-r--r--test/rubygems/test_gem_commands_query_command.rb97
-rw-r--r--test/rubygems/test_gem_commands_sources_command.rb17
-rw-r--r--test/rubygems/test_gem_commands_specification_command.rb16
-rw-r--r--test/rubygems/test_gem_commands_stale_command.rb8
-rw-r--r--test/rubygems/test_gem_commands_unpack_command.rb57
-rw-r--r--test/rubygems/test_gem_commands_update_command.rb69
-rw-r--r--test/rubygems/test_gem_commands_which_command.rb11
-rw-r--r--test/rubygems/test_gem_dependency.rb29
-rw-r--r--test/rubygems/test_gem_dependency_installer.rb120
-rw-r--r--test/rubygems/test_gem_dependency_list.rb12
-rw-r--r--test/rubygems/test_gem_doc_manager.rb6
-rw-r--r--test/rubygems/test_gem_format.rb2
-rw-r--r--test/rubygems/test_gem_gem_path_searcher.rb74
-rw-r--r--test/rubygems/test_gem_gem_runner.rb5
-rw-r--r--test/rubygems/test_gem_indexer.rb95
-rw-r--r--test/rubygems/test_gem_install_update_options.rb11
-rw-r--r--test/rubygems/test_gem_installer.rb102
-rw-r--r--test/rubygems/test_gem_package_tar_output.rb1
-rw-r--r--test/rubygems/test_gem_path_support.rb64
-rw-r--r--test/rubygems/test_gem_platform.rb2
-rw-r--r--test/rubygems/test_gem_remote_fetcher.rb194
-rw-r--r--test/rubygems/test_gem_requirement.rb13
-rw-r--r--test/rubygems/test_gem_server.rb38
-rw-r--r--test/rubygems/test_gem_silent_ui.rb4
-rw-r--r--test/rubygems/test_gem_source_index.rb463
-rw-r--r--test/rubygems/test_gem_spec_fetcher.rb91
-rw-r--r--test/rubygems/test_gem_specification.rb437
-rw-r--r--test/rubygems/test_gem_text.rb15
-rw-r--r--test/rubygems/test_gem_uninstaller.rb66
-rw-r--r--test/rubygems/test_kernel.rb3
103 files changed, 4707 insertions, 3416 deletions
@@ -1,3 +1,8 @@
Wed Jun 1 12:34:00 2011 Kenta Murata <[email protected]>
* NEWS: add new features of bigdecimal.
@@ -33,7 +33,9 @@ end
require 'rubygems/defaults'
require "rubygems/dependency_list"
require 'rbconfig'
##
# RubyGems is the Ruby standard for publishing and managing third party
@@ -124,7 +126,7 @@ require 'rbconfig'
# -The RubyGems Team
module Gem
- VERSION = '1.6.2'
##
# Raised when RubyGems is unable to load or activate a gem. Contains the
@@ -160,11 +162,6 @@ module Gem
end
end
- ##
- # Default directories in a gem repository
-
- DIRECTORIES = %w[cache doc gems specifications] unless defined?(DIRECTORIES)
-
RubyGemsPackageVersion = VERSION
RUBYGEMS_DIR = File.dirname File.expand_path(__FILE__)
@@ -188,16 +185,17 @@ module Gem
@configuration = nil
@loaded_specs = {}
- @loaded_stacks = {}
@platforms = []
@ruby = nil
- @sources = []
@post_build_hooks ||= []
@post_install_hooks ||= []
@post_uninstall_hooks ||= []
@pre_uninstall_hooks ||= []
@pre_install_hooks ||= []
##
# Try to activate a gem containing +path+. Returns true if
@@ -205,17 +203,18 @@ module Gem
# activated. Returns false if it can't find the path in a gem.
def self.try_activate path
# finds the _latest_ version... regardless of loaded specs and their deps
# TODO: use find_all and bork if ambiguous
- spec = Gem.searcher.find path
return false unless spec
begin
- Gem.activate spec.name, "= #{spec.version}"
rescue Gem::LoadError # this could fail due to gem dep collisions, go lax
- Gem.activate spec.name
end
return true
@@ -238,94 +237,18 @@ module Gem
# Gem::Requirement and Gem::Version documentation.
def self.activate(dep, *requirements)
- # TODO: remove options entirely
- if requirements.last.is_a?(Hash)
- options = requirements.pop
- else
- options = {}
- end
-
- requirements = Gem::Requirement.default if requirements.empty?
- dep = Gem::Dependency.new(dep, requirements) unless Gem::Dependency === dep
-
- # TODO: remove sources entirely
- sources = options[:sources] || []
- matches = Gem.source_index.search dep, true
- report_activate_error(dep) if matches.empty?
-
- if @loaded_specs[dep.name] then
- # This gem is already loaded. If the currently loaded gem is not in the
- # list of candidate gems, then we have a version conflict.
- existing_spec = @loaded_specs[dep.name]
-
- # TODO: unless dep.matches_spec? existing_spec then
- unless matches.any? { |spec| spec.version == existing_spec.version } then
- sources_message = sources.map { |spec| spec.full_name }
- stack_message = @loaded_stacks[dep.name].map { |spec| spec.full_name }
-
- msg = "can't activate #{dep} for #{sources_message.inspect}, "
- msg << "already activated #{existing_spec.full_name} for "
- msg << "#{stack_message.inspect}"
-
- e = Gem::LoadError.new msg
- e.name = dep.name
- e.requirement = dep.requirement
-
- raise e
- end
-
- return false
- end
-
- spec = matches.last
-
- conf = spec.conflicts
- unless conf.empty? then
- why = conf.map { |act,con|
- "#{act.full_name} conflicts with #{con.join(", ")}"
- }.join ", "
-
- # TODO: improve message by saying who activated `con`
-
- raise LoadError, "Unable to activate #{spec.full_name}, because #{why}"
- end
-
- return false if spec.loaded?
-
- spec.loaded = true
- @loaded_specs[spec.name] = spec
- @loaded_stacks[spec.name] = sources.dup
-
- spec.runtime_dependencies.each do |spec_dep|
- next if Gem.loaded_specs.include? spec_dep.name
- specs = Gem.source_index.search spec_dep, true
-
- if specs.size == 1 then
- self.activate spec_dep
- else
- name = spec_dep.name
- unresolved_deps[name] = unresolved_deps[name].merge spec_dep
- end
- end
-
- unresolved_deps.delete spec.name
- require_paths = spec.require_paths.map do |path|
- File.join spec.full_gem_path, path
- end
-
- # gem directories must come after -I and ENV['RUBYLIB']
- insert_index = load_path_insert_index
- if insert_index then
- # gem directories must come after -I and ENV['RUBYLIB']
- $LOAD_PATH.insert(insert_index, *require_paths)
- else
- # we are probably testing in core, -I and RUBYLIB don't apply
- $LOAD_PATH.unshift(*require_paths)
- end
- return true
end
def self.unresolved_deps
@@ -341,7 +264,7 @@ module Gem
Gem.path.each do |gemdir|
each_load_path all_partials(gemdir) do |load_path|
- result << load_path
end
end
@@ -352,7 +275,7 @@ module Gem
# Return all the partial paths in +gemdir+.
def self.all_partials(gemdir)
- Dir[File.join(gemdir, 'gems/*')]
end
private_class_method :all_partials
@@ -360,15 +283,14 @@ module Gem
##
# See if a given gem is available.
- def self.available?(gem, *requirements)
requirements = Gem::Requirement.default if requirements.empty?
- unless gem.respond_to?(:name) and
- gem.respond_to?(:requirement) then
- gem = Gem::Dependency.new gem, requirements
end
- !Gem.source_index.search(gem).empty?
end
##
@@ -378,30 +300,29 @@ module Gem
# you to specify specific gem versions.
def self.bin_path(name, exec_name = nil, *requirements)
requirements = Gem::Requirement.default if
requirements.empty?
- specs = Gem.source_index.find_name(name, requirements)
raise Gem::GemNotFoundException,
"can't find gem #{name} (#{requirements})" if specs.empty?
- specs = specs.find_all do |spec|
- spec.executables.include?(exec_name)
- end if exec_name
unless spec = specs.last
msg = "can't find gem #{name} (#{requirements}) with executable #{exec_name}"
raise Gem::GemNotFoundException, msg
end
- exec_name ||= spec.default_executable
-
- unless exec_name
- msg = "no default executable for #{spec.full_name} and none given"
- raise Gem::Exception, msg
- end
-
- File.join(spec.full_gem_path, spec.bindir, exec_name)
end
##
@@ -415,8 +336,9 @@ module Gem
# The path where gem executables are to be installed.
def self.bindir(install_dir=Gem.dir)
- return File.join(install_dir, 'bin') unless
- install_dir.to_s == Gem.default_dir
Gem.default_bindir
end
@@ -426,20 +348,18 @@ module Gem
# mainly used by the unit tests to provide test isolation.
def self.clear_paths
- @gem_home = nil
- @gem_path = nil
- @user_home = nil
-
@@source_index = nil
-
- @searcher = nil
end
##
# The path to standard location of the user's .gemrc file.
def self.config_file
- File.join Gem.user_home, '.gemrc'
end
##
@@ -462,9 +382,10 @@ module Gem
# package is not available as a gem, return nil.
def self.datadir(gem_name)
spec = @loaded_specs[gem_name]
return nil if spec.nil?
- File.join(spec.full_gem_path, 'data', gem_name)
end
##
@@ -475,13 +396,29 @@ module Gem
Zlib::Deflate.deflate data
end
##
# The path where gems are to be installed.
def self.dir
- @gem_home ||= nil
- set_home(ENV['GEM_HOME'] || default_dir) unless @gem_home
- @gem_home
end
##
@@ -490,33 +427,35 @@ module Gem
def self.each_load_path(partials)
partials.each do |gp|
- base = File.basename(gp)
- specfn = File.join(dir, "specifications", base + ".gemspec")
- if File.exist?(specfn)
- spec = eval(File.read(specfn))
spec.require_paths.each do |rp|
- yield(File.join(gp, rp))
end
else
- filename = File.join(gp, 'lib')
- yield(filename) if File.exist?(filename)
end
end
end
private_class_method :each_load_path
##
# Quietly ensure the named Gem directory contains all the proper
# subdirectories. If we can't create a directory due to a permission
# problem, then we will silently continue.
- def self.ensure_gem_subdirectories(gemdir)
require 'fileutils'
- Gem::DIRECTORIES.each do |filename|
- fn = File.join gemdir, filename
- FileUtils.mkdir_p fn rescue nil unless File.exist? fn
end
end
@@ -541,11 +480,9 @@ module Gem
}.flatten.select { |file| File.file? file.untaint }
end
- specs = searcher.find_all glob
-
- specs.each do |spec|
- files.concat searcher.matching_files(spec, glob)
- end
# $LOAD_PATH might contain duplicate entries or reference
# the spec dirs directly, so we prune.
@@ -565,25 +502,30 @@ module Gem
# it should fallback to USERPROFILE and HOMEDRIVE + HOMEPATH (at
# least on Win32).
#++
def self.find_home
- unless RUBY_VERSION > '1.9' then
- ['HOME', 'USERPROFILE'].each do |homekey|
- return File.expand_path(ENV[homekey]) if ENV[homekey]
end
if ENV['HOMEDRIVE'] && ENV['HOMEPATH'] then
- return File.expand_path("#{ENV['HOMEDRIVE']}#{ENV['HOMEPATH']}")
end
end
-
- File.expand_path "~"
rescue
- if File::ALT_SEPARATOR then
- drive = ENV['HOMEDRIVE'] || ENV['SystemDrive']
- File.join(drive.to_s, '/')
else
- "/"
end
end
@@ -593,6 +535,7 @@ module Gem
# Zlib::GzipReader wrapper that unzips +data+.
def self.gunzip(data)
require 'stringio'
require 'zlib'
data = StringIO.new data
@@ -604,6 +547,7 @@ module Gem
# Zlib::GzipWriter wrapper that zips +data+.
def self.gzip(data)
require 'stringio'
require 'zlib'
zipped = StringIO.new
@@ -617,6 +561,7 @@ module Gem
# A Zlib::Inflate#inflate wrapper
def self.inflate(data)
require 'zlib'
Zlib::Inflate.inflate data
end
@@ -626,12 +571,14 @@ module Gem
# <tt>https://rubygems.org</tt>.
def self.host
@host ||= "https://rubygems.org"
end
## Set the default RubyGems API host.
def self.host= host
@host = host
end
@@ -644,7 +591,7 @@ module Gem
Gem.path.each do |gemdir|
each_load_path(latest_partials(gemdir)) do |load_path|
- result << load_path
end
end
@@ -657,8 +604,9 @@ module Gem
def self.latest_partials(gemdir)
latest = {}
all_partials(gemdir).each do |gp|
- base = File.basename(gp)
- if base =~ /(.*)-((\d+\.)*\d+)/ then
name, version = $1, $2
ver = Gem::Version.new(version)
if latest[name].nil? || ver > latest[name][0]
@@ -712,6 +660,7 @@ module Gem
file = $1
lineno = $2.to_i
[file, lineno]
end
@@ -723,25 +672,6 @@ module Gem
end
##
- # Array of paths to search for Gems.
-
- def self.path
- @gem_path ||= nil
-
- unless @gem_path then
- paths = [ENV['GEM_PATH'] || default_path]
-
- if defined?(APPLE_GEM_HOME) and not ENV['GEM_PATH'] then
- paths << APPLE_GEM_HOME
- end
-
- set_paths paths.compact.join(File::PATH_SEPARATOR)
- end
-
- @gem_path
- end
-
- ##
# Get the appropriate cache path.
#
# Pass a string to use a different base path, or nil/false (default) for
@@ -749,7 +679,7 @@ module Gem
#
def self.cache_dir(custom_dir=false)
- File.join(custom_dir ? custom_dir : Gem.dir, 'cache')
end
##
@@ -759,7 +689,7 @@ module Gem
# nil/false (default) for Gem.dir.
def self.cache_gem(filename, user_dir=false)
- File.join(cache_dir(user_dir), filename)
end
##
@@ -800,6 +730,14 @@ module Gem
end
##
# Adds a post-uninstall hook that will be passed a Gem::Uninstaller instance
# and the spec that was uninstalled when Gem::Uninstaller#uninstall is
# called
@@ -818,6 +756,14 @@ module Gem
end
##
# Adds a pre-uninstall hook that will be passed an Gem::Uninstaller instance
# and the spec that will be uninstalled when Gem::Uninstaller#uninstall is
# called
@@ -853,10 +799,10 @@ module Gem
raise ArgumentError, "gem #{gem_name} is not activated" if gem.nil?
raise ArgumentError, "gem #{over_name} is not activated" if over.nil?
- last_gem_path = File.join gem.full_gem_path, gem.require_paths.last
over_paths = over.require_paths.map do |path|
- File.join over.full_gem_path, path
end
over_paths.each do |path|
@@ -872,8 +818,8 @@ module Gem
# Refresh source_index from disk and clear searcher.
def self.refresh
- source_index.refresh!
-
@searcher = nil
end
@@ -890,7 +836,7 @@ module Gem
# any version by the requested name.
def self.report_activate_error(gem)
- matches = Gem.source_index.find_name(gem.name)
if matches.empty? then
error = Gem::LoadError.new(
@@ -915,14 +861,14 @@ module Gem
def self.required_location(gemname, libfile, *requirements)
requirements = Gem::Requirement.default if requirements.empty?
- matches = Gem.source_index.find_name gemname, requirements
return nil if matches.empty?
spec = matches.last
spec.require_paths.each do |path|
- result = File.join spec.full_gem_path, path, libfile
- return result if File.exist? result
end
nil
@@ -934,11 +880,9 @@ module Gem
def self.ruby
if @ruby.nil? then
@ruby = File.join(ConfigMap[:bindir],
- ConfigMap[:ruby_install_name])
- @ruby << ConfigMap[:EXEEXT]
- # escape string in case path to ruby executable contain spaces.
- @ruby.sub!(/.*\s.*/m, '"\&"')
end
@ruby
@@ -991,44 +935,12 @@ module Gem
end
##
- # Set the Gem home directory (as reported by Gem.dir).
-
- def self.set_home(home)
- home = home.gsub File::ALT_SEPARATOR, File::SEPARATOR if File::ALT_SEPARATOR
- @gem_home = home
- end
-
- private_class_method :set_home
-
- ##
- # Set the Gem search path (as reported by Gem.path).
-
- def self.set_paths(gpaths)
- if gpaths
- @gem_path = gpaths.split(File::PATH_SEPARATOR)
-
- if File::ALT_SEPARATOR then
- @gem_path.map! do |path|
- path.gsub File::ALT_SEPARATOR, File::SEPARATOR
- end
- end
-
- @gem_path << Gem.dir
- else
- # TODO: should this be Gem.default_path instead?
- @gem_path = [Gem.dir]
- end
-
- @gem_path.uniq!
- end
-
- private_class_method :set_paths
-
- ##
# Returns the Gem::SourceIndex of specifications that are in the Gem.path
def self.source_index
- @@source_index ||= SourceIndex.from_installed_gems
end
##
@@ -1037,23 +949,14 @@ module Gem
# default_sources if it is not installed.
def self.sources
- if @sources.empty? then
- begin
- gem 'sources', '> 0.0.1'
- require 'sources'
- rescue LoadError
- @sources = default_sources
- end
- end
-
- @sources
end
##
# Need to be able to set the sources without calling
# Gem.sources.replace since that would cause an infinite loop.
- def self.sources=(new_sources)
@sources = new_sources
end
@@ -1115,9 +1018,8 @@ module Gem
# by the unit tests to provide environment isolation.
def self.use_paths(home, paths=[])
- clear_paths
- set_home(home) if home
- set_paths(paths.join(File::PATH_SEPARATOR)) if paths
end
##
@@ -1202,6 +1104,11 @@ module Gem
attr_reader :post_install_hooks
##
# The list of hooks to be run before Gem::Uninstall#uninstall does any
# work
@@ -1213,18 +1120,17 @@ module Gem
attr_reader :pre_install_hooks
##
# The list of hooks to be run after Gem::Uninstall#uninstall is finished
attr_reader :pre_uninstall_hooks
-
end
def self.cache # :nodoc:
- warn "#{Gem.location_of_caller.join ':'}:Warning: " \
- "Gem::cache is deprecated and will be removed on or after " \
- "August 2011. " \
- "Use Gem::source_index."
-
source_index
end
@@ -1233,17 +1139,17 @@ module Gem
MARSHAL_SPEC_DIR = "quick/Marshal.#{Gem.marshal_version}/"
- autoload :Version, 'rubygems/version'
- autoload :Requirement, 'rubygems/requirement'
- autoload :Dependency, 'rubygems/dependency'
autoload :GemPathSearcher, 'rubygems/gem_path_searcher'
- autoload :SpecFetcher, 'rubygems/spec_fetcher'
- autoload :Specification, 'rubygems/specification'
- autoload :Cache, 'rubygems/source_index'
- autoload :SourceIndex, 'rubygems/source_index'
- autoload :Platform, 'rubygems/platform'
- autoload :Builder, 'rubygems/builder'
- autoload :ConfigFile, 'rubygems/config_file'
end
module Kernel
@@ -1279,7 +1185,8 @@ module Kernel
def gem(gem_name, *requirements) # :doc:
skip_list = (ENV['GEM_SKIP'] || "").split(/:/)
raise Gem::LoadError, "skipping #{gem_name}" if skip_list.include? gem_name
- Gem.activate(gem_name, *requirements)
end
private :gem
@@ -1300,8 +1207,7 @@ def RbConfig.datadir(package_name)
require 'rbconfig/datadir'
- Gem.datadir(package_name) ||
- File.join(Gem::ConfigMap[:datadir], package_name)
end
require 'rubygems/exceptions'
@@ -1334,3 +1240,25 @@ require 'rubygems/custom_require'
Gem.clear_paths
@@ -44,7 +44,7 @@ class Gem::Builder
@signer = sign
write_package
say success if Gem.configuration.verbose
- @spec.file_name
end
def success
@@ -52,7 +52,7 @@ class Gem::Builder
Successfully built RubyGem
Name: #{@spec.name}
Version: #{@spec.version}
- File: #{@spec.file_name}
EOM
end
@@ -79,16 +79,17 @@ EOM
end
def write_package
- open @spec.file_name, 'wb' do |gem_io|
Gem::Package.open gem_io, 'w', @signer do |pkg|
yaml = @spec.to_yaml
pkg.metadata = yaml
@spec.files.each do |file|
- next if File.directory? file
- next if file == @spec.file_name # Don't add gem onto itself
- stat = File.stat file
mode = stat.mode & 0777
size = stat.size
@@ -410,10 +410,12 @@ class Gem::Command
end
end
- @parser.separator nil
- @parser.separator " Summary:"
- wrap(@summary, 80 - 4).split("\n").each do |line|
- @parser.separator " #{line.strip}"
end
if description then
@@ -44,6 +44,13 @@ class Gem::CommandManager
end
##
# Register all the subcommands supported by the gem command.
def initialize
@@ -87,6 +94,13 @@ class Gem::CommandManager
end
##
# Return the registered command from the command name.
def [](command_name)
@@ -166,7 +180,7 @@ class Gem::CommandManager
retried = false
begin
- commands.const_get const_name
rescue NameError
raise if retried
@@ -179,7 +193,7 @@ class Gem::CommandManager
Gem.configuration.backtrace
end
retry
- end.new
end
end
@@ -23,32 +23,34 @@ class Gem::Commands::BuildCommand < Gem::Command
def execute
gemspec = get_one_gem_name
- if File.exist?(gemspec)
- specs = load_gemspecs(gemspec)
- specs.each do |spec|
Gem::Builder.new(spec).build
end
else
alert_error "Gemspec file not found: #{gemspec}"
end
end
- def load_gemspecs(filename)
if yaml?(filename)
- result = []
open(filename) do |f|
begin
- while not f.eof? and spec = Gem::Specification.from_yaml(f)
- result << spec
- end
rescue Gem::EndOfYAMLException
- # OK
end
end
else
- result = [Gem::Specification.load(filename)]
end
- result
end
def yaml?(filename)
@@ -56,7 +56,7 @@ class Gem::Commands::CertCommand < Gem::Command
'Build private key and self-signed',
'certificate for EMAIL_ADDR.') do |value, options|
vals = Gem::Security.build_self_signed_cert(value)
- File.chmod 0600, vals[:key_path]
say "Public Cert: #{vals[:cert_path]}"
say "Private Key: #{vals[:key_path]}"
say "Don't forget to move the key file to somewhere private..."
@@ -5,7 +5,6 @@
######################################################################
require 'rubygems/command'
-require 'rubygems/source_index'
require 'rubygems/dependency_list'
require 'rubygems/uninstaller'
@@ -44,28 +43,20 @@ installed elsewhere in GEM_PATH the cleanup command won't touch it.
say "Cleaning up installed gems..."
primary_gems = {}
- Gem.source_index.each do |name, spec|
if primary_gems[spec.name].nil? or
primary_gems[spec.name].version < spec.version then
primary_gems[spec.name] = spec
end
end
- gems_to_cleanup = []
-
- unless options[:args].empty? then
- options[:args].each do |gem_name|
- dep = Gem::Dependency.new gem_name, Gem::Requirement.default
- specs = Gem.source_index.search dep
- specs.each do |spec|
- gems_to_cleanup << spec
- end
- end
- else
- Gem.source_index.each do |name, spec|
- gems_to_cleanup << spec
- end
- end
gems_to_cleanup = gems_to_cleanup.select { |spec|
primary_gems[spec.name].version != spec.version
@@ -89,8 +80,8 @@ installed elsewhere in GEM_PATH the cleanup command won't touch it.
:version => "= #{spec.version}",
}
- if Gem.user_dir == spec.installation_path then
- uninstall_options[:install_dir] = spec.installation_path
end
uninstaller = Gem::Uninstaller.new spec.name, uninstall_options
@@ -58,24 +58,24 @@ class Gem::Commands::ContentsCommand < Gem::Command
end.flatten
path_kind = if spec_dirs.empty? then
- spec_dirs = Gem::SourceIndex.installed_spec_directories
"default gem paths"
else
"specified path"
end
- si = Gem::SourceIndex.from_gems_in(*spec_dirs)
-
gem_names = if options[:all] then
- si.map { |_, spec| spec.name }
else
get_all_gem_names
end
gem_names.each do |name|
- gem_spec = si.find_name(name, version).last
- unless gem_spec then
say "Unable to find gem '#{name}' in #{path_kind}"
if Gem.configuration.verbose then
@@ -86,16 +86,19 @@ class Gem::Commands::ContentsCommand < Gem::Command
terminate_interaction 1 if gem_names.length == 1
end
- files = options[:lib_only] ? gem_spec.lib_files : gem_spec.files
- files.each do |f|
- path = if options[:prefix] then
- File.join gem_spec.full_gem_path, f
- else
- f
- end
- say path
end
end
end
@@ -49,13 +49,13 @@ class Gem::Commands::DependencyCommand < Gem::Command
end
def execute
- options[:args] << '' if options[:args].empty?
- specs = {}
-
- source_indexes = Hash.new do |h, source_uri|
- h[source_uri] = Gem::SourceIndex.new
end
pattern = if options[:args].length == 1 and
options[:args].first =~ /\A\/(.*)\/(i)?\z/m then
flags = $2 ? Regexp::IGNORECASE : nil
@@ -64,34 +64,30 @@ class Gem::Commands::DependencyCommand < Gem::Command
/\A#{Regexp.union(*options[:args])}/
end
- dependency = Gem::Dependency.new pattern, options[:version]
dependency.prerelease = options[:prerelease]
- if options[:reverse_dependencies] and remote? and not local? then
- alert_error 'Only reverse dependencies for local gems are supported.'
- terminate_interaction 1
- end
- if local? then
- Gem.source_index.search(dependency).each do |spec|
- source_indexes[:local].add_spec spec
- end
- end
if remote? and not options[:reverse_dependencies] then
fetcher = Gem::SpecFetcher.fetcher
- specs_and_sources = fetcher.find_matching(dependency, false, true,
dependency.prerelease?)
- specs_and_sources.each do |spec_tuple, source_uri|
- spec = fetcher.fetch_spec spec_tuple, URI.parse(source_uri)
-
- source_indexes[source_uri].add_spec spec
- end
end
- if source_indexes.empty? then
patterns = options[:args].join ','
say "No gems found matching #{patterns} (#{options[:version]})" if
Gem.configuration.verbose
@@ -99,24 +95,18 @@ class Gem::Commands::DependencyCommand < Gem::Command
terminate_interaction 1
end
- specs = {}
-
- source_indexes.values.each do |source_index|
- source_index.gems.each do |name, spec|
- specs[spec.full_name] = [source_index, spec]
- end
- end
reverse = Hash.new { |h, k| h[k] = [] }
if options[:reverse_dependencies] then
- specs.values.each do |_, spec|
reverse[spec.full_name] = find_reverse_dependencies spec
end
end
if options[:pipe_format] then
- specs.values.sort_by { |_, spec| spec }.each do |_, spec|
unless spec.dependencies.empty?
spec.dependencies.sort_by { |dep| dep.name }.each do |dep|
say "#{dep.name} --version '#{dep.requirement}'"
@@ -126,7 +116,7 @@ class Gem::Commands::DependencyCommand < Gem::Command
else
response = ''
- specs.values.sort_by { |_, spec| spec }.each do |_, spec|
response << print_dependencies(spec)
unless reverse[spec.full_name].empty? then
response << " Used by\n"
@@ -158,7 +148,7 @@ class Gem::Commands::DependencyCommand < Gem::Command
def find_reverse_dependencies(spec)
result = []
- Gem.source_index.each do |name, sp|
sp.dependencies.each do |dep|
dep = Gem::Dependency.new(*dep) unless Gem::Dependency === dep
@@ -172,17 +162,5 @@ class Gem::Commands::DependencyCommand < Gem::Command
result
end
- def find_gems(name, source_index)
- specs = {}
-
- spec_list = source_index.search name, options[:version]
-
- spec_list.each do |spec|
- specs[spec.full_name] = [source_index, spec]
- end
-
- specs
- end
-
end
@@ -41,19 +41,22 @@ class Gem::Commands::FetchCommand < Gem::Command
version = options[:version] || Gem::Requirement.default
all = Gem::Requirement.default != version
gem_names = get_all_gem_names
gem_names.each do |gem_name|
dep = Gem::Dependency.new gem_name, version
dep.prerelease = options[:prerelease]
- specs_and_sources = Gem::SpecFetcher.fetcher.fetch(dep, all, true,
- dep.prerelease?)
-
specs_and_sources, errors =
Gem::SpecFetcher.fetcher.fetch_with_errors(dep, all, true,
dep.prerelease?)
spec, source_uri = specs_and_sources.sort_by { |s,| s.version }.last
if spec.nil? then
@@ -62,7 +65,7 @@ class Gem::Commands::FetchCommand < Gem::Command
end
path = Gem::RemoteFetcher.fetcher.download spec, source_uri
- FileUtils.mv path, spec.file_name
say "Downloaded #{spec.full_name}"
end
@@ -120,7 +120,8 @@ to write the specification by hand. For example:
get_all_gem_names.each do |gem_name|
begin
- next if options[:conservative] && Gem.available?(gem_name, options[:version])
inst = Gem::DependencyInstaller.new options
inst.install gem_name, options[:version]
@@ -93,7 +93,7 @@ lock it down to the exact version.
spec.runtime_dependencies.each do |dep|
next if locked[dep.name]
- candidates = Gem.source_index.search dep
if candidates.empty? then
complain "Unable to satisfy '#{dep}' from currently installed gems"
@@ -105,11 +105,11 @@ lock it down to the exact version.
end
def spec_path(gem_full_name)
- gemspecs = Gem.path.map do |path|
File.join path, "specifications", "#{gem_full_name}.gemspec"
- end
- gemspecs.find { |gemspec| File.exist? gemspec }
end
end
@@ -22,10 +22,8 @@ class Gem::Commands::OutdatedCommand < Gem::Command
end
def execute
- locals = Gem::SourceIndex.from_installed_gems
-
- locals.outdated.sort.each do |name|
- local = locals.find_name(name).last
dep = Gem::Dependency.new local.name, ">= #{local.version}"
remotes = Gem::SpecFetcher.fetcher.fetch dep
@@ -35,6 +33,4 @@ class Gem::Commands::OutdatedCommand < Gem::Command
say "#{local.name} (#{local.version} < #{remote.version})"
end
end
-
end
-
@@ -16,7 +16,8 @@ class Gem::Commands::PristineCommand < Gem::Command
def initialize
super 'pristine',
'Restores installed gems to pristine condition from files located in the gem cache',
- :version => Gem::Requirement.default
add_option('--all',
'Restore all installed gems to pristine',
@@ -24,6 +25,11 @@ class Gem::Commands::PristineCommand < Gem::Command
options[:all] = value
end
add_version_option('restore to', 'pristine condition')
end
@@ -32,7 +38,7 @@ class Gem::Commands::PristineCommand < Gem::Command
end
def defaults_str # :nodoc:
- "--all"
end
def description # :nodoc:
@@ -46,6 +52,9 @@ for the gem are regenerated.
If the cached gem cannot be found, you will need to use `gem install` to
revert the gem.
EOF
end
@@ -54,21 +63,17 @@ revert the gem.
end
def execute
- gem_name = nil
-
specs = if options[:all] then
- Gem::SourceIndex.from_installed_gems.map do |name, spec|
- spec
- end
else
- gem_name = get_one_gem_name
- Gem::SourceIndex.from_installed_gems.find_name(gem_name,
- options[:version])
end
- if specs.empty? then
raise Gem::Exception,
- "Failed to find gem #{gem_name} #{options[:version]}"
end
install_dir = Gem.dir # TODO use installer option
@@ -76,25 +81,32 @@ revert the gem.
raise Gem::FilePermissionError.new(install_dir) unless
File.writable?(install_dir)
- say "Restoring gem(s) to pristine condition..."
specs.each do |spec|
- gem = spec.cache_gem
- if gem.nil? then
say "Cached gem for #{spec.full_name} not found, attempting to fetch..."
dep = Gem::Dependency.new spec.name, spec.version
Gem::RemoteFetcher.fetcher.download_to_cache dep
- gem = spec.cache_gem
end
# TODO use installer options
- installer = Gem::Installer.new gem, :wrappers => true, :force => true
installer.install
say "Restored #{spec.full_name}"
end
end
-
end
-
@@ -80,10 +80,12 @@ class Gem::Commands::QueryCommand < Gem::Command
exit_code |= 1
end
- raise Gem::SystemExitException, exit_code
end
- dep = Gem::Dependency.new name, Gem::Requirement.default
if local? then
if prerelease and not both? then
@@ -96,7 +98,9 @@ class Gem::Commands::QueryCommand < Gem::Command
say
end
- specs = Gem.source_index.search dep
spec_tuples = specs.map do |spec|
[[spec.name, spec.version, spec.original_platform, spec], :local]
@@ -129,9 +133,8 @@ class Gem::Commands::QueryCommand < Gem::Command
##
# Check if gem +name+ version +version+ is installed.
- def installed?(name, version = Gem::Requirement.default)
- dep = Gem::Dependency.new name, version
- !Gem.source_index.search(dep).empty?
end
def output_query_results(spec_tuples)
@@ -50,7 +50,7 @@ class Gem::Commands::ServerCommand < Gem::Command
options[:addresses].push(*address)
end
- add_option '-l', '--launch[=COMMAND]',
'launches a browser window',
"COMMAND defaults to 'start' on Windows",
"and 'open' on all other platforms" do |launch, options|
@@ -338,7 +338,7 @@ abort "#{deprecation_message}"
args << '--main' << 'README.rdoc' << '--quiet'
args << '.'
args << 'README.rdoc' << 'UPGRADING.rdoc'
- args << 'LICENSE.txt' << 'GPL.txt' << 'History.txt'
r = RDoc::RDoc.new
r.document args
@@ -72,18 +72,8 @@ FIELD name of gemspec field to show
field = get_one_optional_argument
- if field then
- field = field.intern
-
- if options[:format] == :ruby then
- raise Gem::CommandLineError, "--ruby and FIELD are mutually exclusive"
- end
-
- unless Gem::Specification.attribute_names.include? field then
- raise Gem::CommandLineError,
- "no field %p on Gem::Specification" % field.to_s
- end
- end
if local? then
if File.exist? gem then
@@ -91,7 +81,7 @@ FIELD name of gemspec field to show
end
if specs.empty? then
- specs.push(*Gem.source_index.search(dep))
end
end
@@ -106,7 +96,11 @@ FIELD name of gemspec field to show
terminate_interaction 1
end
- output = lambda do |s|
s = s.send field if field
say case options[:format]
@@ -117,14 +111,5 @@ FIELD name of gemspec field to show
say "\n"
end
-
- if options[:all] then
- specs.each(&output)
- else
- spec = specs.sort_by { |s| s.version }.last
- output[spec]
- end
end
-
end
-
@@ -17,7 +17,8 @@ class Gem::Commands::StaleCommand < Gem::Command
def execute
gem_to_atime = {}
- Gem.source_index.each do |name, spec|
Dir["#{spec.full_gem_path}/**/*.*"].each do |file|
next if File.directory?(file)
stat = File.stat(file)
@@ -25,6 +25,10 @@ class Gem::Commands::UnpackCommand < Gem::Command
options[:target] = value
end
add_version_option
end
@@ -50,14 +54,30 @@ class Gem::Commands::UnpackCommand < Gem::Command
dependency = Gem::Dependency.new name, options[:version]
path = get_path dependency
- if path then
basename = File.basename path, '.gem'
target_dir = File.expand_path basename, options[:target]
FileUtils.mkdir_p target_dir
Gem::Installer.new(path, :unpack => true).unpack target_dir
say "Unpacked gem: '#{target_dir}'"
- else
- alert_error "Gem '#{name}' not installed."
end
end
end
@@ -70,9 +90,8 @@ class Gem::Commands::UnpackCommand < Gem::Command
# TODO: see comments in get_path() about general service.
def find_in_cache(filename)
-
Gem.path.each do |path|
- this_path = Gem.cache_gem(filename, path)
return this_path if File.exist? this_path
end
@@ -99,9 +118,9 @@ class Gem::Commands::UnpackCommand < Gem::Command
def get_path dependency
return dependency.name if dependency.name =~ /\.gem$/i
- specs = Gem.source_index.search dependency
- selected = specs.sort_by { |s| s.version }.last
return Gem::RemoteFetcher.fetcher.download_to_cache(dependency) unless
selected
@@ -111,12 +130,37 @@ class Gem::Commands::UnpackCommand < Gem::Command
# We expect to find (basename).gem in the 'cache' directory. Furthermore,
# the name match must be exact (ignoring case).
- path = find_in_cache selected.file_name
return Gem::RemoteFetcher.fetcher.download_to_cache(dependency) unless path
path
end
end
@@ -71,14 +71,14 @@ class Gem::Commands::UpdateCommand < Gem::Command
hig = {} # highest installed gems
- Gem.source_index.each do |name, spec|
if hig[spec.name].nil? or hig[spec.name].version < spec.version then
hig[spec.name] = spec
end
end
end
- gems_to_update = which_to_update hig, options[:args]
updated = update_gems gems_to_update
@@ -123,8 +123,8 @@ class Gem::Commands::UpdateCommand < Gem::Command
end
def update_gems gems_to_update
- gems_to_update.uniq.sort.each do |name|
- update_gem name
end
@updated
@@ -141,6 +141,9 @@ class Gem::Commands::UpdateCommand < Gem::Command
options[:user_install] = false
version = options[:system]
if version == true then
version = Gem::Version.new Gem::VERSION
@@ -158,18 +161,25 @@ class Gem::Commands::UpdateCommand < Gem::Command
'rubygems-update' => rubygems_update
}
- gems_to_update = which_to_update hig, options[:args]
- if gems_to_update.empty? then
say "Latest version currently installed. Aborting."
terminate_interaction
end
- update_gem gems_to_update.first, requirement
- Gem.source_index.refresh!
-
- installed_gems = Gem.source_index.find_name 'rubygems-update', requirement
version = installed_gems.last.version
args = []
@@ -193,7 +203,7 @@ class Gem::Commands::UpdateCommand < Gem::Command
end
end
- def which_to_update(highest_installed_gems, gem_names)
result = []
highest_installed_gems.each do |l_name, l_spec|
@@ -213,9 +223,11 @@ class Gem::Commands::UpdateCommand < Gem::Command
version
end.last
- if highest_remote_gem and
- l_spec.version < highest_remote_gem.first[1] then
- result << l_name
end
end
@@ -5,12 +5,8 @@
######################################################################
require 'rubygems/command'
-require 'rubygems/gem_path_searcher'
class Gem::Commands::WhichCommand < Gem::Command
-
- EXT = %w[.rb .rbw .so .dll .bundle] # HACK
-
def initialize
super 'which', 'Find the location of a library file you can require',
:search_gems_first => false, :show_all => false
@@ -34,14 +30,13 @@ class Gem::Commands::WhichCommand < Gem::Command
end
def execute
- searcher = Gem::GemPathSearcher.new
-
found = false
options[:args].each do |arg|
- arg = arg.sub(/#{Regexp.union(*EXT)}$/, '')
dirs = $LOAD_PATH
- spec = searcher.find arg
if spec then
if options[:search_gems_first] then
@@ -51,6 +46,7 @@ class Gem::Commands::WhichCommand < Gem::Command
end
end
paths = find_paths arg, dirs
if paths.empty? then
@@ -68,7 +64,7 @@ class Gem::Commands::WhichCommand < Gem::Command
result = []
dirs.each do |dir|
- EXT.each do |ext|
full_path = File.join dir, "#{package_name}#{ext}"
if File.exist? full_path then
result << full_path
@@ -207,11 +207,15 @@ class Gem::ConfigFile
# Location of RubyGems.org credentials
def credentials_path
- File.join(Gem.user_home, '.gem', 'credentials')
end
def load_api_keys
- @api_keys = File.exists?(credentials_path) ? load_file(credentials_path) : @hash
if @api_keys.key? :rubygems_api_key then
@rubygems_api_key = @api_keys[:rubygems_api_key]
@api_keys[:rubygems] = @api_keys.delete :rubygems_api_key unless @api_keys.key? :rubygems
@@ -221,8 +225,8 @@ class Gem::ConfigFile
def rubygems_api_key=(api_key)
config = load_file(credentials_path).merge(:rubygems_api_key => api_key)
- dirname = File.dirname(credentials_path)
- Dir.mkdir(dirname) unless File.exists?(dirname)
Gem.load_yaml
@@ -236,7 +240,7 @@ class Gem::ConfigFile
def load_file(filename)
Gem.load_yaml
- return {} unless filename and File.exists?(filename)
begin
YAML.load(File.read(filename))
rescue ArgumentError
@@ -360,6 +364,4 @@ class Gem::ConfigFile
protected
attr_reader :hash
-
end
-
@@ -41,19 +41,20 @@ module Kernel
if Gem.unresolved_deps.empty? or Gem.loaded_path? path then
gem_original_require path
else
- spec = Gem.searcher.find_active path
unless spec then
- found_specs = Gem.searcher.find_in_unresolved path
unless found_specs.empty? then
found_specs = [found_specs.last]
else
- found_specs = Gem.searcher.find_in_unresolved_tree path
end
found_specs.each do |found_spec|
- # FIX: this is dumb, activate a spec instead of name/version
- Gem.activate found_spec.name, found_spec.version
end
end
@@ -6,6 +6,8 @@
module Gem
@post_install_hooks ||= []
@post_uninstall_hooks ||= []
@pre_uninstall_hooks ||= []
@@ -23,16 +25,28 @@ module Gem
# specified in the environment
def self.default_dir
- if defined? RUBY_FRAMEWORK_VERSION then
- File.join File.dirname(ConfigMap[:sitedir]), 'Gems',
- ConfigMap[:ruby_version]
- elsif ConfigMap[:rubylibprefix] then
- File.join(ConfigMap[:rubylibprefix], 'gems',
- ConfigMap[:ruby_version])
- else
- File.join(ConfigMap[:libdir], ruby_engine, 'gems',
- ConfigMap[:ruby_version])
- end
end
##
@@ -82,14 +96,18 @@ module Gem
# The default system-wide source info cache directory
def self.default_system_source_cache_dir
- File.join Gem.dir, 'source_cache'
end
##
# The default user-specific source info cache directory
def self.default_user_source_cache_dir
- File.join Gem.user_home, '.gem', 'source_cache'
end
##
@@ -102,6 +120,4 @@ module Gem
'ruby'
end
end
-
end
-
@@ -38,6 +38,12 @@ class Gem::Dependency
# <tt>:runtime</tt>.
def initialize name, *requirements
type = Symbol === requirements.last ? requirements.pop : :runtime
requirements = requirements.first if 1 == requirements.length # unpack
@@ -212,5 +218,49 @@ class Gem::Dependency
self.class.new name, self_req.as_list.concat(other_req.as_list)
end
-end
@@ -21,14 +21,14 @@ class Gem::DependencyInstaller
attr_reader :installed_gems
DEFAULT_OPTIONS = {
- :env_shebang => false,
- :domain => :both, # HACK dup
- :force => false,
- :format_executable => false, # HACK dup
:ignore_dependencies => false,
- :prerelease => false,
- :security_policy => nil, # HACK NoSecurity requires OpenSSL. AlmostNo? Low?
- :wrappers => true,
}
##
@@ -51,25 +51,26 @@ class Gem::DependencyInstaller
def initialize(options = {})
if options[:install_dir] then
- spec_dir = options[:install_dir], 'specifications'
- @source_index = Gem::SourceIndex.from_gems_in spec_dir
- else
- @source_index = Gem.source_index
end
options = DEFAULT_OPTIONS.merge options
- @bin_dir = options[:bin_dir]
- @development = options[:development]
- @domain = options[:domain]
- @env_shebang = options[:env_shebang]
- @force = options[:force]
- @format_executable = options[:format_executable]
@ignore_dependencies = options[:ignore_dependencies]
- @prerelease = options[:prerelease]
- @security_policy = options[:security_policy]
- @user_install = options[:user_install]
- @wrappers = options[:wrappers]
@installed_gems = []
@@ -101,6 +102,7 @@ class Gem::DependencyInstaller
if @domain == :both or @domain == :remote then
begin
requirements = dep.requirement.requirements.map do |req, ver|
req
end
@@ -146,8 +148,8 @@ class Gem::DependencyInstaller
add_found_dependencies to_do, dependency_list unless @ignore_dependencies
dependency_list.specs.reject! { |spec|
- ! keep_names.include? spec.full_name and
- @source_index.any? { |n,_| n == spec.full_name }
}
unless dependency_list.ok? or @ignore_dependencies or @force then
@@ -181,7 +183,7 @@ class Gem::DependencyInstaller
to_do.push dep_spec
# already locally installed
- @source_index.any? do |_, installed_spec|
dep.name == installed_spec.name and
dep.requirement.satisfied_by? installed_spec.version
end
@@ -216,23 +218,20 @@ class Gem::DependencyInstaller
local_gems = Dir["#{glob}*"].sort.reverse
- unless local_gems.empty? then
- local_gems.each do |gem_file|
- next unless gem_file =~ /gem$/
- begin
- spec = Gem::Format.from_file_by_path(gem_file).spec
- spec_and_source = [spec, gem_file]
- break
- rescue SystemCallError, Gem::Package::FormatError
- end
end
end
- if spec_and_source.nil? then
dep = Gem::Dependency.new gem_name, version
dep.prerelease = true if prerelease
spec_and_sources = find_gems_with_sources(dep).reverse
-
spec_and_source = spec_and_sources.find { |spec, source|
Gem::Platform.match spec.platform
}
@@ -273,9 +272,9 @@ class Gem::DependencyInstaller
gather_dependencies
- @gems_to_install.each do |spec|
- last = spec == @gems_to_install.last
- next if @source_index.any? { |n,_| n == spec.full_name } and not last
# TODO: make this sorta_verbose so other users can benefit from it
say "Installing gem #{spec.full_name}" if Gem.configuration.really_verbose
@@ -298,7 +297,6 @@ class Gem::DependencyInstaller
:ignore_dependencies => @ignore_dependencies,
:install_dir => @install_dir,
:security_policy => @security_policy,
- :source_index => @source_index,
:user_install => @user_install,
:wrappers => @wrappers
@@ -309,6 +307,4 @@ class Gem::DependencyInstaller
@installed_gems
end
-
end
-
@@ -11,6 +11,7 @@
#++
require 'tsort'
##
# Gem::DependencyList is used for installing and uninstalling gems in the
@@ -28,16 +29,21 @@ class Gem::DependencyList
attr_accessor :development
##
- # Creates a DependencyList from a Gem::SourceIndex +source_index+
- def self.from_source_index(source_index)
list = new
- source_index.each do |full_name, spec|
- list.add spec
- end
- list
end
##
@@ -120,10 +126,9 @@ class Gem::DependencyList
def why_not_ok? quick = false
unsatisfied = Hash.new { |h,k| h[k] = [] }
- source_index = Gem.source_index
each do |spec|
spec.runtime_dependencies.each do |dep|
- inst = source_index.any? { |_, installed_spec|
dep.name == installed_spec.name and
dep.requirement.satisfied_by? installed_spec.version
}
@@ -134,6 +139,7 @@ class Gem::DependencyList
end
end
end
unsatisfied
end
@@ -242,6 +248,11 @@ class Gem::DependencyList
def active_count(specs, ignored)
specs.count { |spec| ignored[spec.full_name].nil? }
end
-
end
@@ -0,0 +1,74 @@
@@ -92,7 +92,7 @@ class Gem::DocManager
def initialize(spec, rdoc_args="")
require 'fileutils'
@spec = spec
- @doc_dir = File.join(spec.installation_path, "doc", spec.full_name)
@rdoc_args = rdoc_args.nil? ? [] : rdoc_args.split
end
@@ -224,25 +224,24 @@ class Gem::DocManager
# Remove RDoc and RI documentation
def uninstall_doc
- raise Gem::FilePermissionError.new(@spec.installation_path) unless
- File.writable? @spec.installation_path
- original_name = [
@spec.name, @spec.version, @spec.original_platform].join '-'
- doc_dir = File.join @spec.installation_path, 'doc', @spec.full_name
unless File.directory? doc_dir then
- doc_dir = File.join @spec.installation_path, 'doc', original_name
end
- FileUtils.rm_rf doc_dir
-
- ri_dir = File.join @spec.installation_path, 'ri', @spec.full_name
-
unless File.directory? ri_dir then
- ri_dir = File.join @spec.installation_path, 'ri', original_name
end
FileUtils.rm_rf ri_dir
end
@@ -19,7 +19,7 @@ class Gem::Ext::Builder
def self.make(dest_path, results)
unless File.exist? 'Makefile' then
- raise Gem::InstallError, "Makefile not found:\n\n#{results.join "\n"}"
end
mf = File.read('Makefile')
@@ -23,12 +23,12 @@ class Gem::Ext::RakeBuilder < Gem::Ext::Builder
end
# Deal with possible spaces in the path, e.g. C:/Program Files
- dest_path = '"' + dest_path + '"' if dest_path.include?(' ')
rake = ENV['rake']
rake ||= begin
- "\"#{Gem.ruby}\" -rubygems #{Gem.bin_path('rake')}"
rescue Gem::Exception
end
@@ -4,6 +4,9 @@
# File a instead and assign it to Ryan Davis or Eric Hodel.
######################################################################
##
# GemPathSearcher has the capability to find loadable files inside
# gems. It generates data up front to speed up searches later.
@@ -56,6 +59,15 @@ class Gem::GemPathSearcher
end
end
def find_active(glob)
# HACK violation of encapsulation
@gemspecs.find do |spec|
@@ -138,9 +150,7 @@ class Gem::GemPathSearcher
# in reverse version order. (bar-2, bar-1, foo-2)
def init_gemspecs
- specs = Gem.source_index.map { |_, spec| spec }
-
- specs.sort { |a, b|
names = a.name <=> b.name
next names if names.nonzero?
b.version <=> a.version
@@ -156,5 +166,13 @@ class Gem::GemPathSearcher
spec.require_paths
end
-end
@@ -10,6 +10,7 @@
# See LICENSE.txt for permissions.
#++
require 'rubygems/command_manager'
require 'rubygems/config_file'
require 'rubygems/doc_manager'
@@ -31,6 +32,7 @@ Gem.load_env_plugins rescue nil
class Gem::GemRunner
def initialize(options={})
@command_manager_class = options[:command_manager] || Gem::CommandManager
@config_file_class = options[:config_file] || Gem::ConfigFile
@doc_manager_class = options[:doc_manager] || Gem::DocManager
@@ -80,7 +82,7 @@ class Gem::GemRunner
def do_configuration(args)
Gem.configuration = @config_file_class.new(args)
- Gem.use_paths(Gem.configuration[:gemhome], Gem.configuration[:gempath])
Gem::Command.extra_args = Gem.configuration[:gem]
@doc_manager_class.configured_args = Gem.configuration[:rdoc]
end
@@ -79,7 +79,7 @@ class Gem::Indexer
@rss_gems_host = options[:rss_gems_host]
@dest_directory = directory
- @directory = File.join Dir.tmpdir, "gem_generate_index_#{$$}"
marshal_name = "Marshal.#{Gem.marshal_version}"
@@ -87,24 +87,23 @@ class Gem::Indexer
@marshal_index = File.join @directory, marshal_name
@quick_dir = File.join @directory, 'quick'
-
@quick_marshal_dir = File.join @quick_dir, marshal_name
@quick_index = File.join @quick_dir, 'index'
@latest_index = File.join @quick_dir, 'latest_index'
@specs_index = File.join @directory, "specs.#{Gem.marshal_version}"
- @latest_specs_index = File.join @directory,
- "latest_specs.#{Gem.marshal_version}"
- @prerelease_specs_index = File.join(@directory,
- "prerelease_specs.#{Gem.marshal_version}")
-
- @dest_specs_index = File.join @dest_directory,
- "specs.#{Gem.marshal_version}"
- @dest_latest_specs_index = File.join @dest_directory,
- "latest_specs.#{Gem.marshal_version}"
- @dest_prerelease_specs_index = File.join @dest_directory,
- "prerelease_specs.#{Gem.marshal_version}"
@rss_index = File.join @directory, 'index.rss'
@@ -129,12 +128,16 @@ class Gem::Indexer
##
# Build various indicies
- def build_indicies(index)
# Marshal gemspecs are used by both modern and legacy RubyGems
- build_marshal_gemspecs index
- build_legacy_indicies index if @build_legacy
- build_modern_indicies index if @build_modern
- build_rss index
compress_indicies
end
@@ -142,7 +145,9 @@ class Gem::Indexer
##
# Builds indicies for RubyGems older than 1.2.x
- def build_legacy_indicies(index)
say "Generating Marshal master index"
Gem.time 'Generated Marshal master index' do
@@ -158,16 +163,17 @@ class Gem::Indexer
##
# Builds Marshal quick index gemspecs.
- def build_marshal_gemspecs(index)
- progress = ui.progress_reporter index.size,
- "Generating Marshal quick index gemspecs for #{index.size} gems",
"Complete"
files = []
Gem.time 'Generated Marshal quick index gemspecs' do
- index.gems.each do |original_name, spec|
- spec_file_name = "#{original_name}.gemspec.rz"
marshal_name = File.join @quick_marshal_dir, spec_file_name
marshal_zipped = Gem.deflate Marshal.dump(spec)
@@ -175,7 +181,7 @@ class Gem::Indexer
files << marshal_name
- progress.updated original_name
end
progress.done
@@ -195,8 +201,8 @@ class Gem::Indexer
Gem.time "Generated #{name} index" do
open(file, 'wb') do |io|
specs = index.map do |*spec|
- # We have to splat here because latest_specs is an array,
- # while the others are hashes. See the TODO in source_index.rb
spec = spec.flatten.last
platform = spec.original_platform
@@ -219,13 +225,15 @@ class Gem::Indexer
##
# Builds indicies for RubyGems 1.2 and newer. Handles full, latest, prerelease
- def build_modern_indicies(index)
- build_modern_index(index.released_specs.sort, @specs_index, 'specs')
- build_modern_index(index.latest_specs.sort,
- @latest_specs_index,
- 'latest specs')
- build_modern_index(index.prerelease_specs.sort,
- @prerelease_specs_index,
'prerelease specs')
@files += [@specs_index,
@@ -240,7 +248,7 @@ class Gem::Indexer
# Builds an RSS feed for past two days gem releases according to the gem's
# date.
- def build_rss(index)
if @rss_host.nil? or @rss_gems_host.nil? then
if Gem.configuration.really_verbose then
alert_warning "no --rss-host or --rss-gems-host, RSS generation disabled"
@@ -272,31 +280,18 @@ class Gem::Indexer
today = Gem::Specification::TODAY
yesterday = today - 86400
- index = index.select do |_, spec|
- spec_date = spec.date
-
- case spec_date
- when Date
- Time.parse(spec_date.to_s) >= yesterday
- when Time
- spec_date >= yesterday
- end
- end
-
- index = index.select do |_, spec|
spec_date = spec.date
- case spec_date
- when Date
- Time.parse(spec_date.to_s) <= today
- when Time
- spec_date <= today
- end
end
- index.sort_by { |_, spec| [-spec.date.to_i, spec] }.each do |_, spec|
- gem_path = CGI.escapeHTML "http://#{@rss_gems_host}/gems/#{spec.file_name}"
- size = File.stat(spec.loaded_from).size rescue next
description = spec.description || spec.summary || ''
authors = Array spec.authors
@@ -347,54 +342,56 @@ class Gem::Indexer
@files << @rss_index
end
##
# Collect specifications from .gem files from the gem directory.
def collect_specs(gems = gem_file_list)
- index = Gem::SourceIndex.new
-
- progress = ui.progress_reporter gems.size,
- "Loading #{gems.size} gems from #{@dest_directory}",
- "Loaded all gems"
- Gem.time 'loaded' do
- gems.each do |gemfile|
- if File.size(gemfile.to_s) == 0 then
- alert_warning "Skipping zero-length gem: #{gemfile}"
- next
- end
-
- begin
- spec = Gem::Format.from_file_by_path(gemfile).spec
- spec.loaded_from = gemfile
-
- unless gemfile =~ /\/#{Regexp.escape spec.original_name}.*\.gem\z/i then
- expected_name = spec.full_name
- expected_name << " (#{spec.original_name})" if
- spec.original_name != spec.full_name
- alert_warning "Skipping misnamed gem: #{gemfile} should be named #{expected_name}"
- next
- end
-
- abbreviate spec
- sanitize spec
-
- index.add_spec spec, spec.original_name
-
- progress.updated spec.original_name
-
- rescue SignalException => e
- alert_error "Received signal, exiting"
- raise
- rescue Exception => e
- alert_error "Unable to process #{gemfile}\n#{e.message} (#{e.class})\n\t#{e.backtrace.join "\n\t"}"
- end
end
- progress.done
end
-
- index
end
##
@@ -454,7 +451,7 @@ class Gem::Indexer
# List of gem file names to index.
def gem_file_list
- Dir.glob(File.join(@dest_directory, "gems", "*.gem"))
end
##
@@ -462,8 +459,7 @@ class Gem::Indexer
def generate_index
make_temp_directories
- index = collect_specs
- build_indicies index
install_indicies
rescue SignalException
ensure
@@ -487,24 +483,22 @@ class Gem::Indexer
say "Moving index into production dir #{@dest_directory}" if verbose
- files = @files.dup
files.delete @quick_marshal_dir if files.include? @quick_dir
- if files.include? @quick_marshal_dir and
- not files.include? @quick_dir then
files.delete @quick_marshal_dir
- quick_marshal_dir = @quick_marshal_dir.sub @directory, ''
- dst_name = File.join @dest_directory, quick_marshal_dir
FileUtils.mkdir_p File.dirname(dst_name), :verbose => verbose
FileUtils.rm_rf dst_name, :verbose => verbose
- FileUtils.mv @quick_marshal_dir, dst_name, :verbose => verbose,
- :force => true
end
files = files.map do |path|
- path.sub @directory, ''
end
files.each do |file|
@@ -512,8 +506,8 @@ class Gem::Indexer
dst_name = File.join @dest_directory, file
FileUtils.rm_rf dst_name, :verbose => verbose
- FileUtils.mv src_name, @dest_directory, :verbose => verbose,
- :force => true
end
end
@@ -544,10 +538,10 @@ class Gem::Indexer
# be replaced by their XML entity equivalent.
def sanitize(spec)
- spec.summary = sanitize_string(spec.summary)
- spec.description = sanitize_string(spec.description)
spec.post_install_message = sanitize_string(spec.post_install_message)
- spec.authors = spec.authors.collect { |a| sanitize_string(a) }
spec
end
@@ -593,14 +587,16 @@ class Gem::Indexer
terminate_interaction 0
end
- index = collect_specs updated_gems
- files = build_marshal_gemspecs index
Gem.time 'Updated indexes' do
- update_specs_index index.released_gems, @dest_specs_index, @specs_index
- update_specs_index index.released_gems, @dest_latest_specs_index, @latest_specs_index
- update_specs_index(index.prerelease_gems, @dest_prerelease_specs_index,
@prerelease_specs_index)
end
@@ -618,12 +614,12 @@ class Gem::Indexer
files << "#{@prerelease_specs_index}.gz"
files = files.map do |path|
- path.sub @directory, ''
end
files.each do |file|
src_name = File.join @directory, file
- dst_name = File.join @dest_directory, File.dirname(file)
FileUtils.mv src_name, dst_name, :verbose => verbose,
:force => true
@@ -639,7 +635,7 @@ class Gem::Indexer
def update_specs_index(index, source, dest)
specs_index = Marshal.load Gem.read_binary(source)
- index.each do |_, spec|
platform = spec.original_platform
platform = Gem::Platform::RUBY if platform.nil? or platform.empty?
specs_index << [spec.name, spec.version, platform]
@@ -651,6 +647,4 @@ class Gem::Indexer
Marshal.dump specs_index, io
end
end
-
end
-
@@ -47,6 +47,8 @@ class Gem::Installer
include Gem::RequirePathsBuilder if Gem::QUICKLOADER_SUCKAGE
##
# The directory a gem's executables will be installed into
@@ -58,11 +60,6 @@ class Gem::Installer
attr_reader :gem_home
##
- # The Gem::Specification for the gem being installed
-
- attr_reader :spec
-
- ##
# The options passed when the Gem::Installer was instantiated.
attr_reader :options
@@ -106,18 +103,36 @@ class Gem::Installer
@gem = gem
@options = options
process_options
- load_gem_file
if options[:user_install] and not options[:unpack] then
@gem_home = Gem.user_dir
check_that_user_bin_dir_is_in_path
end
- verify_gem_home(options[:unpack])
- @spec = @format.spec
- @gem_dir = File.join(@gem_home, "gems", @spec.full_name).untaint
end
##
@@ -132,6 +147,12 @@ class Gem::Installer
# specifications/<gem-version>.gemspec #=> the Gem::Specification
def install
# If we're forcing the install then disable security unless the security
# policy says that we only install signed gems.
@security_policy = nil if @force and @security_policy and
@@ -149,17 +170,17 @@ class Gem::Installer
if result == false then
location = " at #{$1}" if hook.inspect =~ /@(.*:\d+)/
- message = "pre-install hook#{location} failed for #{@spec.full_name}"
raise Gem::InstallError, message
end
end
- Gem.ensure_gem_subdirectories @gem_home
# Completely remove any previous gem files
- FileUtils.rm_rf(@gem_dir) if File.exist?(@gem_dir)
- FileUtils.mkdir_p @gem_dir
extract_files
build_extensions
@@ -168,11 +189,11 @@ class Gem::Installer
result = hook.call self
if result == false then
- FileUtils.rm_rf @gem_dir
location = " at #{$1}" if hook.inspect =~ /@(.*:\d+)/
- message = "post-build hook#{location} failed for #{@spec.full_name}"
raise Gem::InstallError, message
end
end
@@ -182,24 +203,27 @@ class Gem::Installer
write_require_paths_file_if_needed if Gem::QUICKLOADER_SUCKAGE
- cached_gem = Gem.cache_gem(File.basename(@gem), @gem_home)
- unless File.exist? cached_gem then
- FileUtils.cp @gem, Gem.cache_dir(@gem_home)
- end
- say @spec.post_install_message unless @spec.post_install_message.nil?
- @spec.loaded_from = File.join(@gem_home, 'specifications', @spec.spec_name)
- @source_index.add_spec @spec
Gem.post_install_hooks.each do |hook|
hook.call self
end
- return @spec
rescue Zlib::GzipFile::Error
- raise Gem::InstallError, "gzip error installing #{@gem}"
end
##
@@ -220,7 +244,7 @@ class Gem::Installer
# True if the gems in the source_index satisfy +dependency+.
def installation_satisfies_dependency?(dependency)
- @source_index.find_name(dependency.name, dependency.requirement).size > 0
end
##
@@ -228,7 +252,7 @@ class Gem::Installer
def unpack(directory)
@gem_dir = directory
- @format = Gem::Format.from_file_by_path @gem, @security_policy
extract_files
end
@@ -237,14 +261,10 @@ class Gem::Installer
# specifications directory.
def write_spec
- rubycode = @spec.to_ruby_for_cache
-
- file_name = File.join @gem_home, 'specifications', @spec.spec_name
-
- file_name.untaint
File.open(file_name, "w") do |file|
- file.puts rubycode
end
end
@@ -264,24 +284,28 @@ class Gem::Installer
end
def generate_bin
- return if @spec.executables.nil? or @spec.executables.empty?
# If the user has asked for the gem to be installed in a directory that is
# the system gem directory, then use the system bin directory, else create
# (or use) a new bin dir under the gem_home.
- bindir = @bin_dir ? @bin_dir : Gem.bindir(@gem_home)
Dir.mkdir bindir unless File.exist? bindir
raise Gem::FilePermissionError.new(bindir) unless File.writable? bindir
- @spec.executables.each do |filename|
filename.untaint
- bin_path = File.expand_path "#{@spec.bindir}/#{filename}", @gem_dir
- if File.exist?(bin_path)
- mode = File.stat(bin_path).mode | 0111
- File.chmod mode, bin_path
end
if @wrappers then
generate_bin_script filename, bindir
else
@@ -322,14 +346,14 @@ class Gem::Installer
return
end
- src = File.join @gem_dir, 'bin', filename
dst = File.join bindir, formatted_program_filename(filename)
if File.exist? dst then
if File.symlink? dst then
link = File.readlink(dst).split File::SEPARATOR
cur_version = Gem::Version.create(link[-3].sub(/^.*-/, ''))
- return if @spec.version < cur_version
end
File.unlink dst
end
@@ -343,7 +367,7 @@ class Gem::Installer
def shebang(bin_file_name)
ruby_name = Gem::ConfigMap[:ruby_install_name] if @env_shebang
- path = File.join @gem_dir, @spec.bindir, bin_file_name
first_line = File.open(path, "rb") {|file| file.gets}
if /\A#!/ =~ first_line then
@@ -365,29 +389,29 @@ class Gem::Installer
end
def ensure_required_ruby_version_met
- if rrv = @spec.required_ruby_version then
unless rrv.satisfied_by? Gem.ruby_version then
- raise Gem::InstallError, "#{@spec.name} requires Ruby version #{rrv}."
end
end
end
def ensure_required_rubygems_version_met
- if rrgv = @spec.required_rubygems_version then
unless rrgv.satisfied_by? Gem::Version.new(Gem::VERSION) then
raise Gem::InstallError,
- "#{@spec.name} requires RubyGems version #{rrgv}. " +
"Try 'gem update --system' to update RubyGems itself."
end
end
end
def ensure_dependencies_met
- deps = @spec.runtime_dependencies
- deps |= @spec.development_dependencies if @development
deps.each do |dep_gem|
- ensure_dependency @spec, dep_gem
end
end
@@ -398,32 +422,24 @@ class Gem::Installer
:exec_format => false,
:force => false,
:install_dir => Gem.dir,
- :source_index => Gem.source_index,
}.merge options
@env_shebang = options[:env_shebang]
@force = options[:force]
- gem_home = options[:install_dir]
- @gem_home = File.expand_path(gem_home)
@ignore_dependencies = options[:ignore_dependencies]
@format_executable = options[:format_executable]
@security_policy = options[:security_policy]
@wrappers = options[:wrappers]
@bin_dir = options[:bin_dir]
@development = options[:development]
- @source_index = options[:source_index]
- end
- def load_gem_file
- begin
- @format = Gem::Format.from_file_by_path @gem, @security_policy
- rescue Gem::Package::FormatError
- raise Gem::InstallError, "invalid gem format for #{@gem}"
- end
end
def check_that_user_bin_dir_is_in_path
- user_bin_dir = File.join(@gem_home, 'bin')
unless ENV['PATH'].split(File::PATH_SEPARATOR).include? user_bin_dir then
unless self.class.path_warning then
alert_warning "You don't have #{user_bin_dir} in your PATH,\n\t gem executables will not run."
@@ -433,21 +449,21 @@ class Gem::Installer
end
def verify_gem_home(unpack = false)
- FileUtils.mkdir_p @gem_home
- raise Gem::FilePermissionError, @gem_home unless
- unpack or File.writable? @gem_home
end
##
# Return the text for an application file.
def app_script_text(bin_file_name)
- <<-TEXT
#{shebang bin_file_name}
#
# This file was generated by RubyGems.
#
-# The application '#{@spec.name}' is installed as part of a gem, and
# this file is here to facilitate running it.
#
@@ -460,8 +476,8 @@ if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then
ARGV.shift
end
-gem '#{@spec.name}', version
-load Gem.bin_path('#{@spec.name}', '#{bin_file_name}', version)
TEXT
end
@@ -469,14 +485,16 @@ TEXT
# return the stub script text used to launch the true ruby script
def windows_stub_script(bindir, bin_file_name)
- <<-TEXT
@ECHO OFF
IF NOT "%~f0" == "~f0" GOTO :WinNT
-@"#{File.basename(Gem.ruby).chomp('"')}" "#{File.join(bindir, bin_file_name)}" %1 %2 %3 %4 %5 %6 %7 %8 %9
GOTO :EOF
:WinNT
-@"#{File.basename(Gem.ruby).chomp('"')}" "%~dpn0" %*
TEXT
end
##
@@ -484,12 +502,12 @@ TEXT
# configure scripts and rakefiles or mkrf_conf files.
def build_extensions
- return if @spec.extensions.empty?
say "Building native extensions. This could take a while..."
- dest_path = File.join @gem_dir, @spec.require_paths.first
ran_rake = false # only run rake once
- @spec.extensions.each do |extension|
break if ran_rake
results = []
@@ -508,15 +526,15 @@ TEXT
extension_dir = begin
- File.join @gem_dir, File.dirname(extension)
rescue TypeError # extension == nil
- @gem_dir
end
begin
Dir.chdir extension_dir do
- results = builder.build(extension, @gem_dir, dest_path, results)
say results.join("\n") if Gem.configuration.really_verbose
end
@@ -532,7 +550,7 @@ ERROR: Failed to build gem native extension.
#{results}
-Gem files will remain installed in #{@gem_dir} for inspection.
Results logged to #{gem_make_out}
EOF
@@ -547,35 +565,27 @@ EOF
# Ensures that files can't be installed outside the gem directory.
def extract_files
- @gem_dir = File.expand_path @gem_dir
-
raise ArgumentError, "format required to extract from" if @format.nil?
- dirs = []
-
@format.file_entries.each do |entry, file_data|
path = entry['path'].untaint
- if path =~ /\A\// then # for extra sanity
- raise Gem::InstallError,
- "attempt to install file into #{entry['path'].inspect}"
end
- path = File.expand_path File.join(@gem_dir, path)
- if path !~ /\A#{Regexp.escape @gem_dir}/ then
- msg = "attempt to install file into %p under %p" %
- [entry['path'], @gem_dir]
raise Gem::InstallError, msg
end
- FileUtils.rm_rf(path) if File.exists?(path)
- dir = File.dirname(path)
- if !dirs.include?(dir)
- dirs << dir
- FileUtils.mkdir_p dir
- end
File.open(path, "wb") do |out|
out.write file_data
@@ -598,5 +608,14 @@ EOF
end
end
end
@@ -12,7 +12,7 @@ class Gem::Installer
##
# Available through requiring rubygems/installer_test_case
- attr_accessor :gem_dir
##
# Available through requiring rubygems/installer_test_case
@@ -63,29 +63,38 @@ class Gem::InstallerTestCase < Gem::TestCase
def setup
super
- @spec = quick_gem 'a'
- util_make_exec @spec
- @gem = File.join @tempdir, @spec.file_name
- @installer = util_installer @spec, @gem, @gemhome
@user_spec = quick_gem 'b'
util_make_exec @user_spec
- @user_gem = File.join @tempdir, @user_spec.file_name
- @user_installer = util_installer @user_spec, @user_gem, Gem.user_dir
- @user_installer.gem_dir = File.join(Gem.user_dir, 'gems',
- @user_spec.full_name)
end
def util_gem_bindir spec = @spec
- File.join util_gem_dir(spec), "bin"
end
def util_gem_dir spec = @spec
- File.join @gemhome, "gems", spec.full_name
end
def util_inst_bindir
@@ -96,16 +105,13 @@ class Gem::InstallerTestCase < Gem::TestCase
spec.executables = %w[executable]
spec.files << 'bin/executable'
- bindir = util_gem_bindir spec
- FileUtils.mkdir_p bindir
- exec_path = File.join bindir, 'executable'
- open exec_path, 'w' do |io|
io.puts shebang
end
- temp_bin = File.join(@tempdir, 'bin')
- FileUtils.mkdir_p temp_bin
- open File.join(temp_bin, 'executable'), 'w' do |io|
io.puts shebang
end
end
@@ -128,23 +134,15 @@ class Gem::InstallerTestCase < Gem::TestCase
use_ui ui do
FileUtils.rm @gem
- Gem::Builder.new(@spec).build
end
end
@installer = Gem::Installer.new @gem
end
- def util_installer(spec, gem_path, gem_home)
- util_build_gem spec
- FileUtils.mv Gem.cache_gem(spec.file_name), @tempdir
- installer = Gem::Installer.new gem_path
- installer.gem_dir = util_gem_dir
- installer.gem_home = gem_home
- installer.spec = spec
-
- installer
end
-
end
-
@@ -82,7 +82,7 @@ module Gem::LocalRemoteOptions
add_option(:"Local/Remote", '--clear-sources',
'Clear the gem sources') do |value, options|
- Gem.sources.clear
options[:sources_cleared] = true
end
end
@@ -123,7 +123,7 @@ module Gem::LocalRemoteOptions
# Add the --update-sources option
def add_update_sources_option
- add_option(:"Local/Remote", '-u', '--[no-]update-sources',
'Update local source cache') do |value, options|
Gem.configuration.update_sources = value
end
@@ -12,7 +12,15 @@ require 'rubygems/user_interaction'
# retrieval during tests.
class Gem::MockGemUi < Gem::StreamUI
- class TermError < RuntimeError; end
module TTY
@@ -61,8 +69,8 @@ class Gem::MockGemUi < Gem::StreamUI
def terminate_interaction(status=0)
@terminated = true
- raise TermError unless status == 0
- raise Gem::SystemExitException, status
end
end
@@ -12,32 +12,6 @@
require 'rubygems/specification'
-##
-# Wrapper for FileUtils meant to provide logging and additional operations if
-# needed.
-
-class Gem::FileOperations
-
- def initialize(logger = nil)
- require 'fileutils'
- @logger = logger
- end
-
- def method_missing(meth, *args, &block)
- case
- when FileUtils.respond_to?(meth)
- @logger.log "#{meth}: #{args}" if @logger
- FileUtils.send meth, *args, &block
- when Gem::FileOperations.respond_to?(meth)
- @logger.log "#{meth}: #{args}" if @logger
- Gem::FileOperations.send meth, *args, &block
- else
- super
- end
- end
-
-end
-
module Gem::Package
class Error < StandardError; end
@@ -63,6 +37,8 @@ module Gem::Package
class TarInvalidError < Error; end
def self.open(io, mode = "r", signer = nil, &block)
tar_type = case mode
when 'r' then TarInput
@@ -55,6 +55,7 @@ class Gem::Package::TarInput
sio.rewind
end
gzis = Zlib::GzipReader.new(sio || entry)
# YAML wants an instance of IO
@metadata = load_gemspec(gzis)
@@ -115,7 +116,6 @@ class Gem::Package::TarInput
end
@tarreader.rewind
- @fileops = Gem::FileOperations.new
unless has_meta then
path = io.path if io.respond_to? :path
@@ -151,9 +151,9 @@ class Gem::Package::TarInput
dest = File.join destdir, entry.full_name
if File.directory? dest then
- @fileops.chmod entry.header.mode, dest, :verbose => false
else
- @fileops.mkdir_p dest, :mode => entry.header.mode, :verbose => false
end
fsync_dir dest
@@ -165,9 +165,9 @@ class Gem::Package::TarInput
# it's a file
md5 = Digest::MD5.new if expected_md5sum
destdir = File.join destdir, File.dirname(entry.full_name)
- @fileops.mkdir_p destdir, :mode => 0755, :verbose => false
destfile = File.join destdir, File.basename(entry.full_name)
- @fileops.chmod 0600, destfile, :verbose => false rescue nil # Errno::ENOENT
open destfile, "wb", entry.header.mode do |os|
loop do
@@ -181,7 +181,7 @@ class Gem::Package::TarInput
os.fsync
end
- @fileops.chmod entry.header.mode, destfile, :verbose => false
fsync_dir File.dirname(destfile)
fsync_dir File.join(File.dirname(destfile), "..")
@@ -236,7 +236,7 @@ class Gem::Package::TarWriter
name = newname
if name.size > 100 or prefix.size > 155 then
- raise Gem::Package::TooLongFileName
end
end
@@ -106,7 +106,7 @@ class Gem::PackageTask < Rake::PackageTask
task :package => [:gem]
- gem_file = gem_spec.file_name
gem_path = File.join package_dir, gem_file
gem_dir = File.join package_dir, gem_spec.full_name
@@ -0,0 +1,78 @@
@@ -4,6 +4,8 @@
# File a instead and assign it to Ryan Davis or Eric Hodel.
######################################################################
##
# Available list of platforms for targeting Gem installations.
@@ -121,8 +123,13 @@ class Gem::Platform
# the same CPU, OS and version.
def ==(other)
- self.class === other and
- @cpu == other.cpu and @os == other.os and @version == other.version
end
##
@@ -185,5 +192,8 @@ class Gem::Platform
CURRENT = 'current'
end
@@ -75,6 +75,7 @@ class Gem::RemoteFetcher
when URI::HTTP then proxy
else URI.parse(proxy)
end
end
##
@@ -85,7 +86,8 @@ class Gem::RemoteFetcher
# larger, more emcompassing effort. -erikh
def download_to_cache dependency
- found = Gem::SpecFetcher.fetcher.fetch dependency
return if found.empty?
@@ -103,12 +105,12 @@ class Gem::RemoteFetcher
Gem.ensure_gem_subdirectories(install_dir) rescue nil
if File.writable?(install_dir)
- cache_dir = Gem.cache_dir(install_dir)
else
- cache_dir = Gem.cache_dir(Gem.user_dir)
end
- gem_file_name = spec.file_name
local_gem_path = File.join cache_dir, gem_file_name
FileUtils.mkdir_p cache_dir rescue nil unless File.exist? cache_dir
@@ -116,8 +118,8 @@ class Gem::RemoteFetcher
# Always escape URI's to deal with potential spaces and such
unless URI::Generic === source_uri
source_uri = URI.parse(URI.const_defined?(:DEFAULT_PARSER) ?
- URI::DEFAULT_PARSER.escape(source_uri) :
- URI.escape(source_uri))
end
scheme = source_uri.scheme
@@ -193,18 +195,54 @@ class Gem::RemoteFetcher
end
##
# Downloads +uri+ and returns it as a String.
def fetch_path(uri, mtime = nil, head = false)
- data = open_uri_or_path uri, mtime, head
data = Gem.gunzip data if data and not head and uri.to_s =~ /gz$/
data
rescue FetchError
raise
rescue Timeout::Error
- raise FetchError.new('timed out', uri)
rescue IOError, SocketError, SystemCallError => e
- raise FetchError.new("#{e.class}: #{e}", uri)
end
##
@@ -306,36 +344,8 @@ class Gem::RemoteFetcher
# read from the filesystem instead.
def open_uri_or_path(uri, last_modified = nil, head = false, depth = 0)
- raise "block is dead" if block_given?
-
- uri = URI.parse uri unless URI::Generic === uri
-
- # This check is redundant unless Gem::RemoteFetcher is likely
- # to be used directly, since the scheme is checked elsewhere.
- # - Daniel Berger
- unless ['http', 'https', 'file'].include?(uri.scheme)
- raise ArgumentError, 'uri scheme is invalid'
- end
-
- if uri.scheme == 'file'
- path = correct_for_windows_path(uri.path)
- return Gem.read_binary(path)
- end
-
- fetch_type = head ? Net::HTTP::Head : Net::HTTP::Get
- response = request uri, fetch_type, last_modified
-
- case response
- when Net::HTTPOK, Net::HTTPNotModified then
- head ? response : response.body
- when Net::HTTPMovedPermanently, Net::HTTPFound, Net::HTTPSeeOther,
- Net::HTTPTemporaryRedirect then
- raise FetchError.new('too many redirects', uri) if depth > 10
-
- open_uri_or_path(response['Location'], last_modified, head, depth + 1)
- else
- raise FetchError.new("bad response #{response.message} #{response.code}", uri)
- end
end
##
@@ -350,12 +360,7 @@ class Gem::RemoteFetcher
request.basic_auth uri.user, uri.password
end
- ua = "RubyGems/#{Gem::VERSION} #{Gem::Platform.local}"
- ua << " Ruby/#{RUBY_VERSION} (#{RUBY_RELEASE_DATE}"
- ua << " level #{RUBY_LEVEL}" if defined? RUBY_LEVEL
- ua << ")"
-
- request.add_field 'User-Agent', ua
request.add_field 'Connection', 'keep-alive'
request.add_field 'Keep-Alive', '30'
@@ -447,5 +452,24 @@ class Gem::RemoteFetcher
connection.start
end
end
@@ -141,6 +141,18 @@ class Gem::Requirement
requirements.all? { |op, rv| (OPS[op] || OPS["="]).call version, rv }
end
def to_s # :nodoc:
as_list.join ", "
end
@@ -393,7 +393,7 @@ module Gem::Security
:munge_re => Regexp.new(/[^a-z0-9_.-]+/),
# output directory for trusted certificate checksums
- :trust_dir => File::join(Gem.user_home, '.gem', 'trust'),
# default permissions for trust directory and certs
:perms => {
@@ -81,47 +81,47 @@ class Gem::Server
<dl>
<% values["specs"].each do |spec| %>
- <dt>
- <% if spec["first_name_entry"] then %>
- <a name="<%=spec["name"]%>"></a>
- <% end %>
-
- <b><%=spec["name"]%> <%=spec["version"]%></b>
-
- <% if spec["rdoc_installed"] then %>
- <a href="<%=spec["doc_path"]%>">[rdoc]</a>
- <% else %>
- <span title="rdoc not installed">[rdoc]</span>
- <% end %>
-
- <% if spec["homepage"] then %>
- <a href="<%=spec["homepage"]%>" title="<%=spec["homepage"]%>">[www]</a>
- <% else %>
- <span title="no homepage available">[www]</span>
- <% end %>
-
- <% if spec["has_deps"] then %>
- - depends on
- <%= spec["dependencies"].map { |v| "<a href=\"##{v["name"]}\">#{v["name"]}</a>" }.join ', ' %>.
- <% end %>
- </dt>
- <dd>
- <%=spec["summary"]%>
- <% if spec["executables"] then %>
- <br/>
-
- <% if spec["only_one_executable"] then %>
- Executable is
- <% else %>
- Executables are
- <%end%>
-
- <%= spec["executables"].map { |v| "<span class=\"context-item-name\">#{v["executable"]}</span>"}.join ', ' %>.
-
- <%end%>
- <br/>
- <br/>
- </dd>
<% end %>
</dl>
@@ -460,15 +460,15 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; }
spec_dir
end
- @source_index = Gem::SourceIndex.from_gems_in(*@spec_dirs)
end
def Marshal(req, res)
- @source_index.refresh!
add_date res
- index = Marshal.dump @source_index
if req.request_method == 'HEAD' then
res['content-length'] = index.length
@@ -492,15 +492,16 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; }
end
def latest_specs(req, res)
- @source_index.refresh!
res['content-type'] = 'application/x-gzip'
add_date res
- specs = @source_index.latest_specs.sort.map do |spec|
- platform = spec.original_platform
- platform = Gem::Platform::RUBY if platform.nil?
[spec.name, spec.version, platform]
end
@@ -552,21 +553,20 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; }
end
def quick(req, res)
- @source_index.refresh!
res['content-type'] = 'text/plain'
add_date res
case req.request_uri.path
when %r|^/quick/(Marshal.#{Regexp.escape Gem.marshal_version}/)?(.*?)-([0-9.]+)(-.*?)?\.gemspec\.rz$| then
- dep = Gem::Dependency.new $2, $3
- specs = @source_index.search dep
- marshal_format = $1
- selector = [$2, $3, $4].map { |s| s.inspect }.join ' '
- platform = if $4 then
- Gem::Platform.new $4.sub(/^-/, '')
else
Gem::Platform::RUBY
end
@@ -589,7 +589,7 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; }
end
def root(req, res)
- @source_index.refresh!
add_date res
raise WEBrick::HTTPStatus::NotFound, "`#{req.path}' not found." unless
@@ -598,13 +598,15 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; }
specs = []
total_file_count = 0
- @source_index.each do |path, spec|
total_file_count += spec.files.size
- deps = spec.dependencies.map do |dep|
- { "name" => dep.name,
"type" => dep.type,
- "version" => dep.requirement.to_s, }
- end
deps = deps.sort_by { |dep| [dep["name"].downcase, dep["version"]] }
deps.last["is_last"] = true unless deps.empty?
@@ -798,13 +800,12 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; }
end
def specs(req, res)
- @source_index.refresh!
add_date res
- specs = @source_index.sort.map do |_, spec|
- platform = spec.original_platform
- platform = Gem::Platform::RUBY if platform.nil?
[spec.name, spec.version, platform]
end
@@ -827,12 +828,11 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; }
def launch
listeners = @server.listeners.map{|l| l.addr[2] }
host = listeners.any?{|l| l == '0.0.0.0'} ? 'localhost' : listeners.first
say "Launching browser to http://#{host}:#{@port}"
system("#{@launch} http://#{host}:#{@port}")
end
-
end
-
@@ -11,6 +11,7 @@
#++
require 'rubygems/specification'
##
# The SourceIndex object indexes all the gems available from a
@@ -34,79 +35,86 @@ class Gem::SourceIndex
attr_accessor :spec_dirs
- class << self
- ##
- # Factory method to construct a source index instance for a given
- # path.
- #
- # deprecated::
- # If supplied, from_installed_gems will act just like
- # +from_gems_in+. This argument is deprecated and is provided
- # just for backwards compatibility, and should not generally
- # be used.
- #
- # return::
- # SourceIndex instance
-
- def from_installed_gems(*deprecated)
- if deprecated.empty?
- from_gems_in(*installed_spec_directories)
- else
- from_gems_in(*deprecated) # HACK warn
- end
end
- ##
- # Returns a list of directories from Gem.path that contain specifications.
- def installed_spec_directories
- Gem.path.collect { |dir| File.join(dir, "specifications") }
- end
- ##
- # Creates a new SourceIndex from the ruby format gem specifications in
- # +spec_dirs+.
- def from_gems_in(*spec_dirs)
- source_index = new
- source_index.spec_dirs = spec_dirs
- source_index.refresh!
- end
- ##
- # Loads a ruby-format specification from +file_name+ and returns the
- # loaded spec.
- def load_specification(file_name)
- Gem::Specification.load file_name
end
-
end
##
# Constructs a source index instance from the provided specifications, which
# is a Hash of gem full names and Gem::Specifications.
- #--
- # TODO merge @gems and @prerelease_gems and provide a separate method
- # #prerelease_gems
- def initialize(specifications={})
@gems = {}
- specifications.each{ |full_name, spec| add_spec spec }
@spec_dirs = nil
end
- # TODO: remove method
def all_gems
- @gems
end
def prerelease_gems
- @gems.reject{ |name, gem| !gem.version.prerelease? }
end
def released_gems
- @gems.reject{ |name, gem| gem.version.prerelease? }
end
##
@@ -116,10 +124,12 @@ class Gem::SourceIndex
@gems.clear
spec_dirs.reverse_each do |spec_dir|
- spec_files = Dir.glob File.join(spec_dir, '*.gemspec')
spec_files.each do |spec_file|
- gemspec = Gem::Specification.load spec_file
add_spec gemspec if gemspec
end
end
@@ -159,8 +169,6 @@ class Gem::SourceIndex
result[name] << spec
end
- # TODO: why is this a hash while @gems is an array? Seems like
- # structural similarity would be good.
result.values.flatten
end
@@ -246,7 +254,10 @@ class Gem::SourceIndex
def find_name(gem_name, requirement = Gem::Requirement.default)
dep = Gem::Dependency.new gem_name, requirement
- search dep
end
##
@@ -258,9 +269,9 @@ class Gem::SourceIndex
# +gem_pattern+, and a Gem::Requirement for +platform_only+. This
# behavior is deprecated and will be removed.
- def search(gem_pattern, platform_only = false)
requirement = nil
- only_platform = false
# TODO - Remove support and warning for legacy arguments after 2008/11
unless Gem::Dependency === gem_pattern
@@ -269,9 +280,9 @@ class Gem::SourceIndex
case gem_pattern
when Regexp then
- requirement = platform_only || Gem::Requirement.default
when Gem::Dependency then
- only_platform = platform_only
requirement = gem_pattern.requirement
gem_pattern = if Regexp === gem_pattern.name then
@@ -282,7 +293,7 @@ class Gem::SourceIndex
/^#{Regexp.escape gem_pattern.name}$/
end
else
- requirement = platform_only || Gem::Requirement.default
gem_pattern = /#{gem_pattern}/i
end
@@ -290,7 +301,7 @@ class Gem::SourceIndex
requirement = Gem::Requirement.create requirement
end
- specs = all_gems.values.select do |spec|
spec.name =~ gem_pattern and
requirement.satisfied_by? spec.version
end
@@ -343,7 +354,6 @@ class Gem::SourceIndex
def dump
Marshal.dump(self)
end
-
end
# :stopdoc:
@@ -356,5 +366,45 @@ module Gem
Cache = SourceIndex
end
-# :startdoc:
@@ -91,6 +91,7 @@ class Gem::SpecFetcher
all = false,
matching_platform = true,
prerelease = false)
specs_and_sources, errors = find_matching_with_errors(dependency,
all,
matching_platform,
@@ -144,7 +145,10 @@ class Gem::SpecFetcher
# matching released versions are returned. If +matching_platform+
# is false, gems for all platforms are returned.
- def find_matching_with_errors(dependency, all = false, matching_platform = true, prerelease = false)
found = {}
rejected_specs = {}
@@ -257,13 +261,12 @@ class Gem::SpecFetcher
loaded = false
if File.exist? local_file then
- spec_dump = @fetcher.fetch_path spec_path, File.mtime(local_file)
- if spec_dump.nil? then
- spec_dump = Gem.read_binary local_file
- else
- loaded = true
- end
else
spec_dump = @fetcher.fetch_path spec_path
loaded = true
@@ -13,6 +13,7 @@
require 'rubygems/version'
require 'rubygems/requirement'
require 'rubygems/platform'
# :stopdoc:
class Date; end # for ruby_code if date.rb wasn't required
@@ -34,11 +35,6 @@ class Date; end # for ruby_code if date.rb wasn't required
class Gem::Specification
##
- # Allows deinstallation of gems with legacy platforms.
-
- attr_accessor :original_platform # :nodoc:
-
- ##
# The the version number of a specification that does not specify one
# (i.e. RubyGems 0.7 or earlier).
@@ -48,6 +44,17 @@ class Gem::Specification
# The specification version applied to any new Specification instances
# created. This should be bumped whenever something in the spec format
# changes.
#--
# When updating this number, be sure to also update #to_ruby.
#
@@ -55,423 +62,423 @@ class Gem::Specification
CURRENT_SPECIFICATION_VERSION = 3
- ##
- # An informal list of changes to the specification. The highest-valued
- # key should be equal to the CURRENT_SPECIFICATION_VERSION.
-
- SPECIFICATION_VERSION_HISTORY = {
- -1 => ['(RubyGems versions up to and including 0.7 did not have versioned specifications)'],
- 1 => [
- 'Deprecated "test_suite_file" in favor of the new, but equivalent, "test_files"',
- '"test_file=x" is a shortcut for "test_files=[x]"'
- ],
- 2 => [
- 'Added "required_rubygems_version"',
- 'Now forward-compatible with future versions',
- ],
- 3 => [
- 'Added Fixnum validation to the specification_version'
- ]
- }
-
# :stopdoc:
MARSHAL_FIELDS = { -1 => 16, 1 => 16, 2 => 16, 3 => 17 }
- now = Time.at(Time.now.to_i)
- TODAY = now - ((now.to_i + now.gmt_offset) % 86400)
# :startdoc:
##
- # Optional block used to gather newly defined instances.
- @@gather = nil
##
- # List of attribute names: [:name, :version, ...]
- @@required_attributes = []
##
- # List of _all_ attributes and default values:
- #
- # [[:name, nil],
- # [:bindir, 'bin'],
- # ...]
- @@attributes = []
- @@nil_attributes = []
- @@non_nil_attributes = [:@original_platform]
##
- # List of array attributes
- @@array_attributes = []
##
- # Map of attribute names to default values.
- @@default_value = {}
##
- # Names of all specification attributes
- def self.attribute_names
- @@attributes.map { |name, default| name }
- end
##
- # Default values for specification attributes
- def self.attribute_defaults
- @@attributes.dup
- end
##
- # The default value for specification attribute +name+
- def self.default_value(name)
- @@default_value[name]
- end
##
- # Required specification attributes
- def self.required_attributes
- @@required_attributes.dup
- end
##
- # Is +name+ a required attribute?
- def self.required_attribute?(name)
- @@required_attributes.include? name.to_sym
- end
##
- # Specification attributes that are arrays (appendable and so-forth)
- def self.array_attributes
- @@array_attributes.dup
- end
##
- # Specifies the +name+ and +default+ for a specification attribute, and
- # creates a reader and writer method like Module#attr_accessor.
#
- # The reader method returns the default if the value hasn't been set.
- def self.attribute(name, default=nil)
- ivar_name = "@#{name}".intern
- if default.nil? then
- @@nil_attributes << ivar_name
- else
- @@non_nil_attributes << [ivar_name, default]
- end
- @@attributes << [name, default]
- @@default_value[name] = default
- attr_accessor(name)
- end
##
- # Same as :attribute, but ensures that values assigned to the attribute
- # are array values by applying :to_a to the value.
- def self.array_attribute(name)
- @@non_nil_attributes << ["@#{name}".intern, []]
- @@array_attributes << name
- @@attributes << [name, []]
- @@default_value[name] = []
- code = %{
- def #{name}
- @#{name} ||= []
- end
- def #{name}=(value)
- @#{name} = Array(value)
- end
- }
- module_eval code, __FILE__, __LINE__ - 9
- end
##
- # Same as attribute above, but also records this attribute as mandatory.
- def self.required_attribute(*args)
- @@required_attributes << args.first
- attribute(*args)
- end
##
- # Sometimes we don't want the world to use a setter method for a
- # particular attribute.
- #
- # +read_only+ makes it private so we can still use it internally.
- def self.read_only(*names)
- names.each do |name|
- private "#{name}="
- end
- end
- # Shortcut for creating several attributes at once (each with a default
- # value of +nil+).
- def self.attributes(*args)
- args.each do |arg|
- attribute(arg, nil)
- end
- end
##
- # Some attributes require special behaviour when they are accessed. This
- # allows for that.
- def self.overwrite_accessor(name, &block)
- remove_method name
- define_method(name, &block)
- end
##
- # Defines a _singular_ version of an existing _plural_ attribute (i.e. one
- # whose value is expected to be an array). This means just creating a
- # helper method that takes a single value and appends it to the array.
- # These are created for convenience, so that in a spec, one can write
- #
- # s.require_path = 'mylib'
- #
- # instead of:
- #
- # s.require_paths = ['mylib']
- #
- # That above convenience is available courtesy of:
- #
- # attribute_alias_singular :require_path, :require_paths
- def self.attribute_alias_singular(singular, plural)
- define_method("#{singular}=") { |val|
- send("#{plural}=", [val])
- }
- define_method("#{singular}") {
- val = send("#{plural}")
- val.nil? ? nil : val.first
- }
- end
##
- # Dump only crucial instance variables.
- #--
- # MAINTAIN ORDER!
- def _dump(limit)
- Marshal.dump [
- @rubygems_version,
- @specification_version,
- @name,
- @version,
- (Time === @date ? @date : (require 'time'; Time.parse(@date.to_s))),
- @summary,
- @required_ruby_version,
- @required_rubygems_version,
- @original_platform,
- @dependencies,
- @rubyforge_project,
- @email,
- @authors,
- @description,
- @homepage,
- @has_rdoc,
- @new_platform,
- @licenses
- ]
- end
##
- # Load custom marshal format, re-initializing defaults as needed
- def self._load(str)
- array = Marshal.load str
- spec = Gem::Specification.new
- spec.instance_variable_set :@specification_version, array[1]
- current_version = CURRENT_SPECIFICATION_VERSION
- field_count = if spec.specification_version > current_version then
- spec.instance_variable_set :@specification_version,
- current_version
- MARSHAL_FIELDS[current_version]
- else
- MARSHAL_FIELDS[spec.specification_version]
- end
- if array.size < field_count then
- raise TypeError, "invalid Gem::Specification format #{array.inspect}"
end
- spec.instance_variable_set :@rubygems_version, array[0]
- # spec version
- spec.instance_variable_set :@name, array[2]
- spec.instance_variable_set :@version, array[3]
- spec.instance_variable_set :@date, array[4]
- spec.instance_variable_set :@summary, array[5]
- spec.instance_variable_set :@required_ruby_version, array[6]
- spec.instance_variable_set :@required_rubygems_version, array[7]
- spec.instance_variable_set :@original_platform, array[8]
- spec.instance_variable_set :@dependencies, array[9]
- spec.instance_variable_set :@rubyforge_project, array[10]
- spec.instance_variable_set :@email, array[11]
- spec.instance_variable_set :@authors, array[12]
- spec.instance_variable_set :@description, array[13]
- spec.instance_variable_set :@homepage, array[14]
- spec.instance_variable_set :@has_rdoc, array[15]
- spec.instance_variable_set :@new_platform, array[16]
- spec.instance_variable_set :@platform, array[16].to_s
- spec.instance_variable_set :@license, array[17]
- spec.instance_variable_set :@loaded, false
- spec
end
##
- # List of dependencies that will automatically be activated at runtime.
- def runtime_dependencies
- # TODO: fix #type to return :runtime if nil
- dependencies.select { |d| d.type == :runtime }
end
##
- # List of dependencies that are used for development
- def development_dependencies
- dependencies.select { |d| d.type == :development }
end
- def test_suite_file # :nodoc:
- warn 'test_suite_file deprecated, use test_files'
- test_files.first
end
- def test_suite_file=(val) # :nodoc:
- warn 'test_suite_file= deprecated, use test_files='
- @test_files = [] unless defined? @test_files
- @test_files << val
end
##
- # true when this gemspec has been loaded from a specifications directory.
- # This attribute is not persisted.
- attr_accessor :loaded
##
- # Path this gemspec was loaded from. This attribute is not persisted.
- attr_accessor :loaded_from
##
- # Returns an array with bindir attached to each executable in the
- # executables list
- def add_bindir(executables)
- return nil if executables.nil?
- if @bindir then
- Array(executables).map { |e| File.join(@bindir, e) }
- else
- executables
- end
- rescue
- return nil
end
##
- # Files in the Gem under one of the require_paths
- def lib_files
- @files.select do |file|
- require_paths.any? do |path|
- file.index(path) == 0
- end
end
end
##
- # True if this gem was loaded from disk
- alias :loaded? :loaded
- ##
- # True if this gem has files in test_files
- def has_unit_tests?
- not test_files.empty?
end
- # :stopdoc:
- alias has_test_suite? has_unit_tests?
- # :startdoc:
-
##
- # Specification constructor. Assigns the default values to the
- # attributes and yields itself for further
- # initialization. Optionally takes +name+ and +version+.
- def initialize name = nil, version = nil
- @new_platform = nil
- assign_defaults
- @loaded = false
- @loaded_from = nil
- self.name = name if name
- self.version = version if version
- yield self if block_given?
- @@gather.call(self) if @@gather
end
##
- # Duplicates array_attributes from +other_spec+ so state isn't shared.
- def initialize_copy(other_spec)
- other_ivars = other_spec.instance_variables
- other_ivars = other_ivars.map { |ivar| ivar.intern } if # for 1.9
- other_ivars.any? { |ivar| String === ivar }
- self.class.array_attributes.each do |name|
- name = :"@#{name}"
- next unless other_ivars.include? name
- instance_variable_set name, other_spec.instance_variable_get(name).dup
- end
end
##
- # Each attribute has a default value (possibly nil). Here, we initialize
- # all attributes to their default value. This is done through the
- # accessor methods, so special behaviours will be honored. Furthermore,
- # we take a _copy_ of the default so each specification instance has its
- # own empty arrays, etc.
- def assign_defaults
- @@nil_attributes.each do |name|
- instance_variable_set name, nil
- end
- @@non_nil_attributes.each do |name, default|
- value = case default
- when Time, Numeric, Symbol, true, false, nil then default
- else default.dup
- end
- instance_variable_set name, value
end
- # HACK
- instance_variable_set :@new_platform, Gem::Platform::RUBY
end
##
@@ -480,7 +487,7 @@ class Gem::Specification
# routine (#initialize). This method makes up for that and deals with
# gems of different ages.
#
- # 'input' can be anything that YAML.load() accepts: String or IO.
def self.from_yaml(input)
input = normalize_yaml_input input
@@ -505,6 +512,27 @@ class Gem::Specification
end
##
# Loads Ruby format gemspec from +file+.
def self.load file
@@ -524,7 +552,7 @@ class Gem::Specification
spec = eval code, binding, file
if Gem::Specification === spec
- spec.loaded_from = file
return spec
end
@@ -539,451 +567,472 @@ class Gem::Specification
end
##
# Make sure the YAML specification is properly formatted with dashes
def self.normalize_yaml_input(input)
result = input.respond_to?(:read) ? input.read : input
result = "--- " + result unless result =~ /\A--- /
- result.gsub(/ !!null \n/, " \n")
end
##
- # Sets the rubygems_version to the current RubyGems version
- def mark_version
- @rubygems_version = Gem::VERSION
- end
- ##
- # Ignore unknown attributes while loading
- def method_missing(sym, *a, &b) # :nodoc:
- if @specification_version > CURRENT_SPECIFICATION_VERSION and
- sym.to_s =~ /=$/ then
- warn "ignoring #{sym} loading #{full_name}" if $DEBUG
- else
- super
- end
- end
- ##
- # Adds a development dependency named +gem+ with +requirements+ to this
- # Gem. For example:
- #
- # spec.add_development_dependency 'jabber4r', '> 0.1', '<= 0.5'
- #
- # Development dependencies aren't installed by default and aren't
- # activated when a gem is required.
- def add_development_dependency(gem, *requirements)
- add_dependency_with_type(gem, :development, *requirements)
end
##
- # Adds a runtime dependency named +gem+ with +requirements+ to this Gem.
- # For example:
- #
- # spec.add_runtime_dependency 'jabber4r', '> 0.1', '<= 0.5'
- def add_runtime_dependency(gem, *requirements)
- add_dependency_with_type(gem, :runtime, *requirements)
end
##
- # Adds a runtime dependency
- alias add_dependency add_runtime_dependency
##
- # Returns the full name (name-version) of this Gem. Platform information
- # is included (name-version-platform) if it is specified and not the
- # default Ruby platform.
- def full_name
- if platform == Gem::Platform::RUBY or platform.nil? then
- "#{@name}-#{@version}"
- else
- "#{@name}-#{@version}-#{platform}"
- end
end
##
- # Returns the full name (name-version) of this gemspec using the original
- # platform. For use with legacy gems.
- def original_name # :nodoc:
- if platform == Gem::Platform::RUBY or platform.nil? then
- "#{@name}-#{@version}"
- else
- "#{@name}-#{@version}-#{@original_platform}"
- end
end
##
- # The full path to the gem (install path + full name).
- def full_gem_path
- path = File.join installation_path, 'gems', full_name
- return path if File.directory? path
- File.join installation_path, 'gems', original_name
- end
- ##
- # The default (generated) file name of the gem. See also #spec_name.
- #
- # spec.file_name # => "example-1.0.gem"
- def file_name
- full_name + '.gem'
- end
- ##
- # The directory that this gem was installed into.
- def installation_path
- unless @loaded_from then
- raise Gem::Exception, "spec #{full_name} is not from an installed gem"
end
- File.expand_path File.dirname(File.dirname(@loaded_from))
end
- ##
- # Checks if this specification meets the requirement of +dependency+.
- def satisfies_requirement?(dependency)
- return @name == dependency.name &&
- dependency.requirement.satisfied_by?(@version)
end
##
- # Returns an object you can use to sort specifications in #sort_by.
- def sort_obj
- [@name, @version, @new_platform == Gem::Platform::RUBY ? -1 : 1]
end
##
- # The default name of the gemspec. See also #file_name
- #
- # spec.spec_name # => "example-1.0.gemspec"
- def spec_name
- full_name + '.gemspec'
- end
- def <=>(other) # :nodoc:
- sort_obj <=> other.sort_obj
- end
- ##
- # Tests specs for equality (across all attributes).
-
- def ==(other) # :nodoc:
- self.class === other && same_attributes?(other)
- end
- alias eql? == # :nodoc:
- ##
- # A macro to yield cached gem path
- #
- def cache_gem
- cache_name = File.join(Gem.dir, 'cache', file_name)
- return File.exist?(cache_name) ? cache_name : nil
end
##
- # True if this gem has the same attributes as +other+.
- def same_attributes?(other)
- @@attributes.each do |name, default|
- return false unless self.send(name) == other.send(name)
end
- true
end
- private :same_attributes?
- def hash # :nodoc:
- @@attributes.inject(0) { |hash_code, (name, _)|
- hash_code ^ self.send(name).hash
- }
end
- def encode_with coder # :nodoc:
- mark_version
- attributes = @@attributes.map { |name,| name.to_s }.sort
- attributes = attributes - %w[name version platform]
- coder.add 'name', @name
- coder.add 'version', @version
- platform = case @original_platform
- when nil, '' then
- 'ruby'
- when String then
- @original_platform
- else
- @original_platform.to_s
- end
- coder.add 'platform', platform
- attributes.each do |name|
- coder.add name, instance_variable_get("@#{name}")
end
- end
- def to_yaml(opts = {}) # :nodoc:
- if YAML.const_defined?(:ENGINE) && !YAML::ENGINE.syck? then
- super.gsub(/ !!null \n/, " \n")
- else
- YAML.quick_emit object_id, opts do |out|
- out.map taguri, to_yaml_style do |map|
- encode_with map
- end
- end
- end
end
- def init_with coder # :nodoc:
- yaml_initialize coder.tag, coder.map
- end
- def yaml_initialize(tag, vals) # :nodoc:
- vals.each do |ivar, val|
- instance_variable_set "@#{ivar}", val
- end
- @original_platform = @platform # for backwards compatibility
- self.platform = Gem::Platform.new @platform
end
##
- # Returns a Ruby code representation of this specification, such that it
- # can be eval'ed and reconstruct the same specification later. Attributes
- # that still have their default values are omitted.
-
- def to_ruby
- mark_version
- result = []
- result << "# -*- encoding: utf-8 -*-"
- result << nil
- result << "Gem::Specification.new do |s|"
- result << " s.name = #{ruby_code name}"
- result << " s.version = #{ruby_code version}"
- unless platform.nil? or platform == Gem::Platform::RUBY then
- result << " s.platform = #{ruby_code original_platform}"
- end
- result << ""
- result << " s.required_rubygems_version = #{ruby_code required_rubygems_version} if s.respond_to? :required_rubygems_version="
- handled = [
- :dependencies,
- :name,
- :platform,
- :required_rubygems_version,
- :specification_version,
- :version,
- ]
- attributes = @@attributes.sort_by { |attr_name,| attr_name.to_s }
- attributes.each do |attr_name, default|
- next if handled.include? attr_name
- current_value = self.send(attr_name)
- if current_value != default or
- self.class.required_attribute? attr_name then
- result << " s.#{attr_name} = #{ruby_code current_value}"
- end
end
- result << nil
- result << " if s.respond_to? :specification_version then"
- result << " s.specification_version = #{specification_version}"
- result << nil
-
- result << " if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then"
- dependencies.each do |dep|
- req = dep.requirements_list.inspect
- dep.instance_variable_set :@type, :runtime if dep.type.nil? # HACK
- result << " s.add_#{dep.type}_dependency(%q<#{dep.name}>, #{req})"
end
- result << " else"
- dependencies.each do |dep|
- version_reqs_param = dep.requirements_list.inspect
- result << " s.add_dependency(%q<#{dep.name}>, #{version_reqs_param})"
- end
- result << ' end'
- result << " else"
- dependencies.each do |dep|
- version_reqs_param = dep.requirements_list.inspect
- result << " s.add_dependency(%q<#{dep.name}>, #{version_reqs_param})"
- end
- result << " end"
- result << "end"
- result << nil
- result.join "\n"
end
- def to_ruby_for_cache
- s = dup
- # remove large blobs that aren't used at runtime:
- s.files = nil
- s.extra_rdoc_files = nil
- s.rdoc_options = nil
- s.to_ruby
end
##
- # Checks that the specification contains all required fields, and does a
- # very basic sanity check.
#
- # Raises InvalidSpecificationException if the spec does not pass the
- # checks..
- def validate
- require 'rubygems/user_interaction'
- extend Gem::UserInteraction
- normalize
-
- if rubygems_version != Gem::VERSION then
- raise Gem::InvalidSpecificationException,
- "expected RubyGems version #{Gem::VERSION}, was #{rubygems_version}"
- end
- @@required_attributes.each do |symbol|
- unless self.send symbol then
- raise Gem::InvalidSpecificationException,
- "missing value for attribute #{symbol}"
- end
- end
- unless String === name then
- raise Gem::InvalidSpecificationException,
- "invalid value for attribute name: \"#{name.inspect}\""
- end
- if require_paths.empty? then
- raise Gem::InvalidSpecificationException,
- 'specification must have at least one require_path'
- end
- @files.delete_if do |file| File.directory? file end
- @test_files.delete_if do |file| File.directory? file end
- @executables.delete_if do |file|
- File.directory? File.join(bindir, file)
- end
- @extra_rdoc_files.delete_if do |file| File.directory? file end
- @extensions.delete_if do |file| File.directory? file end
- non_files = files.select do |file|
- !File.file? file
- end
- unless non_files.empty? then
- non_files = non_files.map { |file| file.inspect }
- raise Gem::InvalidSpecificationException,
- "[#{non_files.join ", "}] are not files"
- end
- unless specification_version.is_a?(Fixnum)
- raise Gem::InvalidSpecificationException,
- 'specification_version must be a Fixnum (did you mean version?)'
- end
- case platform
- when Gem::Platform, Gem::Platform::RUBY then # ok
- else
- raise Gem::InvalidSpecificationException,
- "invalid platform #{platform.inspect}, see Gem::Platform"
- end
- unless Array === authors and
- authors.all? { |author| String === author } then
- raise Gem::InvalidSpecificationException,
- 'authors must be Array of Strings'
- end
- licenses.each { |license|
- if license.length > 64
- raise Gem::InvalidSpecificationException,
- "each license must be 64 characters or less"
- end
- }
- # reject FIXME and TODO
- unless authors.grep(/FIXME|TODO/).empty? then
- raise Gem::InvalidSpecificationException,
- '"FIXME" or "TODO" is not an author'
end
- unless Array(email).grep(/FIXME|TODO/).empty? then
- raise Gem::InvalidSpecificationException,
- '"FIXME" or "TODO" is not an email address'
- end
- if description =~ /FIXME|TODO/ then
- raise Gem::InvalidSpecificationException,
- '"FIXME" or "TODO" is not a description'
- end
- if summary =~ /FIXME|TODO/ then
- raise Gem::InvalidSpecificationException,
- '"FIXME" or "TODO" is not a summary'
end
- if homepage and not homepage.empty? and
- homepage !~ /\A[a-z][a-z\d+.-]*:/i then
- raise Gem::InvalidSpecificationException,
- "\"#{homepage}\" is not a URI"
- end
- # Warnings
- %w[author description email homepage summary].each do |attribute|
- value = self.send attribute
- alert_warning "no #{attribute} specified" if value.nil? or value.empty?
- end
- if summary and not summary.empty? and description == summary then
- alert_warning 'description and summary are identical'
- end
- alert_warning "deprecated autorequire specified" if autorequire
- executables.each do |executable|
- executable_path = File.join bindir, executable
- shebang = File.read(executable_path, 2) == '#!'
- alert_warning "#{executable_path} is missing #! line" unless shebang
end
- true
end
##
- # Normalize the list of files so that:
- # * All file lists have redundancies removed.
- # * Files referenced in the extra_rdoc_files are included in the package
- # file list.
- def normalize
- if defined?(@extra_rdoc_files) and @extra_rdoc_files then
- @extra_rdoc_files.uniq!
- @files ||= []
- @files.concat(@extra_rdoc_files)
- end
- @files.uniq! if @files
end
##
@@ -994,436 +1043,493 @@ class Gem::Specification
def dependent_gems
out = []
- Gem.source_index.each do |name,gem|
- gem.dependencies.each do |dep|
if self.satisfies_requirement?(dep) then
sats = []
find_all_satisfiers(dep) do |sat|
sats << sat
end
- out << [gem, dep, sats]
end
end
end
out
end
- def to_s # :nodoc:
- "#<Gem::Specification name=#{@name} version=#{@version}>"
- end
-
- def pretty_print(q) # :nodoc:
- q.group 2, 'Gem::Specification.new do |s|', 'end' do
- q.breakable
-
- attributes = @@attributes.sort_by { |attr_name,| attr_name.to_s }
- attributes.each do |attr_name, default|
- current_value = self.send attr_name
- if current_value != default or
- self.class.required_attribute? attr_name then
- q.text "s.#{attr_name} = "
- if attr_name == :date then
- current_value = current_value.utc
- q.text "Time.utc(#{current_value.year}, #{current_value.month}, #{current_value.day})"
- else
- q.pp current_value
- end
- q.breakable
- end
- end
- end
end
##
- # Adds a dependency on gem +dependency+ with type +type+ that requires
- # +requirements+. Valid types are currently <tt>:runtime</tt> and
- # <tt>:development</tt>.
- def add_dependency_with_type(dependency, type, *requirements)
- requirements = if requirements.empty? then
- Gem::Requirement.default
- else
- requirements.flatten
- end
- unless dependency.respond_to?(:name) &&
- dependency.respond_to?(:version_requirements)
- dependency = Gem::Dependency.new(dependency, requirements, type)
end
- dependencies << dependency
end
- private :add_dependency_with_type
##
- # Finds all gems that satisfy +dep+
- def find_all_satisfiers(dep)
- Gem.source_index.each do |_, gem|
- yield gem if gem.satisfies_requirement? dep
- end
end
- private :find_all_satisfiers
##
- # Return a string containing a Ruby code representation of the given
- # object.
- def ruby_code(obj)
- case obj
- when String then '%q{' + obj + '}'
- when Array then obj.inspect
- when Gem::Version then obj.to_s.inspect
- when Date then '%q{' + obj.strftime('%Y-%m-%d') + '}'
- when Time then '%q{' + obj.strftime('%Y-%m-%d') + '}'
- when Numeric then obj.inspect
- when true, false, nil then obj.inspect
- when Gem::Platform then "Gem::Platform.new(#{obj.to_a.inspect})"
- when Gem::Requirement then "Gem::Requirement.new(#{obj.to_s.inspect})"
- else raise Gem::Exception, "ruby_code case not handled: #{obj.class}"
- end
end
- private :ruby_code
- # :section: Required gemspec attributes
##
- # :attr_accessor: rubygems_version
- #
- # The version of RubyGems used to create this gem.
- #
- # Do not set this, it is set automatically when the gem is packaged.
- required_attribute :rubygems_version, Gem::VERSION
##
- # :attr_accessor: specification_version
- #
- # The Gem::Specification version of this gemspec.
- #
- # Do not set this, it is set automatically when the gem is packaged.
- required_attribute :specification_version, CURRENT_SPECIFICATION_VERSION
##
- # :attr_accessor: name
- #
- # This gem's name
- required_attribute :name
##
- # :attr_accessor: version
#
- # This gem's version
- required_attribute :version
##
- # :attr_accessor: date
#
- # The date this gem was created
#
- # Do not set this, it is set automatically when the gem is packaged.
- required_attribute :date, TODAY
##
- # :attr_accessor: summary
- #
- # A short summary of this gem's description. Displayed in `gem list -d`.
- #
- # The description should be more detailed than the summary. For example,
- # you might wish to copy the entire README into the description.
- #
- # As of RubyGems 1.3.2 newlines are no longer stripped.
- required_attribute :summary
##
- # :attr_accessor: require_paths
- #
- # Paths in the gem to add to $LOAD_PATH when this gem is activated.
- #
- # The default 'lib' is typically sufficient.
- required_attribute :require_paths, ['lib']
- # :section: Optional gemspec attributes
##
- # :attr_accessor: email
- #
- # A contact email for this gem
- #
- # If you are providing multiple authors and multiple emails they should be
- # in the same order such that:
- #
- # Hash[*spec.authors.zip(spec.emails).flatten]
- #
- # Gives a hash of author name to email address.
- attribute :email
- ##
- # :attr_accessor: homepage
- #
- # The URL of this gem's home page
- attribute :homepage
##
- # :attr_accessor: rubyforge_project
- #
- # The rubyforge project this gem lives under. i.e. RubyGems'
- # rubyforge_project is "rubygems".
- attribute :rubyforge_project
- ##
- # :attr_accessor: description
- #
- # A long description of this gem
- attribute :description
##
- # :attr_accessor: autorequire
- #
- # Autorequire was used by old RubyGems to automatically require a file.
- # It no longer is supported.
- attribute :autorequire
##
- # :attr_accessor: default_executable
- #
- # The default executable for this gem.
- #
- # This is not used.
- attribute :default_executable
##
- # :attr_accessor: bindir
- #
- # The path in the gem for executable scripts
- attribute :bindir, 'bin'
##
- # :attr_accessor: has_rdoc
- #
# Deprecated and ignored, defaults to true.
#
# Formerly used to indicate this gem was RDoc-capable.
- attribute :has_rdoc, true
##
- # True if this gem supports RDoc
alias :has_rdoc? :has_rdoc
##
- # :attr_accessor: required_ruby_version
- #
- # The version of ruby required by this gem
-
- attribute :required_ruby_version, Gem::Requirement.default
- ##
- # :attr_accessor: required_rubygems_version
- #
- # The RubyGems version required by this gem
- attribute :required_rubygems_version, Gem::Requirement.default
- ##
- # :attr_accessor: platform
- #
- # The platform this gem runs on. See Gem::Platform for details.
- #
- # Setting this to any value other than Gem::Platform::RUBY or
- # Gem::Platform::CURRENT is probably wrong.
- attribute :platform, Gem::Platform::RUBY
##
- # :attr_accessor: signing_key
- #
- # The key used to sign this gem. See Gem::Security for details.
- attribute :signing_key, nil
- ##
- # :attr_accessor: cert_chain
- #
- # The certificate chain used to sign this gem. See Gem::Security for
- # details.
- attribute :cert_chain, []
- ##
- # :attr_accessor: post_install_message
- #
- # A message that gets displayed after the gem is installed
- attribute :post_install_message, nil
- ##
- # :attr_accessor: authors
- #
- # The list of author names who wrote this gem.
- #
- # If you are providing multiple authors and multiple emails they should be
- # in the same order such that:
- #
- # Hash[*spec.authors.zip(spec.emails).flatten]
- #
- # Gives a hash of author name to email address.
- array_attribute :authors
##
- # :attr_accessor: licenses
- #
- # The license(s) for the library. Each license must be a short name, no
- # more than 64 characters.
-
- array_attribute :licenses
- ##
- # :attr_accessor: files
- #
- # Files included in this gem. You cannot append to this accessor, you must
- # assign to it.
- #
- # Only add files you can require to this list, not directories, etc.
- #
- # Directories are automatically stripped from this list when building a gem,
- # other non-files cause an error.
- array_attribute :files
- ##
- # :attr_accessor: test_files
- #
- # Test files included in this gem. You cannot append to this accessor, you
- # must assign to it.
- array_attribute :test_files
##
- # :attr_accessor: rdoc_options
- #
- # An ARGV style array of options to RDoc
- array_attribute :rdoc_options
##
- # :attr_accessor: extra_rdoc_files
- #
- # Extra files to add to RDoc such as README or doc/examples.txt
- array_attribute :extra_rdoc_files
##
- # :attr_accessor: executables
- #
- # Executables included in the gem.
- array_attribute :executables
##
- # :attr_accessor: extensions
- #
- # Extensions to build when installing the gem. See
- # Gem::Installer#build_extensions for valid values.
- array_attribute :extensions
##
- # :attr_accessor: requirements
- #
- # An array or things required by this gem. Not used by anything
- # presently.
- array_attribute :requirements
##
- # :attr_reader: dependencies
- #
- # A list of Gem::Dependency objects this gem depends on.
- #
- # Use #add_dependency or #add_development_dependency to add dependencies to
- # a gem.
- array_attribute :dependencies
- read_only :dependencies
- # :section: Aliased gemspec attributes
##
- # Singular accessor for #executables
- attribute_alias_singular :executable, :executables
##
- # Singular accessor for #authors
- attribute_alias_singular :author, :authors
##
- # Singular accessor for #licenses
- attribute_alias_singular :license, :licenses
##
- # Singular accessor for #require_paths
- attribute_alias_singular :require_path, :require_paths
##
- # Singular accessor for #test_files
- attribute_alias_singular :test_file, :test_files
##
- # has_rdoc is now ignored
- overwrite_accessor :has_rdoc do
- true
end
##
- # has_rdoc is now ignored
- overwrite_accessor :has_rdoc= do |value|
- @has_rdoc = true
end
- overwrite_accessor :version= do |version|
- @version = Gem::Version.create(version)
- self.required_rubygems_version = '> 1.3.1' if @version.prerelease?
- return @version
- end
- overwrite_accessor :platform do
- @new_platform
end
- overwrite_accessor :platform= do |platform|
if @original_platform.nil? or
@original_platform == Gem::Platform::RUBY then
@original_platform = platform
@@ -1455,68 +1561,237 @@ class Gem::Specification
@new_platform
end
- overwrite_accessor :required_ruby_version= do |value|
- @required_ruby_version = Gem::Requirement.create(value)
- end
- overwrite_accessor :required_rubygems_version= do |value|
- @required_rubygems_version = Gem::Requirement.create(value)
end
- overwrite_accessor :date= do |date|
- # We want to end up with a Time object with one-day resolution.
- # This is the cleanest, most-readable, faster-than-using-Date
- # way to do it.
- case date
- when String then
- @date = if /\A(\d{4})-(\d{2})-(\d{2})\Z/ =~ date then
- Time.local($1.to_i, $2.to_i, $3.to_i)
- else
- require 'time'
- Time.parse date
- end
- when Time then
- @date = Time.local(date.year, date.month, date.day)
- when Date then
- @date = Time.local(date.year, date.month, date.day)
- else
- @date = TODAY
end
end
- overwrite_accessor :date do
- self.date = nil if @date.nil? # HACK Sets the default value for date
- @date
end
- overwrite_accessor :summary= do |str|
- @summary = if str then
- str.strip.
- gsub(/(\w-)\n[ \t]*(\w)/, '\1\2').
- gsub(/\n[ \t]*/, " ")
- end
end
- overwrite_accessor :description= do |str|
- @description = str.to_s
end
- overwrite_accessor :default_executable do
- begin
- if defined?(@default_executable) and @default_executable
- result = @default_executable
- elsif @executables and @executables.size == 1
- result = Array(@executables).first
- else
- result = nil
- end
- result
- rescue
- nil
end
end
- overwrite_accessor :test_files do
# Handle the possibility that we have @test_suite_file but not
# @test_files. This will happen when an old gem is loaded via
# YAML.
@@ -1531,41 +1806,323 @@ class Gem::Specification
end
end
- overwrite_accessor :files do
- # DO NOT CHANGE TO ||= ! This is not a normal accessor. (yes, it sucks)
- @files = [@files,
- @test_files,
- add_bindir(@executables),
- @extra_rdoc_files,
- @extensions,
- ].flatten.uniq.compact
end
- def conflicts
- conflicts = {}
- Gem.loaded_specs.values.each do |spec|
- bad = self.runtime_dependencies.find_all { |dep|
- spec.name == dep.name and not spec.satisfies_requirement? dep
- }
- conflicts[spec] = bad unless bad.empty?
end
- conflicts
end
- def traverse trail = [], &b
trail = trail + [self]
runtime_dependencies.each do |dep|
- dep_specs = Gem.source_index.search dep, true
- dep_specs.each do |dep_spec|
- b[self, dep, dep_spec, trail + [dep_spec]]
- dep_spec.traverse(trail, &b) unless
trail.map(&:name).include? dep_spec.name
end
end
end
- def dependent_specs
- runtime_dependencies.map { |dep| Gem.source_index.search dep, true }.flatten
end
end
@@ -17,6 +17,7 @@ begin
rescue Gem::LoadError
end
require 'minitest/autorun'
require 'fileutils'
require 'tmpdir'
@@ -25,6 +26,7 @@ require 'rubygems/package'
require 'rubygems/test_utilities'
require 'pp'
require 'zlib'
Gem.load_yaml
require 'rubygems/mock_gem_ui'
@@ -44,6 +46,8 @@ module Gem
# requiring 'rubygems/test_case'
def self.source_index=(si)
@@source_index = si
end
@@ -82,12 +86,24 @@ end
class Gem::TestCase < MiniTest::Unit::TestCase
include Gem::DefaultUserInteraction
undef_method :default_test if instance_methods.include? 'default_test' or
instance_methods.include? :default_test
- @@project_dir = Dir.pwd unless defined?(@@project_dir)
##
# #setup prepares a sandboxed location to install gems. All installs are
@@ -106,14 +122,15 @@ class Gem::TestCase < MiniTest::Unit::TestCase
@orig_gem_home = ENV['GEM_HOME']
@orig_gem_path = ENV['GEM_PATH']
- @current_dir = Dir.pwd
@ui = Gem::MockGemUi.new
tmpdir = nil
Dir.chdir Dir.tmpdir do tmpdir = Dir.pwd end # HACK OSX /private/tmp
if ENV['KEEP_FILES'] then
- @tempdir = File.join tmpdir, "test_rubygems_#{$$}.#{Time.now.to_i}"
else
- @tempdir = File.join tmpdir, "test_rubygems_#{$$}"
end
@tempdir.untaint
@gemhome = File.join @tempdir, 'gemhome'
@@ -126,6 +143,9 @@ class Gem::TestCase < MiniTest::Unit::TestCase
Gem.ensure_gem_subdirectories @gemhome
Dir.chdir @tempdir
@orig_ENV_HOME = ENV['HOME']
@@ -136,6 +156,7 @@ class Gem::TestCase < MiniTest::Unit::TestCase
FileUtils.mkdir_p @userhome
Gem.use_paths(@gemhome)
Gem.loaded_specs.clear
Gem.unresolved_deps.clear
@@ -191,8 +212,6 @@ class Gem::TestCase < MiniTest::Unit::TestCase
Gem.pre_uninstall do |uninstaller|
@pre_uninstall_hook_arg = uninstaller
end
-
- @orig_LOAD_PATH = $LOAD_PATH.dup
end
##
@@ -209,15 +228,13 @@ class Gem::TestCase < MiniTest::Unit::TestCase
Gem::RemoteFetcher.fetcher = nil
end
- Dir.chdir @current_dir
FileUtils.rm_rf @tempdir unless ENV['KEEP_FILES']
ENV['GEM_HOME'] = @orig_gem_home
ENV['GEM_PATH'] = @orig_gem_path
- Gem.clear_paths
-
_ = @orig_ruby
Gem.class_eval { @ruby = _ } if _
@@ -240,7 +257,7 @@ class Gem::TestCase < MiniTest::Unit::TestCase
end
end
- gem = File.join(@tempdir, spec.file_name).untaint
Gem::Installer.new(gem, :wrappers => true).install
end
@@ -250,9 +267,19 @@ class Gem::TestCase < MiniTest::Unit::TestCase
def uninstall_gem spec
require 'rubygems/uninstaller'
- uninstaller = Gem::Uninstaller.new spec.name, :executables => true,
- :user_install => true
- uninstaller.uninstall
end
##
@@ -285,7 +312,7 @@ class Gem::TestCase < MiniTest::Unit::TestCase
# Writes a binary file to +path+ which is relative to +@gemhome+
def write_file(path)
- path = File.join @gemhome, path
dir = File.dirname path
FileUtils.mkdir_p dir
@@ -296,6 +323,10 @@ class Gem::TestCase < MiniTest::Unit::TestCase
path
end
##
# Creates a Gem::Specification with a minimum of extra work. +name+ and
# +version+ are the gem's name and version, platform, author, email,
@@ -317,26 +348,27 @@ class Gem::TestCase < MiniTest::Unit::TestCase
s.author = 'A User'
s.email = '[email protected]'
s.homepage = 'http://example.com'
- s.has_rdoc = true
s.summary = "this is a summary"
s.description = "This is a test description"
yield(s) if block_given?
end
- path = File.join "specifications", spec.spec_name
- written_path = write_file path do |io|
- io.write(spec.to_ruby)
end
- spec.loaded_from = written_path
- Gem.source_index.add_spec spec
return spec
end
def quick_spec name, version = '2'
require 'rubygems/specification'
spec = Gem::Specification.new do |s|
@@ -346,16 +378,15 @@ class Gem::TestCase < MiniTest::Unit::TestCase
s.author = 'A User'
s.email = '[email protected]'
s.homepage = 'http://example.com'
- s.has_rdoc = true
s.summary = "this is a summary"
s.description = "This is a test description"
yield(s) if block_given?
end
- spec.loaded_from = @gemhome
- Gem.source_index.add_spec spec
return spec
end
@@ -365,7 +396,7 @@ class Gem::TestCase < MiniTest::Unit::TestCase
# 'cache'</tt>. Automatically creates files based on +spec.files+
def util_build_gem(spec)
- dir = File.join(@gemhome, 'gems', spec.full_name)
FileUtils.mkdir_p dir
Dir.chdir dir do
@@ -379,8 +410,8 @@ class Gem::TestCase < MiniTest::Unit::TestCase
Gem::Builder.new(spec).build
end
- FileUtils.mv spec.file_name,
- Gem.cache_gem("#{spec.original_name}.gem")
end
end
@@ -388,19 +419,16 @@ class Gem::TestCase < MiniTest::Unit::TestCase
# Removes all installed gems from +@gemhome+.
def util_clear_gems
- FileUtils.rm_rf File.join(@gemhome, 'gems')
- FileUtils.rm_rf File.join(@gemhome, 'specifications')
- Gem.source_index.refresh!
end
##
# Install the provided specs
def install_specs(*specs)
- specs.each do |spec|
- # TODO: inverted responsibility
- Gem.source_index.add_spec spec
- end
Gem.searcher = nil
end
@@ -409,19 +437,42 @@ class Gem::TestCase < MiniTest::Unit::TestCase
# up properly. Use this instead of util_spec and util_gem.
def new_spec name, version, deps = nil, *files
- # TODO: unfactor and deprecate util_gem and util_spec
- spec, = unless files.empty? then
- util_gem name, version do |s|
- Array(deps).each do |n,v|
- s.add_dependency n, v
- end
- s.files.push(*files)
- end
- else
- util_spec name, version, deps
- end
- spec.loaded_from = File.join @gemhome, 'specifications', spec.spec_name
- spec.loaded = false
spec
end
@@ -429,6 +480,7 @@ class Gem::TestCase < MiniTest::Unit::TestCase
# Creates a spec with +name+, +version+ and +deps+.
def util_spec(name, version, deps = nil, &block)
raise "deps or block, not both" if deps and block
if deps then
@@ -449,6 +501,7 @@ class Gem::TestCase < MiniTest::Unit::TestCase
# location are returned.
def util_gem(name, version, deps = nil, &block)
raise "deps or block, not both" if deps and block
if deps then
@@ -465,11 +518,10 @@ class Gem::TestCase < MiniTest::Unit::TestCase
cache_file = File.join @tempdir, 'gems', "#{spec.original_name}.gem"
FileUtils.mkdir_p File.dirname cache_file
- FileUtils.mv Gem.cache_gem("#{spec.original_name}.gem"), cache_file
- FileUtils.rm File.join(@gemhome, 'specifications', spec.spec_name)
spec.loaded_from = nil
- spec.loaded = false
[spec, cache_file]
end
@@ -517,8 +569,8 @@ class Gem::TestCase < MiniTest::Unit::TestCase
This line is really, really long. So long, in fact, that it is more than eighty characters long! The purpose of this line is for testing wrapping behavior because sometimes people don't wrap their text to eighty characters. Without the wrapping, the text might not look good in the RSS feed.
Also, a list:
- * An entry that's actually kind of sort
- * an entry that's really long, which will probably get wrapped funny. That's ok, somebody wasn't thinking straight when they made it more than eighty characters.
DESC
end
@@ -557,9 +609,7 @@ Also, a list:
util_build_gem spec
end
- FileUtils.rm_r File.join(@gemhome, 'gems', @pl1.original_name)
-
- Gem.source_index = nil
end
##
@@ -589,6 +639,7 @@ Also, a list:
@fetcher = Gem::FakeFetcher.new
util_make_gems(prerelease)
@all_gems = [@a1, @a2, @a3a, @a_evil9, @b2, @c1_2].sort
@all_gem_names = @all_gems.map { |gem| gem.full_name }
@@ -596,14 +647,6 @@ Also, a list:
gem_names = [@a1.full_name, @a2.full_name, @a3a.full_name, @b2.full_name]
@gem_names = gem_names.sort.join("\n")
- @source_index = Gem::SourceIndex.new
- @source_index.add_spec @a1
- @source_index.add_spec @a2
- @source_index.add_spec @a3a
- @source_index.add_spec @a_evil9
- @source_index.add_spec @c1_2
- @source_index.add_spec @a2_pre if prerelease
-
Gem::RemoteFetcher.fetcher = @fetcher
end
@@ -612,37 +655,42 @@ Also, a list:
# Best used with +@all_gems+ from #util_setup_fake_fetcher.
def util_setup_spec_fetcher(*specs)
- specs = Hash[*specs.map { |spec| [spec.full_name, spec] }.flatten]
- si = Gem::SourceIndex.new specs
spec_fetcher = Gem::SpecFetcher.fetcher
spec_fetcher.specs[@uri] = []
- si.gems.sort_by { |_, spec| spec }.each do |_, spec|
spec_tuple = [spec.name, spec.version, spec.original_platform]
spec_fetcher.specs[@uri] << spec_tuple
end
spec_fetcher.latest_specs[@uri] = []
- si.latest_specs.sort.each do |spec|
spec_tuple = [spec.name, spec.version, spec.original_platform]
spec_fetcher.latest_specs[@uri] << spec_tuple
end
spec_fetcher.prerelease_specs[@uri] = []
- si.prerelease_specs.sort.each do |spec|
spec_tuple = [spec.name, spec.version, spec.original_platform]
spec_fetcher.prerelease_specs[@uri] << spec_tuple
end
- (si.gems.merge si.prerelease_gems).sort_by { |_,spec| spec }.each do |_, spec|
- path = "#{@gem_repo}quick/Marshal.#{Gem.marshal_version}/#{spec.original_name}.gemspec.rz"
data = Marshal.dump spec
data_deflate = Zlib::Deflate.deflate data
@fetcher.data[path] = data_deflate
end
- si
end
##
@@ -103,8 +103,8 @@ class Gem::FakeFetcher
end
def download spec, source_uri, install_dir = Gem.dir
- name = spec.file_name
- path = Gem.cache_gem(name, install_dir)
Gem.ensure_gem_subdirectories install_dir
@@ -120,7 +120,8 @@ class Gem::FakeFetcher
end
def download_to_cache dependency
- found = Gem::SpecFetcher.fetcher.fetch dependency
return if found.empty?
@@ -21,7 +21,7 @@ module Gem::Text
while work.length > wrap do
if work =~ /^(.{0,#{wrap}})[ \n]/ then
- result << $1
work.slice!(0, $&.length)
else
result << work.slice!(0, wrap)
@@ -48,26 +48,23 @@ class Gem::Uninstaller
# Constructs an uninstaller that will uninstall +gem+
def initialize(gem, options = {})
- @gem = gem
- @version = options[:version] || Gem::Requirement.default
- gem_home = options[:install_dir] || Gem.dir
- @gem_home = File.expand_path gem_home
@force_executables = options[:executables]
- @force_all = options[:all]
- @force_ignore = options[:ignore]
- @bin_dir = options[:bin_dir]
@format_executable = options[:format_executable]
# only add user directory if install_dir is not set
@user_install = false
@user_install = options[:user_install] unless options[:install_dir]
- spec_dir = File.join @gem_home, 'specifications'
- @source_index = Gem::SourceIndex.from_gems_in spec_dir
-
if @user_install then
- user_dir = File.join Gem.user_dir, 'specifications'
- @user_index = Gem::SourceIndex.from_gems_in user_dir
end
end
@@ -76,14 +73,13 @@ class Gem::Uninstaller
# directory, and the cached .gem file.
def uninstall
- list = @source_index.find_name @gem, @version
- list += @user_index.find_name @gem, @version if @user_install
if list.empty? then
raise Gem::InstallError, "cannot uninstall, check `gem list -d #{@gem}`"
elsif list.size > 1 and @force_all then
- remove_all list.dup
elsif list.size > 1 then
gem_names = list.collect {|gem| gem.full_name} + ["All versions"]
@@ -92,21 +88,21 @@ class Gem::Uninstaller
_, index = choose_from_list "Select gem to uninstall:", gem_names
if index == list.size then
- remove_all list.dup
elsif index >= 0 && index < list.size then
- uninstall_gem list[index], list.dup
else
say "Error: must enter a number [1-#{list.size+1}]"
end
else
- uninstall_gem list.first, list.dup
end
end
##
# Uninstalls gem +spec+
- def uninstall_gem(spec, specs)
@spec = spec
unless dependencies_ok? spec
@@ -121,7 +117,7 @@ class Gem::Uninstaller
end
remove_executables @spec
- remove @spec, specs
Gem.post_uninstall_hooks.each do |hook|
hook.call self
@@ -137,10 +133,8 @@ class Gem::Uninstaller
def remove_executables(spec)
return if spec.nil? or spec.executables.empty?
- bindir = @bin_dir ? @bin_dir : Gem.bindir(spec.installation_path)
-
- list = @source_index.find_name(spec.name).delete_if { |s|
- s.version == spec.version
}
executables = spec.executables.clone
@@ -165,6 +159,8 @@ class Gem::Uninstaller
unless remove then
say "Executables and scripts will remain installed."
else
raise Gem::FilePermissionError, bindir unless File.writable? bindir
spec.executables.each do |exe_name|
@@ -181,7 +177,7 @@ class Gem::Uninstaller
# NOTE: removes uninstalled gems from +list+.
def remove_all(list)
- list.dup.each { |spec| uninstall_gem spec, list }
end
##
@@ -191,7 +187,7 @@ class Gem::Uninstaller
# Warning: this method modifies the +list+ parameter. Once it has
# uninstalled a gem, it is removed from that list.
- def remove(spec, list)
unless path_ok?(@gem_home, spec) or
(@user_install and path_ok?(Gem.user_dir, spec)) then
e = Gem::GemNotInHomeException.new \
@@ -201,28 +197,27 @@ class Gem::Uninstaller
raise e
end
- raise Gem::FilePermissionError, spec.installation_path unless
- File.writable?(spec.installation_path)
FileUtils.rm_rf spec.full_gem_path
- original_platform_name = [
- spec.name, spec.version, spec.original_platform].join '-'
- spec_dir = File.join spec.installation_path, 'specifications'
- gemspec = File.join spec_dir, spec.spec_name
unless File.exist? gemspec then
- gemspec = File.join spec_dir, "#{original_platform_name}.gemspec"
end
FileUtils.rm_rf gemspec
- gem = Gem.cache_gem(spec.file_name, spec.installation_path)
-
- unless File.exist? gem then
- gem = Gem.cache_gem("#{original_platform_name}.gem", spec.installation_path)
- end
FileUtils.rm_rf gem
@@ -230,14 +225,14 @@ class Gem::Uninstaller
say "Successfully uninstalled #{spec.full_name}"
- list.delete spec
end
##
# Is +spec+ in +gem_dir+?
def path_ok?(gem_dir, spec)
- full_path = File.join gem_dir, 'gems', spec.full_name
original_path = File.join gem_dir, 'gems', spec.original_name
full_path == spec.full_gem_path || original_path == spec.full_gem_path
@@ -246,8 +241,7 @@ class Gem::Uninstaller
def dependencies_ok?(spec)
return true if @force_ignore
- deplist = Gem::DependencyList.from_source_index @source_index
- deplist.add(*@user_index.gems.values) if @user_install
deplist.ok_to_remove?(spec.full_name)
end
@@ -255,11 +249,13 @@ class Gem::Uninstaller
msg = ['']
msg << 'You have requested to uninstall the gem:'
msg << "\t#{spec.full_name}"
- spec.dependent_gems.each do |gem,dep,satlist|
msg <<
- ("#{gem.name}-#{gem.version} depends on " +
- "[#{dep.name} (#{dep.requirement})]")
end
msg << 'If you remove this gems, one or more dependencies will not be met.'
msg << 'Continue with Uninstall?'
return ask_yes_no(msg.join("\n"), true)
@@ -272,7 +268,4 @@ class Gem::Uninstaller
filename
end
end
-
-
end
-
@@ -90,44 +90,40 @@ module Gem::UserInteraction
include Gem::DefaultUserInteraction
- ##
- # :method: alert
- ##
- # :method: alert_error
- ##
- # :method: alert_warning
- ##
- # :method: ask
- ##
- # :method: ask_yes_no
- ##
- # :method: choose_from_list
- ##
- # :method: say
- ##
- # :method: terminate_interaction
-
- [:alert,
- :alert_error,
- :alert_warning,
- :ask,
- :ask_for_password,
- :ask_yes_no,
- :choose_from_list,
- :say,
- :terminate_interaction ].each do |methname|
- class_eval %{
- def #{methname}(*args)
- ui.#{methname}(*args)
- end
- }, __FILE__, __LINE__
end
end
@@ -1,98 +0,0 @@
-######################################################################
-# This file is imported from the rubygems project.
-# DO NOT make modifications in this repo. They _will_ be reverted!
-# File a instead and assign it to Ryan Davis or Eric Hodel.
-######################################################################
-
-require 'rubygems'
-require 'minitest/unit'
-require 'test/insure_session'
-require 'rubygems/format'
-require 'rubygems/command_manager'
-
-class FunctionalTest < MiniTest::Unit::TestCase
-
- def setup
- @gem_path = File.expand_path("bin/gem")
- lib_path = File.expand_path("lib")
- @ruby_options = "-I#{lib_path} -I."
- @verbose = false
- end
-
- def test_gem_help_options
- gem_nossl 'help options'
- assert_match(/Usage:/, @out, @err)
- assert_status
- end
-
- def test_gem_help_commands
- gem_nossl 'help commands'
- assert_match(/gem install/, @out)
- assert_status
- end
-
- def test_gem_no_args_shows_help
- gem_nossl
- assert_match(/Usage:/, @out)
- assert_status 1
- end
-
- # This test is disabled because of the insanely long time it takes
- # to time out.
- def xtest_bogus_source_hoses_up_remote_install_but_gem_command_gives_decent_error_message
- @ruby_options << " -rtest/bogussources"
- gem_nossl "install asdf --remote"
- assert_match(/error/im, @err)
- assert_status 1
- end
-
- def test_all_command_helps
- mgr = Gem::CommandManager.new
- mgr.command_names.each do |cmdname|
- gem_nossl "help #{cmdname}"
- assert_match(/Usage: gem #{cmdname}/, @out,
- "should see help for #{cmdname}")
- end
- end
-
- # :section: Help Methods
-
- # Run a gem command without the SSL library.
- def gem_nossl(options="")
- old_options = @ruby_options.dup
- @ruby_options << " -Itest/fake_certlib"
- gem(options)
- ensure
- @ruby_options = old_options
- end
-
- # Run a gem command with the SSL library.
- def gem_withssl(options="")
- gem(options)
- end
-
- # Run a gem command for the functional test.
- def gem(options="")
- shell = Session::Shell.new
- options = options + " --config-file missing_file" if options !~ /--config-file/
- command = "#{Gem.ruby} #{@ruby_options} #{@gem_path} #{options}"
- puts "\n\nCOMMAND: [#{command}]" if @verbose
- @out, @err = shell.execute command
- @status = shell.exit_status
- puts "STATUS: [#{@status}]" if @verbose
- puts "OUTPUT: [#{@out}]" if @verbose
- puts "ERROR: [#{@err}]" if @verbose
- puts "PWD: [#{Dir.pwd}]" if @verbose
- shell.close
- end
-
- private
-
- def assert_status(expected_status=0)
- assert_equal expected_status, @status
- end
-
-end
-
-MiniTest::Unit.autorun
-
@@ -29,12 +29,12 @@ class TestGem < Gem::TestCase
def assert_activate expected, *specs
specs.each do |spec|
case spec
- when Array
- Gem.activate(*spec)
- when String
- Gem.activate spec
else
- Gem.activate spec.name
end
end
@@ -57,17 +57,21 @@ class TestGem < Gem::TestCase
Gem.unresolved_deps.values.map(&:to_s).sort
end
def test_self_activate_via_require
- new_spec "a", "1", "b" => "= 1"
- new_spec "b", "1", nil, "lib/b/c.rb"
- new_spec "b", "2", nil, "lib/b/c.rb"
- Gem.activate "a", "= 1"
require "b/c"
assert_equal %w(a-1 b-1), loaded_spec_names
end
def test_self_activate_deep_unambiguous
a1 = new_spec "a", "1", "b" => "= 1"
b1 = new_spec "b", "1", "c" => "= 1"
@@ -77,7 +81,7 @@ class TestGem < Gem::TestCase
install_specs a1, b1, b2, c1, c2
- Gem.activate "a", "= 1"
assert_equal %w(a-1 b-1 c-1), loaded_spec_names
end
@@ -88,6 +92,7 @@ class TestGem < Gem::TestCase
$LOADED_FEATURES.replace old_loaded_features
end
def test_self_activate_ambiguous_direct
save_loaded_features do
a1 = new_spec "a", "1", "b" => "> 0"
@@ -96,9 +101,10 @@ class TestGem < Gem::TestCase
c1 = new_spec "c", "1"
c2 = new_spec "c", "2"
install_specs a1, b1, b2, c1, c2
- Gem.activate "a", "= 1"
assert_equal %w(a-1), loaded_spec_names
assert_equal ["b (> 0)"], unresolved_names
@@ -109,6 +115,7 @@ class TestGem < Gem::TestCase
end
end
def test_self_activate_ambiguous_indirect
save_loaded_features do
a1 = new_spec "a", "1", "b" => "> 0"
@@ -119,7 +126,7 @@ class TestGem < Gem::TestCase
install_specs a1, b1, b2, c1, c2
- Gem.activate "a", "= 1"
assert_equal %w(a-1), loaded_spec_names
assert_equal ["b (> 0)"], unresolved_names
@@ -130,6 +137,7 @@ class TestGem < Gem::TestCase
end
end
def test_self_activate_ambiguous_unrelated
save_loaded_features do
a1 = new_spec "a", "1", "b" => "> 0"
@@ -141,7 +149,7 @@ class TestGem < Gem::TestCase
install_specs a1, b1, b2, c1, c2, d1
- Gem.activate "a", "= 1"
assert_equal %w(a-1), loaded_spec_names
assert_equal ["b (> 0)"], unresolved_names
@@ -152,6 +160,7 @@ class TestGem < Gem::TestCase
end
end
def test_self_activate_ambiguous_indirect_conflict
save_loaded_features do
a1 = new_spec "a", "1", "b" => "> 0"
@@ -163,7 +172,7 @@ class TestGem < Gem::TestCase
install_specs a1, a2, b1, b2, c1, c2
- Gem.activate "a", "= 2"
assert_equal %w(a-2), loaded_spec_names
assert_equal ["b (> 0)"], unresolved_names
@@ -174,13 +183,14 @@ class TestGem < Gem::TestCase
end
end
def test_require_already_activated
save_loaded_features do
a1 = new_spec "a", "1", nil, "lib/d.rb"
install_specs a1 # , a2, b1, b2, c1, c2
- Gem.activate "a", "= 1"
assert_equal %w(a-1), loaded_spec_names
assert_equal [], unresolved_names
@@ -191,6 +201,7 @@ class TestGem < Gem::TestCase
end
end
def test_require_already_activated_indirect_conflict
save_loaded_features do
a1 = new_spec "a", "1", "b" => "> 0"
@@ -202,8 +213,8 @@ class TestGem < Gem::TestCase
install_specs a1, a2, b1, b2, c1, c2
- Gem.activate "a", "= 1"
- Gem.activate "c", "= 1"
assert_equal %w(a-1 c-1), loaded_spec_names
assert_equal ["b (> 0)"], unresolved_names
@@ -222,11 +233,26 @@ class TestGem < Gem::TestCase
end
end
def test_self_activate_loaded
- util_spec 'foo', '1'
- assert Gem.activate 'foo'
- refute Gem.activate 'foo'
end
##
@@ -249,15 +275,16 @@ class TestGem < Gem::TestCase
# [B] ~> 1.0
#
# and should resolve using b-1.0
def test_self_activate_over
- util_spec 'a', '1.0', 'b' => '>= 1.0', 'c' => '= 1.0'
util_spec 'b', '1.0'
util_spec 'b', '1.1'
util_spec 'b', '2.0'
util_spec 'c', '1.0', 'b' => '~> 1.0'
- Gem.activate "a"
assert_equal %w[a-1.0 c-1.0], loaded_spec_names
assert_equal ["b (>= 1.0, ~> 1.0)"], unresolved_names
@@ -412,28 +439,22 @@ class TestGem < Gem::TestCase
assert_activate %w[d-1 e-1], e1, "d"
end
- def test_self_all_load_paths
util_make_gems
-
- expected = [
- File.join(@gemhome, *%W[gems #{@a1.full_name} lib]),
- File.join(@gemhome, *%W[gems #{@a2.full_name} lib]),
- File.join(@gemhome, *%W[gems #{@a3a.full_name} lib]),
- File.join(@gemhome, *%W[gems #{@a_evil9.full_name} lib]),
- File.join(@gemhome, *%W[gems #{@b2.full_name} lib]),
- File.join(@gemhome, *%W[gems #{@c1_2.full_name} lib]),
- File.join(@gemhome, *%W[gems #{@pl1.full_name} lib]),
- ]
-
- assert_equal expected, Gem.all_load_paths.sort
end
- def test_self_available?
- util_make_gems
- assert(Gem.available?("a"))
- assert(Gem.available?("a", "1"))
- assert(Gem.available?("a", ">1"))
- assert(!Gem.available?("monkeys"))
end
def test_self_bin_path_bin_name
@@ -446,16 +467,6 @@ class TestGem < Gem::TestCase
assert_equal @abin_path, Gem.bin_path('a', 'abin', '4')
end
- def test_self_bin_path_name
- util_exec_gem
- assert_equal @exec_path, Gem.bin_path('a')
- end
-
- def test_self_bin_path_name_version
- util_exec_gem
- assert_equal @exec_path, Gem.bin_path('a', nil, '4')
- end
-
def test_self_bin_path_nonexistent_binfile
quick_spec 'a', '2' do |s|
s.executables = ['exec']
@@ -467,14 +478,14 @@ class TestGem < Gem::TestCase
def test_self_bin_path_no_bin_file
quick_spec 'a', '1'
- assert_raises(Gem::Exception) do
Gem.bin_path('a', nil, '1')
end
end
def test_self_bin_path_not_found
assert_raises(Gem::GemNotFoundException) do
- Gem.bin_path('non-existent')
end
end
@@ -482,7 +493,6 @@ class TestGem < Gem::TestCase
util_exec_gem
quick_spec 'a', '10' do |s|
s.executables = []
- s.default_executable = nil
end
# Should not find a-10's non-abin (bug)
assert_equal @abin_path, Gem.bin_path('a', 'abin')
@@ -507,17 +517,12 @@ class TestGem < Gem::TestCase
end
def test_self_clear_paths
- Gem.dir
- Gem.path
- searcher = Gem.searcher
- source_index = Gem.source_index
Gem.clear_paths
- assert_equal nil, Gem.instance_variable_get(:@gem_home)
- assert_equal nil, Gem.instance_variable_get(:@gem_path)
- refute_equal searcher, Gem.searcher
- refute_equal source_index.object_id, Gem.source_index.object_id
end
def test_self_configuration
@@ -540,8 +545,6 @@ class TestGem < Gem::TestCase
install_gem foo
end
- Gem.source_index = nil
-
gem 'foo'
expected = File.join @gemhome, 'gems', foo.full_name, 'data', 'foo'
@@ -598,7 +601,7 @@ class TestGem < Gem::TestCase
Gem.ensure_gem_subdirectories @gemhome
- assert File.directory?(Gem.cache_dir(@gemhome))
end
def test_self_ensure_gem_directories_missing_parents
@@ -610,7 +613,7 @@ class TestGem < Gem::TestCase
Gem.ensure_gem_subdirectories gemdir
- assert File.directory?(Gem.cache_dir(gemdir))
end
unless win_platform? then # only for FS that support write protection
@@ -624,7 +627,7 @@ class TestGem < Gem::TestCase
Gem.ensure_gem_subdirectories gemdir
- refute File.exist?(Gem.cache_dir(gemdir))
ensure
FileUtils.chmod 0600, gemdir
end
@@ -641,7 +644,7 @@ class TestGem < Gem::TestCase
Gem.ensure_gem_subdirectories gemdir
- refute File.exist?(Gem.cache_dir(gemdir))
ensure
FileUtils.chmod 0600, parent
end
@@ -661,30 +664,26 @@ class TestGem < Gem::TestCase
end
def test_self_find_files
- discover_path = File.join 'lib', 'sff', 'discover.rb'
cwd = File.expand_path("test/rubygems", @@project_dir)
$LOAD_PATH.unshift cwd
- foo1 = quick_gem 'sff', '1' do |s|
- s.files << discover_path
- end
-
- foo2 = quick_gem 'sff', '2' do |s|
- s.files << discover_path
- end
-
- path = File.join 'gems', foo1.full_name, discover_path
- write_file(path) { |fp| fp.puts "# #{path}" }
- path = File.join 'gems', foo2.full_name, discover_path
- write_file(path) { |fp| fp.puts "# #{path}" }
- @fetcher = Gem::FakeFetcher.new
- Gem::RemoteFetcher.fetcher = @fetcher
- Gem.source_index = util_setup_spec_fetcher foo1, foo2
Gem.searcher = nil
expected = [
File.expand_path('test/rubygems/sff/discover.rb', @@project_dir),
@@ -698,26 +697,11 @@ class TestGem < Gem::TestCase
assert_equal cwd, $LOAD_PATH.shift
end
- def test_self_latest_load_paths
- util_make_gems
-
- expected = [
- File.join(@gemhome, *%W[gems #{@a3a.full_name} lib]),
- File.join(@gemhome, *%W[gems #{@a_evil9.full_name} lib]),
- File.join(@gemhome, *%W[gems #{@b2.full_name} lib]),
- File.join(@gemhome, *%W[gems #{@c1_2.full_name} lib]),
- File.join(@gemhome, *%W[gems #{@pl1.full_name} lib]),
- ]
-
- assert_equal expected, Gem.latest_load_paths.sort
- end
-
def test_self_loaded_specs
foo = quick_spec 'foo'
install_gem foo
- Gem.source_index = nil
- Gem.activate 'foo'
assert_equal true, Gem.loaded_specs.keys.include?('foo')
end
@@ -738,9 +722,10 @@ class TestGem < Gem::TestCase
orig_APPLE_GEM_HOME = APPLE_GEM_HOME
Object.send :remove_const, :APPLE_GEM_HOME
end
- Gem.instance_variable_set :@gem_path, nil
- assert_equal [Gem.default_path, Gem.dir].flatten, Gem.path
ensure
Object.const_set :APPLE_GEM_HOME, orig_APPLE_GEM_HOME
end
@@ -771,7 +756,6 @@ class TestGem < Gem::TestCase
end
def test_self_path_ENV_PATH
- Gem.send :set_paths, nil
path_count = Gem.path.size
Gem.clear_paths
@@ -840,29 +824,20 @@ class TestGem < Gem::TestCase
def test_self_refresh
util_make_gems
- a1_spec = File.join @gemhome, "specifications", @a1.spec_name
-
- FileUtils.mv a1_spec, @tempdir
- refute Gem.source_index.gems.include?(@a1.full_name)
-
- FileUtils.mv File.join(@tempdir, @a1.spec_name), a1_spec
Gem.refresh
- assert_includes Gem.source_index.gems, @a1.full_name
- assert_equal nil, Gem.instance_variable_get(:@searcher)
- end
- def test_self_required_location
- util_make_gems
- assert_equal File.join(@tempdir, *%w[gemhome gems c-1.2 lib code.rb]),
- Gem.required_location("c", "code.rb")
- assert_equal File.join(@tempdir, *%w[gemhome gems a-1 lib code.rb]),
- Gem.required_location("a", "code.rb", "< 2")
- assert_equal File.join(@tempdir, *%w[gemhome gems a-2 lib code.rb]),
- Gem.required_location("a", "code.rb", "= 2")
end
def test_self_ruby_escaping_spaces_in_path
@@ -927,19 +902,20 @@ class TestGem < Gem::TestCase
util_restore_RUBY_VERSION
end
- def test_self_searcher
- assert_kind_of Gem::GemPathSearcher, Gem.searcher
- end
-
- def test_self_set_paths
other = File.join @tempdir, 'other'
path = [@userhome, other].join File::PATH_SEPARATOR
- Gem.send :set_paths, path
assert_equal [@userhome, other, @gemhome], Gem.path
end
- def test_self_set_paths_nonexistent_home
ENV['GEM_HOME'] = @gemhome
Gem.clear_paths
@@ -947,19 +923,37 @@ class TestGem < Gem::TestCase
ENV['HOME'] = other
- Gem.send :set_paths, other
assert_equal [other, @gemhome], Gem.path
end
def test_self_source_index
- assert_kind_of Gem::SourceIndex, Gem.source_index
end
def test_self_sources
assert_equal %w[http://gems.example.com/], Gem.sources
end
def test_ssl_available_eh
orig_Gem_ssl_available = Gem.ssl_available?
@@ -994,20 +988,6 @@ class TestGem < Gem::TestCase
end
end
- def test_self_cache_dir
- util_ensure_gem_dirs
-
- assert_equal File.join(@gemhome, 'cache'), Gem.cache_dir
- assert_equal File.join(@userhome, '.gem', Gem.ruby_engine, Gem::ConfigMap[:ruby_version], 'cache'), Gem.cache_dir(Gem.user_dir)
- end
-
- def test_self_cache_gem
- util_ensure_gem_dirs
-
- assert_equal File.join(@gemhome, 'cache', 'test.gem'), Gem.cache_gem('test.gem')
- assert_equal File.join(@userhome, '.gem', Gem.ruby_engine, Gem::ConfigMap[:ruby_version], 'cache', 'test.gem'), Gem.cache_gem('test.gem', Gem.user_dir)
- end
-
if Gem.win_platform? then
def test_self_user_home_userprofile
skip 'Ruby 1.9 properly handles ~ path expansion' unless '1.9' > RUBY_VERSION
@@ -1069,8 +1049,8 @@ class TestGem < Gem::TestCase
install_gem foo
end
- Gem.source_index = nil
Gem.searcher = nil
gem 'foo'
@@ -1114,6 +1094,10 @@ class TestGem < Gem::TestCase
def util_ensure_gem_dirs
Gem.ensure_gem_subdirectories @gemhome
@additional.each do |dir|
Gem.ensure_gem_subdirectories @gemhome
end
@@ -1121,7 +1105,6 @@ class TestGem < Gem::TestCase
def util_exec_gem
spec, _ = quick_spec 'a', '4' do |s|
- s.default_executable = 'exec'
s.executables = ['exec', 'abin']
end
@@ -1164,5 +1147,9 @@ class TestGem < Gem::TestCase
Gem::Commands.send :remove_const, :InterruptCommand if
Gem::Commands.const_defined? :InterruptCommand
end
end
@@ -6,6 +6,7 @@
require 'rubygems/test_case'
require 'rubygems/builder'
class TestGemBuilder < Gem::TestCase
@@ -29,5 +30,21 @@ class TestGemBuilder < Gem::TestCase
end
end
-end
@@ -29,6 +29,7 @@ class TestGemCommandManager < Gem::TestCase
end
ensure
$:.replace old_load_path
end
def test_run_crash_command
@@ -46,6 +47,7 @@ class TestGemCommandManager < Gem::TestCase
end
ensure
$:.replace old_load_path
end
def test_process_args_bad_arg
@@ -40,10 +40,38 @@ class TestGemCommandsBuildCommand < Gem::TestCase
util_test_build_gem @gem, gemspec_file
end
- def test_execute_bad_gem
@cmd.options[:args] = %w[some_gem]
use_ui @ui do
- @cmd.execute
end
assert_equal '', @ui.output
@@ -67,7 +95,7 @@ class TestGemCommandsBuildCommand < Gem::TestCase
assert_equal [], output
assert_equal '', @ui.error
- gem_file = File.join @tempdir, gem.file_name
assert File.exist?(gem_file)
spec = Gem::Format.from_file_by_path(gem_file).spec
@@ -0,0 +1,57 @@
@@ -15,11 +15,18 @@ class TestGemCommandsContentsCommand < Gem::TestCase
@cmd = Gem::Commands::ContentsCommand.new
end
def test_execute
@cmd.options[:args] = %w[foo]
- quick_gem 'foo' do |gem|
- gem.files = %w[lib/foo.rb Rakefile]
- end
use_ui @ui do
@cmd.execute
@@ -33,13 +40,8 @@ class TestGemCommandsContentsCommand < Gem::TestCase
def test_execute_all
@cmd.options[:all] = true
- quick_gem 'foo' do |gem|
- gem.files = %w[lib/foo.rb Rakefile]
- end
-
- quick_gem 'bar' do |gem|
- gem.files = %w[lib/bar.rb Rakefile]
- end
use_ui @ui do
@cmd.execute
@@ -67,13 +69,8 @@ class TestGemCommandsContentsCommand < Gem::TestCase
def test_execute_exact_match
@cmd.options[:args] = %w[foo]
- quick_gem 'foo' do |gem|
- gem.files = %w[lib/foo.rb Rakefile]
- end
-
- quick_gem 'foo_bar' do |gem|
- gem.files = %w[lib/foo_bar.rb Rakefile]
- end
use_ui @ui do
@cmd.execute
@@ -88,9 +85,7 @@ class TestGemCommandsContentsCommand < Gem::TestCase
@cmd.options[:args] = %w[foo]
@cmd.options[:lib_only] = true
- quick_gem 'foo' do |gem|
- gem.files = %w[lib/foo.rb Rakefile]
- end
use_ui @ui do
@cmd.execute
@@ -104,13 +99,9 @@ class TestGemCommandsContentsCommand < Gem::TestCase
def test_execute_multiple
@cmd.options[:args] = %w[foo bar]
- quick_gem 'foo' do |gem|
- gem.files = %w[lib/foo.rb Rakefile]
- end
- quick_gem 'bar' do |gem|
- gem.files = %w[lib/bar.rb Rakefile]
- end
use_ui @ui do
@cmd.execute
@@ -126,17 +117,15 @@ class TestGemCommandsContentsCommand < Gem::TestCase
@cmd.options[:args] = %w[foo]
@cmd.options[:prefix] = false
- quick_gem 'foo' do |gem|
- gem.files = %w[lib/foo.rb Rakefile]
- end
use_ui @ui do
@cmd.execute
end
expected = <<-EOF
-lib/foo.rb
Rakefile
EOF
assert_equal expected, @ui.output
@@ -24,8 +24,6 @@ class TestGemCommandsDependencyCommand < Gem::TestCase
gem.add_dependency 'baz', '> 1'
end
- Gem.source_index = nil
-
@cmd.options[:args] = %w[foo]
use_ui @ui do
@@ -38,8 +36,6 @@ class TestGemCommandsDependencyCommand < Gem::TestCase
end
def test_execute_no_args
- Gem.source_index = nil
-
@cmd.options[:args] = []
use_ui @ui do
@@ -99,8 +95,6 @@ Gem pl-1-x86-linux
end
def test_execute_regexp
- Gem.source_index = nil
-
@cmd.options[:args] = %w[/[ab]/]
use_ui @ui do
@@ -136,8 +130,6 @@ Gem b-2
gem.add_dependency 'foo'
end
- Gem.source_index = nil
-
@cmd.options[:args] = %w[foo]
@cmd.options[:reverse_dependencies] = true
@@ -199,14 +191,31 @@ ERROR: Only reverse dependencies for local gems are supported.
assert_equal '', @ui.error
end
def test_execute_prerelease
@fetcher = Gem::FakeFetcher.new
Gem::RemoteFetcher.fetcher = @fetcher
util_setup_spec_fetcher @a2_pre
- FileUtils.rm File.join(@gemhome, 'specifications', @a2_pre.spec_name)
-
@cmd.options[:args] = %w[a]
@cmd.options[:domain] = :remote
@cmd.options[:prerelease] = true
@@ -22,7 +22,7 @@ class TestGemCommandsFetchCommand < Gem::TestCase
util_setup_spec_fetcher @a2
@fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] =
- File.read(Gem.cache_gem(@a2.file_name, @gemhome))
@cmd.options[:args] = [@a2.name]
@@ -38,12 +38,13 @@ class TestGemCommandsFetchCommand < Gem::TestCase
def test_execute_prerelease
util_setup_fake_fetcher true
util_setup_spec_fetcher @a2, @a2_pre
@fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] =
- File.read(Gem.cache_gem(@a2.file_name, @gemhome))
@fetcher.data["#{@gem_repo}gems/#{@a2_pre.file_name}"] =
- File.read(Gem.cache_gem(@a2_pre.file_name, @gemhome))
@cmd.options[:args] = [@a2.name]
@cmd.options[:prerelease] = true
@@ -63,7 +64,7 @@ class TestGemCommandsFetchCommand < Gem::TestCase
util_setup_spec_fetcher @a1, @a2
@fetcher.data["#{@gem_repo}gems/#{@a1.file_name}"] =
- File.read(Gem.cache_gem(@a1.file_name, @gemhome))
@cmd.options[:args] = [@a2.name]
@cmd.options[:version] = Gem::Requirement.new '1'
@@ -0,0 +1,64 @@
@@ -24,13 +24,13 @@ class TestGemCommandsInstallCommand < Gem::TestCase
end
def test_execute_exclude_prerelease
- util_setup_fake_fetcher(:prerelease)
- util_setup_spec_fetcher @a2, @a2_pre
@fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] =
- read_binary(Gem.cache_gem(@a2.file_name, @gemhome))
@fetcher.data["#{@gem_repo}gems/#{@a2_pre.file_name}"] =
- read_binary(Gem.cache_gem(@a2_pre.file_name, @gemhome))
@cmd.options[:args] = [@a2.name]
@@ -46,13 +46,13 @@ class TestGemCommandsInstallCommand < Gem::TestCase
end
def test_execute_explicit_version_includes_prerelease
- util_setup_fake_fetcher(:prerelease)
- util_setup_spec_fetcher @a2, @a2_pre
@fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] =
- read_binary(Gem.cache_gem(@a2.file_name, @gemhome))
@fetcher.data["#{@gem_repo}gems/#{@a2_pre.file_name}"] =
- read_binary(Gem.cache_gem(@a2_pre.file_name, @gemhome))
@cmd.handle_options [@a2_pre.name, '--version', @a2_pre.version.to_s,
"--no-ri", "--no-rdoc"]
@@ -92,7 +92,7 @@ class TestGemCommandsInstallCommand < Gem::TestCase
util_setup_fake_fetcher
@cmd.options[:domain] = :local
- FileUtils.mv Gem.cache_gem(@a2.file_name, @gemhome), @tempdir
@cmd.options[:args] = [@a2.name]
@@ -121,15 +121,15 @@ class TestGemCommandsInstallCommand < Gem::TestCase
util_setup_fake_fetcher
@cmd.options[:user_install] = false
- FileUtils.mv Gem.cache_gem(@a2.file_name, @gemhome), @tempdir
@cmd.options[:args] = [@a2.name]
use_ui @ui do
orig_dir = Dir.pwd
begin
- File.chmod 0755, @userhome
- File.chmod 0555, @gemhome
Dir.chdir @tempdir
assert_raises Gem::FilePermissionError do
@@ -137,7 +137,7 @@ class TestGemCommandsInstallCommand < Gem::TestCase
end
ensure
Dir.chdir orig_dir
- File.chmod 0755, @gemhome
end
end
end
@@ -208,13 +208,14 @@ ERROR: Possible alternatives: non_existent_with_hint
end
def test_execute_prerelease
- util_setup_fake_fetcher(:prerelease)
util_setup_spec_fetcher @a2, @a2_pre
@fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] =
- read_binary(Gem.cache_gem(@a2.file_name, @gemhome))
@fetcher.data["#{@gem_repo}gems/#{@a2_pre.file_name}"] =
- read_binary(Gem.cache_gem(@a2_pre.file_name, @gemhome))
@cmd.options[:prerelease] = true
@cmd.options[:args] = [@a2_pre.name]
@@ -235,10 +236,10 @@ ERROR: Possible alternatives: non_existent_with_hint
@cmd.options[:generate_ri] = true
util_setup_fake_fetcher
- util_setup_spec_fetcher @a2
@fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] =
- read_binary(Gem.cache_gem(@a2.file_name, @gemhome))
@cmd.options[:args] = [@a2.name]
@@ -265,9 +266,9 @@ ERROR: Possible alternatives: non_existent_with_hint
util_setup_fake_fetcher
@cmd.options[:domain] = :local
- FileUtils.mv Gem.cache_gem(@a2.file_name, @gemhome), @tempdir
- FileUtils.mv Gem.cache_gem(@b2.file_name, @gemhome), @tempdir
@cmd.options[:args] = [@a2.name, @b2.name]
@@ -293,10 +294,10 @@ ERROR: Possible alternatives: non_existent_with_hint
def test_execute_conservative
util_setup_fake_fetcher
- util_setup_spec_fetcher @b2
@fetcher.data["#{@gem_repo}gems/#{@b2.file_name}"] =
- read_binary(Gem.cache_gem(@b2.file_name, @gemhome))
uninstall_gem(@b2)
@@ -308,16 +309,16 @@ ERROR: Possible alternatives: non_existent_with_hint
orig_dir = Dir.pwd
begin
Dir.chdir @tempdir
- e = assert_raises Gem::SystemExitException do
@cmd.execute
end
- assert_equal 0, e.exit_code
ensure
Dir.chdir orig_dir
end
end
out = @ui.output.split "\n"
assert_equal "Successfully installed #{@b2.full_name}", out.shift
assert_equal "1 gem installed", out.shift
assert out.empty?, out.inspect
@@ -26,16 +26,13 @@ class TestGemCommandsListCommand < Gem::TestCase
def test_execute_installed
@cmd.handle_options %w[c --installed]
- e = assert_raises Gem::SystemExitException do
use_ui @ui do
@cmd.execute
end
end
- assert_equal 0, e.exit_code
-
assert_equal "true\n", @ui.output
-
assert_equal '', @ui.error
end
@@ -20,24 +20,25 @@ class TestGemCommandsOutdatedCommand < Gem::TestCase
end
def test_execute
- quick_gem 'foo', '0.1'
- quick_gem 'foo', '0.2'
remote_10 = quick_spec 'foo', '1.0'
remote_20 = quick_spec 'foo', '2.0'
- remote_spec_file = File.join @gemhome, 'specifications', remote_10.spec_name
- remote_spec_file = File.join @gemhome, 'specifications', remote_20.spec_name
-
- @fetcher = Gem::FakeFetcher.new
- Gem::RemoteFetcher.fetcher = @fetcher
util_setup_spec_fetcher remote_10, remote_20
- use_ui @ui do @cmd.execute end
assert_equal "foo (0.2 < 2.0)\n", @ui.output
assert_equal "", @ui.error
end
-
end
@@ -16,8 +16,8 @@ class TestGemCommandsPristineCommand < Gem::TestCase
def test_execute
a = quick_spec 'a' do |s| s.executables = %w[foo] end
- FileUtils.mkdir_p File.join(@tempdir, 'bin')
- File.open File.join(@tempdir, 'bin', 'foo'), 'w' do |fp|
fp.puts "#!/usr/bin/ruby"
end
@@ -25,7 +25,7 @@ class TestGemCommandsPristineCommand < Gem::TestCase
foo_path = File.join @gemhome, 'gems', a.full_name, 'bin', 'foo'
- File.open foo_path, 'w' do |io|
io.puts 'I changed it!'
end
@@ -39,15 +39,14 @@ class TestGemCommandsPristineCommand < Gem::TestCase
out = @ui.output.split "\n"
- assert_equal "Restoring gem(s) to pristine condition...", out.shift
assert_equal "Restored #{a.full_name}", out.shift
assert_empty out, out.inspect
end
def test_execute_all
a = quick_spec 'a' do |s| s.executables = %w[foo] end
- FileUtils.mkdir_p File.join(@tempdir, 'bin')
- File.open File.join(@tempdir, 'bin', 'foo'), 'w' do |fp|
fp.puts "#!/usr/bin/ruby"
end
@@ -67,35 +66,106 @@ class TestGemCommandsPristineCommand < Gem::TestCase
out = @ui.output.split "\n"
- assert_equal "Restoring gem(s) to pristine condition...", out.shift
assert_equal "Restored #{a.full_name}", out.shift
assert_empty out, out.inspect
end
- def test_execute_missing_cache_gem
- a = quick_spec 'a' do |s|
- s.executables = %w[foo]
end
- FileUtils.mkdir_p File.join(@tempdir, 'bin')
- File.open File.join(@tempdir, 'bin', 'foo'), 'w' do |fp|
- fp.puts "#!/usr/bin/ruby"
end
install_gem a
- a_data = nil
- open File.join(@gemhome, 'cache', a.file_name), 'rb' do |fp|
- a_data = fp.read
end
util_setup_fake_fetcher
- util_setup_spec_fetcher a
- Gem::RemoteFetcher.fetcher.data["http://gems.example.com/gems/#{a.file_name}"] = a_data
- FileUtils.rm Gem.cache_gem(a.file_name, @gemhome)
@cmd.options[:args] = %w[a]
@@ -106,11 +176,12 @@ class TestGemCommandsPristineCommand < Gem::TestCase
out = @ui.output.split "\n"
[
- "Restoring gem\(s\) to pristine condition...",
"Restored a-1",
"Cached gem for a-2 not found, attempting to fetch...",
"Restored a-2",
- "Restored a-3.a"
].each do |line|
assert_equal line, out.shift
end
@@ -127,7 +198,7 @@ class TestGemCommandsPristineCommand < Gem::TestCase
end
end
- assert_match %r|specify a gem name|, e.message
end
end
@@ -21,7 +21,7 @@ class TestGemCommandsPushCommand < Gem::TestCase
super
@gems_dir = File.join @tempdir, 'gems'
- @cache_dir = Gem.cache_dir @gemhome
FileUtils.mkdir @gems_dir
@@ -15,8 +15,8 @@ class TestGemCommandsQueryCommand < Gem::TestCase
@cmd = Gem::Commands::QueryCommand.new
util_setup_fake_fetcher
-
- @si = util_setup_spec_fetcher @a1, @a2, @pl1, @a3a
@fetcher.data["#{@gem_repo}Marshal.#{Gem.marshal_version}"] = proc do
raise Gem::RemoteFetcher::FetchError
@@ -48,7 +48,8 @@ pl (1 i386-linux)
@a1.platform = 'x86-linux'
@a2.platform = 'universal-darwin'
- @si = util_setup_spec_fetcher @a1, @a1r, @a2, @b2, @pl1
@cmd.handle_options %w[-r -a]
@@ -113,7 +114,8 @@ pl (1 i386-linux)
@a2.homepage = 'http://a.example.com/'
@a2.rubyforge_project = 'rubygems'
- @si = util_setup_spec_fetcher @a1, @a2, @pl1
@cmd.handle_options %w[-r -d]
@@ -154,7 +156,8 @@ pl (1)
@a2.rubyforge_project = 'rubygems'
@a2.platform = 'universal-darwin'
- @si = util_setup_spec_fetcher @a1, @a2, @pl1
@cmd.handle_options %w[-r -d]
@@ -190,25 +193,22 @@ pl (1)
end
def test_execute_installed
- @cmd.handle_options %w[-n c --installed]
- e = assert_raises Gem::SystemExitException do
use_ui @ui do
@cmd.execute
end
end
- assert_equal 0, e.exit_code
-
assert_equal "true\n", @ui.output
-
assert_equal '', @ui.error
end
def test_execute_installed_no_name
@cmd.handle_options %w[--installed]
- e = assert_raises Gem::SystemExitException do
use_ui @ui do
@cmd.execute
end
@@ -223,7 +223,7 @@ pl (1)
def test_execute_installed_not_installed
@cmd.handle_options %w[-n not_installed --installed]
- e = assert_raises Gem::SystemExitException do
use_ui @ui do
@cmd.execute
end
@@ -236,9 +236,9 @@ pl (1)
end
def test_execute_installed_version
- @cmd.handle_options %w[-n c --installed --version 1.2]
- e = assert_raises Gem::SystemExitException do
use_ui @ui do
@cmd.execute
end
@@ -246,14 +246,12 @@ pl (1)
assert_equal "true\n", @ui.output
assert_equal '', @ui.error
-
- assert_equal 0, e.exit_code
end
def test_execute_installed_version_not_installed
@cmd.handle_options %w[-n c --installed --version 2]
- e = assert_raises Gem::SystemExitException do
use_ui @ui do
@cmd.execute
end
@@ -265,65 +263,6 @@ pl (1)
assert_equal 1, e.exit_code
end
- def test_execute_local_details
- @a3a.summary = 'This is a lot of text. ' * 4
- @a3a.authors = ['Abraham Lincoln', 'Hirohito']
- @a3a.homepage = 'http://a.example.com/'
- @a3a.rubyforge_project = 'rubygems'
-
- @cmd.handle_options %w[--local --details]
-
- use_ui @ui do
- @cmd.execute
- end
-
- expected = <<-EOF
-
-*** LOCAL GEMS ***
-
-a (3.a, 2, 1)
- Author: A User
- Homepage: http://example.com
- Installed at (3.a): #{@gemhome}
- (2): #{@gemhome}
- (1): #{@gemhome}
-
- this is a summary
-
-a_evil (9)
- Author: A User
- Homepage: http://example.com
- Installed at: #{@gemhome}
-
- this is a summary
-
-b (2)
- Author: A User
- Homepage: http://example.com
- Installed at: #{@gemhome}
-
- this is a summary
-
-c (1.2)
- Author: A User
- Homepage: http://example.com
- Installed at: #{@gemhome}
-
- this is a summary
-
-pl (1)
- Platform: i386-linux
- Author: A User
- Homepage: http://example.com
- Installed at: #{@gemhome}
-
- this is a summary
- EOF
-
- assert_equal expected, @ui.output
- assert_equal '', @ui.error
- end
-
def test_execute_local_notty
@cmd.handle_options %w[]
@@ -335,9 +274,6 @@ pl (1)
expected = <<-EOF
a (3.a, 2, 1)
-a_evil (9)
-b (2)
-c (1.2)
pl (1 i386-linux)
EOF
@@ -412,9 +348,6 @@ a (3.a)
*** LOCAL GEMS ***
a (3.a, 2, 1)
-a_evil (9)
-b (2)
-c (1.2)
pl (1 i386-linux)
EOF
@@ -42,12 +42,11 @@ class TestGemCommandsSourcesCommand < Gem::TestCase
def test_execute_add
util_setup_fake_fetcher
- si = Gem::SourceIndex.new
- si.add_spec @a1
- specs = si.map do |_, spec|
[spec.name, spec.version, spec.original_platform]
- end
specs_dump_gz = StringIO.new
Zlib::GzipWriter.wrap specs_dump_gz do |io|
@@ -187,18 +186,18 @@ beta-gems.example.com is not a URI
@cmd.handle_options %w[--update]
util_setup_fake_fetcher
- source_index = util_setup_spec_fetcher @a1
- specs = source_index.map do |name, spec|
[spec.name, spec.version, spec.original_platform]
- end
@fetcher.data["#{@gem_repo}specs.#{Gem.marshal_version}.gz"] =
util_gzip Marshal.dump(specs)
- latest_specs = source_index.latest_specs.map do |spec|
[spec.name, spec.version, spec.original_platform]
- end
@fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz"] =
util_gzip Marshal.dump(latest_specs)
@@ -17,7 +17,8 @@ class TestGemCommandsSpecificationCommand < Gem::TestCase
def test_execute
foo = quick_spec 'foo'
- Gem.source_index.add_spec foo
@cmd.options[:args] = %w[foo]
@@ -77,8 +78,9 @@ class TestGemCommandsSpecificationCommand < Gem::TestCase
end
def test_execute_field
- foo = quick_spec 'foo'
- Gem.source_index.add_spec foo
@cmd.options[:args] = %w[foo name]
@@ -90,8 +92,9 @@ class TestGemCommandsSpecificationCommand < Gem::TestCase
end
def test_execute_marshal
- foo = quick_spec 'foo'
- Gem.source_index.add_spec foo
@cmd.options[:args] = %w[foo]
@cmd.options[:format] = :marshal
@@ -127,7 +130,8 @@ class TestGemCommandsSpecificationCommand < Gem::TestCase
def test_execute_ruby
foo = quick_spec 'foo'
- Gem.source_index.add_spec foo
@cmd.options[:args] = %w[foo]
@cmd.options[:format] = :ruby
@@ -25,12 +25,12 @@ class TestGemCommandsStaleCommand < Gem::TestCase
end
files.each do |file|
- filename = bar_baz.full_gem_path + "/#{file}"
- FileUtils.mkdir_p(File.dirname(filename))
FileUtils.touch(filename, :mtime => Time.now)
- filename = foo_bar.full_gem_path + "/#{file}"
- FileUtils.mkdir_p(File.dirname(filename))
FileUtils.touch(filename, :mtime => Time.now - 86400)
end
@@ -21,20 +21,20 @@ class TestGemCommandsUnpackCommand < Gem::TestCase
util_make_gems
assert_equal(
- @cmd.find_in_cache(@a1.file_name),
- Gem.cache_gem(@a1.file_name, @gemhome),
'found a-1.gem in the cache'
)
end
def test_get_path
- util_make_gems
util_setup_fake_fetcher
util_setup_spec_fetcher @a1
a1_data = nil
- open Gem.cache_gem(@a1.file_name, @gemhome), 'rb' do |fp|
a1_data = fp.read
end
@@ -44,15 +44,15 @@ class TestGemCommandsUnpackCommand < Gem::TestCase
dep = Gem::Dependency.new(@a1.name, @a1.version)
assert_equal(
@cmd.get_path(dep),
- Gem.cache_gem(@a1.file_name, @gemhome),
'fetches a-1 and returns the cache path'
)
- FileUtils.rm Gem.cache_gem(@a1.file_name, @gemhome)
assert_equal(
@cmd.get_path(dep),
- Gem.cache_gem(@a1.file_name, @gemhome),
'when removed from cache, refetches a-1'
)
end
@@ -73,16 +73,14 @@ class TestGemCommandsUnpackCommand < Gem::TestCase
end
def test_execute_gem_path
- util_make_gems
- util_setup_spec_fetcher
util_setup_fake_fetcher
Gem.clear_paths
gemhome2 = File.join @tempdir, 'gemhome2'
- Gem.send :set_paths, [gemhome2, @gemhome].join(File::PATH_SEPARATOR)
- Gem.send :set_home, gemhome2
@cmd.options[:args] = %w[a]
@@ -96,15 +94,14 @@ class TestGemCommandsUnpackCommand < Gem::TestCase
end
def test_execute_gem_path_missing
- util_make_gems
util_setup_spec_fetcher
Gem.clear_paths
gemhome2 = File.join @tempdir, 'gemhome2'
- Gem.send :set_paths, [gemhome2, @gemhome].join(File::PATH_SEPARATOR)
- Gem.send :set_home, gemhome2
@cmd.options[:args] = %w[z]
@@ -123,7 +120,7 @@ class TestGemCommandsUnpackCommand < Gem::TestCase
util_clear_gems
a2_data = nil
- open Gem.cache_gem(@a2.file_name, @gemhome), 'rb' do |fp|
a2_data = fp.read
end
@@ -142,10 +139,28 @@ class TestGemCommandsUnpackCommand < Gem::TestCase
assert File.exist?(File.join(@tempdir, 'a-2')), 'a should be unpacked'
end
def test_execute_sudo
util_make_gems
- File.chmod 0555, @gemhome
@cmd.options[:args] = %w[b]
@@ -157,7 +172,7 @@ class TestGemCommandsUnpackCommand < Gem::TestCase
assert File.exist?(File.join(@tempdir, 'b-2')), 'b should be unpacked'
ensure
- File.chmod 0755, @gemhome
end
def test_execute_with_target_option
@@ -203,5 +218,13 @@ class TestGemCommandsUnpackCommand < Gem::TestCase
assert File.exist?(File.join(@tempdir, foo_spec.full_name))
end
end
@@ -24,15 +24,15 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
@cmd.options[:generate_ri] = false
util_setup_fake_fetcher
-
- @a1_path = Gem.cache_gem(@a1.file_name, @gemhome)
- @a2_path = Gem.cache_gem(@a2.file_name, @gemhome)
-
util_setup_spec_fetcher @a1, @a2
- @fetcher.data["#{@gem_repo}gems/#{@a1.file_name}"] =
read_binary @a1_path
- @fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] =
read_binary @a2_path
end
@@ -81,18 +81,19 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
def util_add_to_fetcher *specs
specs.each do |spec|
- gem_file = Gem.cache_gem(spec.file_name, @gemhome)
- @fetcher.data["http://gems.example.com/gems/#{spec.file_name}"] =
Gem.read_binary gem_file
end
end
def test_execute_system
util_setup_rubygem9
util_setup_spec_fetcher @rubygem9
util_add_to_fetcher @rubygem9
- util_clear_gems
@cmd.options[:args] = []
@cmd.options[:system] = true
@@ -113,17 +114,17 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
end
def test_execute_system_at_latest
util_setup_rubygem_current
util_setup_spec_fetcher @rubygem_current
util_add_to_fetcher @rubygem_current
- util_clear_gems
@cmd.options[:args] = []
@cmd.options[:system] = true
@cmd.options[:generate_rdoc] = false
@cmd.options[:generate_ri] = false
- assert_raises Gem::SystemExitException do
use_ui @ui do
@cmd.execute
end
@@ -135,11 +136,11 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
end
def test_execute_system_multiple
util_setup_rubygem9
util_setup_rubygem8
util_setup_spec_fetcher @rubygem8, @rubygem9
util_add_to_fetcher @rubygem8, @rubygem9
- util_clear_gems
@cmd.options[:args] = []
@cmd.options[:system] = true
@@ -184,6 +185,31 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
assert_empty out
end
def test_execute_system_with_gems
@cmd.options[:args] = %w[gem]
@cmd.options[:system] = true
@@ -218,16 +244,11 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
@a2.add_dependency 'c', '2'
@a2.add_dependency 'b', '2'
- @b2_path = Gem.cache_gem(@b2.file_name, @gemhome)
- @c1_2_path = Gem.cache_gem(@c1_2.file_name, @gemhome)
- @c2_path = Gem.cache_gem(@c2.file_name, @gemhome)
- @source_index = Gem::SourceIndex.new
- @source_index.add_spec @a1
- @source_index.add_spec @a2
- @source_index.add_spec @b2
- @source_index.add_spec @c1_2
- @source_index.add_spec @c2
util_build_gem @a1
util_build_gem @a2
@@ -236,16 +257,16 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
@fetcher.data["#{@gem_repo}gems/#{@a1.file_name}"] = read_binary @a1_path
@fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] = read_binary @a2_path
@fetcher.data["#{@gem_repo}gems/#{@b2.file_name}"] = read_binary @b2_path
- @fetcher.data["#{@gem_repo}gems/#{@c1_2.file_name}"] =
- read_binary @c1_2_path
@fetcher.data["#{@gem_repo}gems/#{@c2.file_name}"] = read_binary @c2_path
util_setup_spec_fetcher @a1, @a2, @b2, @c1_2, @c2
- util_clear_gems
Gem::Installer.new(@c1_2_path).install
Gem::Installer.new(@a1_path).install
@cmd.options[:args] = []
use_ui @ui do
@@ -11,6 +11,7 @@ class TestGemCommandsWhichCommand < Gem::TestCase
def setup
super
@cmd = Gem::Commands::WhichCommand.new
end
@@ -28,6 +29,8 @@ class TestGemCommandsWhichCommand < Gem::TestCase
end
def test_execute_one_missing
util_foo_bar
@cmd.handle_options %w[foo_bar missing]
@@ -37,7 +40,7 @@ class TestGemCommandsWhichCommand < Gem::TestCase
end
assert_equal "#{@foo_bar.full_gem_path}/lib/foo_bar.rb\n", @ui.output
- assert_match %r%Can't find ruby library file or shared library missing\n%,
@ui.error
end
@@ -51,7 +54,7 @@ class TestGemCommandsWhichCommand < Gem::TestCase
end
assert_equal '', @ui.output
- assert_match %r%Can't find ruby library file or shared library missing\n%,
@ui.error
end
@@ -62,8 +65,8 @@ class TestGemCommandsWhichCommand < Gem::TestCase
end
files.each do |file|
- filename = @foo_bar.full_gem_path + "/#{file}"
- FileUtils.mkdir_p File.dirname(filename)
FileUtils.touch filename
end
end
@@ -67,16 +67,20 @@ class TestGemDependency < Gem::TestCase
assert_match d, d, "match self"
assert_match dep("a", ">= 0"), d, "match version exact"
assert_match dep("a", ">= 0"), dep("a", "1"), "match version"
- assert_match dep(/a/, ">= 0"), d, "match simple regexp"
- assert_match dep(/a|b/, ">= 0"), d, "match scary regexp"
-
- refute_match dep(/a/), dep("b")
refute_match dep("a"), Object.new
end
def test_equals_tilde_escape
refute_match dep("a|b"), dep("a", "1")
- assert_match dep(/a|b/), dep("a", "1")
end
def test_equals_tilde_object
@@ -90,9 +94,11 @@ class TestGemDependency < Gem::TestCase
def test_equals_tilde_spec
assert_match dep("a", ">= 0"), spec("a", "0")
assert_match dep("a", "1"), spec("a", "1")
- assert_match dep(/a/, ">= 0"), spec("a", "0")
- assert_match dep(/a|b/, ">= 0"), spec("b", "0")
- refute_match dep(/a/, ">= 0"), spec("b", "0")
end
def test_hash
@@ -166,5 +172,12 @@ class TestGemDependency < Gem::TestCase
assert d.prerelease?
end
end
@@ -14,10 +14,14 @@ class TestGemDependencyInstaller < Gem::TestCase
super
@gems_dir = File.join @tempdir, 'gems'
- @cache_dir = Gem.cache_dir(@gemhome)
FileUtils.mkdir @gems_dir
@a1, @a1_gem = util_gem 'a', '1' do |s| s.executables << 'a_bin' end
@a1_pre, @a1_pre_gem = util_gem 'a', '1.a'
@b1, @b1_gem = util_gem 'b', '1' do |s|
@@ -25,12 +29,13 @@ class TestGemDependencyInstaller < Gem::TestCase
s.add_development_dependency 'aa'
end
- Gem::RemoteFetcher.fetcher = @fetcher = Gem::FakeFetcher.new
-
util_reset_gems
end
def test_install
FileUtils.mv @a1_gem, @tempdir
inst = nil
@@ -39,13 +44,13 @@ class TestGemDependencyInstaller < Gem::TestCase
inst.install 'a'
end
- assert_equal Gem::SourceIndex.new(@a1.full_name => @a1),
- Gem::SourceIndex.from_installed_gems
-
assert_equal [@a1], inst.installed_gems
end
def test_install_all_dependencies
_, e1_gem = util_gem 'e', '1' do |s|
s.add_dependency 'b'
end
@@ -71,6 +76,8 @@ class TestGemDependencyInstaller < Gem::TestCase
end
def test_install_cache_dir
FileUtils.mv @a1_gem, @tempdir
FileUtils.mv @b1_gem, @tempdir
inst = nil
@@ -82,15 +89,18 @@ class TestGemDependencyInstaller < Gem::TestCase
assert_equal %w[a-1 b-1], inst.installed_gems.map { |s| s.full_name }
- assert Gem.cache_gem(@a1.file_name, @gemhome)
- assert Gem.cache_gem(@b1.file_name, @gemhome)
end
def test_install_dependencies_satisfied
a2, a2_gem = util_gem 'a', '2'
FileUtils.rm_rf File.join(@gemhome, 'gems')
- Gem.source_index.refresh!
FileUtils.mv @a1_gem, @tempdir
FileUtils.mv a2_gem, @tempdir # not in index
@@ -109,14 +119,13 @@ class TestGemDependencyInstaller < Gem::TestCase
inst.install 'b'
end
- installed = Gem::SourceIndex.from_installed_gems.map { |n,s| s.full_name }
-
- assert_equal %w[a-2 b-1], installed.sort
-
assert_equal %w[b-1], inst.installed_gems.map { |s| s.full_name }
end
def test_install_dependency
FileUtils.mv @a1_gem, @tempdir
FileUtils.mv @b1_gem, @tempdir
inst = nil
@@ -130,6 +139,8 @@ class TestGemDependencyInstaller < Gem::TestCase
end
def test_install_dependency_development
@aa1, @aa1_gem = util_gem 'aa', '1'
util_reset_gems
@@ -148,6 +159,8 @@ class TestGemDependencyInstaller < Gem::TestCase
end
def test_install_dependency_existing
Gem::Installer.new(@a1_gem).install
FileUtils.mv @a1_gem, @tempdir
FileUtils.mv @b1_gem, @tempdir
@@ -180,6 +193,8 @@ class TestGemDependencyInstaller < Gem::TestCase
end
def test_install_local
FileUtils.mv @a1_gem, @tempdir
inst = nil
@@ -192,6 +207,8 @@ class TestGemDependencyInstaller < Gem::TestCase
end
def test_install_local_dependency
FileUtils.mv @a1_gem, @tempdir
FileUtils.mv @b1_gem, @tempdir
@@ -206,6 +223,8 @@ class TestGemDependencyInstaller < Gem::TestCase
end
def test_install_local_dependency_installed
FileUtils.mv @a1_gem, @tempdir
FileUtils.mv @b1_gem, @tempdir
@@ -222,6 +241,8 @@ class TestGemDependencyInstaller < Gem::TestCase
end
def test_install_local_subdir
inst = nil
Dir.chdir @tempdir do
@@ -233,11 +254,13 @@ class TestGemDependencyInstaller < Gem::TestCase
end
def test_install_env_shebang
FileUtils.mv @a1_gem, @tempdir
inst = nil
Dir.chdir @tempdir do
- inst = Gem::DependencyInstaller.new :env_shebang => true, :wrappers => true
inst.install 'a'
end
@@ -248,6 +271,8 @@ class TestGemDependencyInstaller < Gem::TestCase
end
def test_install_force
FileUtils.mv @b1_gem, @tempdir
si = util_setup_spec_fetcher @b1
@fetcher.data['http://gems.example.com/gems/yaml'] = si.to_yaml
@@ -262,6 +287,8 @@ class TestGemDependencyInstaller < Gem::TestCase
end
def test_install_ignore_dependencies
FileUtils.mv @b1_gem, @tempdir
inst = nil
@@ -274,6 +301,8 @@ class TestGemDependencyInstaller < Gem::TestCase
end
def test_install_install_dir
FileUtils.mv @a1_gem, @tempdir
gemhome2 = File.join @tempdir, 'gemhome2'
Dir.mkdir gemhome2
@@ -287,10 +316,12 @@ class TestGemDependencyInstaller < Gem::TestCase
assert_equal %w[a-1], inst.installed_gems.map { |s| s.full_name }
assert File.exist?(File.join(gemhome2, 'specifications', @a1.spec_name))
- assert File.exist?(Gem.cache_gem(@a1.file_name, gemhome2))
end
def test_install_domain_both
a1_data = nil
File.open @a1_gem, 'rb' do |fp|
a1_data = fp.read
@@ -309,14 +340,13 @@ class TestGemDependencyInstaller < Gem::TestCase
assert_equal %w[a-1 b-1], inst.installed_gems.map { |s| s.full_name }
a1, b1 = inst.installed_gems
- a1_expected = File.join(@gemhome, 'specifications', a1.spec_name)
- b1_expected = File.join(@gemhome, 'specifications', b1.spec_name)
-
- assert_equal a1_expected, a1.loaded_from
- assert_equal b1_expected, b1.loaded_from
end
def test_install_domain_both_no_network
@fetcher.data["http://gems.example.com/gems/Marshal.#{@marshal_version}"] =
proc do
raise Gem::RemoteFetcher::FetchError
@@ -335,12 +365,11 @@ class TestGemDependencyInstaller < Gem::TestCase
end
def test_install_domain_local
FileUtils.mv @b1_gem, @tempdir
inst = nil
- Gem.source_index.remove_spec @a1.full_name
- Gem.source_index.remove_spec @a1_pre.full_name
-
Dir.chdir @tempdir do
e = assert_raises Gem::DependencyError do
inst = Gem::DependencyInstaller.new :domain => :local
@@ -355,6 +384,8 @@ class TestGemDependencyInstaller < Gem::TestCase
end
def test_install_domain_remote
a1_data = nil
File.open @a1_gem, 'rb' do |fp|
a1_data = fp.read
@@ -369,6 +400,8 @@ class TestGemDependencyInstaller < Gem::TestCase
end
def test_install_dual_repository
FileUtils.mv @a1_gem, @tempdir
FileUtils.mv @b1_gem, @tempdir
inst = nil
@@ -393,6 +426,8 @@ class TestGemDependencyInstaller < Gem::TestCase
end
def test_install_reinstall
Gem::Installer.new(@a1_gem).install
FileUtils.mv @a1_gem, @tempdir
inst = nil
@@ -402,13 +437,13 @@ class TestGemDependencyInstaller < Gem::TestCase
inst.install 'a'
end
- assert_equal Gem::SourceIndex.new(@a1.full_name => @a1),
- Gem::SourceIndex.from_installed_gems
-
- assert_equal %w[a-1], inst.installed_gems.map { |s| s.full_name }
end
def test_install_remote
a1_data = nil
File.open @a1_gem, 'rb' do |fp|
a1_data = fp.read
@@ -426,6 +461,8 @@ class TestGemDependencyInstaller < Gem::TestCase
end
def test_install_remote_dep
a1_data = nil
File.open @a1_gem, 'rb' do |fp|
a1_data = fp.read
@@ -444,6 +481,8 @@ class TestGemDependencyInstaller < Gem::TestCase
end
def test_install_remote_platform_newer
a2_o, a2_o_gem = util_gem 'a', '2' do |s|
s.platform = Gem::Platform.new %w[cpu other_platform 1]
end
@@ -473,6 +512,8 @@ class TestGemDependencyInstaller < Gem::TestCase
if defined? OpenSSL then
def test_install_security_policy
data = File.open(@a1_gem, 'rb') { |f| f.read }
@fetcher.data['http://gems.example.com/gems/a-1.gem'] = data
@@ -495,9 +536,11 @@ class TestGemDependencyInstaller < Gem::TestCase
# Wrappers don't work on mswin
unless win_platform? then
def test_install_no_wrappers
@fetcher.data['http://gems.example.com/gems/a-1.gem'] = read_binary(@a1_gem)
- inst = Gem::DependencyInstaller.new :wrappers => false
inst.install 'a'
refute_match(%r|This file was generated by RubyGems.|,
@@ -537,14 +580,19 @@ class TestGemDependencyInstaller < Gem::TestCase
end
def test_find_gems_gems_with_sources
inst = Gem::DependencyInstaller.new
dep = Gem::Dependency.new 'b', '>= 0'
- assert_equal [[@b1, @gem_repo]],
- inst.find_gems_with_sources(dep)
end
def test_find_gems_with_sources_local
FileUtils.mv @a1_gem, @tempdir
inst = Gem::DependencyInstaller.new
dep = Gem::Dependency.new 'a', '>= 0'
@@ -566,6 +614,8 @@ class TestGemDependencyInstaller < Gem::TestCase
end
def test_find_gems_with_sources_prerelease
installer = Gem::DependencyInstaller.new
dependency = Gem::Dependency.new('a', Gem::Requirement.default)
@@ -586,8 +636,8 @@ class TestGemDependencyInstaller < Gem::TestCase
def assert_resolve expected, *specs
util_clear_gems
-
util_setup_spec_fetcher(*specs)
inst = Gem::DependencyInstaller.new
inst.find_spec_by_name_and_version specs.first.name
@@ -601,6 +651,7 @@ class TestGemDependencyInstaller < Gem::TestCase
util_clear_gems
util_setup_spec_fetcher(*specs)
spec = specs.first
@@ -613,6 +664,9 @@ class TestGemDependencyInstaller < Gem::TestCase
end
def test_gather_dependencies
inst = Gem::DependencyInstaller.new
inst.find_spec_by_name_and_version 'b'
inst.gather_dependencies
@@ -725,6 +779,7 @@ class TestGemDependencyInstaller < Gem::TestCase
end
def test_gather_dependencies_prerelease
util_setup_c1_pre
assert_resolve_pre %w[a-1.a b-1 c-1.a], @c1_pre, @a1_pre, @b1
@@ -782,6 +837,9 @@ class TestGemDependencyInstaller < Gem::TestCase
end
def util_reset_gems
@c1_pre ||= nil
@d1 ||= nil
@d2 ||= nil
@@ -12,8 +12,11 @@ class TestGemDependencyList < Gem::TestCase
def setup
super
@deplist = Gem::DependencyList.new
@a1 = quick_spec 'a', '1'
@a2 = quick_spec 'a', '2'
@a3 = quick_spec 'a', '3'
@@ -28,13 +31,10 @@ class TestGemDependencyList < Gem::TestCase
end
def test_self_from_source_index
- hash = {
- 'a-1' => @a1,
- 'b-2' => @b2,
- }
- si = Gem::SourceIndex.new hash
- deps = Gem::DependencyList.from_source_index si
assert_equal %w[b-2 a-1], deps.dependency_order.map { |s| s.full_name }
end
@@ -17,21 +17,21 @@ class TestGemDocManager < Gem::TestCase
end
def test_uninstall_doc_unwritable
- path = @spec.installation_path
orig_mode = File.stat(path).mode
# File.chmod has no effect on MS Windows directories (it needs ACL).
if win_platform?
skip("test_uninstall_doc_unwritable skipped on MS Windows")
else
- File.chmod 0000, path
end
assert_raises Gem::FilePermissionError do
@manager.uninstall_doc
end
ensure
- File.chmod orig_mode, path
end
end
@@ -20,7 +20,7 @@ class TestGemFormat < Gem::Package::TarTestCase
def test_class_from_file_by_path
util_make_gems
- gems = Dir[Gem.cache_gem('*.gem', @gemhome)]
names = [@a1, @a2, @a3a, @a_evil9, @b2, @c1_2, @pl1].map do |spec|
spec.original_name
@@ -13,72 +13,88 @@ class Gem::GemPathSearcher
end
class TestGemGemPathSearcher < Gem::TestCase
-
def setup
super
- @foo1 = quick_gem 'foo', '0.1' do |s|
- s.require_paths << 'lib2'
- s.files << 'lib/foo.rb'
- end
-
path = File.join 'gems', @foo1.full_name, 'lib', 'foo.rb'
write_file(path) { |fp| fp.puts "# #{path}" }
- @foo2 = quick_gem 'foo', '0.2'
- @bar1 = quick_gem 'bar', '0.1'
- @bar2 = quick_gem 'bar', '0.2'
- @nrp = quick_gem 'nil_require_paths', '0.1'
- @nrp.require_paths = nil
@fetcher = Gem::FakeFetcher.new
Gem::RemoteFetcher.fetcher = @fetcher
- Gem.source_index = util_setup_spec_fetcher @foo1, @foo2, @bar1, @bar2
-
- @gps = Gem::GemPathSearcher.new
end
def test_find
- assert_equal @foo1, @gps.find('foo')
end
def test_find_all
- assert_equal [@foo1], @gps.find_all('foo')
end
def test_init_gemspecs
- assert_equal [@bar2, @bar1, @foo2, @foo1], @gps.init_gemspecs
end
def test_lib_dirs_for
- lib_dirs = @gps.lib_dirs_for(@foo1)
- expected = File.join @gemhome, 'gems', @foo1.full_name, '{lib,lib2}'
- assert_equal expected, lib_dirs
end
def test_lib_dirs_for_nil_require_paths
- assert_nil @gps.lib_dirs_for(@nrp)
end
def test_matching_file_eh
- refute @gps.matching_file?(@foo1, 'bar')
- assert @gps.matching_file?(@foo1, 'foo')
end
def test_matching_files
- assert_equal [], @gps.matching_files(@foo1, 'bar')
- expected = File.join @foo1.full_gem_path, 'lib', 'foo.rb'
- assert_equal [expected], @gps.matching_files(@foo1, 'foo')
end
def test_matching_files_nil_require_paths
- assert_empty @gps.matching_files(@nrp, 'foo')
end
-
end
-
@@ -39,10 +39,7 @@ class TestGemGemRunner < Gem::TestCase
def test_build_args__are_handled
Gem.clear_paths
- gr = Gem::GemRunner.new
- assert_raises(Gem::SystemExitException) do
- gr.run(%W[--help -- --build_arg1 --build_arg2])
- end
assert_equal %w[--build_arg1 --build_arg2], Gem::Command.build_args
end
@@ -16,6 +16,7 @@ class TestGemIndexer < Gem::TestCase
def setup
super
util_make_gems
@d2_0 = quick_spec 'd', '2.0' do |s|
@@ -33,11 +34,12 @@ class TestGemIndexer < Gem::TestCase
gems = File.join(@tempdir, 'gems')
FileUtils.mkdir_p gems
- FileUtils.mv Dir[Gem.cache_gem('*.gem', @gemhome)], gems
- @indexer = Gem::Indexer.new @tempdir, :rss_title => 'ExampleForge gems',
- :rss_host => 'example.com',
- :rss_gems_host => 'gems.example.com'
end
def test_initialize
@@ -61,36 +63,37 @@ class TestGemIndexer < Gem::TestCase
end
def test_build_indicies
- spec = quick_spec 'd', '2.0'
- spec.instance_variable_set :@original_platform, ''
-
@indexer.make_temp_directories
- index = Gem::SourceIndex.new
- index.add_spec spec
-
use_ui @ui do
- @indexer.build_indicies index
end
specs_path = File.join @indexer.directory, "specs.#{@marshal_version}"
specs_dump = Gem.read_binary specs_path
specs = Marshal.load specs_dump
- expected = [
- ['d', Gem::Version.new('2.0'), 'ruby'],
- ]
- assert_equal expected, specs, 'specs'
- latest_specs_path = File.join @indexer.directory,
- "latest_specs.#{@marshal_version}"
latest_specs_dump = Gem.read_binary latest_specs_path
latest_specs = Marshal.load latest_specs_dump
- expected = [
- ['d', Gem::Version.new('2.0'), 'ruby'],
- ]
assert_equal expected, latest_specs, 'latest_specs'
end
@@ -109,10 +112,10 @@ class TestGemIndexer < Gem::TestCase
assert File.directory?(quickdir)
assert File.directory?(marshal_quickdir)
- assert_indexed marshal_quickdir, "#{@a1.spec_name}.rz"
- assert_indexed marshal_quickdir, "#{@a2.spec_name}.rz"
- refute_indexed marshal_quickdir, @c1_2.spec_name
assert_indexed @tempdir, "specs.#{@marshal_version}"
assert_indexed @tempdir, "specs.#{@marshal_version}.gz"
@@ -230,12 +233,12 @@ class TestGemIndexer < Gem::TestCase
<description>
&lt;pre&gt;This line is really, really long. So long, in fact, that it is more than
eighty characters long! The purpose of this line is for testing wrapping
-behavior because sometimes people don't wrap their text to eighty characters.
Without the wrapping, the text might not look good in the RSS feed.
Also, a list:
* An entry that's actually kind of sort
- * an entry that's really long, which will probably get wrapped funny.
That's ok, somebody wasn't thinking straight when they made it more than
eighty characters.&lt;/pre&gt;
</description>
@@ -272,10 +275,10 @@ eighty characters.&lt;/pre&gt;
assert File.directory?(quickdir)
assert File.directory?(marshal_quickdir)
- assert_indexed marshal_quickdir, "#{@a1.spec_name}.rz"
- assert_indexed marshal_quickdir, "#{@a2.spec_name}.rz"
- refute_indexed marshal_quickdir, "#{@c1_2.spec_name}"
refute_indexed @tempdir, "specs.#{@marshal_version}"
refute_indexed @tempdir, "specs.#{@marshal_version}.gz"
@@ -308,8 +311,8 @@ eighty characters.&lt;/pre&gt;
assert File.directory?(marshal_quickdir)
- assert_indexed marshal_quickdir, "#{@a1.spec_name}.rz"
- assert_indexed marshal_quickdir, "#{@a2.spec_name}.rz"
assert_indexed @tempdir, "specs.#{@marshal_version}"
assert_indexed @tempdir, "specs.#{@marshal_version}.gz"
@@ -343,19 +346,19 @@ eighty characters.&lt;/pre&gt;
refute_indexed quickdir, "latest_index"
refute_indexed quickdir, "latest_index.rz"
- refute_indexed quickdir, "#{@a1.spec_name}.rz"
- refute_indexed quickdir, "#{@a2.spec_name}.rz"
- refute_indexed quickdir, "#{@b2.spec_name}.rz"
- refute_indexed quickdir, "#{@c1_2.spec_name}.rz"
refute_indexed quickdir, "#{@pl1.original_name}.gemspec.rz"
- refute_indexed quickdir, "#{@pl1.spec_name}.rz"
- assert_indexed marshal_quickdir, "#{@a1.spec_name}.rz"
- assert_indexed marshal_quickdir, "#{@a2.spec_name}.rz"
- refute_indexed quickdir, "#{@c1_2.spec_name}"
- refute_indexed marshal_quickdir, "#{@c1_2.spec_name}"
assert_indexed @tempdir, "specs.#{@marshal_version}"
assert_indexed @tempdir, "specs.#{@marshal_version}.gz"
@@ -389,8 +392,8 @@ eighty characters.&lt;/pre&gt;
assert File.directory?(quickdir)
assert File.directory?(marshal_quickdir)
- assert_indexed marshal_quickdir, "#{@a1.spec_name}.rz"
- assert_indexed marshal_quickdir, "#{@a2.spec_name}.rz"
assert_indexed @tempdir, "specs.#{@marshal_version}"
assert_indexed @tempdir, "specs.#{@marshal_version}.gz"
@@ -404,10 +407,7 @@ eighty characters.&lt;/pre&gt;
@indexer.generate_index
end
- assert_match %r%^Loading 10 gems from #{Regexp.escape @tempdir}$%,
- @ui.output
assert_match %r%^\.\.\.\.\.\.\.\.\.\.$%, @ui.output
- assert_match %r%^Loaded all gems$%, @ui.output
assert_match %r%^Generating Marshal quick index gemspecs for 10 gems$%,
@ui.output
assert_match %r%^Complete$%, @ui.output
@@ -520,14 +520,15 @@ eighty characters.&lt;/pre&gt;
@d2_1_a_tuple = [@d2_1_a.name, @d2_1_a.version, @d2_1_a.original_platform]
gems = File.join @tempdir, 'gems'
- FileUtils.mv Gem.cache_gem(@d2_1.file_name, @gemhome), gems
- FileUtils.mv Gem.cache_gem(@d2_1_a.file_name, @gemhome), gems
use_ui @ui do
@indexer.update_index
end
- assert_indexed marshal_quickdir, "#{@d2_1.spec_name}.rz"
specs_index = Marshal.load Gem.read_binary(@indexer.dest_specs_index)
@@ -46,9 +46,8 @@ class TestGemInstallUpdateOptions < Gem::InstallerTestCase
@installer = Gem::Installer.new @gem, @cmd.options
@installer.install
- assert File.exist?(File.join(Gem.user_dir, 'gems'))
- assert File.exist?(File.join(Gem.user_dir, 'gems',
- @spec.full_name))
end
def test_user_install_disabled_read_only
@@ -59,11 +58,13 @@ class TestGemInstallUpdateOptions < Gem::InstallerTestCase
refute @cmd.options[:user_install]
- File.chmod 0755, @userhome
FileUtils.chmod 0000, @gemhome
assert_raises(Gem::FilePermissionError) do
- @installer = Gem::Installer.new @gem, @cmd.options
end
end
ensure
@@ -8,6 +8,25 @@ require 'rubygems/installer_test_case'
class TestGemInstaller < Gem::InstallerTestCase
def test_app_script_text
@spec.version = 2
util_make_exec @spec, ''
@@ -108,7 +127,7 @@ load Gem.bin_path('a', 'executable', version)
def test_extract_files
format = Object.new
def format.file_entries
- [[{'size' => 7, 'mode' => 0400, 'path' => 'thefile'}, 'thefile']]
end
@installer.format = format
@@ -116,7 +135,7 @@ load Gem.bin_path('a', 'executable', version)
@installer.extract_files
thefile_path = File.join(util_gem_dir, 'thefile')
- assert_equal 'thefile', File.read(thefile_path)
unless Gem.win_platform? then
assert_equal 0400, File.stat(thefile_path).mode & 0777
@@ -145,8 +164,9 @@ load Gem.bin_path('a', 'executable', version)
@installer.extract_files
end
- assert_equal "attempt to install file into \"../thefile\" under #{util_gem_dir.inspect}",
- e.message
assert_equal false, File.file?(File.join(@tempdir, '../thefile')),
"You may need to remove this file if you broke the test once"
end
@@ -163,7 +183,7 @@ load Gem.bin_path('a', 'executable', version)
@installer.extract_files
end
- assert_equal 'attempt to install file into "/thefile"', e.message
assert_equal false, File.file?(File.join('/thefile')),
"You may need to remove this file if you broke the test once"
end
@@ -241,7 +261,7 @@ load Gem.bin_path('a', 'executable', version)
@installer.wrappers = true
@spec.executables = %w[executable]
- gem_dir = File.join "#{@gemhome}2", 'gems', @spec.full_name
gem_bindir = File.join gem_dir, 'bin'
FileUtils.mkdir_p gem_bindir
File.open File.join(gem_bindir, 'executable'), 'w' do |f|
@@ -253,7 +273,7 @@ load Gem.bin_path('a', 'executable', version)
@installer.generate_bin
- installed_exec = File.join("#{@gemhome}2", 'bin', 'executable')
assert_equal true, File.exist?(installed_exec)
assert_equal mask, File.stat(installed_exec).mode unless win_platform?
@@ -279,14 +299,14 @@ load Gem.bin_path('a', 'executable', version)
if win_platform?
skip('test_generate_bin_script_no_perms skipped on MS Windows')
else
- File.chmod 0000, util_inst_bindir
assert_raises Gem::FilePermissionError do
@installer.generate_bin
end
end
ensure
- File.chmod 0700, util_inst_bindir unless $DEBUG
end
def test_generate_bin_script_no_shebang
@@ -346,7 +366,7 @@ load Gem.bin_path('a', 'executable', version)
@installer.generate_bin
assert_equal true, File.directory?(util_inst_bindir)
- installed_exec = File.join(util_inst_bindir, 'executable')
assert_equal true, File.symlink?(installed_exec)
assert_equal(File.join(util_gem_dir, 'bin', 'executable'),
File.readlink(installed_exec))
@@ -371,14 +391,14 @@ load Gem.bin_path('a', 'executable', version)
if win_platform?
skip('test_generate_bin_symlink_no_perms skipped on MS Windows')
else
- File.chmod 0000, util_inst_bindir
assert_raises Gem::FilePermissionError do
@installer.generate_bin
end
end
ensure
- File.chmod 0700, util_inst_bindir unless $DEBUG
end
def test_generate_bin_symlink_update_newer
@@ -404,10 +424,10 @@ load Gem.bin_path('a', 'executable', version)
@spec.version = 3
util_make_exec
- @installer.gem_dir = File.join util_gem_dir @spec
@installer.generate_bin
installed_exec = File.join(util_inst_bindir, 'executable')
- assert_equal(File.join(util_gem_bindir(@spec), 'executable'),
File.readlink(installed_exec),
"Ensure symlink moved to latest version")
end
@@ -441,8 +461,9 @@ load Gem.bin_path('a', 'executable', version)
@installer.generate_bin
- installed_exec = File.join(util_inst_bindir, 'executable')
- assert_equal(File.join(util_gem_dir, 'bin', 'executable'),
File.readlink(installed_exec),
"Ensure symlink not moved")
end
@@ -455,7 +476,7 @@ load Gem.bin_path('a', 'executable', version)
@installer.gem_dir = util_gem_dir
@installer.generate_bin
- installed_exec = File.join(util_inst_bindir, 'executable')
assert_equal true, File.exist?(installed_exec)
@spec = Gem::Specification.new do |s|
@@ -522,7 +543,7 @@ load Gem.bin_path('a', 'executable', version)
Dir.mkdir util_inst_bindir
util_build_gem spec
- FileUtils.mv Gem.cache_gem(spec.file_name, @gemhome), @tempdir
installer = Gem::Installer.new gem
@@ -535,7 +556,7 @@ load Gem.bin_path('a', 'executable', version)
util_clear_gems
gemdir = File.join @gemhome, 'gems', @spec.full_name
- cache_file = Gem.cache_gem(@spec.file_name, @gemhome)
stub_exe = File.join @gemhome, 'bin', 'executable'
rakefile = File.join gemdir, 'ext', 'a', 'Rakefile'
@@ -555,12 +576,14 @@ load Gem.bin_path('a', 'executable', version)
assert File.exist?(cache_file), 'cache file must exist'
end
build_rake_in do
use_ui @ui do
- assert_equal @spec, @installer.install
end
end
assert File.exist? gemdir
assert File.exist?(stub_exe), 'gem executable must exist'
@@ -576,7 +599,7 @@ load Gem.bin_path('a', 'executable', version)
spec_file = File.join(@gemhome, 'specifications', @spec.spec_name)
- assert_equal spec_file, @spec.loaded_from
assert File.exist?(spec_file)
assert_same @installer, @post_build_hook_arg
@@ -656,17 +679,17 @@ load Gem.bin_path('a', 'executable', version)
gemhome2 = "#{@gemhome}2"
@spec.add_dependency 'b'
- b2 = quick_spec 'b', 2
FileUtils.mv @gemhome, gemhome2
- Gem.source_index.gems.delete b2.full_name
- source_index = Gem::SourceIndex.from_gems_in File.join(gemhome2,
- 'specifications')
util_setup_gem
- @installer = Gem::Installer.new @gem, :install_dir => gemhome2,
- :source_index => source_index
build_rake_in do
use_ui @ui do
@@ -675,6 +698,7 @@ load Gem.bin_path('a', 'executable', version)
end
assert File.exist?(File.join(gemhome2, 'gems', @spec.full_name))
end
def test_install_force
@@ -712,7 +736,7 @@ load Gem.bin_path('a', 'executable', version)
end
def test_install_missing_dirs
- FileUtils.rm_f Gem.cache_dir
FileUtils.rm_f File.join(Gem.dir, 'docs')
FileUtils.rm_f File.join(Gem.dir, 'specifications')
@@ -722,11 +746,11 @@ load Gem.bin_path('a', 'executable', version)
@installer.install
end
- File.directory? Gem.cache_dir
File.directory? File.join(Gem.dir, 'docs')
File.directory? File.join(Gem.dir, 'specifications')
- assert File.exist?(Gem.cache_gem(@spec.file_name, @gemhome))
assert File.exist?(File.join(@gemhome, 'specifications', @spec.spec_name))
end
@@ -812,8 +836,9 @@ load Gem.bin_path('a', 'executable', version)
@spec.post_install_message = 'I am a shiny gem!'
use_ui @ui do
- Dir.chdir @tempdir do Gem::Builder.new(@spec).build end
@installer.install
end
@@ -838,7 +863,7 @@ load Gem.bin_path('a', 'executable', version)
util_build_gem spec
- gem = Gem.cache_gem(spec.file_name, @gemhome)
use_ui @ui do
@installer = Gem::Installer.new gem
@@ -1002,6 +1027,10 @@ load Gem.bin_path('a', 'executable', version)
assert_equal @spec, eval(File.read(spec_file))
end
def old_ruby_required
spec = quick_spec 'old_ruby_required', '1' do |s|
s.required_ruby_version = '= 1.4.6'
@@ -1009,20 +1038,17 @@ load Gem.bin_path('a', 'executable', version)
util_build_gem spec
- Gem.cache_gem(spec.file_name, @gemhome)
end
def util_execless
@spec = quick_spec 'z'
- gem = File.join @tempdir, @spec.file_name
-
- @installer = util_installer @spec, gem, @gemhome
end
def mask
0100755 & (~File.umask)
end
-
end
-
@@ -6,6 +6,7 @@
require 'rubygems/package/tar_test_case'
require 'rubygems/package/tar_output'
class TestGemPackageTarOutput < Gem::Package::TarTestCase
@@ -0,0 +1,64 @@
@@ -144,7 +144,7 @@ class TestGemPlatform < Gem::TestCase
def test_empty
platform = Gem::Platform.new 'cpu-other_platform1'
assert_respond_to platform, :empty?
- assert_equal false, platform.empty?
end
def test_to_s
@@ -99,7 +99,7 @@ gems:
# REFACTOR: copied from test_gem_dependency_installer.rb
@gems_dir = File.join @tempdir, 'gems'
- @cache_dir = Gem.cache_dir(@gemhome)
FileUtils.mkdir @gems_dir
# TODO: why does the remote fetcher need it written to disk?
@@ -152,7 +152,7 @@ gems:
fetcher.fetch_size 'gems.example.com/yaml'
end
- assert_equal 'uri scheme is invalid', e.message
end
def test_fetch_size_socket_error
@@ -209,7 +209,7 @@ gems:
fetcher = util_fuck_with_fetcher a1_data
- a1_cache_gem = Gem.cache_gem(@a1.file_name, @gemhome)
assert_equal a1_cache_gem, fetcher.download(@a1, 'http://gems.example.com')
assert_equal("http://gems.example.com/gems/a-1.gem",
fetcher.instance_variable_get(:@test_arg).to_s)
@@ -221,8 +221,7 @@ gems:
inst = Gem::RemoteFetcher.fetcher
- assert_equal Gem.cache_gem(@a1.file_name, @gemhome),
- inst.download(@a1, 'http://gems.example.com')
end
def test_download_local
@@ -234,8 +233,7 @@ gems:
inst = Gem::RemoteFetcher.fetcher
end
- assert_equal Gem.cache_gem(@a1.file_name, @gemhome),
- inst.download(@a1, local_path)
end
def test_download_local_space
@@ -249,21 +247,19 @@ gems:
inst = Gem::RemoteFetcher.fetcher
end
- assert_equal Gem.cache_gem(@a1.file_name, @gemhome),
- inst.download(@a1, local_path)
end
def test_download_install_dir
- a1_data = nil
- File.open @a1_gem, 'rb' do |fp|
- a1_data = fp.read
end
fetcher = util_fuck_with_fetcher a1_data
install_dir = File.join @tempdir, 'more_gems'
- a1_cache_gem = Gem.cache_gem(@a1.file_name, install_dir)
FileUtils.mkdir_p(File.dirname(a1_cache_gem))
actual = fetcher.download(@a1, 'http://gems.example.com', install_dir)
@@ -279,7 +275,7 @@ gems:
FileUtils.mv @a1_gem, @tempdir
local_path = File.join @tempdir, @a1.file_name
inst = nil
- File.chmod 0555, Gem.cache_dir(@gemhome)
Dir.chdir @tempdir do
inst = Gem::RemoteFetcher.fetcher
@@ -288,19 +284,20 @@ gems:
assert_equal File.join(@tempdir, @a1.file_name),
inst.download(@a1, local_path)
ensure
- File.chmod 0755, Gem.cache_dir(@gemhome)
end
def test_download_read_only
- File.chmod 0555, Gem.cache_dir(@gemhome)
- File.chmod 0555, File.join(@gemhome)
fetcher = util_fuck_with_fetcher File.read(@a1_gem)
fetcher.download(@a1, 'http://gems.example.com')
- assert File.exist?(Gem.cache_gem(@a1.file_name, Gem.user_dir))
ensure
- File.chmod 0755, @gemhome
- File.chmod 0755, Gem.cache_dir(@gemhome)
end
end
@@ -319,7 +316,7 @@ gems:
fetcher = util_fuck_with_fetcher e1_data, :blow_chunks
- e1_cache_gem = Gem.cache_gem(e1.file_name, @gemhome)
assert_equal e1_cache_gem, fetcher.download(e1, 'http://gems.example.com')
@@ -337,7 +334,7 @@ gems:
inst = Gem::RemoteFetcher.fetcher
end
- cache_path = Gem.cache_gem(@a1.file_name, @gemhome)
FileUtils.mv local_path, cache_path
gem = Gem::Format.from_file_by_path cache_path
@@ -422,7 +419,7 @@ gems:
def test_fetch_path_gzip
fetcher = Gem::RemoteFetcher.new nil
- def fetcher.open_uri_or_path(uri, mtime, head = nil)
Gem.gzip 'foo'
end
@@ -432,7 +429,7 @@ gems:
def test_fetch_path_gzip_unmodified
fetcher = Gem::RemoteFetcher.new nil
- def fetcher.open_uri_or_path(uri, mtime, head = nil)
nil
end
@@ -442,53 +439,59 @@ gems:
def test_fetch_path_io_error
fetcher = Gem::RemoteFetcher.new nil
- def fetcher.open_uri_or_path(uri, mtime, head = nil)
raise EOFError
end
e = assert_raises Gem::RemoteFetcher::FetchError do
- fetcher.fetch_path 'uri'
end
- assert_equal 'EOFError: EOFError (uri)', e.message
- assert_equal 'uri', e.uri
end
def test_fetch_path_socket_error
fetcher = Gem::RemoteFetcher.new nil
- def fetcher.open_uri_or_path(uri, mtime, head = nil)
raise SocketError
end
e = assert_raises Gem::RemoteFetcher::FetchError do
- fetcher.fetch_path 'uri'
end
- assert_equal 'SocketError: SocketError (uri)', e.message
- assert_equal 'uri', e.uri
end
def test_fetch_path_system_call_error
fetcher = Gem::RemoteFetcher.new nil
- def fetcher.open_uri_or_path(uri, mtime = nil, head = nil)
raise Errno::ECONNREFUSED, 'connect(2)'
end
e = assert_raises Gem::RemoteFetcher::FetchError do
- fetcher.fetch_path 'uri'
end
- assert_match %r|ECONNREFUSED:.*connect\(2\) \(uri\)\z|,
e.message
- assert_equal 'uri', e.uri
end
def test_fetch_path_unmodified
fetcher = Gem::RemoteFetcher.new nil
- def fetcher.open_uri_or_path(uri, mtime, head = nil)
nil
end
@@ -551,16 +554,18 @@ gems:
end
end
- def test_open_uri_or_path
fetcher = Gem::RemoteFetcher.new nil
conn = Object.new
def conn.started?() true end
def conn.request(req)
unless defined? @requested then
@requested = true
res = Net::HTTPMovedPermanently.new nil, 301, nil
- res.add_field 'Location', 'http://gems.example.com/real_path'
res
else
res = Net::HTTPOK.new nil, 200, nil
@@ -572,19 +577,21 @@ gems:
conn = { "#{Thread.current.object_id}:gems.example.com:80" => conn }
fetcher.instance_variable_set :@connections, conn
- data = fetcher.open_uri_or_path 'http://gems.example.com/redirect'
assert_equal 'real_path', data
end
- def test_open_uri_or_path_limited_redirects
fetcher = Gem::RemoteFetcher.new nil
conn = Object.new
def conn.started?() true end
def conn.request(req)
res = Net::HTTPMovedPermanently.new nil, 301, nil
- res.add_field 'Location', 'http://gems.example.com/redirect'
res
end
@@ -592,11 +599,10 @@ gems:
fetcher.instance_variable_set :@connections, conn
e = assert_raises Gem::RemoteFetcher::FetchError do
- fetcher.open_uri_or_path 'http://gems.example.com/redirect'
end
- assert_equal 'too many redirects (http://gems.example.com/redirect)',
- e.message
end
def test_request
@@ -631,6 +637,85 @@ gems:
assert_equal t.rfc2822, conn.payload['if-modified-since']
end
def test_yaml_error_on_size
use_ui @ui do
self.class.enable_yaml = false
@@ -753,5 +838,24 @@ gems:
assert_equal "/home/skillet", @fetcher.correct_for_windows_path(path)
end
end
@@ -256,6 +256,19 @@ class TestGemRequirement < Gem::TestCase
refute_satisfied_by "2.0", "~> 1.4.4"
end
def test_bad
refute_satisfied_by "", "> 0.1"
refute_satisfied_by "1.2.3", "!= 1.2.3"
@@ -9,12 +9,10 @@ require 'rubygems/server'
require 'stringio'
class Gem::Server
- attr_accessor :source_index
attr_reader :server
end
class TestGemServer < Gem::TestCase
-
def setup
super
@@ -41,52 +39,64 @@ class TestGemServer < Gem::TestCase
data = StringIO.new "GET /Marshal.#{Gem.marshal_version} HTTP/1.0\r\n\r\n"
@req.parse data
- @server.Marshal @req, @res
assert_equal 200, @res.status, @res.body
assert_match %r| \d\d:\d\d:\d\d |, @res['date']
assert_equal 'application/octet-stream', @res['content-type']
- si = Gem::SourceIndex.new
- si.add_specs @a1, @a2
- assert_equal si, Marshal.load(@res.body)
end
def test_Marshal_Z
data = StringIO.new "GET /Marshal.#{Gem.marshal_version}.Z HTTP/1.0\r\n\r\n"
@req.parse data
- @server.Marshal @req, @res
assert_equal 200, @res.status, @res.body
assert_match %r| \d\d:\d\d:\d\d |, @res['date']
assert_equal 'application/x-deflate', @res['content-type']
- si = Gem::SourceIndex.new
- si.add_specs @a1, @a2
- assert_equal si, Marshal.load(Gem.inflate(@res.body))
end
def test_latest_specs
data = StringIO.new "GET /latest_specs.#{Gem.marshal_version} HTTP/1.0\r\n\r\n"
@req.parse data
- @server.latest_specs @req, @res
assert_equal 200, @res.status, @res.body
assert_match %r| \d\d:\d\d:\d\d |, @res['date']
assert_equal 'application/octet-stream', @res['content-type']
assert_equal [['a', Gem::Version.new(2), Gem::Platform::RUBY]],
- Marshal.load(@res.body)
end
def test_latest_specs_gz
data = StringIO.new "GET /latest_specs.#{Gem.marshal_version}.gz HTTP/1.0\r\n\r\n"
@req.parse data
- @server.latest_specs @req, @res
assert_equal 200, @res.status, @res.body
assert_match %r| \d\d:\d\d:\d\d |, @res['date']
@@ -227,6 +237,4 @@ class TestGemServer < Gem::TestCase
@server.instance_variable_set :@server, webrick
end
-
end
-
@@ -55,7 +55,7 @@ class TestGemSilentUI < Gem::TestCase
assert_empty out, 'No output'
assert_empty err, 'No output'
-
out, err = capture_io do
use_ui @sui do
value = @sui.ask_yes_no 'Problem?', true
@@ -66,7 +66,7 @@ class TestGemSilentUI < Gem::TestCase
assert_empty err, 'No output'
assert value, 'Value is true'
-
out, err = capture_io do
use_ui @sui do
value = @sui.ask_yes_no 'Problem?', false
@@ -7,397 +7,250 @@
require 'rubygems/test_case'
require 'rubygems/source_index'
require 'rubygems/config_file'
class TestGemSourceIndex < Gem::TestCase
-
def setup
super
util_setup_fake_fetcher
- end
-
- def test_self_from_gems_in
- spec_dir = File.join @gemhome, 'specifications'
-
- FileUtils.rm_r spec_dir
-
- FileUtils.mkdir_p spec_dir
-
- a1 = quick_spec 'a', '1' do |spec| spec.author = 'author 1' end
-
- spec_file = File.join spec_dir, a1.spec_name
-
- File.open spec_file, 'w' do |fp|
- fp.write a1.to_ruby
- end
-
- si = Gem::SourceIndex.from_gems_in spec_dir
-
- assert_equal [spec_dir], si.spec_dirs
- assert_equal [a1.full_name], si.gems.keys
- end
-
- def test_self_load_specification
- spec_dir = File.join @gemhome, 'specifications'
-
- FileUtils.rm_r spec_dir
-
- FileUtils.mkdir_p spec_dir
- a1 = quick_spec 'a', '1' do |spec| spec.author = 'author 1' end
-
- spec_file = File.join spec_dir, a1.spec_name
-
- File.open spec_file, 'w' do |fp|
- fp.write a1.to_ruby
- end
-
- spec = Gem::SourceIndex.load_specification spec_file
-
- assert_equal a1.author, spec.author
end
- def test_self_load_specification_utf_8
- spec_dir = File.join @gemhome, 'specifications'
-
- FileUtils.rm_r spec_dir
-
- FileUtils.mkdir_p spec_dir
-
- spec_file = File.join spec_dir, "utf-8.gemspec"
- spec_data = <<-SPEC
-Gem::Specification.new do |s|
- s.name = %q{utf}
- s.version = "8"
- s.required_rubygems_version = Gem::Requirement.new(">= 0")
- s.authors = ["\317\200"]
- s.date = %q{2008-09-10}
- s.description = %q{This is a test description}
- s.email = %q{[email protected]}
- s.has_rdoc = true
- s.homepage = %q{http://example.com}
- s.require_paths = ["lib"]
- s.rubygems_version = %q{1.2.0}
- s.summary = %q{this is a summary}
- if s.respond_to? :specification_version then
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
- s.specification_version = 2
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
- else
end
- else
end
-end
- SPEC
-
- spec_data.force_encoding 'UTF-8'
-
- File.open spec_file, 'w' do |io| io.write spec_data end
-
- spec = Gem::SourceIndex.load_specification spec_file
-
- pi = "\317\200"
- pi.force_encoding 'UTF-8' if pi.respond_to? :force_encoding
-
- assert_equal pi, spec.author
- end if Gem.ruby_version > Gem::Version.new('1.9')
- def test_self_load_specification_exception
- spec_dir = File.join @gemhome, 'specifications'
-
- FileUtils.mkdir_p spec_dir
-
- spec_file = File.join spec_dir, 'a-1.gemspec'
-
- File.open spec_file, 'w' do |fp|
- fp.write 'raise Exception, "epic fail"'
- end
-
- out, err = capture_io do
- assert_equal nil, Gem::SourceIndex.load_specification(spec_file)
end
-
- assert_equal '', out
-
- expected = "Invalid gemspec in [#{spec_file}]: epic fail\n"
- assert_equal expected, err
end
- def test_self_load_specification_interrupt
- spec_dir = File.join @gemhome, 'specifications'
-
- FileUtils.mkdir_p spec_dir
-
- spec_file = File.join spec_dir, 'a-1.gemspec'
-
- File.open spec_file, 'w' do |fp|
- fp.write 'raise Interrupt, "^C"'
- end
-
- use_ui @ui do
- assert_raises Interrupt do
- Gem::SourceIndex.load_specification(spec_file)
end
- end
-
- assert_equal '', @ui.output
- assert_equal '', @ui.error
- end
-
- def test_self_load_specification_syntax_error
- spec_dir = File.join @gemhome, 'specifications'
-
- FileUtils.mkdir_p spec_dir
-
- spec_file = File.join spec_dir, 'a-1.gemspec'
-
- File.open spec_file, 'w' do |fp|
- fp.write '1 +'
- end
-
- out, err = capture_io do
- assert_equal nil, Gem::SourceIndex.load_specification(spec_file)
- end
-
- assert_equal '', out
-
- assert_match(/syntax error/, err)
- end
-
- def test_self_load_specification_system_exit
- spec_dir = File.join @gemhome, 'specifications'
-
- FileUtils.mkdir_p spec_dir
- spec_file = File.join spec_dir, 'a-1.gemspec'
-
- File.open spec_file, 'w' do |fp|
- fp.write 'raise SystemExit, "bye-bye"'
- end
-
- use_ui @ui do
- assert_raises SystemExit do
- Gem::SourceIndex.load_specification(spec_file)
end
- end
-
- assert_equal '', @ui.output
- assert_equal '', @ui.error
- end
-
- def test_create_from_directory
- # TODO
- end
- def test_find_name
- assert_equal [@a1, @a2, @a3a], @source_index.find_name('a')
- assert_equal [@a2], @source_index.find_name('a', '= 2')
- assert_equal [], @source_index.find_name('bogusstring')
- assert_equal [], @source_index.find_name('a', '= 3')
-
- source_index = Gem::SourceIndex.new
- source_index.add_spec @a1
- source_index.add_spec @a2
-
- assert_equal [@a1], source_index.find_name(@a1.name, '= 1')
-
- r1 = Gem::Requirement.create '= 1'
- assert_equal [@a1], source_index.find_name(@a1.name, r1)
- end
-
- def test_find_name_empty_cache
- empty_source_index = Gem::SourceIndex.new({})
- assert_equal [], empty_source_index.find_name("foo")
- end
-
- def test_latest_specs
- p1_ruby = quick_spec 'p', '1'
- p1_platform = quick_spec 'p', '1' do |spec|
- spec.platform = Gem::Platform::CURRENT
- end
-
- a1_platform = quick_spec @a1.name, (@a1.version) do |s|
- s.platform = Gem::Platform.new 'x86-my_platform1'
- end
- a2_platform = quick_spec @a2.name, (@a2.version) do |s|
- s.platform = Gem::Platform.new 'x86-my_platform1'
- end
- a2_platform_other = quick_spec @a2.name, (@a2.version) do |s|
- s.platform = Gem::Platform.new 'x86-other_platform1'
- end
- a3_platform_other = quick_spec @a2.name, (@a2.version.bump) do |s|
- s.platform = Gem::Platform.new 'x86-other_platform1'
end
-
- @source_index.add_spec p1_ruby
- @source_index.add_spec p1_platform
- @source_index.add_spec a1_platform
- @source_index.add_spec a2_platform
- @source_index.add_spec a2_platform_other
- @source_index.add_spec a3_platform_other
-
- expected = [
- @a2.full_name,
- a2_platform.full_name,
- a3_platform_other.full_name,
- @c1_2.full_name,
- @a_evil9.full_name,
- p1_ruby.full_name,
- p1_platform.full_name,
- ].sort
-
- latest_specs = @source_index.latest_specs.map { |s| s.full_name }.sort
-
- assert_equal expected, latest_specs
end
def test_load_gems_in
- spec_dir1 = File.join @gemhome, 'specifications'
- spec_dir2 = File.join @tempdir, 'gemhome2', 'specifications'
- FileUtils.rm_r spec_dir1
- FileUtils.mkdir_p spec_dir1
- FileUtils.mkdir_p spec_dir2
- a1 = quick_spec 'a', '1' do |spec| spec.author = 'author 1' end
- a2 = quick_spec 'a', '1' do |spec| spec.author = 'author 2' end
- File.open File.join(spec_dir1, a1.spec_name), 'w' do |fp|
- fp.write a1.to_ruby
- end
- File.open File.join(spec_dir2, a2.spec_name), 'w' do |fp|
- fp.write a2.to_ruby
- end
- @source_index.load_gems_in spec_dir1, spec_dir2
- assert_equal a1.author, @source_index.specification(a1.full_name).author
end
def test_outdated
- util_setup_spec_fetcher
- assert_equal [], @source_index.outdated
- updated = quick_spec @a2.name, (@a2.version.bump)
- util_setup_spec_fetcher updated
- assert_equal [updated.name], @source_index.outdated
- updated_platform = quick_spec @a2.name, (updated.version.bump) do |s|
- s.platform = Gem::Platform.new 'x86-other_platform1'
- end
- util_setup_spec_fetcher updated, updated_platform
- assert_equal [updated_platform.name], @source_index.outdated
end
def test_prerelease_specs_kept_in_right_place
- gem_a1_alpha = quick_spec 'abba', '1.a'
- @source_index.add_spec gem_a1_alpha
-
- refute @source_index.latest_specs.include?(gem_a1_alpha)
- assert @source_index.latest_specs(true).include?(gem_a1_alpha)
- assert @source_index.find_name(gem_a1_alpha.full_name).empty?
- assert @source_index.prerelease_specs.include?(gem_a1_alpha)
end
def test_refresh_bang
- a1_spec = File.join @gemhome, "specifications", @a1.spec_name
-
- FileUtils.mv a1_spec, @tempdir
- source_index = Gem::SourceIndex.from_installed_gems
- refute source_index.gems.include?(@a1.full_name)
- FileUtils.mv File.join(@tempdir, @a1.spec_name), a1_spec
- source_index.refresh!
-
- assert source_index.gems.include?(@a1.full_name)
- end
- def test_refresh_bang_not_from_dir
- source_index = Gem::SourceIndex.new
-
- e = assert_raises RuntimeError do
source_index.refresh!
- end
- assert_equal 'source index not created from disk', e.message
end
def test_remove_spec
- deleted = @source_index.remove_spec 'a-1'
- assert_equal %w[a-2 a-3.a a_evil-9 c-1.2],
- @source_index.all_gems.values.map { |s| s.full_name }.sort
- deleted = @source_index.remove_spec 'a-3.a'
- assert_equal %w[a-2 a_evil-9 c-1.2],
- @source_index.all_gems.values.map { |s| s.full_name }.sort
end
def test_search
- requirement = Gem::Requirement.create '= 9'
- with_version = Gem::Dependency.new(/^a/, requirement)
- assert_equal [@a_evil9], @source_index.search(with_version)
- with_default = Gem::Dependency.new(/^a/, Gem::Requirement.default)
- assert_equal [@a1, @a2, @a3a, @a_evil9], @source_index.search(with_default)
- c1_1_dep = Gem::Dependency.new 'c', '~> 1.1'
- assert_equal [@c1_2], @source_index.search(c1_1_dep)
end
def test_search_platform
- util_set_arch 'x86-my_platform1'
- a1 = quick_spec 'a', '1'
- a1_mine = quick_spec 'a', '1' do |s|
- s.platform = Gem::Platform.new 'x86-my_platform1'
- end
- a1_other = quick_spec 'a', '1' do |s|
- s.platform = Gem::Platform.new 'x86-other_platform1'
- end
- si = Gem::SourceIndex.new(a1.full_name => a1, a1_mine.full_name => a1_mine,
- a1_other.full_name => a1_other)
- dep = Gem::Dependency.new 'a', Gem::Requirement.new('1')
- gems = si.search dep, true
- assert_equal [a1, a1_mine], gems.sort
end
def test_signature
- sig = @source_index.gem_signature('foo-1.2.3')
- assert_equal 64, sig.length
- assert_match(/^[a-f0-9]{64}$/, sig)
end
def test_specification
- assert_equal @a1, @source_index.specification(@a1.full_name)
- assert_nil @source_index.specification("foo-1.2.4")
end
def test_index_signature
- sig = @source_index.index_signature
- assert_match(/^[a-f0-9]{64}$/, sig)
end
-
end
-
@@ -16,43 +16,43 @@ class TestGemSpecFetcher < Gem::TestCase
util_setup_fake_fetcher
- @a_pre = quick_spec 'a', '1.a'
- @source_index.add_spec @pl1
- @source_index.add_spec @a_pre
- @specs = @source_index.gems.sort.map do |name, spec|
- [spec.name, spec.version, spec.original_platform]
- end.sort
- @latest_specs = @source_index.latest_specs.sort.map do |spec|
- [spec.name, spec.version, spec.original_platform]
- end
- @prerelease_specs = @source_index.prerelease_gems.sort.map do |name, spec|
[spec.name, spec.version, spec.original_platform]
- end.sort
- @fetcher.data["#{@gem_repo}specs.#{Gem.marshal_version}.gz"] =
- util_gzip(Marshal.dump(@specs))
- @fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz"] =
- util_gzip(Marshal.dump(@latest_specs))
- @fetcher.data["#{@gem_repo}prerelease_specs.#{Gem.marshal_version}.gz"] =
- util_gzip(Marshal.dump(@prerelease_specs))
@sf = Gem::SpecFetcher.new
end
def test_fetch_all
- @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a1.spec_name}.rz"] =
- util_zip(Marshal.dump(@a1))
- @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a2.spec_name}.rz"] =
- util_zip(Marshal.dump(@a2))
- @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a_pre.spec_name}.rz"] =
- util_zip(Marshal.dump(@a_pre))
- @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a3a.spec_name}.rz"] =
- util_zip(Marshal.dump(@a3a))
dep = Gem::Dependency.new 'a', 1
@@ -70,12 +70,10 @@ class TestGemSpecFetcher < Gem::TestCase
end
def test_fetch_latest
- @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a1.spec_name}.rz"] =
- util_zip(Marshal.dump(@a1))
- @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a2.spec_name}.rz"] =
- util_zip(Marshal.dump(@a2))
- @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a_pre.spec_name}.rz"] =
- util_zip(Marshal.dump(@a_pre))
dep = Gem::Dependency.new 'a', 1
specs_and_sources = @sf.fetch dep
@@ -88,15 +86,12 @@ class TestGemSpecFetcher < Gem::TestCase
end
def test_fetch_prerelease
- @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a1.spec_name}.rz"] =
- util_zip(Marshal.dump(@a1))
- @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a2.spec_name}.rz"] =
- util_zip(Marshal.dump(@a2))
- @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a_pre.spec_name}.rz"] =
- util_zip(Marshal.dump(@a_pre))
- dep = Gem::Dependency.new 'a', '1.a'
- specs_and_sources = @sf.fetch dep, false, true, true
spec_names = specs_and_sources.map do |spec, source_uri|
[spec.full_name, source_uri]
@@ -293,11 +288,11 @@ class TestGemSpecFetcher < Gem::TestCase
assert_equal [@uri], specs.keys
- assert_equal([["a", Gem::Version.new("1"), "ruby"],
- ["a", Gem::Version.new("2"), "ruby"],
- ["a_evil", Gem::Version.new("9"), "ruby"],
- ["c", Gem::Version.new("1.2"), "ruby"],
- ["pl", Gem::Version.new("1"), "i386-linux"]],
specs[@uri].sort)
end
@@ -347,19 +342,17 @@ class TestGemSpecFetcher < Gem::TestCase
end
def test_load_specs
- specs = @sf.load_specs @uri, 'specs'
-
expected = [
- ['a', Gem::Version.new('1.a'), Gem::Platform::RUBY],
['a', Gem::Version.new(1), Gem::Platform::RUBY],
['a', Gem::Version.new(2), Gem::Platform::RUBY],
- ['a', Gem::Version.new('3.a'), Gem::Platform::RUBY],
['a_evil', Gem::Version.new(9), Gem::Platform::RUBY],
['c', Gem::Version.new('1.2'), Gem::Platform::RUBY],
['pl', Gem::Version.new(1), 'i386-linux'],
]
- assert_equal expected, specs
cache_dir = File.join Gem.user_home, '.gem', 'specs', 'gems.example.com%80'
assert File.exist?(cache_dir), "#{cache_dir} does not exist"
@@ -35,8 +35,8 @@ Gem::Specification.new do |s|
s.version = %q{0.4.0}
s.has_rdoc = true
s.summary = %q{A Hash which automatically computes keys.}
- s.files = ["lib/keyedlist.rb"]
- s.require_paths = ["lib"]
s.autorequire = %q{keyedlist}
s.author = %q{Florian Gross}
s.email = %q{[email protected]}
@@ -46,11 +46,9 @@ end
def setup
super
- # TODO: there is no reason why the spec tests need to write to disk
- @a1 = quick_gem 'a', '1' do |s|
s.executable = 'exec'
s.extensions << 'ext/a/extconf.rb'
- s.has_rdoc = 'true'
s.test_file = 'test/suite.rb'
s.requirements << 'A working computer'
s.rubyforge_project = 'example'
@@ -64,15 +62,10 @@ end
s.files = %w[lib/code.rb]
end
- @a2 = quick_gem 'a', '2' do |s|
s.files = %w[lib/code.rb]
end
- FileUtils.mkdir_p File.join(@tempdir, 'bin')
- File.open File.join(@tempdir, 'bin', 'exec'), 'w' do |fp|
- fp.puts "#!#{Gem.ruby}"
- end
-
@current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
end
@@ -83,7 +76,6 @@ end
bindir
cert_chain
date
- default_executable
dependencies
description
email
@@ -91,7 +83,6 @@ end
extensions
extra_rdoc_files
files
- has_rdoc
homepage
licenses
name
@@ -129,18 +120,39 @@ end
assert_equal @current_version, new_spec.specification_version
end
def test_self_load
- spec = File.join @gemhome, 'specifications', @a2.spec_name
- gs = Gem::Specification.load spec
- assert_equal @a2, gs
end
def test_self_load_legacy_ruby
- spec = eval LEGACY_RUBY_SPEC
assert_equal 'keyedlist', spec.name
assert_equal '0.4.0', spec.version.to_s
- assert_equal true, spec.has_rdoc?
assert_equal Gem::Specification::TODAY, spec.date
assert spec.required_ruby_version.satisfied_by?(Gem::Version.new('1'))
assert_equal false, spec.has_unit_tests?
@@ -195,8 +207,6 @@ end
assert_equal [], spec.requirements
assert_equal [], spec.dependencies
assert_equal 'bin', spec.bindir
- assert_equal true, spec.has_rdoc
- assert_equal true, spec.has_rdoc?
assert_equal '>= 0', spec.required_ruby_version.to_s
assert_equal '>= 0', spec.required_rubygems_version.to_s
end
@@ -279,9 +289,6 @@ end
assert_equal 'bin', spec.bindir
assert_same spec.bindir, new_spec.bindir
- assert_equal true, spec.has_rdoc
- assert_same spec.has_rdoc, new_spec.has_rdoc
-
assert_equal '>= 0', spec.required_ruby_version.to_s
assert_same spec.required_ruby_version, new_spec.required_ruby_version
@@ -290,6 +297,23 @@ end
new_spec.required_rubygems_version
end
def test__dump
@a2.platform = Gem::Platform.local
@a2.instance_variable_set :@original_platform, 'old_platform'
@@ -338,37 +362,33 @@ end
def test_date_equals_date
@a1.date = Date.new(2003, 9, 17)
- assert_equal Time.local(2003, 9, 17, 0,0,0), @a1.date
end
def test_date_equals_string
@a1.date = '2003-09-17'
- assert_equal Time.local(2003, 9, 17, 0,0,0), @a1.date
end
def test_date_equals_time
@a1.date = Time.local(2003, 9, 17, 0,0,0)
- assert_equal Time.local(2003, 9, 17, 0,0,0), @a1.date
end
def test_date_equals_time_local
- # HACK PDT
- @a1.date = Time.local(2003, 9, 17, 19,50,0)
- assert_equal Time.local(2003, 9, 17, 0,0,0), @a1.date
end
def test_date_equals_time_utc
- # HACK PDT
- @a1.date = Time.local(2003, 9, 17, 19,50,0)
- assert_equal Time.local(2003, 9, 17, 0,0,0), @a1.date
- end
-
- def test_default_executable
- assert_equal 'exec', @a1.default_executable
-
- @a1.default_executable = nil
- @a1.instance_variable_set :@executables, nil
- assert_equal nil, @a1.default_executable
end
def test_dependencies
@@ -391,60 +411,20 @@ end
end
def test_eql_eh
- g1 = quick_spec 'gem'
- g2 = quick_spec 'gem'
assert_equal g1, g2
assert_equal g1.hash, g2.hash
assert_equal true, g1.eql?(g2)
end
- def test_equals2
- assert_equal @a1, @a1
- assert_equal @a1, @a1.dup
- refute_equal @a1, @a2
- refute_equal @a1, Object.new
- end
-
- # The cgikit specification was reported to be causing trouble in at least
- # one version of RubyGems, so we test explicitly for it.
- def test_equals2_cgikit
- cgikit = Gem::Specification.new do |s|
- s.name = %q{cgikit}
- s.version = "1.1.0"
- s.date = %q{2004-03-13}
- s.summary = %q{CGIKit is a componented-oriented web application } +
- %q{framework like Apple Computers WebObjects. } +
- %{This framework services Model-View-Controller architecture } +
- %q{programming by components based on a HTML file, a definition } +
- %q{file and a Ruby source. }
- s.email = %q{[email protected]}
- s.homepage = %q{http://www.spice-of-life.net/download/cgikit/}
- s.autorequire = %q{cgikit}
- s.bindir = nil
- s.has_rdoc = true
- s.required_ruby_version = nil
- s.platform = nil
- s.files = ["lib/cgikit", "lib/cgikit.rb", "lib/cgikit/components", "..."]
- end
-
- assert_equal cgikit, cgikit
- end
-
- def test_equals2_default_executable
- spec = @a1.dup
- spec.default_executable = 'xx'
-
- refute_equal @a1, spec
- refute_equal spec, @a1
- end
-
- def test_equals2_extensions
spec = @a1.dup
spec.extensions = 'xx'
- refute_equal @a1, spec
- refute_equal spec, @a1
end
def test_executables
@@ -542,9 +522,26 @@ end
assert_kind_of Integer, @a1.hash
end
def test_full_gem_path
- assert_equal File.join(@gemhome, 'gems', @a1.full_name),
- @a1.full_gem_path
@a1.original_platform = 'mswin32'
@@ -553,11 +550,11 @@ end
end
def test_full_gem_path_double_slash
- gemhome = @gemhome.sub(/\w\//, '\&/')
- @a1.loaded_from = File.join gemhome, 'specifications', @a1.spec_name
- assert_equal File.join(@gemhome, 'gems', @a1.full_name),
- @a1.full_gem_path
end
def test_full_name
@@ -589,21 +586,6 @@ end
end
end
- def test_has_rdoc_eh
- assert @a1.has_rdoc?
- end
-
- def test_has_rdoc_equals
-
- use_ui @ui do
- @a1.has_rdoc = false
- end
-
- assert_equal '', @ui.output
-
- assert_equal true, @a1.has_rdoc
- end
-
def test_hash
assert_equal @a1.hash, @a1.hash
assert_equal @a1.hash, @a1.dup.hash
@@ -611,15 +593,14 @@ end
end
def test_installation_path
- assert_equal @gemhome, @a1.installation_path
- @a1.instance_variable_set :@loaded_from, nil
- e = assert_raises Gem::Exception do
- @a1.installation_path
end
-
- assert_equal 'spec a-1 is not from an installed gem', e.message
end
def test_lib_files
@@ -717,8 +698,8 @@ end
end
def test_spaceship_name
- s1 = quick_spec 'a', '1'
- s2 = quick_spec 'b', '1'
assert_equal(-1, (s1 <=> s2))
assert_equal( 0, (s1 <=> s1))
@@ -726,8 +707,8 @@ end
end
def test_spaceship_platform
- s1 = quick_spec 'a', '1'
- s2 = quick_spec 'a', '1' do |s|
s.platform = Gem::Platform.new 'x86-my_platform1'
end
@@ -737,8 +718,8 @@ end
end
def test_spaceship_version
- s1 = quick_spec 'a', '1'
- s2 = quick_spec 'a', '2'
assert_equal( -1, (s1 <=> s2))
assert_equal( 0, (s1 <=> s1))
@@ -773,13 +754,13 @@ Gem::Specification.new do |s|
s.version = \"2\"
s.required_rubygems_version = Gem::Requirement.new(\"> 0\") if s.respond_to? :required_rubygems_version=
- s.authors = [\"A User\"]
s.date = %q{#{Gem::Specification::TODAY.strftime "%Y-%m-%d"}}
s.description = %q{This is a test description}
s.email = %q{[email protected]}
- s.files = [\"lib/code.rb\"]
s.homepage = %q{http://example.com}
- s.require_paths = [\"lib\"]
s.rubygems_version = %q{#{Gem::VERSION}}
s.summary = %q{this is a summary}
@@ -820,12 +801,12 @@ Gem::Specification.new do |s|
s.version = \"2\"
s.required_rubygems_version = Gem::Requirement.new(\"> 0\") if s.respond_to? :required_rubygems_version=
- s.authors = [\"A User\"]
s.date = %q{#{Gem::Specification::TODAY.strftime "%Y-%m-%d"}}
s.description = %q{This is a test description}
s.email = %q{[email protected]}
s.homepage = %q{http://example.com}
- s.require_paths = [\"lib\"]
s.rubygems_version = %q{#{Gem::VERSION}}
s.summary = %q{this is a summary}
@@ -868,22 +849,21 @@ Gem::Specification.new do |s|
s.platform = Gem::Platform.new(#{expected_platform})
s.required_rubygems_version = Gem::Requirement.new(\">= 0\") if s.respond_to? :required_rubygems_version=
- s.authors = [\"A User\"]
s.date = %q{#{Gem::Specification::TODAY.strftime "%Y-%m-%d"}}
- s.default_executable = %q{exec}
s.description = %q{This is a test description}
s.email = %q{[email protected]}
- s.executables = [\"exec\"]
- s.extensions = [\"ext/a/extconf.rb\"]
- s.files = [\"lib/code.rb\", \"test/suite.rb\", \"bin/exec\", \"ext/a/extconf.rb\"]
s.homepage = %q{http://example.com}
- s.licenses = [\"MIT\"]
- s.require_paths = [\"lib\"]
- s.requirements = [\"A working computer\"]
s.rubyforge_project = %q{example}
s.rubygems_version = %q{#{Gem::VERSION}}
s.summary = %q{this is a summary}
- s.test_files = [\"test/suite.rb\"]
if s.respond_to? :specification_version then
s.specification_version = 3
@@ -913,7 +893,9 @@ end
end
def test_to_ruby_legacy
- gemspec1 = eval LEGACY_RUBY_SPEC
ruby_code = gemspec1.to_ruby
gemspec2 = eval ruby_code
@@ -936,7 +918,7 @@ end
refute_match '!!null', yaml_str
- same_spec = YAML.load(yaml_str)
assert_equal @a1, same_spec
end
@@ -945,7 +927,7 @@ end
@a1.platform = Gem::Platform.local
yaml_str = @a1.to_yaml
- same_spec = YAML.load(yaml_str)
assert_equal Gem::Platform.local, same_spec.platform
@@ -984,41 +966,48 @@ end
end
end
def test_validate_authors
util_setup_validate
Dir.chdir @tempdir do
- @a1.authors = []
use_ui @ui do
@a1.validate
end
- assert_equal "WARNING: no author specified\n", @ui.error, 'error'
@a1.authors = [Object.new]
e = assert_raises Gem::InvalidSpecificationException do
@a1.validate
end
- assert_equal 'authors must be Array of Strings', e.message
- @a1.authors = ['FIXME (who is writing this software)']
e = assert_raises Gem::InvalidSpecificationException do
@a1.validate
end
- assert_equal '"FIXME" or "TODO" is not an author', e.message
- @a1.authors = ['TODO (who is writing this software)']
e = assert_raises Gem::InvalidSpecificationException do
@a1.validate
end
- assert_equal '"FIXME" or "TODO" is not an author', e.message
end
end
@@ -1032,7 +1021,7 @@ end
@a1.validate
end
- assert_equal "WARNING: deprecated autorequire specified\n",
@ui.error, 'error'
end
end
@@ -1047,34 +1036,34 @@ end
@a1.validate
end
- assert_equal "WARNING: no description specified\n", @ui.error, 'error'
@ui = Gem::MockGemUi.new
- @a1.summary = 'this is my summary'
@a1.description = @a1.summary
use_ui @ui do
@a1.validate
end
- assert_equal "WARNING: description and summary are identical\n",
- @ui.error, 'error'
- @a1.description = 'FIXME (describe your package)'
e = assert_raises Gem::InvalidSpecificationException do
@a1.validate
end
- assert_equal '"FIXME" or "TODO" is not a description', e.message
- @a1.description = 'TODO (describe your package)'
e = assert_raises Gem::InvalidSpecificationException do
@a1.validate
end
- assert_equal '"FIXME" or "TODO" is not a description', e.message
end
end
@@ -1082,35 +1071,33 @@ end
util_setup_validate
Dir.chdir @tempdir do
- @a1.email = ''
use_ui @ui do
@a1.validate
end
- assert_equal "WARNING: no email specified\n", @ui.error, 'error'
- @a1.email = 'FIXME (your e-mail)'
e = assert_raises Gem::InvalidSpecificationException do
@a1.validate
end
- assert_equal '"FIXME" or "TODO" is not an email address', e.message
- @a1.email = 'TODO (your e-mail)'
e = assert_raises Gem::InvalidSpecificationException do
@a1.validate
end
- assert_equal '"FIXME" or "TODO" is not an email address', e.message
end
end
def test_validate_empty
- util_setup_validate
-
e = assert_raises Gem::InvalidSpecificationException do
Gem::Specification.new.validate
end
@@ -1134,7 +1121,7 @@ end
assert_equal %w[exec], @a1.executables
assert_equal '', @ui.output, 'output'
- assert_equal "WARNING: bin/exec is missing #! line\n", @ui.error, 'error'
end
def test_validate_empty_require_paths
@@ -1183,7 +1170,7 @@ end
@a1.validate
end
- assert_equal "WARNING: no homepage specified\n", @ui.error, 'error'
@ui = Gem::MockGemUi.new
@@ -1193,7 +1180,7 @@ end
@a1.validate
end
- assert_equal "WARNING: no homepage specified\n", @ui.error, 'error'
@a1.homepage = 'over at my cool site'
@@ -1216,6 +1203,26 @@ end
assert_equal 'invalid value for attribute name: ":json"', e.message
end
def test_validate_platform_legacy
util_setup_validate
@@ -1270,23 +1277,23 @@ end
@a1.validate
end
- assert_equal "WARNING: no summary specified\n", @ui.error, 'error'
- @a1.summary = 'FIXME (describe your package)'
e = assert_raises Gem::InvalidSpecificationException do
@a1.validate
end
- assert_equal '"FIXME" or "TODO" is not a summary', e.message
- @a1.summary = 'TODO (describe your package)'
e = assert_raises Gem::InvalidSpecificationException do
@a1.validate
end
- assert_equal '"FIXME" or "TODO" is not a summary', e.message
end
end
@@ -1310,6 +1317,67 @@ end
specfile.delete
end
def util_setup_deps
@gem = quick_spec "awesome", "1.0" do |awesome|
awesome.add_runtime_dependency "bonobo", []
@@ -1322,13 +1390,36 @@ end
def util_setup_validate
Dir.chdir @tempdir do
- FileUtils.mkdir_p File.join('ext', 'a')
- FileUtils.mkdir_p 'lib'
- FileUtils.mkdir_p 'test'
- FileUtils.touch File.join('ext', 'a', 'extconf.rb')
- FileUtils.touch File.join('lib', 'code.rb')
- FileUtils.touch File.join('test', 'suite.rb')
end
end
end
@@ -26,6 +26,21 @@ class TestGemText < Gem::TestCase
assert_equal " text to wrap", format_text("text to wrap", 40, 2)
end
def test_levenshtein_distance_add
assert_equal 2, levenshtein_distance("zentest", "zntst")
assert_equal 2, levenshtein_distance("zntst", "zentest")
@@ -14,26 +14,15 @@ class TestGemUninstaller < Gem::InstallerTestCase
@user_spec.executables = ["executable"]
- # HACK util_make_exec
- user_bin_dir = File.join Gem.user_dir, 'gems', @user_spec.full_name, 'bin'
- FileUtils.mkdir_p user_bin_dir
- exec_path = File.join user_bin_dir, "executable"
- open exec_path, 'w' do |f|
- f.puts "#!/usr/bin/ruby"
- end
-
- user_bin_dir = File.join Gem.user_dir, 'bin'
- FileUtils.mkdir_p user_bin_dir
- exec_path = File.join user_bin_dir, "executable"
- open exec_path, 'w' do |f|
- f.puts "#!/usr/bin/ruby"
- end
-
build_rake_in do
use_ui ui do
@installer.install
@user_installer.install
- Gem::Uninstaller.new(@user_spec.name, :executables => false).uninstall
end
end
end
@@ -44,6 +33,18 @@ class TestGemUninstaller < Gem::InstallerTestCase
assert_match %r|/foo/bar$|, uninstaller.instance_variable_get(:@gem_home)
end
def test_remove_executables_force_keep
uninstaller = Gem::Uninstaller.new nil, :executables => false
@@ -114,14 +115,13 @@ class TestGemUninstaller < Gem::InstallerTestCase
end
exec_path = File.join Gem.user_dir, 'bin', 'executable'
- assert_equal false, File.exist?(exec_path), 'removed exec from bin dir'
assert_equal "Removing executable\n", @ui.output
ensure
Gem::Installer.exec_format = nil
end
-
def test_path_ok_eh
uninstaller = Gem::Uninstaller.new nil
@@ -131,7 +131,7 @@ class TestGemUninstaller < Gem::InstallerTestCase
def test_path_ok_eh_legacy
uninstaller = Gem::Uninstaller.new nil
- @spec.loaded_from.gsub! @spec.full_name, '\&-legacy'
@spec.platform = 'legacy'
assert_equal true, uninstaller.path_ok?(@gemhome, @spec)
@@ -190,26 +190,42 @@ class TestGemUninstaller < Gem::InstallerTestCase
end
def test_uninstall_user
- uninstaller = Gem::Uninstaller.new @user_spec.name, :executables => true,
- :user_install => true
gem_dir = File.join Gem.user_dir, 'gems', @user_spec.full_name
Gem.pre_uninstall do
- assert File.exist?(gem_dir), 'gem_dir should exist'
end
Gem.post_uninstall do
- refute File.exist?(gem_dir), 'gem_dir should not exist'
end
uninstaller.uninstall
- refute File.exist?(gem_dir)
assert_same uninstaller, @pre_uninstall_hook_arg
assert_same uninstaller, @post_uninstall_hook_arg
end
-end
@@ -46,10 +46,9 @@ class TestKernel < Gem::TestCase
gem 'a', '= 2'
end
- assert_match(/activate a \(= 2\)/, ex.message)
assert_match(/activated a-1/, ex.message)
assert_equal 'a', ex.name
- assert_equal Gem::Requirement.new('= 2'), ex.requirement
assert $:.any? { |p| %r{a-1/lib} =~ p }
refute $:.any? { |p| %r{a-2/lib} =~ p }