diff options
author | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-11-25 19:14:49 +0000 |
---|---|---|
committer | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-11-25 19:14:49 +0000 |
commit | 04817ae6d3e1d898d6fbf09ad146850d26d2b404 (patch) | |
tree | 7e5482d13830cacf363d21a087b490588a960095 | |
parent | c107372597586e1ad0fea03c00a14bdd7205b5d8 (diff) |
* lib/rubygems: Update to RubyGems master 612f85a. Notable changes:
Fixed installation and activation of git: and path: gems via
Gem.use_gemdeps
Improved documentation coverage
* test/rubygems: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43845 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
38 files changed, 586 insertions, 87 deletions
@@ -1,3 +1,14 @@ +Tue Nov 26 04:12:10 2013 Eric Hodel <[email protected]> + + * lib/rubygems: Update to RubyGems master 612f85a. Notable changes: + + Fixed installation and activation of git: and path: gems via + Gem.use_gemdeps + + Improved documentation coverage + + * test/rubygems: ditto. + Mon Nov 25 22:23:03 2013 Zachary Scott <[email protected]> * lib/xmlrpc.rb: [DOC] Fix link to xmlrpc4r site [Bug #9148] diff --git a/lib/rubygems.rb b/lib/rubygems.rb index 8a0d992141..7570e4ad24 100644 --- a/lib/rubygems.rb +++ b/lib/rubygems.rb @@ -1005,30 +1005,18 @@ module Gem def self.use_gemdeps return unless path = ENV['RUBYGEMS_GEMDEPS'] - path = path.dup.untaint + path = path.dup - if path == "-" - here = Dir.pwd.untaint - start = here + if path == "-" then + require 'rubygems/util' - begin - while true - path = GEM_DEP_FILES.find { |f| File.file?(f) } - - if path - path = File.join here, path - break - end + Gem::Util.traverse_parents Dir.pwd do |directory| + dep_file = GEM_DEP_FILES.find { |f| File.file?(f) } - Dir.chdir ".." + next unless dep_file - # If we're at a toplevel, stop. - return if Dir.pwd == here - - here = Dir.pwd - end - ensure - Dir.chdir start + path = File.join directory, dep_file + break end end @@ -1047,6 +1035,9 @@ module Gem end class << self + ## + # TODO remove with RubyGems 3.0 + alias detect_gemdeps use_gemdeps # :nodoc: end @@ -1218,4 +1209,5 @@ Gem::Specification.load_defaults require 'rubygems/core_ext/kernel_gem' require 'rubygems/core_ext/kernel_require' -Gem.detect_gemdeps +Gem.use_gemdeps + diff --git a/lib/rubygems/available_set.rb b/lib/rubygems/available_set.rb index 4ab4d77716..d8655afc34 100644 --- a/lib/rubygems/available_set.rb +++ b/lib/rubygems/available_set.rb @@ -127,7 +127,7 @@ class Gem::AvailableSet end match.map do |t| - Gem::Resolver::InstalledSpecification.new(self, t.spec, t.source) + Gem::Resolver::LocalSpecification.new(self, t.spec, t.source) end end diff --git a/lib/rubygems/basic_specification.rb b/lib/rubygems/basic_specification.rb index 4f96fcac3d..cfbfbdde92 100644 --- a/lib/rubygems/basic_specification.rb +++ b/lib/rubygems/basic_specification.rb @@ -9,6 +9,11 @@ class Gem::BasicSpecification attr_reader :loaded_from + ## + # Allows correct activation of git: and path: gems. + + attr_writer :full_gem_path # :nodoc: + def self.default_specifications_dir File.join(Gem.default_dir, "specifications", "default") end diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb index 214652a241..f3172752c2 100644 --- a/lib/rubygems/installer.rb +++ b/lib/rubygems/installer.rb @@ -57,6 +57,11 @@ class Gem::Installer attr_reader :options + ## + # Sets the specification for .gem-less installs. + + attr_writer :spec + @path_warning = false class << self diff --git a/lib/rubygems/installer_test_case.rb b/lib/rubygems/installer_test_case.rb index 62a468a8a2..d03e512451 100644 --- a/lib/rubygems/installer_test_case.rb +++ b/lib/rubygems/installer_test_case.rb @@ -56,11 +56,6 @@ class Gem::Installer ## # Available through requiring rubygems/installer_test_case - attr_writer :spec - - ## - # Available through requiring rubygems/installer_test_case - attr_writer :wrappers end diff --git a/lib/rubygems/request_set.rb b/lib/rubygems/request_set.rb index d91a39cb22..d6337e32d8 100644 --- a/lib/rubygems/request_set.rb +++ b/lib/rubygems/request_set.rb @@ -166,29 +166,22 @@ class Gem::RequestSet installed = [] - sorted_requests.each do |req| - if existing.find { |s| s.full_name == req.spec.full_name } - yield req, nil if block_given? - next - end + options[:install_dir] = dir + options[:only_install_dir] = true - path = req.download(dir) + sorted_requests.each do |request| + spec = request.spec - unless path then # already installed - yield req, nil if block_given? + if existing.find { |s| s.full_name == spec.full_name } then + yield request, nil if block_given? next end - options[:install_dir] = dir - options[:only_install_dir] = true - - inst = Gem::Installer.new path, options - - yield req, inst if block_given? - - inst.install + spec.install options do |installer| + yield request, installer if block_given? + end - installed << req + installed << request end installed diff --git a/lib/rubygems/resolver.rb b/lib/rubygems/resolver.rb index 828c61de01..8f11acc197 100644 --- a/lib/rubygems/resolver.rb +++ b/lib/rubygems/resolver.rb @@ -15,12 +15,25 @@ require 'net/http' class Gem::Resolver ## + # If the DEBUG_RESOLVER environment variable is set then debugging mode is + # enabled for the resolver. This will display information about the state + # of the resolver while a set of dependencies is being resolved. + + DEBUG_RESOLVER = !ENV['DEBUG_RESOLVER'].nil? + + ## # Contains all the conflicts encountered while doing resolution attr_reader :conflicts + ## + # Set to true if development dependencies should be considered. + attr_accessor :development + ## + # List of dependencies that could not be found in the configured sources. + attr_reader :missing ## @@ -57,8 +70,8 @@ class Gem::Resolver end ## - # Provide a Resolver that queries only against the already - # installed gems. + # Creates a Resolver that queries only against the already installed gems + # for the +needed+ dependencies. def self.for_current_gems needed new needed, Gem::Resolver::CurrentSet.new @@ -82,16 +95,14 @@ class Gem::Resolver @soft_missing = false end - DEBUG_RESOLVER = !ENV['DEBUG_RESOLVER'].nil? - - def explain(stage, *data) + def explain stage, *data # :nodoc: if DEBUG_RESOLVER d = data.map { |x| x.inspect }.join(", ") STDOUT.printf "%20s %s\n", stage.to_s.upcase, d end end - def explain_list(stage, data) + def explain_list stage, data # :nodoc: if DEBUG_RESOLVER STDOUT.printf "%20s (%d entries)\n", stage.to_s.upcase, data.size data.each do |d| @@ -117,7 +128,7 @@ class Gem::Resolver return spec, activation_request end - def requests s, act, reqs=nil + def requests s, act, reqs=nil # :nodoc: s.dependencies.reverse_each do |d| next if d.type == :development and not @development reqs.add Gem::Resolver::DependencyRequest.new(d, act) @@ -182,7 +193,7 @@ class Gem::Resolver return matching_platform, all end - def handle_conflict(dep, existing) + def handle_conflict(dep, existing) # :nodoc: # There is a conflict! We return the conflict object which will be seen by # the caller and be handled at the right level. @@ -252,7 +263,7 @@ class Gem::Resolver # +specs+ being a list to ActivationRequest, calculate a new list of # ActivationRequest objects. - def resolve_for needed, specs + def resolve_for needed, specs # :nodoc: # The State objects that are used to attempt the activation tree. states = [] @@ -411,5 +422,6 @@ require 'rubygems/resolver/api_specification' require 'rubygems/resolver/git_specification' require 'rubygems/resolver/index_specification' require 'rubygems/resolver/installed_specification' +require 'rubygems/resolver/local_specification' require 'rubygems/resolver/vendor_specification' diff --git a/lib/rubygems/resolver/activation_request.rb b/lib/rubygems/resolver/activation_request.rb index ca82ac408a..2d48cfa927 100644 --- a/lib/rubygems/resolver/activation_request.rb +++ b/lib/rubygems/resolver/activation_request.rb @@ -1,21 +1,33 @@ ## -# Specifies a Specification object that should be activated. -# Also contains a dependency that was used to introduce this -# activation. +# Specifies a Specification object that should be activated. Also contains a +# dependency that was used to introduce this activation. class Gem::Resolver::ActivationRequest + ## + # The parent request for this activation request. + attr_reader :request + ## + # The specification to be activated. + attr_reader :spec - def initialize spec, req, others_possible = true + ## + # Creates a new ActivationRequest that will activate +spec+. The parent + # +request+ is used to provide diagnostics in case of conflicts. + # + # +others_possible+ indicates that other specifications may also match this + # activation request. + + def initialize spec, request, others_possible = true @spec = spec - @request = req + @request = request @others_possible = others_possible end - def == other + def == other # :nodoc: case other when Gem::Specification @spec == other @@ -26,6 +38,9 @@ class Gem::Resolver::ActivationRequest end end + ## + # Downloads a gem at +path+ and returns the file path. + def download path if @spec.respond_to? :source source = @spec.source @@ -38,10 +53,16 @@ class Gem::Resolver::ActivationRequest source.download full_spec, path end + ## + # The full name of the specification to be activated. + def full_name @spec.full_name end + ## + # The Gem::Specification for this activation request. + def full_spec Gem::Specification === @spec ? @spec : @spec.spec end @@ -66,7 +87,7 @@ class Gem::Resolver::ActivationRequest end ## - # Indicates if the requested gem has already been installed. + # True if the requested gem has already been installed. def installed? case @spec @@ -81,6 +102,9 @@ class Gem::Resolver::ActivationRequest end end + ## + # The name of this activation request's specification + def name @spec.name end @@ -130,6 +154,9 @@ class Gem::Resolver::ActivationRequest end end + ## + # The version of this activation request's specification + def version @spec.version end diff --git a/lib/rubygems/resolver/api_specification.rb b/lib/rubygems/resolver/api_specification.rb index 0ab8e830c6..67052af82e 100644 --- a/lib/rubygems/resolver/api_specification.rb +++ b/lib/rubygems/resolver/api_specification.rb @@ -34,6 +34,10 @@ class Gem::Resolver::APISpecification < Gem::Resolver::Specification @dependencies == other.dependencies end + def installable_platform? # :nodoc: + Gem::Platform.match @platform + end + def pretty_print q # :nodoc: q.group 2, '[APISpecification', ']' do q.breakable diff --git a/lib/rubygems/resolver/conflict.rb b/lib/rubygems/resolver/conflict.rb index 20c6eced31..8830e8d1fb 100644 --- a/lib/rubygems/resolver/conflict.rb +++ b/lib/rubygems/resolver/conflict.rb @@ -95,7 +95,6 @@ class Gem::Resolver::Conflict path = [] while current do - spec_name = current.spec.full_name requirement = current.request.dependency.requirement path << "#{current.spec.full_name} (#{requirement})" diff --git a/lib/rubygems/resolver/dependency_request.rb b/lib/rubygems/resolver/dependency_request.rb index e63b443c62..1d51db4945 100644 --- a/lib/rubygems/resolver/dependency_request.rb +++ b/lib/rubygems/resolver/dependency_request.rb @@ -4,16 +4,26 @@ class Gem::Resolver::DependencyRequest + ## + # The wrapped Gem::Dependency + attr_reader :dependency + ## + # The request for this dependency. + attr_reader :requester - def initialize(dep, act) - @dependency = dep - @requester = act + ## + # Creates a new DependencyRequest for +dependency+ from +requester+. + # +requester may be nil if the request came from a user. + + def initialize dependency, requester + @dependency = dependency + @requester = requester end - def ==(other) + def == other # :nodoc: case other when Gem::Dependency @dependency == other @@ -24,26 +34,39 @@ class Gem::Resolver::DependencyRequest end end + ## + # Does this dependency request match +spec+ + def matches_spec?(spec) @dependency.matches_spec? spec end + ## + # The name of the gem this dependency request is requesting. + def name @dependency.name end + ## # Indicate that the request is for a gem explicitly requested by the user + def explicit? @requester.nil? end - # Indicate that the requset is for a gem requested as a dependency of another gem + ## + # Indicate that the request is for a gem requested as a dependency of + # another gem + def implicit? !explicit? end + ## # Return a String indicating who caused this request to be added (only # valid for implicit requests) + def request_context @requester ? @requester.request : "(unknown)" end @@ -59,6 +82,9 @@ class Gem::Resolver::DependencyRequest end end + ## + # The version requirement for this dependency request + def requirement @dependency.requirement end diff --git a/lib/rubygems/resolver/git_specification.rb b/lib/rubygems/resolver/git_specification.rb index ac8d4e9aeb..113e7ea9de 100644 --- a/lib/rubygems/resolver/git_specification.rb +++ b/lib/rubygems/resolver/git_specification.rb @@ -12,5 +12,24 @@ class Gem::Resolver::GitSpecification < Gem::Resolver::SpecSpecification @source == other.source end + ## + # Installing a git gem only involves building the extensions and generating + # the executables. + + def install options + require 'rubygems/installer' + + installer = Gem::Installer.new '', options + installer.spec = spec + + yield installer if block_given? + + installer.run_pre_install_hooks + installer.build_extensions + installer.run_post_build_hooks + installer.generate_bin + installer.run_post_install_hooks + end + end diff --git a/lib/rubygems/resolver/installed_specification.rb b/lib/rubygems/resolver/installed_specification.rb index 647ff7499a..a9438129fb 100644 --- a/lib/rubygems/resolver/installed_specification.rb +++ b/lib/rubygems/resolver/installed_specification.rb @@ -11,16 +11,22 @@ class Gem::Resolver::InstalledSpecification < Gem::Resolver::SpecSpecification end ## + # This is a null install as this specification is already installed. + # +options+ are ignored. + + def install options + yield nil + end + + ## # Returns +true+ if this gem is installable for the current platform. def installable_platform? # BACKCOMPAT If the file is coming out of a specified file, then we # ignore the platform. This code can be removed in RG 3.0. - if @source.kind_of? Gem::Source::SpecificFile - return true - else - Gem::Platform.match @spec.platform - end + return true if @source.kind_of? Gem::Source::SpecificFile + + super end ## diff --git a/lib/rubygems/resolver/installer_set.rb b/lib/rubygems/resolver/installer_set.rb index 73d9e39651..e35e0aabec 100644 --- a/lib/rubygems/resolver/installer_set.rb +++ b/lib/rubygems/resolver/installer_set.rb @@ -20,6 +20,9 @@ class Gem::Resolver::InstallerSet < Gem::Resolver::Set attr_accessor :ignore_installed # :nodoc: + ## + # Creates a new InstallerSet that will look for gems in +domain+. + def initialize domain @domain = domain diff --git a/lib/rubygems/resolver/local_specification.rb b/lib/rubygems/resolver/local_specification.rb new file mode 100644 index 0000000000..dcca6c736a --- /dev/null +++ b/lib/rubygems/resolver/local_specification.rb @@ -0,0 +1,16 @@ +## +# A LocalSpecification comes from a .gem file on the local filesystem. + +class Gem::Resolver::LocalSpecification < Gem::Resolver::SpecSpecification + + ## + # Returns +true+ if this gem is installable for the current platform. + + def installable_platform? + return true if @source.kind_of? Gem::Source::SpecificFile + + super + end + +end + diff --git a/lib/rubygems/resolver/requirement_list.rb b/lib/rubygems/resolver/requirement_list.rb index 04e437b2a9..fe1d77afc3 100644 --- a/lib/rubygems/resolver/requirement_list.rb +++ b/lib/rubygems/resolver/requirement_list.rb @@ -1,19 +1,28 @@ ## -# Used internally to hold the requirements being considered -# while attempting to find a proper activation set. +# The RequirementList is used to hold the requirements being considered +# while resolving a set of gems. +# +# The RequirementList acts like a queue where the oldest items are removed +# first. class Gem::Resolver::RequirementList include Enumerable + ## + # Creates a new RequirementList. + def initialize @list = [] end - def initialize_copy(other) + def initialize_copy other # :nodoc: @list = @list.dup end + ## + # Adds Resolver::DependencyRequest +req+ to this requirements list. + def add(req) @list.push req req @@ -30,14 +39,23 @@ class Gem::Resolver::RequirementList end end + ## + # Is the list empty? + def empty? @list.empty? end + ## + # Remove the oldest DependencyRequest from the list. + def remove @list.shift end + ## + # Returns the oldest five entries from the list. + def next5 @list[0,5] end diff --git a/lib/rubygems/resolver/specification.rb b/lib/rubygems/resolver/specification.rb index 7dd4c2e829..d158225474 100644 --- a/lib/rubygems/resolver/specification.rb +++ b/lib/rubygems/resolver/specification.rb @@ -56,5 +56,34 @@ class Gem::Resolver::Specification "#{@name}-#{@version}" end + ## + # Installs this specification using the Gem::Installer +options+. The + # install method yields a Gem::Installer instance, which indicates the + # gem will be installed, or +nil+, which indicates the gem is already + # installed. + + def install options + require 'rubygems/installer' + + destination = options[:install_dir] || Gem.dir + + Gem.ensure_gem_subdirectories destination + + gem = source.download spec, destination + + installer = Gem::Installer.new gem, options + + yield installer if block_given? + + installer.install + end + + ## + # Returns true if this specification is installable on this platform. + + def installable_platform? + Gem::Platform.match spec.platform + end + end diff --git a/lib/rubygems/resolver/vendor_set.rb b/lib/rubygems/resolver/vendor_set.rb index e9cbcd8303..c8826005a7 100644 --- a/lib/rubygems/resolver/vendor_set.rb +++ b/lib/rubygems/resolver/vendor_set.rb @@ -32,6 +32,8 @@ class Gem::Resolver::VendorSet < Gem::Resolver::Set raise Gem::GemNotFoundException, "unable to find #{gemspec} for gem #{name}" unless spec + spec.full_gem_path = File.expand_path directory + key = "#{spec.name}-#{spec.version}-#{spec.platform}" @specs[key] = spec diff --git a/lib/rubygems/resolver/vendor_specification.rb b/lib/rubygems/resolver/vendor_specification.rb index 24e033d084..c6a8e58d9b 100644 --- a/lib/rubygems/resolver/vendor_specification.rb +++ b/lib/rubygems/resolver/vendor_specification.rb @@ -12,5 +12,13 @@ class Gem::Resolver::VendorSpecification < Gem::Resolver::SpecSpecification @source == other.source end + ## + # This is a null install as this gem was unpacked into a directory. + # +options+ are ignored. + + def install options + yield nil + end + end diff --git a/lib/rubygems/security/trust_dir.rb b/lib/rubygems/security/trust_dir.rb index dd51308ee5..76ef89af7f 100644 --- a/lib/rubygems/security/trust_dir.rb +++ b/lib/rubygems/security/trust_dir.rb @@ -1,10 +1,26 @@ +## +# The TrustDir manages the trusted certificates for gem signature +# verification. + class Gem::Security::TrustDir + ## + # Default permissions for the trust directory and its contents + DEFAULT_PERMISSIONS = { :trust_dir => 0700, :trusted_cert => 0600, } + ## + # The directory where trusted certificates will be stored. + + attr_reader :dir + + ## + # Creates a new TrustDir using +dir+ where the directory and file + # permissions will be checked according to +permissions+ + def initialize dir, permissions = DEFAULT_PERMISSIONS @dir = dir @permissions = permissions @@ -12,8 +28,6 @@ class Gem::Security::TrustDir @digester = Gem::Security::DIGEST_ALGORITHM end - attr_reader :dir - ## # Returns the path to the trusted +certificate+ diff --git a/lib/rubygems/source/git.rb b/lib/rubygems/source/git.rb index c4f2724645..2794735c96 100644 --- a/lib/rubygems/source/git.rb +++ b/lib/rubygems/source/git.rb @@ -91,8 +91,8 @@ class Gem::Source::Git < Gem::Source success = system @git, 'reset', '--quiet', '--hard', @reference success &&= - system @git, 'submodule', 'update', - '--quiet', '--init', '--recursive', out: IO::NULL if @need_submodules + Gem::Util.silent_system @git, 'submodule', 'update', + '--quiet', '--init', '--recursive' if @need_submodules success end @@ -161,7 +161,9 @@ class Gem::Source::Git < Gem::Source file = File.basename spec_file Dir.chdir directory do - Gem::Specification.load file + spec = Gem::Specification.load file + spec.full_gem_path = File.expand_path '.' if spec + spec end end.compact end diff --git a/lib/rubygems/test_utilities.rb b/lib/rubygems/test_utilities.rb index 37f54e601e..f7943adcee 100644 --- a/lib/rubygems/test_utilities.rb +++ b/lib/rubygems/test_utilities.rb @@ -205,6 +205,10 @@ class Gem::TestCase::SpecFetcherSetup @operations << [:clear] end + ## + # Returns a Hash of created Specification full names and the corresponding + # Specification. + def created_specs created = {} @@ -271,7 +275,7 @@ class Gem::TestCase::SpecFetcherSetup end end - def setup_fetcher # :nodoc; + def setup_fetcher # :nodoc: require 'zlib' require 'socket' require 'rubygems/remote_fetcher' diff --git a/lib/rubygems/user_interaction.rb b/lib/rubygems/user_interaction.rb index 0e4449a2ec..fad29b4afd 100644 --- a/lib/rubygems/user_interaction.rb +++ b/lib/rubygems/user_interaction.rb @@ -666,6 +666,11 @@ end # STDOUT, and STDERR. class Gem::ConsoleUI < Gem::StreamUI + + ## + # The Console UI has no arguments as it defaults to reading input from + # stdin, output to stdout and warnings or errors to stderr. + def initialize super STDIN, STDOUT, STDERR, true end @@ -675,6 +680,10 @@ end # SilentUI is a UI choice that is absolutely silent. class Gem::SilentUI < Gem::StreamUI + + ## + # The SilentUI has no arguments as it does not use any stream. + def initialize reader, writer = nil, nil @@ -689,11 +698,11 @@ class Gem::SilentUI < Gem::StreamUI super reader, writer, writer, false end - def download_reporter(*args) + def download_reporter(*args) # :nodoc: SilentDownloadReporter.new(@outs, *args) end - def progress_reporter(*args) + def progress_reporter(*args) # :nodoc: SilentProgressReporter.new(@outs, *args) end end diff --git a/lib/rubygems/util.rb b/lib/rubygems/util.rb index 42663974a5..408942d398 100644 --- a/lib/rubygems/util.rb +++ b/lib/rubygems/util.rb @@ -1,4 +1,10 @@ +## +# This module contains various utility methods as module methods. + module Gem::Util + + @silent_mutex = nil + ## # Zlib::GzipReader wrapper that unzips +data+. @@ -60,4 +66,56 @@ module Gem::Util end end + ## + # Invokes system, but silences all output. + + def self.silent_system *command + require 'thread' + + @silent_mutex ||= Mutex.new + + null_device = Gem.win_platform? ? 'NUL' : '/dev/null' + + @silent_mutex.synchronize do + begin + stdout = STDOUT.dup + stderr = STDERR.dup + + STDOUT.reopen null_device, 'w' + STDERR.reopen null_device, 'w' + + return system(*command) + ensure + STDOUT.reopen stdout + STDERR.reopen stderr + end + end + end + + ## + # Enumerates the parents of +directory+. + + def self.traverse_parents directory + return enum_for __method__, directory unless block_given? + + here = File.expand_path directory + start = here + + Dir.chdir start + + begin + loop do + yield here + + Dir.chdir '..' + + return if Dir.pwd == here # toplevel + + here = Dir.pwd + end + ensure + Dir.chdir start + end + end + end diff --git a/test/rubygems/test_gem_available_set.rb b/test/rubygems/test_gem_available_set.rb index 47023b2b11..9c204d046b 100644 --- a/test/rubygems/test_gem_available_set.rb +++ b/test/rubygems/test_gem_available_set.rb @@ -22,6 +22,25 @@ class TestGemAvailableSet < Gem::TestCase assert_equal [a1], set.all_specs end + def test_find_all + a1, a1_gem = util_gem 'a', 1 + + source = Gem::Source::SpecificFile.new a1_gem + + set = Gem::AvailableSet.new + set.add a1, source + + dep = Gem::Resolver::DependencyRequest.new dep('a'), nil + + specs = set.find_all dep + + spec = specs.first + + assert_kind_of Gem::Resolver::LocalSpecification, spec + + assert_equal 'a-1', spec.full_name + end + def test_match_platform a1, _ = util_gem 'a', '1' do |g| g.platform = "something-weird-yep" diff --git a/test/rubygems/test_gem_dependency_installer.rb b/test/rubygems/test_gem_dependency_installer.rb index f8c3dd493b..5b50017e84 100644 --- a/test/rubygems/test_gem_dependency_installer.rb +++ b/test/rubygems/test_gem_dependency_installer.rb @@ -719,6 +719,9 @@ class TestGemDependencyInstaller < Gem::TestCase inst.install 'a' end + assert_equal %w[a-1], inst.installed_gems.map { |s| s.full_name }, + 'sanity check' + ENV['GEM_HOME'] = @gemhome ENV['GEM_PATH'] = [@gemhome, gemhome2].join File::PATH_SEPARATOR Gem.clear_paths diff --git a/test/rubygems/test_gem_resolver.rb b/test/rubygems/test_gem_resolver.rb index 91cf84c5fc..7383114af4 100644 --- a/test/rubygems/test_gem_resolver.rb +++ b/test/rubygems/test_gem_resolver.rb @@ -151,6 +151,7 @@ class TestGemResolver < Gem::TestCase a2_p1 = a3_p2 = nil spec_fetcher do |fetcher| + fetcher.spec 'a', 2 a2_p1 = fetcher.spec 'a', 2 do |s| s.platform = Gem::Platform.local end a3_p2 = fetcher.spec 'a', 3 do |s| s.platform = unknown end end diff --git a/test/rubygems/test_gem_resolver_api_specification.rb b/test/rubygems/test_gem_resolver_api_specification.rb index 4a94135f06..6b21a9d4d8 100644 --- a/test/rubygems/test_gem_resolver_api_specification.rb +++ b/test/rubygems/test_gem_resolver_api_specification.rb @@ -28,6 +28,42 @@ class TestGemResolverAPISpecification < Gem::TestCase assert_equal expected, spec.dependencies end + def test_installable_platform_eh + set = Gem::Resolver::APISet.new + data = { + :name => 'a', + :number => '1', + :platform => 'ruby', + :dependencies => [], + } + + a_spec = Gem::Resolver::APISpecification.new set, data + + assert a_spec.installable_platform? + + data = { + :name => 'b', + :number => '1', + :platform => 'cpu-other_platform-1', + :dependencies => [], + } + + b_spec = Gem::Resolver::APISpecification.new set, data + + refute b_spec.installable_platform? + + data = { + :name => 'c', + :number => '1', + :platform => Gem::Platform.local.to_s, + :dependencies => [], + } + + c_spec = Gem::Resolver::APISpecification.new set, data + + assert c_spec.installable_platform? + end + def test_source set = Gem::Resolver::APISet.new data = { diff --git a/test/rubygems/test_gem_resolver_git_specification.rb b/test/rubygems/test_gem_resolver_git_specification.rb index f961a7709a..d724106f08 100644 --- a/test/rubygems/test_gem_resolver_git_specification.rb +++ b/test/rubygems/test_gem_resolver_git_specification.rb @@ -32,5 +32,19 @@ class TestGemResolverGitSpecification < Gem::TestCase refute_equal g_spec_a, i_spec end + def test_install + git_gem 'a', 1 + + git_spec = Gem::Resolver::GitSpecification.new @set, @spec + + called = false + + git_spec.install({}) do |installer| + called = installer + end + + assert called + end + end diff --git a/test/rubygems/test_gem_resolver_index_specification.rb b/test/rubygems/test_gem_resolver_index_specification.rb index ef474ab2d4..e52f9c7fc6 100644 --- a/test/rubygems/test_gem_resolver_index_specification.rb +++ b/test/rubygems/test_gem_resolver_index_specification.rb @@ -29,6 +29,28 @@ class TestGemResolverIndexSpecification < Gem::TestCase assert_equal Gem::Platform.local.to_s, spec.platform end + def test_install + spec_fetcher do |fetcher| + fetcher.gem 'a', 2 + end + + set = Gem::Resolver::IndexSet.new + source = Gem::Source.new @gem_repo + + spec = Gem::Resolver::IndexSpecification.new( + set, 'a', v(2), source, Gem::Platform::RUBY) + + called = false + + spec.install({}) do |installer| + called = installer + end + + assert_path_exists File.join @gemhome, 'specifications', 'a-2.gemspec' + + assert_kind_of Gem::Installer, called + end + def test_spec specs = spec_fetcher do |fetcher| fetcher.spec 'a', 2 diff --git a/test/rubygems/test_gem_resolver_installed_specification.rb b/test/rubygems/test_gem_resolver_installed_specification.rb index f9dda29a6c..d52876f030 100644 --- a/test/rubygems/test_gem_resolver_installed_specification.rb +++ b/test/rubygems/test_gem_resolver_installed_specification.rb @@ -2,17 +2,48 @@ require 'rubygems/test_case' class TestGemResolverInstalledSpecification < Gem::TestCase - def test_initialize - set = Gem::Resolver::CurrentSet.new + def setup + super + + @set = Gem::Resolver::CurrentSet.new + end + def test_initialize source_spec = util_spec 'a' - spec = Gem::Resolver::InstalledSpecification.new set, source_spec + spec = Gem::Resolver::InstalledSpecification.new @set, source_spec assert_equal 'a', spec.name assert_equal Gem::Version.new(2), spec.version assert_equal Gem::Platform::RUBY, spec.platform end + def test_install + a = util_spec 'a' + + spec = Gem::Resolver::InstalledSpecification.new @set, a + + called = :junk + + spec.install({}) do |installer| + called = installer + end + + assert_nil called + end + + def test_installable_platform_eh + b, b_gem = util_gem 'a', 1 do |s| + s.platform = Gem::Platform.new %w[cpu other_platform 1] + end + + source = Gem::Source::SpecificFile.new b_gem + + b_spec = Gem::Resolver::InstalledSpecification.new @set, b, source + + assert b_spec.installable_platform? + end + + end diff --git a/test/rubygems/test_gem_resolver_local_specification.rb b/test/rubygems/test_gem_resolver_local_specification.rb new file mode 100644 index 0000000000..fc3175a3f7 --- /dev/null +++ b/test/rubygems/test_gem_resolver_local_specification.rb @@ -0,0 +1,45 @@ +require 'rubygems/test_case' +require 'rubygems/available_set' + +class TestGemResolverLocalSpecification < Gem::TestCase + + def setup + super + + @set = Gem::AvailableSet.new + end + + def test_install + specs = spec_fetcher do |fetcher| + fetcher.gem 'a', 2 + end + + source = Gem::Source::SpecificFile.new 'gems/a-2.gem' + + spec = Gem::Resolver::LocalSpecification.new @set, specs['a-2'], source + + called = false + + spec.install({}) do |installer| + called = installer + end + + assert_path_exists File.join @gemhome, 'specifications', 'a-2.gemspec' + + assert_kind_of Gem::Installer, called + end + + def test_installable_platform_eh + b, b_gem = util_gem 'a', 1 do |s| + s.platform = Gem::Platform.new %w[cpu other_platform 1] + end + + source = Gem::Source::SpecificFile.new b_gem + + b_spec = Gem::Resolver::InstalledSpecification.new @set, b, source + + assert b_spec.installable_platform? + end + +end + diff --git a/test/rubygems/test_gem_resolver_specification.rb b/test/rubygems/test_gem_resolver_specification.rb new file mode 100644 index 0000000000..2c9c143cee --- /dev/null +++ b/test/rubygems/test_gem_resolver_specification.rb @@ -0,0 +1,32 @@ +require 'rubygems/test_case' + +class TestGemResolverSpecification < Gem::TestCase + + class TestSpec < Gem::Resolver::Specification + attr_reader :spec + + def initialize spec + super() + + @spec = spec + end + end + + def test_installable_platform_eh + a = util_spec 'a', 1 + + a_spec = TestSpec.new a + + assert a_spec.installable_platform? + + b = util_spec 'a', 1 do |s| + s.platform = Gem::Platform.new %w[cpu other_platform 1] + end + + b_spec = TestSpec.new b + + refute b_spec.installable_platform? + end + +end + diff --git a/test/rubygems/test_gem_resolver_vendor_set.rb b/test/rubygems/test_gem_resolver_vendor_set.rb index 58519fbf14..985a10723f 100644 --- a/test/rubygems/test_gem_resolver_vendor_set.rb +++ b/test/rubygems/test_gem_resolver_vendor_set.rb @@ -16,6 +16,8 @@ class TestGemResolverVendorSet < Gem::TestCase spec = @set.load_spec name, version, Gem::Platform::RUBY, nil assert_equal "#{name}-#{version}", spec.full_name + + assert_equal File.expand_path(directory), spec.full_gem_path end def test_add_vendor_gem_missing diff --git a/test/rubygems/test_gem_resolver_vendor_specification.rb b/test/rubygems/test_gem_resolver_vendor_specification.rb index d7aca569e2..3d94cfed00 100644 --- a/test/rubygems/test_gem_resolver_vendor_specification.rb +++ b/test/rubygems/test_gem_resolver_vendor_specification.rb @@ -47,6 +47,18 @@ class TestGemResolverVendorSpecification < Gem::TestCase assert_equal 'a-1', v_spec.full_name end + def test_install + spec = Gem::Resolver::VendorSpecification.new @set, @spec + + called = :junk + + spec.install({}) do |installer| + called = installer + end + + assert_nil called + end + def test_name v_spec = Gem::Resolver::VendorSpecification.new @set, @spec diff --git a/test/rubygems/test_gem_source_git.rb b/test/rubygems/test_gem_source_git.rb index e32649c2b0..838ae562a7 100644 --- a/test/rubygems/test_gem_source_git.rb +++ b/test/rubygems/test_gem_source_git.rb @@ -25,7 +25,8 @@ class TestGemSourceGit < Gem::TestCase git_gem 'b' Dir.chdir 'git/a' do - system @git, 'submodule', '--quiet', 'add', File.expand_path('../b'), 'b', out: IO::NULL + Gem::Util.silent_system @git, 'submodule', '--quiet', + 'add', File.expand_path('../b'), 'b' system @git, 'commit', '--quiet', '-m', 'add submodule b' end @@ -161,6 +162,14 @@ class TestGemSourceGit < Gem::TestCase end assert_equal %w[a-1 b-1], specs.map { |spec| spec.full_name } + + a_spec = specs.shift + + assert_equal source.install_dir, a_spec.full_gem_path + + b_spec = specs.shift + + assert_equal File.join(source.install_dir, 'b'), b_spec.full_gem_path end def test_uri_hash diff --git a/test/rubygems/test_gem_util.rb b/test/rubygems/test_gem_util.rb index 17a19dd302..414487acc0 100644 --- a/test/rubygems/test_gem_util.rb +++ b/test/rubygems/test_gem_util.rb @@ -7,9 +7,25 @@ class TestGemUtil < Gem::TestCase assert_equal "0\n", Gem::Util.popen(Gem.ruby, '-e', 'p 0') assert_raises Errno::ECHILD do - Process.wait -1 + Process.wait(-1) end end + def test_silent_system + assert_silent do + Gem::Util.silent_system Gem.ruby, '-e', 'puts "hello"; warn "hello"' + end + end + + def test_traverse_parents + FileUtils.mkdir_p 'a/b/c' + + enum = Gem::Util.traverse_parents 'a/b/c' + + assert_equal File.join(@tempdir, 'a/b/c'), enum.next + assert_equal File.join(@tempdir, 'a/b'), enum.next + assert_equal File.join(@tempdir, 'a'), enum.next + end + end |