summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--lib/rubygems.rb10
-rw-r--r--lib/rubygems/basic_specification.rb74
-rw-r--r--lib/rubygems/commands/pristine_command.rb16
-rw-r--r--lib/rubygems/commands/uninstall_command.rb2
-rw-r--r--lib/rubygems/core_ext/kernel_gem.rb9
-rwxr-xr-xlib/rubygems/core_ext/kernel_require.rb2
-rw-r--r--lib/rubygems/dependency_list.rb6
-rw-r--r--lib/rubygems/ext/ext_conf_builder.rb2
-rw-r--r--lib/rubygems/installer.rb4
-rw-r--r--lib/rubygems/package/tar_writer.rb12
-rw-r--r--lib/rubygems/request_set.rb5
-rw-r--r--lib/rubygems/request_set/lockfile.rb29
-rw-r--r--lib/rubygems/resolver/api_set.rb2
-rw-r--r--lib/rubygems/resolver/api_specification.rb2
-rw-r--r--lib/rubygems/resolver/installer_set.rb2
-rw-r--r--lib/rubygems/source.rb8
-rw-r--r--lib/rubygems/specification.rb12
-rw-r--r--lib/rubygems/stub_specification.rb16
-rw-r--r--lib/rubygems/test_case.rb31
-rw-r--r--lib/rubygems/text.rb4
-rw-r--r--test/rubygems/test_gem.rb47
-rw-r--r--test/rubygems/test_gem_commands_pristine_command.rb92
-rw-r--r--test/rubygems/test_gem_package_tar_writer.rb16
-rw-r--r--test/rubygems/test_gem_request_set_lockfile.rb28
-rw-r--r--test/rubygems/test_gem_resolver_api_specification.rb4
-rw-r--r--test/rubygems/test_gem_resolver_installer_set.rb14
-rw-r--r--test/rubygems/test_gem_source.rb14
-rw-r--r--test/rubygems/test_gem_specification.rb51
-rw-r--r--test/rubygems/test_gem_stub_specification.rb10
-rw-r--r--test/rubygems/test_gem_text.rb16
-rw-r--r--test/rubygems/test_kernel.rb24
32 files changed, 462 insertions, 107 deletions
diff --git a/ChangeLog b/ChangeLog
index 9f75df1abe..e35fb24abb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sun Dec 7 09:52:30 2014 Eric Hodel <drbrain@segment7.net>
+
+ * lib/rubygems: Update to RubyGems 2.4.5.
+ * test/rubygems: ditto.
+
Sat Dec 6 10:05:08 2014 Shugo Maeda <shugo@ruby-lang.org>
* lib/net/imap.rb: Fix undefined variable usage & refactor/DRY
diff --git a/lib/rubygems.rb b/lib/rubygems.rb
index b3b430283f..05690c83f9 100644
--- a/lib/rubygems.rb
+++ b/lib/rubygems.rb
@@ -9,7 +9,7 @@ require 'rbconfig'
require 'thread'
module Gem
- VERSION = '2.4.4'
+ VERSION = '2.4.5'
end
# Must be first since it unloads the prelude from 1.9.2
@@ -232,7 +232,13 @@ module Gem
requirements = Gem::Requirement.default if
requirements.empty?
- specs = Gem::Dependency.new(name, requirements).matching_specs(true)
+ dep = Gem::Dependency.new name, requirements
+
+ loaded = Gem.loaded_specs[name]
+
+ return loaded.bin_file exec_name if loaded && dep.matches_spec?(loaded)
+
+ specs = dep.matching_specs(true)
raise Gem::GemNotFoundException,
"can't find gem #{name} (#{requirements})" if specs.empty?
diff --git a/lib/rubygems/basic_specification.rb b/lib/rubygems/basic_specification.rb
index f9eb193fb4..f5fb0f5d97 100644
--- a/lib/rubygems/basic_specification.rb
+++ b/lib/rubygems/basic_specification.rb
@@ -58,23 +58,28 @@ class Gem::BasicSpecification
# Return true if this spec can require +file+.
def contains_requirable_file? file
- if instance_variable_defined?(:@ignored) or
- instance_variable_defined?('@ignored') then
- return false
- elsif missing_extensions? then
- @ignored = true
-
- warn "Ignoring #{full_name} because its extensions are not built. " +
- "Try: gem pristine #{full_name}"
- return false
- end
-
- suffixes = Gem.suffixes
-
- full_require_paths.any? do |dir|
- base = "#{dir}/#{file}"
- suffixes.any? { |suf| File.file? "#{base}#{suf}" }
- end
+ @contains_requirable_file ||= {}
+ @contains_requirable_file[file] ||=
+ begin
+ if instance_variable_defined?(:@ignored) or
+ instance_variable_defined?('@ignored') then
+ return false
+ elsif missing_extensions? then
+ @ignored = true
+
+ warn "Ignoring #{full_name} because its extensions are not built. " +
+ "Try: gem pristine #{name} --version #{version}"
+ return false
+ end
+
+ suffixes = Gem.suffixes
+
+ full_require_paths.any? do |dir|
+ base = "#{dir}/#{file}"
+ suffixes.any? { |suf| File.file? "#{base}#{suf}" }
+ end
+ end ? :yes : :no
+ @contains_requirable_file[file] == :yes
end
def default_gem?
@@ -134,13 +139,38 @@ class Gem::BasicSpecification
# activated.
def full_require_paths
- full_paths = raw_require_paths.map do |path|
- File.join full_gem_path, path
- end
+ @full_require_paths ||=
+ begin
+ full_paths = raw_require_paths.map do |path|
+ File.join full_gem_path, path
+ end
- full_paths.unshift extension_dir unless @extensions.nil? || @extensions.empty?
+ full_paths.unshift extension_dir unless @extensions.nil? || @extensions.empty?
- full_paths
+ full_paths
+ end
+ end
+
+ ##
+ # Full path of the target library file.
+ # If the file is not in this gem, return nil.
+
+ def to_fullpath path
+ if activated? then
+ @paths_map ||= {}
+ @paths_map[path] ||=
+ begin
+ fullpath = nil
+ suffixes = Gem.suffixes
+ full_require_paths.find do |dir|
+ suffixes.find do |suf|
+ File.file?(fullpath = "#{dir}/#{path}#{suf}")
+ end
+ end ? fullpath : nil
+ end
+ else
+ nil
+ end
end
##
diff --git a/lib/rubygems/commands/pristine_command.rb b/lib/rubygems/commands/pristine_command.rb
index b54e7eac93..dcd5bb76fb 100644
--- a/lib/rubygems/commands/pristine_command.rb
+++ b/lib/rubygems/commands/pristine_command.rb
@@ -109,6 +109,11 @@ extensions will be restored.
next
end
+ if spec.bundled_gem_in_old_ruby?
+ say "Skipped #{spec.full_name}, it is bundled with old Ruby"
+ next
+ end
+
unless spec.extensions.empty? or options[:extensions] then
say "Skipped #{spec.full_name}, it needs to compile an extension"
next
@@ -120,8 +125,17 @@ extensions will be restored.
require 'rubygems/remote_fetcher'
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
+ found, _ = Gem::SpecFetcher.fetcher.spec_for_dependency dep
+
+ if found.empty?
+ say "Skipped #{spec.full_name}, it was not found from cache and remote sources"
+ next
+ end
+
+ spec_candidate, source = found.first
+ Gem::RemoteFetcher.fetcher.download spec_candidate, source.uri.to_s, spec.base_dir
end
env_shebang =
diff --git a/lib/rubygems/commands/uninstall_command.rb b/lib/rubygems/commands/uninstall_command.rb
index 71ffdc89fc..9285e57b77 100644
--- a/lib/rubygems/commands/uninstall_command.rb
+++ b/lib/rubygems/commands/uninstall_command.rb
@@ -124,7 +124,7 @@ that is a dependency of an existing gem. You can use the
end
def uninstall_all
- _, specs = Gem::Specification.partition { |spec| spec.default_gem? }
+ specs = Gem::Specification.reject { |spec| spec.default_gem? }
specs.each do |spec|
options[:version] = spec.version
diff --git a/lib/rubygems/core_ext/kernel_gem.rb b/lib/rubygems/core_ext/kernel_gem.rb
index edce4ee10b..61e77fe3c5 100644
--- a/lib/rubygems/core_ext/kernel_gem.rb
+++ b/lib/rubygems/core_ext/kernel_gem.rb
@@ -55,7 +55,14 @@ module Kernel
gem_name = gem_name.name
end
- spec = Gem::Dependency.new(gem_name, *requirements).to_spec
+ dep = Gem::Dependency.new(gem_name, *requirements)
+
+ loaded = Gem.loaded_specs[gem_name]
+
+ return false if loaded && dep.matches_spec?(loaded)
+
+ spec = dep.to_spec
+
Gem::LOADED_SPECS_MUTEX.synchronize {
spec.activate
} if spec
diff --git a/lib/rubygems/core_ext/kernel_require.rb b/lib/rubygems/core_ext/kernel_require.rb
index bf9618d3bf..8f2cddee4d 100755
--- a/lib/rubygems/core_ext/kernel_require.rb
+++ b/lib/rubygems/core_ext/kernel_require.rb
@@ -66,7 +66,7 @@ module Kernel
begin
RUBYGEMS_ACTIVATION_MONITOR.exit
- return gem_original_require(path)
+ return gem_original_require(spec.to_fullpath(path) || path)
end if spec
# Attempt to find +path+ in any unresolved gems...
diff --git a/lib/rubygems/dependency_list.rb b/lib/rubygems/dependency_list.rb
index 3e40325527..ad7a82a86e 100644
--- a/lib/rubygems/dependency_list.rb
+++ b/lib/rubygems/dependency_list.rb
@@ -219,11 +219,7 @@ class Gem::DependencyList
dependencies.each do |dep|
specs.each do |spec|
if spec.satisfies_requirement? dep then
- begin
- yield spec
- rescue TSort::Cyclic
- # do nothing
- end
+ yield spec
break
end
end
diff --git a/lib/rubygems/ext/ext_conf_builder.rb b/lib/rubygems/ext/ext_conf_builder.rb
index 213bdcb002..d11d1ac328 100644
--- a/lib/rubygems/ext/ext_conf_builder.rb
+++ b/lib/rubygems/ext/ext_conf_builder.rb
@@ -49,7 +49,7 @@ class Gem::Ext::ExtConfBuilder < Gem::Ext::Builder
FileUtils.mkdir_p lib_dir
entries = Dir.entries(tmp_dest) - %w[. ..]
entries = entries.map { |entry| File.join tmp_dest, entry }
- FileUtils.cp_r entries, lib_dir
+ FileUtils.cp_r entries, lib_dir, :remove_destination => true
end
FileEntry.new(tmp_dest).traverse do |ent|
diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb
index d497ba5c05..877cb21b7c 100644
--- a/lib/rubygems/installer.rb
+++ b/lib/rubygems/installer.rb
@@ -421,8 +421,8 @@ class Gem::Installer
next
end
- mode = File.stat(bin_path).mode | 0111
- FileUtils.chmod mode, bin_path
+ mode = File.stat(bin_path).mode
+ FileUtils.chmod mode | 0111, bin_path unless (mode | 0111) == mode
check_executable_overwrite filename
diff --git a/lib/rubygems/package/tar_writer.rb b/lib/rubygems/package/tar_writer.rb
index e1b38ad6b5..51a67ea51c 100644
--- a/lib/rubygems/package/tar_writer.rb
+++ b/lib/rubygems/package/tar_writer.rb
@@ -290,7 +290,9 @@ class Gem::Package::TarWriter
# Splits +name+ into a name and prefix that can fit in the TarHeader
def split_name(name) # :nodoc:
- raise Gem::Package::TooLongFileName if name.bytesize > 256
+ if name.bytesize > 256
+ raise Gem::Package::TooLongFileName.new("File \"#{name}\" has a too long path (should be 256 or less)")
+ end
if name.bytesize <= 100 then
prefix = ""
@@ -308,8 +310,12 @@ class Gem::Package::TarWriter
prefix = (parts + [nxt]).join "/"
name = newname
- if name.bytesize > 100 or prefix.bytesize > 155 then
- raise Gem::Package::TooLongFileName
+ if name.bytesize > 100
+ raise Gem::Package::TooLongFileName.new("File \"#{prefix}/#{name}\" has a too long name (should be 100 or less)")
+ end
+
+ if prefix.bytesize > 155 then
+ raise Gem::Package::TooLongFileName.new("File \"#{prefix}/#{name}\" has a too long base path (should be 155 or less)")
end
end
diff --git a/lib/rubygems/request_set.rb b/lib/rubygems/request_set.rb
index 57f9c39ba9..05bfcbee2c 100644
--- a/lib/rubygems/request_set.rb
+++ b/lib/rubygems/request_set.rb
@@ -403,10 +403,7 @@ class Gem::RequestSet
"Unresolved dependency found during sorting - #{dep} (requested by #{node.spec.full_name})"
end
- begin
- yield match
- rescue TSort::Cyclic
- end
+ yield match
end
end
diff --git a/lib/rubygems/request_set/lockfile.rb b/lib/rubygems/request_set/lockfile.rb
index 918aa971e5..4f2fa0933f 100644
--- a/lib/rubygems/request_set/lockfile.rb
+++ b/lib/rubygems/request_set/lockfile.rb
@@ -200,6 +200,8 @@ class Gem::RequestSet::Lockfile
platforms = @requests.map { |request| request.spec.platform }.uniq
+ platforms = platforms.sort_by { |platform| platform.to_s }
+
platforms.sort.each do |platform|
out << " #{platform}"
end
@@ -277,14 +279,7 @@ class Gem::RequestSet::Lockfile
when :bang then
get :bang
- spec = @set.sets.select { |set|
- Gem::Resolver::GitSet === set or
- Gem::Resolver::VendorSet === set
- }.map { |set|
- set.specs[name]
- }.compact.first
-
- requirements << spec.version
+ requirements << pinned_requirement(name)
when :l_paren then
get :l_paren
@@ -300,6 +295,13 @@ class Gem::RequestSet::Lockfile
end
get :r_paren
+
+ if peek[0] == :bang then
+ requirements.clear
+ requirements << pinned_requirement(name)
+
+ get :bang
+ end
end
@set.gem name, *requirements
@@ -507,6 +509,17 @@ class Gem::RequestSet::Lockfile
@tokens.first || [:EOF]
end
+ def pinned_requirement name # :nodoc:
+ spec = @set.sets.select { |set|
+ Gem::Resolver::GitSet === set or
+ Gem::Resolver::VendorSet === set
+ }.map { |set|
+ set.specs[name]
+ }.compact.first
+
+ spec.version
+ end
+
def skip type # :nodoc:
get while not @tokens.empty? and peek.first == type
end
diff --git a/lib/rubygems/resolver/api_set.rb b/lib/rubygems/resolver/api_set.rb
index dda3579878..17d602f987 100644
--- a/lib/rubygems/resolver/api_set.rb
+++ b/lib/rubygems/resolver/api_set.rb
@@ -72,7 +72,7 @@ class Gem::Resolver::APISet < Gem::Resolver::Set
@to_fetch += needed
end
- def prefetch_now
+ def prefetch_now # :nodoc:
needed, @to_fetch = @to_fetch, []
uri = @dep_uri + "?gems=#{needed.sort.join ','}"
diff --git a/lib/rubygems/resolver/api_specification.rb b/lib/rubygems/resolver/api_specification.rb
index bbd5a6427b..4960e66934 100644
--- a/lib/rubygems/resolver/api_specification.rb
+++ b/lib/rubygems/resolver/api_specification.rb
@@ -19,7 +19,7 @@ class Gem::Resolver::APISpecification < Gem::Resolver::Specification
@set = set
@name = api_data[:name]
@version = Gem::Version.new api_data[:number]
- @platform = api_data[:platform]
+ @platform = Gem::Platform.new api_data[:platform]
@dependencies = api_data[:dependencies].map do |name, ver|
Gem::Dependency.new name, ver.split(/\s*,\s*/)
end
diff --git a/lib/rubygems/resolver/installer_set.rb b/lib/rubygems/resolver/installer_set.rb
index f53b496dc7..a68ff09dbd 100644
--- a/lib/rubygems/resolver/installer_set.rb
+++ b/lib/rubygems/resolver/installer_set.rb
@@ -154,7 +154,7 @@ class Gem::Resolver::InstallerSet < Gem::Resolver::Set
end
def prefetch(reqs)
- @remote_set.prefetch(reqs)
+ @remote_set.prefetch(reqs) if consider_remote?
end
def prerelease= allow_prerelease
diff --git a/lib/rubygems/source.rb b/lib/rubygems/source.rb
index 4858ffb5ba..e5995f005f 100644
--- a/lib/rubygems/source.rb
+++ b/lib/rubygems/source.rb
@@ -26,8 +26,12 @@ class Gem::Source
# Creates a new Source which will use the index located at +uri+.
def initialize(uri)
- unless uri.kind_of? URI
- uri = URI.parse(uri.to_s)
+ begin
+ unless uri.kind_of? URI
+ uri = URI.parse(uri.to_s)
+ end
+ rescue URI::InvalidURIError
+ raise if Gem::Source == self.class
end
@uri = uri
diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb
index 87a9b603d1..8ccaa962b8 100644
--- a/lib/rubygems/specification.rb
+++ b/lib/rubygems/specification.rb
@@ -709,8 +709,6 @@ class Gem::Specification < Gem::BasicSpecification
specs = {}
Gem.loaded_specs.each_value{|s| specs[s] = true}
@@all.each{|s| s.activated = true if specs[s]}
-
- _resort!(@@all)
end
@@all
end
@@ -1479,6 +1477,16 @@ class Gem::Specification < Gem::BasicSpecification
end
##
+ # Used to detect if the gem is bundled in older version of Ruby, but not
+ # detectable as default gem (see BasicSpecification#default_gem?).
+
+ def bundled_gem_in_old_ruby?
+ !default_gem? &&
+ RUBY_VERSION < "2.0.0" &&
+ summary == "This #{name} is bundled with Ruby"
+ end
+
+ ##
# Returns the full path to the cache directory containing this
# spec's cached gem.
diff --git a/lib/rubygems/stub_specification.rb b/lib/rubygems/stub_specification.rb
index 49a6df43a3..b184d29d5e 100644
--- a/lib/rubygems/stub_specification.rb
+++ b/lib/rubygems/stub_specification.rb
@@ -42,6 +42,7 @@ class Gem::StubSpecification < Gem::BasicSpecification
self.loaded_from = filename
@data = nil
@extensions = nil
+ @name = nil
@spec = nil
end
@@ -49,8 +50,11 @@ class Gem::StubSpecification < Gem::BasicSpecification
# True when this gem has been activated
def activated?
- loaded = Gem.loaded_specs[name]
- loaded && loaded.version == version
+ @activated ||=
+ begin
+ loaded = Gem.loaded_specs[name]
+ loaded && loaded.version == version
+ end
end
def build_extensions # :nodoc:
@@ -154,9 +158,11 @@ class Gem::StubSpecification < Gem::BasicSpecification
# The full Gem::Specification for this gem, loaded from evalling its gemspec
def to_spec
- @spec ||= Gem.loaded_specs.values.find { |spec|
- spec.name == @name and spec.version == @version
- }
+ @spec ||= if @data then
+ Gem.loaded_specs.values.find { |spec|
+ spec.name == name and spec.version == version
+ }
+ end
@spec ||= Gem::Specification.load(loaded_from)
@spec.ignored = @ignored if instance_variable_defined? :@ignored
diff --git a/lib/rubygems/test_case.rb b/lib/rubygems/test_case.rb
index e9916dad61..5dc7a1b67c 100644
--- a/lib/rubygems/test_case.rb
+++ b/lib/rubygems/test_case.rb
@@ -1035,6 +1035,37 @@ Also, a list:
Zlib::Deflate.deflate data
end
+ def util_set_RUBY_VERSION(version, patchlevel = nil, revision = nil)
+ if Gem.instance_variables.include? :@ruby_version or
+ Gem.instance_variables.include? '@ruby_version' then
+ Gem.send :remove_instance_variable, :@ruby_version
+ end
+
+ @RUBY_VERSION = RUBY_VERSION
+ @RUBY_PATCHLEVEL = RUBY_PATCHLEVEL if defined?(RUBY_PATCHLEVEL)
+ @RUBY_REVISION = RUBY_REVISION if defined?(RUBY_REVISION)
+
+ Object.send :remove_const, :RUBY_VERSION
+ Object.send :remove_const, :RUBY_PATCHLEVEL if defined?(RUBY_PATCHLEVEL)
+ Object.send :remove_const, :RUBY_REVISION if defined?(RUBY_REVISION)
+
+ Object.const_set :RUBY_VERSION, version
+ Object.const_set :RUBY_PATCHLEVEL, patchlevel if patchlevel
+ Object.const_set :RUBY_REVISION, revision if revision
+ end
+
+ def util_restore_RUBY_VERSION
+ Object.send :remove_const, :RUBY_VERSION
+ Object.send :remove_const, :RUBY_PATCHLEVEL if defined?(RUBY_PATCHLEVEL)
+ Object.send :remove_const, :RUBY_REVISION if defined?(RUBY_REVISION)
+
+ Object.const_set :RUBY_VERSION, @RUBY_VERSION
+ Object.const_set :RUBY_PATCHLEVEL, @RUBY_PATCHLEVEL if
+ defined?(@RUBY_PATCHLEVEL)
+ Object.const_set :RUBY_REVISION, @RUBY_REVISION if
+ defined?(@RUBY_REVISION)
+ end
+
##
# Is this test being run on a Windows platform?
diff --git a/lib/rubygems/text.rb b/lib/rubygems/text.rb
index 8b26bebec8..5c9287ad2e 100644
--- a/lib/rubygems/text.rb
+++ b/lib/rubygems/text.rb
@@ -27,9 +27,9 @@ module Gem::Text
end
def min3 a, b, c # :nodoc:
- if a < b && a < c
+ if a < b && a < c then
a
- elsif b < a && b < c
+ elsif b < c then
b
else
c
diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb
index 0da28bb9fb..47f57abf81 100644
--- a/test/rubygems/test_gem.rb
+++ b/test/rubygems/test_gem.rb
@@ -112,6 +112,20 @@ class TestGem < Gem::TestCase
end
end
+ def test_self_bin_path_active
+ a1 = util_spec 'a', '1' do |s|
+ s.executables = ['exec']
+ end
+
+ util_spec 'a', '2' do |s|
+ s.executables = ['exec']
+ end
+
+ a1.activate
+
+ assert_match 'a-1/bin/exec', Gem.bin_path('a', 'exec', '>= 0')
+ end
+
def test_self_bin_path_no_exec_name
e = assert_raises ArgumentError do
Gem.bin_path 'a'
@@ -895,7 +909,7 @@ class TestGem < Gem::TestCase
end
expected = "Ignoring ext-1 because its extensions are not built. " +
- "Try: gem pristine ext-1\n"
+ "Try: gem pristine ext --version 1\n"
assert_equal expected, err
end
@@ -1551,37 +1565,6 @@ You may need to `gem install -g` to install missing gems
@abin_path = File.join spec.full_gem_path, spec.bindir, 'abin'
end
- def util_set_RUBY_VERSION(version, patchlevel = nil, revision = nil)
- if Gem.instance_variables.include? :@ruby_version or
- Gem.instance_variables.include? '@ruby_version' then
- Gem.send :remove_instance_variable, :@ruby_version
- end
-
- @RUBY_VERSION = RUBY_VERSION
- @RUBY_PATCHLEVEL = RUBY_PATCHLEVEL if defined?(RUBY_PATCHLEVEL)
- @RUBY_REVISION = RUBY_REVISION if defined?(RUBY_REVISION)
-
- Object.send :remove_const, :RUBY_VERSION
- Object.send :remove_const, :RUBY_PATCHLEVEL if defined?(RUBY_PATCHLEVEL)
- Object.send :remove_const, :RUBY_REVISION if defined?(RUBY_REVISION)
-
- Object.const_set :RUBY_VERSION, version
- Object.const_set :RUBY_PATCHLEVEL, patchlevel if patchlevel
- Object.const_set :RUBY_REVISION, revision if revision
- end
-
- def util_restore_RUBY_VERSION
- Object.send :remove_const, :RUBY_VERSION
- Object.send :remove_const, :RUBY_PATCHLEVEL if defined?(RUBY_PATCHLEVEL)
- Object.send :remove_const, :RUBY_REVISION if defined?(RUBY_REVISION)
-
- Object.const_set :RUBY_VERSION, @RUBY_VERSION
- Object.const_set :RUBY_PATCHLEVEL, @RUBY_PATCHLEVEL if
- defined?(@RUBY_PATCHLEVEL)
- Object.const_set :RUBY_REVISION, @RUBY_REVISION if
- defined?(@RUBY_REVISION)
- end
-
def util_remove_interrupt_command
Gem::Commands.send :remove_const, :InterruptCommand if
Gem::Commands.const_defined? :InterruptCommand
diff --git a/test/rubygems/test_gem_commands_pristine_command.rb b/test/rubygems/test_gem_commands_pristine_command.rb
index 7ea2b042c9..554d503811 100644
--- a/test/rubygems/test_gem_commands_pristine_command.rb
+++ b/test/rubygems/test_gem_commands_pristine_command.rb
@@ -287,6 +287,57 @@ class TestGemCommandsPristineCommand < Gem::TestCase
assert_empty out, out.inspect
end
+ def test_execute_missing_cache_gem_when_multi_repo
+ specs = spec_fetcher do |fetcher|
+ fetcher.gem 'a', 1
+ fetcher.gem 'b', 1
+ end
+
+ FileUtils.rm_rf File.join(@gemhome, 'gems', 'a-1')
+ FileUtils.rm_rf File.join(@gemhome, 'gems', 'b-1')
+
+ install_gem specs["a-1"]
+ FileUtils.rm File.join(@gemhome, 'cache', 'a-1.gem')
+
+ Gem.clear_paths
+ gemhome2 = File.join(@tempdir, 'gemhome2')
+ Gem.paths = { "GEM_PATH" => [gemhome2, @gemhome], "GEM_HOME" => gemhome2 }
+
+ install_gem specs["b-1"]
+ FileUtils.rm File.join(gemhome2, 'cache', 'b-1.gem')
+
+ @cmd.options[:args] = %w[a b]
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ out = @ui.output.split "\n"
+
+ [
+ "Restoring gems to pristine condition...",
+ "Cached gem for a-1 not found, attempting to fetch...",
+ "Restored a-1",
+ "Cached gem for b-1 not found, attempting to fetch...",
+ "Restored b-1",
+ ].each do |line|
+ assert_equal line, out.shift
+ end
+
+ assert_empty out, out.inspect
+ assert_empty @ui.error
+
+ assert_path_exists File.join(@gemhome, "cache", 'a-1.gem')
+ refute_path_exists File.join(gemhome2, "cache", 'a-2.gem')
+ assert_path_exists File.join(@gemhome, "gems", 'a-1')
+ refute_path_exists File.join(gemhome2, "gems", 'a-1')
+
+ assert_path_exists File.join(gemhome2, "cache", 'b-1.gem')
+ refute_path_exists File.join(@gemhome, "cache", 'b-2.gem')
+ assert_path_exists File.join(gemhome2, "gems", 'b-1')
+ refute_path_exists File.join(@gemhome, "gems", 'b-1')
+ end
+
def test_execute_no_gem
@cmd.options[:args] = %w[]
@@ -329,6 +380,24 @@ class TestGemCommandsPristineCommand < Gem::TestCase
refute File.exist? gem_lib
end
+ def test_execute_unknown_gem_at_remote_source
+ util_spec 'a'
+
+ @cmd.options[:args] = %w[a]
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ assert_equal([
+ "Restoring gems to pristine condition...",
+ "Cached gem for a-2 not found, attempting to fetch...",
+ "Skipped a-2, it was not found from cache and remote sources"
+ ], @ui.output.split("\n"))
+
+ assert_empty @ui.error
+ end
+
def test_execute_default_gem
default_gem_spec = new_default_spec("default", "2.0.0.0",
nil, "default/gem.rb")
@@ -348,6 +417,29 @@ class TestGemCommandsPristineCommand < Gem::TestCase
assert_empty(@ui.error)
end
+ def test_execute_bundled_gem_on_old_rubies
+ util_set_RUBY_VERSION '1.9.3', 551
+
+ util_spec 'bigdecimal', '1.1.0' do |s|
+ s.summary = "This bigdecimal is bundled with Ruby"
+ end
+
+ @cmd.options[:args] = %w[bigdecimal]
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ assert_equal([
+ "Restoring gems to pristine condition...",
+ "Skipped bigdecimal-1.1.0, it is bundled with old Ruby"
+ ], @ui.output.split("\n"))
+
+ assert_empty @ui.error
+ ensure
+ util_restore_RUBY_VERSION
+ end
+
def test_handle_options
@cmd.handle_options %w[]
diff --git a/test/rubygems/test_gem_package_tar_writer.rb b/test/rubygems/test_gem_package_tar_writer.rb
index 96f62b0f5d..f087df3fcf 100644
--- a/test/rubygems/test_gem_package_tar_writer.rb
+++ b/test/rubygems/test_gem_package_tar_writer.rb
@@ -224,26 +224,30 @@ class TestGemPackageTarWriter < Gem::Package::TarTestCase
name = File.join 'a', 'b' * 100
assert_equal ['b' * 100, 'a'], @tar_writer.split_name(name)
- assert_raises Gem::Package::TooLongFileName do
- name = File.join 'a', 'b' * 101
+ name = File.join 'a', 'b' * 101
+ exception = assert_raises Gem::Package::TooLongFileName do
@tar_writer.split_name name
end
+ assert_includes exception.message, name
end
def test_split_name_too_long_prefix
name = File.join 'a' * 155, 'b'
assert_equal ['b', 'a' * 155], @tar_writer.split_name(name)
- assert_raises Gem::Package::TooLongFileName do
- name = File.join 'a' * 156, 'b'
+ name = File.join 'a' * 156, 'b'
+ exception = assert_raises Gem::Package::TooLongFileName do
@tar_writer.split_name name
end
+ assert_includes exception.message, name
end
def test_split_name_too_long_total
- assert_raises Gem::Package::TooLongFileName do
- @tar_writer.split_name 'a' * 257
+ name = 'a' * 257
+ exception = assert_raises Gem::Package::TooLongFileName do
+ @tar_writer.split_name name
end
+ assert_includes exception.message, name
end
end
diff --git a/test/rubygems/test_gem_request_set_lockfile.rb b/test/rubygems/test_gem_request_set_lockfile.rb
index 1022d035fe..7c5cd5a295 100644
--- a/test/rubygems/test_gem_request_set_lockfile.rb
+++ b/test/rubygems/test_gem_request_set_lockfile.rb
@@ -303,6 +303,34 @@ DEPENDENCIES
assert_equal expected, @set.dependencies
end
+ def test_parse_DEPENDENCIES_git_version
+ write_lockfile <<-LOCKFILE
+GIT
+ remote: git://github.com/progrium/ruby-jwt.git
+ revision: 8d74770c6cd92ea234b428b5d0c1f18306a4f41c
+ specs:
+ jwt (1.1)
+
+GEM
+ remote: http://gems.example/
+ specs:
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ jwt (= 1.1)!
+ LOCKFILE
+
+ @lockfile.parse
+
+ expected = [
+ dep('jwt', '= 1.1'),
+ ]
+
+ assert_equal expected, @set.dependencies
+ end
+
def test_parse_GEM
write_lockfile <<-LOCKFILE
GEM
diff --git a/test/rubygems/test_gem_resolver_api_specification.rb b/test/rubygems/test_gem_resolver_api_specification.rb
index cfeca43453..dfa61e98a0 100644
--- a/test/rubygems/test_gem_resolver_api_specification.rb
+++ b/test/rubygems/test_gem_resolver_api_specification.rb
@@ -7,7 +7,7 @@ class TestGemResolverAPISpecification < Gem::TestCase
data = {
:name => 'rails',
:number => '3.0.3',
- :platform => 'ruby',
+ :platform => Gem::Platform.local.to_s,
:dependencies => [
['bundler', '~> 1.0'],
['railties', '= 3.0.3'],
@@ -18,7 +18,7 @@ class TestGemResolverAPISpecification < Gem::TestCase
assert_equal 'rails', spec.name
assert_equal Gem::Version.new('3.0.3'), spec.version
- assert_equal Gem::Platform::RUBY, spec.platform
+ assert_equal Gem::Platform.local, spec.platform
expected = [
Gem::Dependency.new('bundler', '~> 1.0'),
diff --git a/test/rubygems/test_gem_resolver_installer_set.rb b/test/rubygems/test_gem_resolver_installer_set.rb
index 3096a23011..d7b917b331 100644
--- a/test/rubygems/test_gem_resolver_installer_set.rb
+++ b/test/rubygems/test_gem_resolver_installer_set.rb
@@ -189,6 +189,20 @@ class TestGemResolverInstallerSet < Gem::TestCase
assert_equal specs["a-2-#{Gem::Platform.local}"].full_name, spec.full_name
end
+ def test_prefetch
+ set = Gem::Resolver::InstallerSet.new :remote
+ def (set.remote_set).prefetch(_)
+ raise "called"
+ end
+ assert_raises(RuntimeError){ set.prefetch(nil) }
+
+ set = Gem::Resolver::InstallerSet.new :local
+ def (set.remote_set).prefetch(_)
+ raise "called"
+ end
+ assert_equal nil, set.prefetch(nil)
+ end
+
def test_prerelease_equals
set = Gem::Resolver::InstallerSet.new :remote
diff --git a/test/rubygems/test_gem_source.rb b/test/rubygems/test_gem_source.rb
index 9ded7f7c03..7d23eeea5e 100644
--- a/test/rubygems/test_gem_source.rb
+++ b/test/rubygems/test_gem_source.rb
@@ -21,6 +21,20 @@ class TestGemSource < Gem::TestCase
@source = Gem::Source.new(@gem_repo)
end
+ def test_initialize_invalid_uri
+ assert_raises URI::InvalidURIError do
+ Gem::Source.new 'git@example:a.git'
+ end
+ end
+
+ def test_initialize_git
+ repository = 'git@example:a.git'
+
+ source = Gem::Source::Git.new 'a', repository, 'master', false
+
+ assert_equal repository, source.uri
+ end
+
def test_api_uri
assert_equal @source.api_uri, @source.uri
end
diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb
index dd626d9292..3cadc55d5d 100644
--- a/test/rubygems/test_gem_specification.rb
+++ b/test/rubygems/test_gem_specification.rb
@@ -1353,7 +1353,7 @@ dependencies: []
end
expected = "Ignoring ext-1 because its extensions are not built. " +
- "Try: gem pristine ext-1\n"
+ "Try: gem pristine ext --version 1\n"
assert_equal expected, err
end
@@ -1863,6 +1863,43 @@ dependencies: []
assert_equal expected, @ext.full_require_paths
end
+ def test_to_fullpath
+ ext_spec
+
+ @ext.require_paths = 'lib'
+
+ dir = File.join(@gemhome, 'gems', @ext.original_name, 'lib')
+ expected_rb = File.join(dir, 'code.rb')
+ FileUtils.mkdir_p dir
+ FileUtils.touch expected_rb
+
+ dir = @ext.extension_dir
+ ext = RbConfig::CONFIG["DLEXT"]
+ expected_so = File.join(dir, "ext.#{ext}")
+ FileUtils.mkdir_p dir
+ FileUtils.touch expected_so
+
+ assert_nil @ext.to_fullpath("code")
+ assert_nil @ext.to_fullpath("code.rb")
+ assert_nil @ext.to_fullpath("code.#{ext}")
+
+ assert_nil @ext.to_fullpath("ext")
+ assert_nil @ext.to_fullpath("ext.rb")
+ assert_nil @ext.to_fullpath("ext.#{ext}")
+
+ @ext.activate
+
+ assert_equal expected_rb, @ext.to_fullpath("code")
+ assert_equal expected_rb, @ext.to_fullpath("code.rb")
+ assert_nil @ext.to_fullpath("code.#{ext}")
+
+ assert_equal expected_so, @ext.to_fullpath("ext")
+ assert_nil @ext.to_fullpath("ext.rb")
+ assert_equal expected_so, @ext.to_fullpath("ext.#{ext}")
+
+ assert_nil @ext.to_fullpath("notexist")
+ end
+
def test_require_already_activated
save_loaded_features do
a1 = new_spec "a", "1", nil, "lib/d.rb"
@@ -3010,6 +3047,18 @@ end
assert_equal ["default-2.0.0.0"], Gem::Specification.map(&:full_name)
end
+ def test_detect_bundled_gem_in_old_ruby
+ util_set_RUBY_VERSION '1.9.3', 551
+
+ spec = new_spec 'bigdecimal', '1.1.0' do |s|
+ s.summary = "This bigdecimal is bundled with Ruby"
+ end
+
+ assert spec.bundled_gem_in_old_ruby?
+ ensure
+ util_restore_RUBY_VERSION
+ end
+
def util_setup_deps
@gem = util_spec "awesome", "1.0" do |awesome|
awesome.add_runtime_dependency "bonobo", []
diff --git a/test/rubygems/test_gem_stub_specification.rb b/test/rubygems/test_gem_stub_specification.rb
index d992567a5c..914b06a27a 100644
--- a/test/rubygems/test_gem_stub_specification.rb
+++ b/test/rubygems/test_gem_stub_specification.rb
@@ -55,7 +55,7 @@ class TestStubSpecification < Gem::TestCase
end
expected = "Ignoring stub_e-2 because its extensions are not built. " +
- "Try: gem pristine stub_e-2\n"
+ "Try: gem pristine stub_e --version 2\n"
assert_equal expected, err
end
@@ -122,6 +122,14 @@ class TestStubSpecification < Gem::TestCase
assert_same real_foo, @foo.to_spec
end
+ def test_to_spec_with_other_specs_loaded_does_not_warn
+ real_foo = util_spec @foo.name, @foo.version
+ real_foo.activate
+ bar = Gem::StubSpecification.new BAR
+ refute_predicate Gem.loaded_specs, :empty?
+ assert bar.to_spec
+ end
+
def test_to_spec_activated
assert @foo.to_spec.is_a?(Gem::Specification)
assert_equal "foo", @foo.to_spec.name
diff --git a/test/rubygems/test_gem_text.rb b/test/rubygems/test_gem_text.rb
index 7974bd4e86..e5cfc41e61 100644
--- a/test/rubygems/test_gem_text.rb
+++ b/test/rubygems/test_gem_text.rb
@@ -35,6 +35,22 @@ Without the wrapping, the text might not look good in the RSS feed.
assert_equal expected, format_text(text, 78)
end
+ def test_min3
+ assert_equal 1, min3(1, 1, 1)
+ assert_equal 1, min3(1, 1, 2)
+ assert_equal 1, min3(1, 2, 1)
+ assert_equal 1, min3(2, 1, 1)
+ assert_equal 1, min3(1, 2, 2)
+ assert_equal 1, min3(2, 1, 2)
+ assert_equal 1, min3(2, 2, 1)
+ assert_equal 1, min3(1, 2, 3)
+ assert_equal 1, min3(1, 3, 2)
+ assert_equal 1, min3(2, 1, 3)
+ assert_equal 1, min3(2, 3, 1)
+ assert_equal 1, min3(3, 1, 2)
+ assert_equal 1, min3(3, 2, 1)
+ end
+
def test_levenshtein_distance_add
assert_equal 2, levenshtein_distance("zentest", "zntst")
assert_equal 2, levenshtein_distance("zntst", "zentest")
diff --git a/test/rubygems/test_kernel.rb b/test/rubygems/test_kernel.rb
index 6d25c48bc1..ee8b248797 100644
--- a/test/rubygems/test_kernel.rb
+++ b/test/rubygems/test_kernel.rb
@@ -21,6 +21,30 @@ class TestKernel < Gem::TestCase
assert $:.any? { |p| %r{a-1/lib} =~ p }
end
+ def test_gem_default
+ assert gem('a', '>= 0')
+
+ assert_equal @a2, Gem.loaded_specs['a']
+ end
+
+ def test_gem_default_re_gem
+ assert gem('a', '=1')
+
+ refute gem('a', '>= 0')
+
+ assert_equal @a1, Gem.loaded_specs['a']
+ end
+
+ def test_gem_re_gem_mismatch
+ assert gem('a', '=1')
+
+ assert_raises Gem::LoadError do
+ gem('a', '= 2')
+ end
+
+ assert_equal @a1, Gem.loaded_specs['a']
+ end
+
def test_gem_redundant
assert gem('a', '= 1'), "Should load"
refute gem('a', '= 1'), "Should not load"