Geminstaller C0 Coverage Information - RCov

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

Name Total Lines Lines of Code Total Coverage Code Coverage
spec/fixture/rubygems_dist/rubygems-trunk/lib/rubygems/platform.rb 183 124
83.06%
75.81%

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 # Available list of platforms for targeting Gem installations.
3 
4 class Gem::Platform
5 
6   @local = nil
7 
8   attr_accessor :cpu
9 
10   attr_accessor :os
11 
12   attr_accessor :version
13 
14   def self.local
15     arch = Gem::ConfigMap[:arch]
16     arch = "#{arch}_60" if arch =~ /mswin32$/
17     @local ||= new(arch)
18   end
19 
20   def self.match(platform)
21     Gem.platforms.any? do |local_platform|
22       platform.nil? or local_platform == platform or
23         (local_platform != Gem::Platform::RUBY and local_platform =~ platform)
24     end
25   end
26 
27   def self.new(arch) # :nodoc:
28     case arch
29     when Gem::Platform::CURRENT then
30       Gem::Platform.local
31     when Gem::Platform::RUBY, nil, '' then
32       Gem::Platform::RUBY
33     else
34       super
35     end
36   end
37 
38   def initialize(arch)
39     case arch
40     when Array then
41       @cpu, @os, @version = arch
42     when String then
43       arch = arch.split '-'
44 
45       if arch.length > 2 and arch.last !~ /\d/ then # reassemble x86-linux-gnu
46         extra = arch.pop
47         arch.last << "-#{extra}"
48       end
49 
50       cpu = arch.shift
51 
52       @cpu = case cpu
53              when /i\d86/ then 'x86'
54              else cpu
55              end
56 
57       if arch.length == 2 and arch.last =~ /^\d+(\.\d+)?$/ then # for command-line
58         @os, @version = arch
59         return
60       end
61 
62       os, = arch
63       @cpu, os = nil, cpu if os.nil? # legacy jruby
64 
65       @os, @version = case os
66                       when /aix(\d+)/ then             [ 'aix',       $1  ]
67                       when /cygwin/ then               [ 'cygwin',    nil ]
68                       when /darwin(\d+)?/ then         [ 'darwin',    $1  ]
69                       when /freebsd(\d+)/ then         [ 'freebsd',   $1  ]
70                       when /hpux(\d+)/ then            [ 'hpux',      $1  ]
71                       when /^java$/, /^jruby$/ then    [ 'java',      nil ]
72                       when /^java([\d.]*)/ then        [ 'java',      $1  ]
73                       when /^dotnet$/ then             [ 'dotnet',    nil ]                       
74                       when /^dotnet([\d.]*)/ then      [ 'dotnet',    $1  ]
75                       when /linux/ then                [ 'linux',     $1  ]
76                       when /mingw32/ then              [ 'mingw32',   nil ]
77                       when /(mswin\d+)(\_(\d+))?/ then
78                         os, version = $1, $3
79                         @cpu = 'x86' if @cpu.nil? and os =~ /32$/
80                         [os, version]
81                       when /netbsdelf/ then            [ 'netbsdelf', nil ]
82                       when /openbsd(\d+\.\d+)/ then    [ 'openbsd',   $1  ]
83                       when /solaris(\d+\.\d+)/ then    [ 'solaris',   $1  ]
84                       # test
85                       when /^(\w+_platform)(\d+)/ then [ $1,          $2  ]
86                       else                             [ 'unknown',   nil ]
87                       end
88     when Gem::Platform then
89       @cpu = arch.cpu
90       @os = arch.os
91       @version = arch.version
92     else
93       raise ArgumentError, "invalid argument #{arch.inspect}"
94     end
95   end
96 
97   def inspect
98     "#<%s:0x%x @cpu=%p, @os=%p, @version=%p>" % [self.class, object_id, *to_a]
99   end
100 
101   def to_a
102     [@cpu, @os, @version]
103   end
104 
105   def to_s
106     to_a.compact.join '-'
107   end
108 
109   def empty?
110     to_s.empty?
111   end
112 
113   ##
114   # Is +other+ equal to this platform?  Two platforms are equal if they have
115   # the same CPU, OS and version.
116 
117   def ==(other)
118     self.class === other and
119       @cpu == other.cpu and @os == other.os and @version == other.version
120   end
121 
122   ##
123   # Does +other+ match this platform?  Two platforms match if they have the
124   # same CPU, or either has a CPU of 'universal', they have the same OS, and
125   # they have the same version, or either has no version.
126 
127   def ===(other)
128     return nil unless Gem::Platform === other
129 
130     # cpu
131     (@cpu == 'universal' or other.cpu == 'universal' or @cpu == other.cpu) and
132 
133     # os
134     @os == other.os and
135 
136     # version
137     (@version.nil? or other.version.nil? or @version == other.version)
138   end
139 
140   ##
141   # Does +other+ match this platform?  If +other+ is a String it will be
142   # converted to a Gem::Platform first.  See #=== for matching rules.
143 
144   def =~(other)
145     case other
146     when Gem::Platform then # nop
147     when String then
148       # This data is from http://gems.rubyforge.org/gems/yaml on 19 Aug 2007
149       other = case other
150               when /^i686-darwin(\d)/     then ['x86',       'darwin',  $1    ]
151               when /^i\d86-linux/         then ['x86',       'linux',   nil   ]
152               when 'java', 'jruby'        then [nil,         'java',    nil   ]
153               when /dotnet(\-(\d+\.\d+))?/ then ['universal','dotnet',  $2    ]
154               when /mswin32(\_(\d+))?/    then ['x86',       'mswin32', $2    ]
155               when 'powerpc-darwin'       then ['powerpc',   'darwin',  nil   ]
156               when /powerpc-darwin(\d)/   then ['powerpc',   'darwin',  $1    ]
157               when /sparc-solaris2.8/     then ['sparc',     'solaris', '2.8' ]
158               when /universal-darwin(\d)/ then ['universal', 'darwin',  $1    ]
159               else                             other
160               end
161 
162       other = Gem::Platform.new other
163     else
164       return nil
165     end
166 
167     self === other
168   end
169 
170   ##
171   # A pure-ruby gem that may use Gem::Specification#extensions to build
172   # binary files.
173 
174   RUBY = 'ruby'
175 
176   ##
177   # A platform-specific gem that is built for the packaging ruby's platform.
178   # This will be replaced with Gem::Platform::local.
179 
180   CURRENT = 'current'
181 
182 end
183 

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