Upgrade to RubyGems 1.2.0 r1824. Incorporates [ruby-core:17353].

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17576 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
drbrain 2008-06-26 02:06:00 +00:00
Родитель dbf3fb3d8e
Коммит 8b424513fd
29 изменённых файлов: 515 добавлений и 240 удалений

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

@ -1,3 +1,8 @@
Thu Jun 26 11:04:30 2008 Eric Hodel <drbrain@segment7.net>
* lib/rubygems: Update to RubyGems 1.2.0 r1824. Incorporates patch by
Yusuke ENDOH [ruby-core:17353].
Thu Jun 26 00:48:31 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
* parse.y (primary): not operand might be empty. [ruby-dev:35227]

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

@ -208,17 +208,18 @@ 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) && gem.respond_to?(:version_requirements)
gem = Gem::Dependency.new(gem, requirements)
unless gem.respond_to?(:name) and
gem.respond_to?(:version_requirements) then
gem = Gem::Dependency.new gem, requirements
end
!Gem.source_index.search(gem).empty?
end
##
# The mode needed to read a file as straight binary.
@ -649,6 +650,7 @@ module Gem
@gem_path << Gem.dir
else
# TODO: should this be Gem.default_path instead?
@gem_path = [Gem.dir]
end

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

@ -50,11 +50,7 @@ class Gem::Commands::InstallCommand < Gem::Command
installed_gems = []
if options[:install_dir].nil? and RUBY_VERSION > '1.9' then
ENV.delete 'GEM_PATH'
else
ENV['GEM_PATH'] = options[:install_dir] # HACK what does this do?
end
ENV.delete 'GEM_PATH' if options[:install_dir].nil? and RUBY_VERSION > '1.9'
install_options = {
:env_shebang => options[:env_shebang],

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

@ -18,6 +18,18 @@ class Gem::ConfigFile
DEFAULT_VERBOSITY = true
DEFAULT_UPDATE_SOURCES = true
##
# For Ruby packagers to set configuration defaults. Set in
# rubygems/defaults/operating_system.rb
OPERATING_SYSTEM_DEFAULTS = {}
##
# For Ruby implementers to set configuration defaults. Set in
# rubygems/defaults/#{RUBY_ENGINE}.rb
PLATFORM_DEFAULTS = {}
system_config_path =
begin
require 'Win32API'
@ -98,8 +110,14 @@ class Gem::ConfigFile
@verbose = DEFAULT_VERBOSITY
@update_sources = DEFAULT_UPDATE_SOURCES
@hash = load_file(SYSTEM_WIDE_CONFIG_FILE)
@hash.merge!(load_file(config_file_name.dup.untaint))
operating_system_config = Marshal.load Marshal.dump(OPERATING_SYSTEM_DEFAULTS)
platform_config = Marshal.load Marshal.dump(PLATFORM_DEFAULTS)
system_config = load_file SYSTEM_WIDE_CONFIG_FILE
user_config = load_file config_file_name.dup.untaint
@hash = operating_system_config.merge platform_config
@hash = @hash.merge system_config
@hash = @hash.merge user_config
# HACK these override command-line args, which is bad
@backtrace = @hash[:backtrace] if @hash.key? :backtrace

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

@ -19,9 +19,9 @@ module Gem
end
end
# Default gem path.
# Default gem load path.
def self.default_path
default_dir
[File.join(ENV['HOME'], '.gem'), default_dir]
end
# Deduce Ruby's --program-prefix and --program-suffix from its install name.

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

@ -133,7 +133,9 @@ class Gem::DependencyInstaller
deps.each do |dep|
results = find_gems_with_sources(dep).reverse
results.reject! do
results.reject! do |dep_spec,|
to_do.push dep_spec
@source_index.any? do |_, installed_spec|
dep.name == installed_spec.name and
dep.version_requirements.satisfied_by? installed_spec.version
@ -144,7 +146,6 @@ class Gem::DependencyInstaller
next if seen[dep_spec.name]
@specs_and_sources << [dep_spec, source_uri]
dependency_list.add dep_spec
to_do.push dep_spec
end
end
end

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

@ -16,7 +16,7 @@ class Gem::Ext::RakeBuilder < Gem::Ext::Builder
end
cmd = ENV['rake'] || 'rake'
cmd << " RUBYARCHDIR=#{dest_path} RUBYLIBDIR=#{dest_path}"
cmd += " RUBYARCHDIR=#{dest_path} RUBYLIBDIR=#{dest_path}" # ENV is frozen
run cmd, results

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

@ -116,7 +116,7 @@ class Gem::Indexer
open @specs_index, 'wb' do |io|
specs = index.sort.map do |_, spec|
platform = spec.original_platform
platform = Gem::Platform::RUBY if platform.nil?
platform = Gem::Platform::RUBY if platform.nil? or platform.empty?
[spec.name, spec.version, platform]
end
@ -129,7 +129,9 @@ class Gem::Indexer
open @latest_specs_index, 'wb' do |io|
specs = index.latest_specs.sort.map do |spec|
[spec.name, spec.version, spec.original_platform]
platform = spec.original_platform
platform = Gem::Platform::RUBY if platform.nil? or platform.empty?
[spec.name, spec.version, platform]
end
specs = compact_specs specs
@ -283,10 +285,7 @@ class Gem::Indexer
# Builds and installs indexicies.
def generate_index
FileUtils.rm_rf @directory
FileUtils.mkdir_p @directory, :mode => 0700
FileUtils.mkdir_p @quick_marshal_dir
make_temp_directories
index = collect_specs
build_indicies index
install_indicies
@ -317,10 +316,20 @@ 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
FileUtils.mv src_name, @dest_directory, :verbose => verbose,
:force => true
end
end
##
# Make directories for index generation
def make_temp_directories
FileUtils.rm_rf @directory
FileUtils.mkdir_p @directory, :mode => 0700
FileUtils.mkdir_p @quick_marshal_dir
end
##
# Ensure +path+ and path with +extension+ are identical.
@ -343,6 +352,7 @@ class Gem::Indexer
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

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

@ -90,6 +90,13 @@ module Gem::InstallUpdateOptions
options[:format_executable] = value
end
add_option(:"Install/Update", '--[no-]user-install',
'Install in user\'s home directory instead',
'of GEM_HOME. Defaults to using home directory',
'only if GEM_HOME is not writable.') do |value, options|
options[:user_install] = value
end
add_option(:"Install/Update", "--development",
"Install any additional development",
"dependencies") do |value, options|

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

@ -85,6 +85,32 @@ class Gem::Installer
raise Gem::InstallError, "invalid gem format for #{@gem}"
end
if not File.writable? @gem_home or
# TODO: Shouldn't have to test for existence of bindir; tests need it.
(@gem_home.to_s == Gem.dir and File.exist? Gem.bindir and
not File.writable? Gem.bindir)
if options[:user_install] == false # You explicitly don't want to use ~
raise Gem::FilePermissionError, @gem_home
elsif options[:user_install].nil?
say "Warning: falling back to user-level install since #{@gem_home} and #{@bin_dir} aren't both writable."
end
options[:user_install] = true
end
if options[:user_install]
@gem_home = File.join(ENV['HOME'], '.gem')
user_bin_dir = File.join(@gem_home, 'gems', 'bin')
if !ENV['PATH'].split(':').include?(user_bin_dir)
say "You don't have #{user_bin_dir} in your PATH."
say "You won't be able to run gem-installed executables until you add it."
end
Dir.mkdir @gem_home if ! File.directory? @gem_home
# If it's still not writable, you've got issues.
raise Gem::FilePermissionError, @gem_home if ! File.writable? @gem_home
end
@spec = @format.spec
@gem_dir = File.join(@gem_home, "gems", @spec.full_name).untaint
@ -132,7 +158,6 @@ class Gem::Installer
end
FileUtils.mkdir_p @gem_home unless File.directory? @gem_home
raise Gem::FilePermissionError, @gem_home unless File.writable? @gem_home
Gem.ensure_gem_subdirectories @gem_home
@ -206,6 +231,7 @@ class Gem::Installer
file_name = File.join @gem_home, 'specifications',
"#{@spec.full_name}.gemspec"
file_name.untaint
File.open(file_name, "w") do |file|

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

@ -1,5 +1,6 @@
require 'net/http'
require 'stringio'
require 'time'
require 'uri'
require 'rubygems'
@ -74,7 +75,12 @@ class Gem::RemoteFetcher
# always replaced.
def download(spec, source_uri, install_dir = Gem.dir)
cache_dir = File.join install_dir, 'cache'
if File.writable?(install_dir)
cache_dir = File.join install_dir, 'cache'
else
cache_dir = File.join(ENV['HOME'], '.gem', 'cache')
end
gem_file_name = "#{spec.full_name}.gem"
local_gem_path = File.join cache_dir, gem_file_name
@ -132,49 +138,27 @@ class Gem::RemoteFetcher
##
# Downloads +uri+ and returns it as a String.
def fetch_path(uri)
open_uri_or_path(uri) do |input|
input.read
end
def fetch_path(uri, mtime = nil, head = false)
data = open_uri_or_path(uri, mtime, head)
data = Gem.gunzip data if uri.to_s =~ /gz$/ and not head
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)
rescue => e
raise FetchError.new("#{e.class}: #{e}", uri)
end
##
# Returns the size of +uri+ in bytes.
def fetch_size(uri)
return File.size(get_file_uri_path(uri)) if file_uri? uri
def fetch_size(uri) # TODO: phase this out
response = fetch_path(uri, nil, true)
uri = URI.parse uri unless URI::Generic === uri
raise ArgumentError, 'uri is not an HTTP URI' unless URI::HTTP === uri
response = request uri, Net::HTTP::Head
if response.code !~ /^2/ then
raise FetchError.new("bad response #{response.message} #{response.code}", uri)
end
if response['content-length'] then
return response['content-length'].to_i
else
response = http.get uri.request_uri
return response.body.size
end
rescue SocketError, SystemCallError, Timeout::Error => e
raise FetchError.new("#{e.message} (#{e.class})\n\tfetching size", uri)
response['content-length'].to_i
end
private
def escape(str)
return unless str
URI.escape(str)
@ -245,24 +229,26 @@ class Gem::RemoteFetcher
# Read the data from the (source based) URI, but if it is a file:// URI,
# read from the filesystem instead.
def open_uri_or_path(uri, depth = 0, &block)
if file_uri?(uri)
open(get_file_uri_path(uri), &block)
def open_uri_or_path(uri, last_modified = nil, head = false, depth = 0)
raise "block is dead" if block_given?
return open(get_file_uri_path(uri)) if file_uri? uri
uri = URI.parse uri unless URI::Generic === uri
raise ArgumentError, 'uri is not an HTTP URI' unless URI::HTTP === uri
fetch_type = head ? Net::HTTP::Head : Net::HTTP::Get
response = request uri, fetch_type, last_modified
case response
when Net::HTTPOK then
head ? response : response.body
when Net::HTTPRedirection then
raise FetchError.new('too many redirects', uri) if depth > 10
open_uri_or_path(response['Location'], last_modified, head, depth + 1)
else
uri = URI.parse uri unless URI::Generic === uri
response = request uri
case response
when Net::HTTPOK then
block.call(StringIO.new(response.body)) if block
when Net::HTTPRedirection then
raise FetchError.new('too many redirects', uri) if depth > 10
open_uri_or_path(response['Location'], depth + 1, &block)
else
raise FetchError.new("bad response #{response.message} #{response.code}", uri)
end
raise FetchError.new("bad response #{response.message} #{response.code}", uri)
end
end
@ -271,7 +257,7 @@ class Gem::RemoteFetcher
# a Net::HTTP response object. request maintains a table of persistent
# connections to reduce connect overhead.
def request(uri, request_class = Net::HTTP::Get)
def request(uri, request_class, last_modified = nil)
request = request_class.new uri.request_uri
unless uri.nil? || uri.user.nil? || uri.user.empty? then
@ -287,9 +273,14 @@ class Gem::RemoteFetcher
request.add_field 'Connection', 'keep-alive'
request.add_field 'Keep-Alive', '30'
if last_modified then
request.add_field 'If-Modified-Since', last_modified.rfc2822
end
connection = connection_for uri
retried = false
bad_response = false
# HACK work around EOFError bug in Net::HTTP
# NOTE Errno::ECONNABORTED raised a lot on Windows, and make impossible
@ -299,6 +290,13 @@ class Gem::RemoteFetcher
response = connection.request request
say "#{request.method} #{response.code} #{response.message}: #{uri}" if
Gem.configuration.really_verbose
rescue Net::HTTPBadResponse
reset connection
raise FetchError.new('too many bad responses', uri) if bad_response
bad_response = true
retry
rescue EOFError, Errno::ECONNABORTED, Errno::ECONNRESET
requests = @requests[connection.object_id]
say "connection reset after #{requests} requests, retrying" if
@ -306,10 +304,8 @@ class Gem::RemoteFetcher
raise FetchError.new('too many connection resets', uri) if retried
@requests.delete connection.object_id
reset connection
connection.finish
connection.start
retried = true
retry
end
@ -317,6 +313,16 @@ class Gem::RemoteFetcher
response
end
##
# Resets HTTP connection +connection+.
def reset(connection)
@requests.delete connection.object_id
connection.finish
connection.start
end
##
# Checks if the provided string is a file:// URI.

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

