Geminstaller C0 Coverage Information - RCov

spec/fixture/rubygems_dist/rubygems-trunk/lib/rubygems/dependency_list.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
spec/fixture/rubygems_dist/rubygems-trunk/lib/rubygems/dependency_list.rb 214 115
64.95%
46.09%

Key

Code reported as executed by Ruby looks like this...and this: this line is also marked as covered.Lines considered as run by rcov, but not reported by Ruby, look like this,and this: these lines were inferred by rcov (using simple heuristics).Finally, here's a line marked as not executed.

Coverage Details

1 #--
2 # Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
3 # All rights reserved.
4 # See LICENSE.txt for permissions.
5 #++
6 
7 require 'tsort'
8 
9 ##
10 # Gem::DependencyList is used for installing and uninstalling gems in the
11 # correct order to avoid conflicts.
12 
13 class Gem::DependencyList
14 
15   include Enumerable
16   include TSort
17 
18   ##
19   # Allows enabling/disabling use of development dependencies
20 
21   attr_accessor :development
22 
23   ##
24   # Creates a DependencyList from a Gem::SourceIndex +source_index+
25 
26   def self.from_source_index(source_index)
27     list = new
28 
29     source_index.each do |full_name, spec|
30       list.add spec
31     end
32 
33     list
34   end
35 
36   ##
37   # Creates a new DependencyList.  If +development+ is true, development
38   # dependencies will be included.
39 
40   def initialize development = false
41     @specs = []
42 
43     @development = development
44   end
45 
46   ##
47   # Adds +gemspecs+ to the dependency list.
48 
49   def add(*gemspecs)
50     @specs.push(*gemspecs)
51   end
52 
53   ##
54   # Return a list of the gem specifications in the dependency list, sorted in
55   # order so that no gemspec in the list depends on a gemspec earlier in the
56   # list.
57   #
58   # This is useful when removing gems from a set of installed gems.  By
59   # removing them in the returned order, you don't get into as many dependency
60   # issues.
61   #
62   # If there are circular dependencies (yuck!), then gems will be returned in
63   # order until only the circular dependents and anything they reference are
64   # left.  Then arbitrary gemspecs will be returned until the circular
65   # dependency is broken, after which gems will be returned in dependency
66   # order again.
67 
68   def dependency_order
69     sorted = strongly_connected_components.flatten
70 
71     result = []
72     seen = {}
73 
74     sorted.each do |spec|
75       if index = seen[spec.name] then
76         if result[index].version < spec.version then
77           result[index] = spec
78         end
79       else
80         seen[spec.name] = result.length
81         result << spec
82       end
83     end
84 
85     result.reverse
86   end
87 
88   ##
89   # Iterator over dependency_order
90 
91   def each(&block)
92     dependency_order.each(&block)
93   end
94 
95   def find_name(full_name)
96     @specs.find { |spec| spec.full_name == full_name }
97   end
98 
99   def inspect # :nodoc:
100     "#<%s:0x%x %p>" % [self.class, object_id, map { |s| s.full_name }]
101   end
102 
103   ##
104   # Are all the dependencies in the list satisfied?
105 
106   def ok?
107     @specs.all? do |spec|
108       spec.runtime_dependencies.all? do |dep|
109         @specs.find { |s| s.satisfies_requirement? dep }
110       end
111     end
112   end
113 
114   ##
115   # Is is ok to remove a gemspec from the dependency list?
116   #
117   # If removing the gemspec creates breaks a currently ok dependency, then it
118   # is NOT ok to remove the gemspec.
119 
120   def ok_to_remove?(full_name)
121     gem_to_remove = find_name full_name
122 
123     siblings = @specs.find_all { |s|
124       s.name == gem_to_remove.name &&
125         s.full_name != gem_to_remove.full_name
126     }
127 
128     deps = []
129 
130     @specs.each do |spec|
131       spec.dependencies.each do |dep|
132         deps << dep if gem_to_remove.satisfies_requirement?(dep)
133       end
134     end
135 
136     deps.all? { |dep|
137       siblings.any? { |s|
138         s.satisfies_requirement? dep
139       }
140     }
141   end
142 
143   ##
144   # Removes the gemspec matching +full_name+ from the dependency list
145 
146   def remove_by_name(full_name)
147     @specs.delete_if { |spec| spec.full_name == full_name }
148   end
149 
150   ##
151   # Return a hash of predecessors.  <tt>result[spec]</tt> is an Array of
152   # gemspecs that have a dependency satisfied by the named gemspec.
153 
154   def spec_predecessors
155     result = Hash.new { |h,k| h[k] = [] }
156 
157     specs = @specs.sort.reverse
158 
159     specs.each do |spec|
160       specs.each do |other|
161         next if spec == other
162 
163         other.dependencies.each do |dep|
164           if spec.satisfies_requirement? dep then
165             result[spec] << other
166           end
167         end
168       end
169     end
170 
171     result
172   end
173 
174   def tsort_each_node(&block)
175     @specs.each(&block)
176   end
177 
178   def tsort_each_child(node, &block)
179     specs = @specs.sort.reverse
180 
181     dependencies = node.runtime_dependencies
182     dependencies.push(*node.development_dependencies) if @development
183 
184     dependencies.each do |dep|
185       specs.each do |spec|
186         if spec.satisfies_requirement? dep then
187           begin
188             yield spec
189           rescue TSort::Cyclic
190           end
191           break
192         end
193       end
194     end
195   end
196 
197   private
198 
199   ##
200   # Count the number of gemspecs in the list +specs+ that are not in
201   # +ignored+.
202 
203   def active_count(specs, ignored)
204     result = 0
205 
206     specs.each do |spec|
207       result += 1 unless ignored[spec.full_name]
208     end
209 
210     result
211   end
212 
213 end
214 

Generated on Mon May 10 23:40:28 -0700 2010 with rcov 0.9.8