@ -2,5 +2,5 @@
# This file is auto-generated by build scripts.
# See: rake update_version
module Gem
RubyGemsVersion = '1.1.1'
RubyGemsVersion = '1.2.0.1824'
end

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

@ -183,29 +183,23 @@ class Gem::SpecFetcher
end
def load_specs(source_uri, file)
file_name = "#{file}.#{Gem.marshal_version}.gz"
spec_path = source_uri + file_name
cache_dir = cache_dir spec_path
local_file = File.join(cache_dir, file_name).chomp '.gz'
file_name = "#{file}.#{Gem.marshal_version}"
spec_path = source_uri + "#{file_name}.gz"
cache_dir = cache_dir spec_path
local_file = File.join(cache_dir, file_name)
loaded = false
if File.exist? local_file then
local_size = File.stat(local_file).size
spec_dump = @fetcher.fetch_path spec_path, File.mtime(local_file)
remote_file = spec_path.dup
remote_file.path = remote_file.path.chomp '.gz'
remote_size = @fetcher.fetch_size remote_file
spec_dump = Gem.read_binary local_file if remote_size == local_size
end
unless spec_dump then
if spec_dump.empty? then
spec_dump = Gem.read_binary local_file
else
loaded = true
end
else
spec_dump = @fetcher.fetch_path spec_path
loaded = true
spec_dump_gz = @fetcher.fetch_path spec_path
spec_dump = Gem.gunzip spec_dump_gz
end
specs = Marshal.load spec_dump

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

@ -60,8 +60,10 @@ module Gem
# changes.
#--
# When updating this number, be sure to also update #to_ruby.
#
# NOTE RubyGems < 1.2 cannot load specification versions > 2.
CURRENT_SPECIFICATION_VERSION = 3
CURRENT_SPECIFICATION_VERSION = 2
##
# An informal list of changes to the specification. The highest-valued
@ -77,13 +79,10 @@ module Gem
'Added "required_rubygems_version"',
'Now forward-compatible with future versions',
],
3 => [
'Added dependency types',
],
}
# :stopdoc:
MARSHAL_FIELDS = { -1 => 16, 1 => 16, 2 => 16, 3 => 16 }
MARSHAL_FIELDS = { -1 => 16, 1 => 16, 2 => 16 }
now = Time.at(Time.now.to_i)
TODAY = now - ((now.to_i + now.gmt_offset) % 86400)
@ -248,10 +247,12 @@ module Gem
}
end
##
# Dump only crucial instance variables.
#
#--
# MAINTAIN ORDER!
def _dump(limit) # :nodoc:
def _dump(limit)
Marshal.dump [
@rubygems_version,
@specification_version,
@ -273,7 +274,9 @@ module Gem
]
end
##
# Load custom marshal format, re-initializing defaults as needed
def self._load(str)
array = Marshal.load str
@ -282,9 +285,15 @@ module Gem
current_version = CURRENT_SPECIFICATION_VERSION
field_count = MARSHAL_FIELDS[spec.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 field_count.nil? or array.size < field_count then
if array.size < field_count then
raise TypeError, "invalid Gem::Specification format #{array.inspect}"
end

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

@ -30,7 +30,7 @@ class Gem::FakeFetcher
@paths = []
end
def fetch_path(path)
def fetch_path path, mtime = nil
path = path.to_s
@paths << path
raise ArgumentError, 'need full URI' unless path =~ %r'^http://'
@ -40,7 +40,12 @@ class Gem::FakeFetcher
raise Gem::RemoteFetcher::FetchError.new('no data', path)
end
data.respond_to?(:call) ? data.call : data
if data.respond_to?(:call) then
data.call
else
data = Gem.gunzip data if path.to_s =~ /gz$/ unless data.empty?
data
end
end
def fetch_size(path)

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

@ -30,7 +30,7 @@ class Gem::Uninstaller
@force_executables = options[:executables]
@force_all = options[:all]
@force_ignore = options[:ignore]
@bin_dir = options[:bin_dir]
@bin_dir = options[:bin_dir]
end
##
@ -41,17 +41,17 @@ class Gem::Uninstaller
list = Gem.source_index.search(/^#{@gem}$/, @version)
if list.empty? then
raise Gem::InstallError, "Unknown gem #{@gem}-#{@version}"
raise Gem::InstallError, "Unknown gem #{@gem} #{@version}"
elsif list.size > 1 && @force_all
remove_all(list.dup)
remove_all(list.dup)
remove_executables(list.last)
elsif list.size > 1
say
elsif list.size > 1
say
gem_names = list.collect {|gem| gem.full_name} + ["All versions"]
gem_name, index =
choose_from_list("Select gem to uninstall:", gem_names)
if index == list.size
remove_all(list.dup)
remove_all(list.dup)
remove_executables(list.last)
elsif index >= 0 && index < list.size
to_remove = list[index]
@ -65,7 +65,7 @@ class Gem::Uninstaller
remove_executables(list.last)
end
end
##
# Removes installed executables and batch files (windows only) for
# +gemspec+.
@ -111,7 +111,7 @@ class Gem::Uninstaller
end
end
end
##
# Removes all gems in +list+.
#

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

@ -7,6 +7,8 @@
at_exit { $SAFE = 1 }
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'fileutils'
require 'test/unit'
require 'tmpdir'
@ -24,6 +26,10 @@ module Gem
def self.win_platform=(val)
@@win_platform = val
end
module DefaultUserInteraction
@ui = MockGemUi.new
end
end
class RubyGemTestCase < Test::Unit::TestCase

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

@ -279,16 +279,16 @@ class TestGem < RubyGemTestCase
end
def test_self_path_ENV_PATH
Gem.clear_paths
Gem.send :set_paths, nil
path_count = Gem.path.size
path_count -= 1 if defined? APPLE_GEM_HOME
Gem.clear_paths
util_ensure_gem_dirs
ENV['GEM_PATH'] = @additional.join(File::PATH_SEPARATOR)
assert_equal @additional, Gem.path[0,2]
assert_equal path_count + @additional.size, Gem.path.size
assert_equal path_count + @additional.size, Gem.path.size,
"extra path components: #{Gem.path[2..-1].inspect}"
assert_match Gem.dir, Gem.path.last
end
@ -337,6 +337,7 @@ class TestGem < RubyGemTestCase
file_name = File.expand_path __FILE__
prefix = File.dirname File.dirname(file_name)
prefix = File.dirname prefix if File.basename(prefix) == 'test'
Gem::ConfigMap[:libdir] = prefix
@ -350,6 +351,7 @@ class TestGem < RubyGemTestCase
file_name = File.expand_path __FILE__
prefix = File.dirname File.dirname(file_name)
prefix = File.dirname prefix if File.basename(prefix) == 'test'
Gem::ConfigMap[:sitelibdir] = prefix

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

@ -22,11 +22,15 @@ class TestGemConfigFile < RubyGemTestCase
Gem::ConfigFile.send :remove_const, :SYSTEM_WIDE_CONFIG_FILE
Gem::ConfigFile.send :const_set, :SYSTEM_WIDE_CONFIG_FILE,
File.join(@tempdir, 'system-gemrc')
Gem::ConfigFile::OPERATING_SYSTEM_DEFAULTS.clear
Gem::ConfigFile::PLATFORM_DEFAULTS.clear
util_config_file
end
def teardown
Gem::ConfigFile::OPERATING_SYSTEM_DEFAULTS.clear
Gem::ConfigFile::PLATFORM_DEFAULTS.clear
Gem::ConfigFile.send :remove_const, :SYSTEM_WIDE_CONFIG_FILE
Gem::ConfigFile.send :const_set, :SYSTEM_WIDE_CONFIG_FILE,
@orig_SYSTEM_WIDE_CONFIG_FILE
@ -84,6 +88,48 @@ class TestGemConfigFile < RubyGemTestCase
assert_equal @temp_conf, @cfg.config_file_name
end
def test_initialize_operating_system_override
Gem::ConfigFile::OPERATING_SYSTEM_DEFAULTS[:bulk_threshold] = 1
Gem::ConfigFile::OPERATING_SYSTEM_DEFAULTS['install'] = '--no-env-shebang'
Gem::ConfigFile::PLATFORM_DEFAULTS[:bulk_threshold] = 2
util_config_file
assert_equal 2, @cfg.bulk_threshold
assert_equal '--no-env-shebang', @cfg[:install]
end
def test_initialize_platform_override
Gem::ConfigFile::PLATFORM_DEFAULTS[:bulk_threshold] = 2
Gem::ConfigFile::PLATFORM_DEFAULTS['install'] = '--no-env-shebang'
File.open Gem::ConfigFile::SYSTEM_WIDE_CONFIG_FILE, 'w' do |fp|
fp.puts ":bulk_threshold: 3"
end
util_config_file
assert_equal 3, @cfg.bulk_threshold
assert_equal '--no-env-shebang', @cfg[:install]
end
def test_initialize_system_wide_override
File.open Gem::ConfigFile::SYSTEM_WIDE_CONFIG_FILE, 'w' do |fp|
fp.puts ":backtrace: false"
fp.puts ":bulk_threshold: 2048"
end
File.open @temp_conf, 'w' do |fp|
fp.puts ":backtrace: true"
end
util_config_file
assert_equal 2048, @cfg.bulk_threshold
assert_equal true, @cfg.backtrace
end
def test_handle_arguments
args = %w[--backtrace --bunch --of --args here]
@ -222,23 +268,6 @@ class TestGemConfigFile < RubyGemTestCase
assert_equal %w[http://even-more-gems.example.com], Gem.sources
end
def test_global_config_file
File.open(@temp_conf, 'w') do |fp|
fp.puts ":backtrace: true"
end
File.open(File.join(Gem::ConfigFile::SYSTEM_WIDE_CONFIG_FILE),
'w') do |fp|
fp.puts ":backtrace: false"
fp.puts ":bulk_threshold: 2048"
end
util_config_file
assert_equal 2048, @cfg.bulk_threshold
assert @cfg.backtrace
end
def util_config_file(args = @cfg_args)
@cfg = Gem::ConfigFile.new args
end

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

@ -66,6 +66,31 @@ class TestGemDependencyInstaller < RubyGemTestCase
assert_equal [@a1], inst.installed_gems
end
def test_install_all_dependencies
e1, e1_gem = util_gem 'e', '1' do |s|
s.add_dependency 'b'
end
util_clear_gems
FileUtils.mv @a1_gem, @tempdir
FileUtils.mv @b1_gem, @tempdir
FileUtils.mv e1_gem, @tempdir
inst = nil
Dir.chdir @tempdir do
inst = Gem::DependencyInstaller.new :ignore_dependencies => true
inst.install 'b'
end
Dir.chdir @tempdir do
inst = Gem::DependencyInstaller.new
inst.install 'e'
end
assert_equal %w[e-1 a-1], inst.installed_gems.map { |s| s.full_name }
end
def test_install_cache_dir
FileUtils.mv @a1_gem, @tempdir
FileUtils.mv @b1_gem, @tempdir

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

@ -29,12 +29,12 @@ class TestGemExtConfigureBuilder < RubyGemTestCase
Gem::Ext::ConfigureBuilder.build nil, nil, @dest_path, output
end
expected = [
"sh ./configure --prefix=#{@dest_path}",
"", "make", "ok\n", "make install", "ok\n"
]
assert_equal expected, output
assert_equal "sh ./configure --prefix=#{@dest_path}", output.shift
assert_equal "", output.shift
assert_equal "make", output.shift
assert_match(/^ok$/m, output.shift)
assert_equal "make install", output.shift
assert_match(/^ok$/m, output.shift)
end
def test_self_build_fail

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

@ -34,7 +34,7 @@ class TestGemExtRakeBuilder < RubyGemTestCase
expected = [
"#{Gem.ruby} mkrf_conf.rb",
"",
"rake RUBYARCHDIR=#{@dest_path} RUBYLIBDIR=#{@dest_path}",
"#{ENV['rake'] || 'rake'} RUBYARCHDIR=#{@dest_path} RUBYLIBDIR=#{@dest_path}",
"(in #{realdir})\n"
]
@ -63,7 +63,7 @@ rake failed:
#{Gem.ruby} mkrf_conf.rb
rake RUBYARCHDIR=#{@dest_path} RUBYLIBDIR=#{@dest_path}
#{ENV['rake'] || 'rake'} RUBYARCHDIR=#{@dest_path} RUBYLIBDIR=#{@dest_path}
EOF
assert_equal expected, error.message.split("\n")[0..4].join("\n")

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

@ -21,7 +21,6 @@ class TestGemIndexer < RubyGemTestCase
util_make_gems
@d2_0 = quick_gem 'd', '2.0'
write_file File.join(*%W[gems #{@d2_0.original_name} lib code.rb]) do end
util_build_gem @d2_0
gems = File.join(@tempdir, 'gems')
@ -38,6 +37,41 @@ class TestGemIndexer < RubyGemTestCase
@indexer.directory
end
def test_build_indicies
spec = quick_gem '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
def test_generate_index
use_ui @ui do
@indexer.generate_index

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

@ -1,20 +1,21 @@
require 'test/unit'
require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
require File.join(File.expand_path(File.dirname(__FILE__)),
'gem_installer_test_case')
require 'rubygems/install_update_options'
require 'rubygems/command'
class TestGemInstallUpdateOptions < RubyGemTestCase
class TestGemInstallUpdateOptions < GemInstallerTestCase
def setup
super
@cmd = Gem::Command.new 'dummy', 'dummy'
@cmd.extend Gem::InstallUpdateOptions
@cmd.add_install_update_options
end
def test_add_install_update_options
@cmd.add_install_update_options
args = %w[-i /install_to --rdoc --ri -E -f -t -w -P HighSecurity
--ignore-dependencies --format-exec --include-dependencies]
@ -22,8 +23,6 @@ class TestGemInstallUpdateOptions < RubyGemTestCase
end
def test_security_policy
@cmd.add_install_update_options
@cmd.handle_options %w[-P HighSecurity]
assert_equal Gem::Security::HighSecurity, @cmd.options[:security_policy]
@ -37,4 +36,26 @@ class TestGemInstallUpdateOptions < RubyGemTestCase
end
end
def test_user_install_enabled
@cmd.handle_options %w[--user-install]
@installer = Gem::Installer.new @gem, @cmd.options
@installer.install
assert File.exist?(File.join(@userhome, '.gem', 'gems'))
assert File.exist?(File.join(@userhome, '.gem', 'gems',
@spec.full_name))
end
def test_user_install_disabled_read_only
@cmd.handle_options %w[--no-user-install]
File.chmod 0755, @userhome
FileUtils.chmod 0000, @gemhome
assert_raises(Gem::FilePermissionError) do
@installer = Gem::Installer.new @gem, @cmd.options
end
ensure
FileUtils.chmod 0755, @gemhome
end
end

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

@ -515,6 +515,7 @@ load 'my_exec'
spec = quick_gem 'a' do |s| s.platform = Gem::Platform.new 'mswin32' end
gem = File.join @tempdir, "#{spec.full_name}.gem"
Dir.mkdir util_inst_bindir
util_build_gem spec
FileUtils.mv File.join(@gemhome, 'cache', "#{spec.full_name}.gem"),
@tempdir
@ -525,6 +526,7 @@ load 'my_exec'
end
def test_install
Dir.mkdir util_inst_bindir
util_setup_gem
use_ui @ui do
@ -593,6 +595,7 @@ load 'my_exec'
end
def test_install_ignore_dependencies
Dir.mkdir util_inst_bindir
@spec.add_dependency 'b', '> 5'
util_setup_gem
@installer.ignore_dependencies = true
@ -634,7 +637,44 @@ load 'my_exec'
assert File.exist?(File.join(@gemhome, 'specifications',
"#{@spec.full_name}.gemspec"))
end
unless win_platform? # File.chmod doesn't work
def test_install_user_local_fallback
Dir.mkdir util_inst_bindir
File.chmod 0755, @userhome
File.chmod 0000, util_inst_bindir
File.chmod 0000, Gem.dir
install_dir = File.join @userhome, '.gem', 'gems', @spec.full_name
@spec.executables = ["executable"]
use_ui @ui do
util_setup_gem
@installer.install
end
assert File.exist?(File.join(install_dir, 'lib', 'code.rb'))
assert File.exist?(File.join(@userhome, '.gem', 'bin', 'executable'))
ensure
File.chmod 0755, Gem.dir
File.chmod 0755, util_inst_bindir
end
def test_install_bindir_read_only
Dir.mkdir util_inst_bindir
File.chmod 0755, @userhome
File.chmod 0000, util_inst_bindir
use_ui @ui do
setup
util_setup_gem
@installer.install
end
assert File.exist?(File.join(@userhome, '.gem', 'bin', 'executable'))
ensure
File.chmod 0755, util_inst_bindir
end
end
def test_install_with_message
@spec.post_install_message = 'I am a shiny gem!'
@ -647,22 +687,6 @@ load 'my_exec'
assert_match %r|I am a shiny gem!|, @ui.output
end
def test_install_writable
util_setup_gem
orig_mode = File.stat(Gem.dir).mode
File.chmod 0000, Gem.dir
e = assert_raise Gem::FilePermissionError do
@installer.install
end
assert_equal "You don't have write permissions into the #{@gemhome} directory.",
e.message
ensure
File.chmod orig_mode, Gem.dir
end
def test_install_wrong_ruby_version
use_ui @ui do
installer = Gem::Installer.new old_ruby_required

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

@ -1,40 +0,0 @@
require 'test/unit'
require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
require 'rubygems/commands/outdated_command'
class TestGemOutdatedCommand < RubyGemTestCase
def setup
super
@cmd = Gem::Commands::OutdatedCommand.new
end
def test_initialize
assert @cmd.handles?(%W[--platform #{Gem::Platform.local}])
end
def test_execute
local_01 = quick_gem 'foo', '0.1'
local_02 = quick_gem 'foo', '0.2'
remote_10 = quick_gem 'foo', '1.0'
remote_20 = quick_gem 'foo', '2.0'
remote_spec_file = File.join @gemhome, 'specifications',
remote_10.full_name + ".gemspec"
FileUtils.rm remote_spec_file
remote_spec_file = File.join @gemhome, 'specifications',
remote_20.full_name + ".gemspec"
FileUtils.rm remote_spec_file
util_setup_source_info_cache 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

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

@ -10,6 +10,7 @@ require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
require 'webrick'
require 'zlib'
require 'rubygems/remote_fetcher'
require 'ostruct'
# = Testing Proxy Settings
#
@ -106,6 +107,8 @@ gems:
@a1, @a1_gem = util_gem 'a', '1' do |s| s.executables << 'a_bin' end
Gem::RemoteFetcher.fetcher = nil
@fetcher = Gem::RemoteFetcher.fetcher
end
def test_self_fetcher
@ -117,7 +120,10 @@ gems:
def test_self_fetcher_with_proxy
proxy_uri = 'http://proxy.example.com'
Gem.configuration[:http_proxy] = proxy_uri
Gem::RemoteFetcher.fetcher = nil
fetcher = Gem::RemoteFetcher.fetcher
assert_not_nil fetcher
assert_kind_of Gem::RemoteFetcher, fetcher
assert_equal proxy_uri, fetcher.instance_variable_get(:@proxy_uri).to_s
@ -145,7 +151,7 @@ gems:
def test_fetch_size_socket_error
fetcher = Gem::RemoteFetcher.new nil
def fetcher.connection_for(uri)
raise SocketError
raise SocketError, "tarded"
end
uri = 'http://gems.example.com/yaml'
@ -153,15 +159,13 @@ gems:
fetcher.fetch_size uri
end
assert_equal "SocketError (SocketError)\n\tfetching size (#{uri})",
e.message
assert_equal "SocketError: tarded (#{uri})", e.message
end
def test_no_proxy
use_ui @ui do
fetcher = Gem::RemoteFetcher.new nil
assert_data_from_server fetcher.fetch_path(@server_uri)
assert_equal SERVER_DATA.size, fetcher.fetch_size(@server_uri)
assert_data_from_server @fetcher.fetch_path(@server_uri)
assert_equal SERVER_DATA.size, @fetcher.fetch_size(@server_uri)
end
end
@ -238,6 +242,7 @@ gems:
install_dir = File.join @tempdir, 'more_gems'
a1_cache_gem = File.join install_dir, 'cache', "#{@a1.full_name}.gem"
FileUtils.mkdir_p(File.dirname(a1_cache_gem))
actual = fetcher.download(@a1, 'http://gems.example.com', install_dir)
assert_equal a1_cache_gem, actual
@ -247,7 +252,7 @@ gems:
assert File.exist?(a1_cache_gem)
end
unless win_platform? then # File.chmod doesn't work
unless win_platform? # File.chmod doesn't work
def test_download_local_read_only
FileUtils.mv @a1_gem, @tempdir
local_path = File.join @tempdir, "#{@a1.full_name}.gem"
@ -263,6 +268,19 @@ gems:
ensure
File.chmod 0755, File.join(@gemhome, 'cache')
end
def test_download_read_only
File.chmod 0555, File.join(@gemhome, 'cache')
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?(File.join(@userhome, '.gem',
'cache', "#{@a1.full_name}.gem"))
ensure
File.chmod 0755, File.join(@gemhome)
File.chmod 0755, File.join(@gemhome, 'cache')
end
end
def test_download_platform_legacy
@ -363,10 +381,22 @@ gems:
end
end
def test_fetch_path_gzip
fetcher = Gem::RemoteFetcher.new nil
def fetcher.open_uri_or_path(uri, mtime, head = nil)
Gem.gzip 'foo'
end
assert_equal 'foo', fetcher.fetch_path(@uri + 'foo.gz')
end
def test_fetch_path_io_error
fetcher = Gem::RemoteFetcher.new nil
def fetcher.open_uri_or_path(uri) raise EOFError; end
def fetcher.open_uri_or_path(uri, mtime, head = nil)
raise EOFError
end
e = assert_raise Gem::RemoteFetcher::FetchError do
fetcher.fetch_path 'uri'
@ -379,7 +409,9 @@ gems:
def test_fetch_path_socket_error
fetcher = Gem::RemoteFetcher.new nil
def fetcher.open_uri_or_path(uri) raise SocketError; end
def fetcher.open_uri_or_path(uri, mtime, head = nil)
raise SocketError
end
e = assert_raise Gem::RemoteFetcher::FetchError do
fetcher.fetch_path 'uri'
@ -392,7 +424,7 @@ gems:
def test_fetch_path_system_call_error
fetcher = Gem::RemoteFetcher.new nil
def fetcher.open_uri_or_path(uri);
def fetcher.open_uri_or_path(uri, mtime = nil, head = nil)
raise Errno::ECONNREFUSED, 'connect(2)'
end
@ -405,6 +437,16 @@ gems:
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)
''
end
assert_equal '', fetcher.fetch_path(URI.parse(@gem_repo), Time.at(0))
end
def test_get_proxy_from_env_empty
orig_env_HTTP_PROXY = ENV['HTTP_PROXY']
orig_env_http_proxy = ENV['http_proxy']
@ -475,9 +517,9 @@ gems:
conn = { 'gems.example.com:80' => conn }
fetcher.instance_variable_set :@connections, conn
fetcher.send :open_uri_or_path, 'http://gems.example.com/redirect' do |io|
assert_equal 'real_path', io.read
end
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
@ -495,29 +537,43 @@ gems:
fetcher.instance_variable_set :@connections, conn
e = assert_raise Gem::RemoteFetcher::FetchError do
fetcher.send :open_uri_or_path, 'http://gems.example.com/redirect'
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_zip
use_ui @ui do
self.class.enable_zip = true
fetcher = Gem::RemoteFetcher.new nil
assert_equal SERVER_DATA.size, fetcher.fetch_size(@server_uri), "probably not from proxy"
zip_data = fetcher.fetch_path(@server_z_uri)
assert zip_data.size < SERVER_DATA.size, "Zipped data should be smaller"
end
def test_request
uri = URI.parse "#{@gem_repo}/specs.#{Gem.marshal_version}"
util_stub_connection_for :body => :junk, :code => 200
response = @fetcher.request uri, Net::HTTP::Get
assert_equal 200, response.code
assert_equal :junk, response.body
end
def test_no_zip
use_ui @ui do
self.class.enable_zip = false
fetcher = Gem::RemoteFetcher.new nil
assert_error { fetcher.fetch_path(@server_z_uri) }
end
def test_request_head
uri = URI.parse "#{@gem_repo}/specs.#{Gem.marshal_version}"
util_stub_connection_for :body => '', :code => 200
response = @fetcher.request uri, Net::HTTP::Head
assert_equal 200, response.code
assert_equal '', response.body
end
def test_request_unmodifed
uri = URI.parse "#{@gem_repo}/specs.#{Gem.marshal_version}"
conn = util_stub_connection_for :body => '', :code => 304
t = Time.now
response = @fetcher.request uri, Net::HTTP::Head, t
assert_equal 304, response.code
assert_equal '', response.body
assert_equal t.rfc2822, conn.payload['if-modified-since']
end
def test_yaml_error_on_size
@ -528,7 +584,17 @@ gems:
end
end
private
def util_stub_connection_for hash
def @fetcher.connection= conn
@conn = conn
end
def @fetcher.connection_for uri
@conn
end
@fetcher.connection = Conn.new OpenStruct.new(hash)
end
def assert_error(exception_class=Exception)
got_exception = false
@ -548,6 +614,20 @@ gems:
assert_block("Data is not from proxy") { data =~ /0\.4\.2/ }
end
class Conn
attr_accessor :payload
def initialize(response)
@response = response
self.payload = nil
end
def request(req)
self.payload = req
@response
end
end
class NilLog < WEBrick::Log
def log(level, data) #Do nothing
end

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

@ -280,7 +280,7 @@ RubyGems will revert to legacy indexes degrading performance.
end
def test_load_specs_cached
@fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz"] = nil
@fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz"] = ''
@fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}"] =
' ' * Marshal.dump(@latest_specs).length
@ -294,9 +294,9 @@ RubyGems will revert to legacy indexes degrading performance.
Marshal.dump @latest_specs, io
end
specs = @sf.load_specs @uri, 'specs'
latest_specs = @sf.load_specs @uri, 'latest_specs'
assert_equal @specs, specs
assert_equal @latest_specs, latest_specs
end
end

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

@ -71,6 +71,8 @@ end
File.open File.join(@tempdir, 'bin', 'exec'), 'w' do |fp|
fp.puts "#!#{Gem.ruby}"
end
@current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
end
def test_self_attribute_names
@ -112,6 +114,19 @@ end
assert_equal expected_value, actual_value
end
def test_self__load_future
spec = Gem::Specification.new
spec.name = 'a'
spec.version = '1'
spec.specification_version = @current_version + 1
new_spec = Marshal.load Marshal.dump(spec)
assert_equal 'a', new_spec.name
assert_equal Gem::Version.new(1), new_spec.version
assert_equal @current_version, new_spec.specification_version
end
def test_self_load
spec = File.join @gemhome, 'specifications', "#{@a2.full_name}.gemspec"
gs = Gem::Specification.load spec
@ -689,7 +704,7 @@ end
if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 3
s.specification_version = 2
if current_version >= 3 then
s.add_runtime_dependency(%q<rake>, [\"> 0.4\"])