Skip to content
This repository
Browse code

Replace version strings with Version objects

  • Loading branch information...
commit 4affbabfb7aef915f716531ad0a39eff04ff9933 1 parent 7cfc6be
Jack Nagel authored July 10, 2012
2  Library/Formula/bash.rb
@@ -10,7 +10,7 @@ class Bash < Formula
10 10
   depends_on 'readline'
11 11
 
12 12
   def patches
13  
-    patch_level = version.split('.').last.to_i
  13
+    patch_level = version.to_s.split('.').last.to_i
14 14
     {'p0' => (1..patch_level).map { |i| "http://ftpmirror.gnu.org/bash/bash-4.2-patches/bash42-%03d" % i }}
15 15
   end
16 16
 
2  Library/Formula/lua.rb
@@ -53,7 +53,7 @@ def install
53 53
 
54 54
     # this ensures that this symlinking for lua starts at lib/lua/5.1 and not
55 55
     # below that, thus making luarocks work
56  
-    (HOMEBREW_PREFIX/"lib/lua"/version.split('.')[0..1].join('.')).mkpath
  56
+    (HOMEBREW_PREFIX/"lib/lua"/version.to_s.split('.')[0..1].join('.')).mkpath
57 57
 
58 58
     system "make", "macosx", "INSTALL_TOP=#{prefix}", "INSTALL_MAN=#{man1}"
59 59
     system "make", "install", "INSTALL_TOP=#{prefix}", "INSTALL_MAN=#{man1}"
2  Library/Formula/shapelib.rb
@@ -25,7 +25,7 @@ def install
25 25
     include.install 'shapefil.h'
26 26
 
27 27
     cd lib do
28  
-      ln_s "libshp.#{version}.dylib", "libshp.#{version.split('.').first}.dylib"
  28
+      ln_s "libshp.#{version}.dylib", "libshp.#{version.to_s.split('.').first}.dylib"
29 29
       ln_s "libshp.#{version}.dylib", "libshp.dylib"
30 30
     end
31 31
   end
2  Library/Formula/sip.rb
@@ -28,7 +28,7 @@ def install
28 28
     else
29 29
       sip_version = version
30 30
     end
31  
-    inreplace 'build.py', /@SIP_VERSION@/, (sip_version.gsub '.', ',')
  31
+    inreplace 'build.py', /@SIP_VERSION@/, (sip_version.to_s.gsub '.', ',')
32 32
 
33 33
     system "python", "build.py", "prepare"
34 34
     # Set --destdir such that the python modules will be in the HOMEBREWPREFIX/lib/pythonX.Y/site-packages
2  Library/Homebrew/cmd/diy.rb
@@ -21,7 +21,7 @@ def diy
21 21
       end
22 22
     end
23 23
 
24  
-    prefix = HOMEBREW_CELLAR+name+version
  24
+    prefix = HOMEBREW_CELLAR/name/version
25 25
 
26 26
     if File.file? 'CMakeLists.txt'
27 27
       puts "-DCMAKE_INSTALL_PREFIX=#{prefix}"
2  Library/Homebrew/cmd/versions.rb
@@ -13,7 +13,7 @@ def versions
13 13
       else
14 14
         f.versions do |version, sha|
15 15
           print Tty.white.to_s
16  
-          print "#{version.ljust(8)} "
  16
+          print "#{version.to_s.ljust(8)} "
17 17
           print Tty.reset.to_s
18 18
           puts "git checkout #{sha} #{f.pretty_relative_path}"
19 19
         end
3  Library/Homebrew/extend/pathname.rb
@@ -163,8 +163,7 @@ def abv
163 163
 
164 164
   def version
165 165
     require 'version'
166  
-    version = Version.parse(self)
167  
-    version.to_s unless version.nil?
  166
+    Version.parse(self)
168 167
   end
169 168
 
170 169
   def compression_type
4  Library/Homebrew/formula.rb
@@ -108,7 +108,7 @@ def installed_prefix
108 108
   def prefix
109 109
     validate_variable :name
110 110
     validate_variable :version
111  
-    HOMEBREW_CELLAR+@name+@version
  111
+    HOMEBREW_CELLAR/@name/@version
112 112
   end
113 113
   def rack; prefix.parent end
114 114
 
@@ -543,7 +543,7 @@ def patch
543 543
 
544 544
   def validate_variable name
545 545
     v = instance_variable_get("@#{name}")
546  
-    raise "Invalid @#{name}" if v.to_s.empty? or v =~ /\s/
  546
+    raise "Invalid @#{name}" if v.to_s.empty? or v.to_s =~ /\s/
547 547
   end
548 548
 
549 549
   def set_instance_variable(type)
13  Library/Homebrew/formula_support.rb
... ...
@@ -1,5 +1,6 @@
1 1
 require 'download_strategy'
2 2
 require 'checksums'
  3
+require 'version'
3 4
 
4 5
 class SoftwareSpec
5 6
   attr_reader :checksum, :mirrors, :specs
@@ -58,12 +59,12 @@ def url val=nil, specs=nil
58 59
   end
59 60
 
60 61
   def version val=nil
61  
-    unless val.nil?
62  
-      @version = val
  62
+    if val.nil?
  63
+      @version ||= Version.parse(@url)
  64
+    else
  65
+      @version = Version.new(val)
63 66
       @explicit_version = true
64 67
     end
65  
-    @version ||= Pathname.new(@url).version
66  
-    return @version
67 68
   end
68 69
 
69 70
   def mirror val
@@ -73,7 +74,7 @@ def mirror val
73 74
 end
74 75
 
75 76
 class HeadSoftwareSpec < SoftwareSpec
76  
-  def initialize url=nil, version='HEAD'
  77
+  def initialize url=nil, version=Version.new(:HEAD)
77 78
     super
78 79
   end
79 80
 
@@ -120,7 +121,7 @@ def url val=nil
120 121
   # as accessor for @version to preserve the interface
121 122
   def version val=nil
122 123
     if val.nil?
123  
-      return @version ||= Pathname.new(@url).version
  124
+      return @version ||= Version.parse(@url)
124 125
     else
125 126
       @revision = val
126 127
     end
12  Library/Homebrew/test/test_bucket.rb
@@ -22,6 +22,8 @@ def initialize
22 22
 # separate TestCase classes.
23 23
 
24 24
 class BeerTasting < Test::Unit::TestCase
  25
+  include VersionAssertions
  26
+
25 27
   def test_supported_compressed_types
26 28
     assert_nothing_raised do
27 29
       MockFormula.new 'test-0.1.tar.gz'
@@ -129,12 +131,6 @@ def test_my_float_assumptions
129 131
     assert_equal 10.7, f+0.1
130 132
   end
131 133
 
132  
-  def test_pathname_version
133  
-    d=HOMEBREW_CELLAR+'foo-0.1.9'
134  
-    d.mkpath
135  
-    assert_equal '0.1.9', d.version
136  
-  end
137  
-
138 134
   def test_pathname_plus_yeast
139 135
     nostdout do
140 136
       assert_nothing_raised do
@@ -176,12 +172,12 @@ def test_pathname_properties
176 172
 
177 173
     assert_equal '.tar.gz', foo1.extname
178 174
     assert_equal 'foo-0.1', foo1.stem
179  
-    assert_equal '0.1', foo1.version
  175
+    assert_version_equal '0.1', foo1.version
180 176
 
181 177
     foo1 = HOMEBREW_CACHE/'foo-0.1.cpio.gz'
182 178
     assert_equal '.cpio.gz', foo1.extname
183 179
     assert_equal 'foo-0.1', foo1.stem
184  
-    assert_equal '0.1', foo1.version
  180
+    assert_version_equal '0.1', foo1.version
185 181
   end
186 182
 
187 183
   class MockMockFormula < Struct.new(:name); end
29  Library/Homebrew/test/test_formula.rb
@@ -10,6 +10,7 @@ class MostlyAbstractFormula < Formula
10 10
 end
11 11
 
12 12
 class FormulaTests < Test::Unit::TestCase
  13
+  include VersionAssertions
13 14
 
14 15
   def test_prefix
15 16
     nostdout do
@@ -65,7 +66,7 @@ def test_formula_specs
65 66
     assert_equal 'http://example.com', f.homepage
66 67
     assert_equal 'file:///foo.com/testball-0.1.tbz', f.url
67 68
     assert_equal 1, f.mirrors.length
68  
-    assert_equal '0.1', f.version
  69
+    assert_version_equal '0.1', f.version
69 70
     assert_equal f.stable, f.active_spec
70 71
     assert_equal CurlDownloadStrategy, f.download_strategy
71 72
     assert_instance_of CurlDownloadStrategy, f.downloader
@@ -124,10 +125,10 @@ def test_formula_specs
124 125
     assert !f.stable.explicit_version?
125 126
     assert !f.bottle.explicit_version?
126 127
     assert !f.devel.explicit_version?
127  
-    assert_equal '0.1', f.stable.version
128  
-    assert_equal '0.1', f.bottle.version
129  
-    assert_equal '0.2', f.devel.version
130  
-    assert_equal 'HEAD', f.head.version
  128
+    assert_version_equal '0.1', f.stable.version
  129
+    assert_version_equal '0.1', f.bottle.version
  130
+    assert_version_equal '0.2', f.devel.version
  131
+    assert_version_equal 'HEAD', f.head.version
131 132
     assert_equal 0, f.bottle.revision
132 133
   end
133 134
 
@@ -135,7 +136,7 @@ def test_devel_active_spec
135 136
     ARGV.push '--devel'
136 137
     f = SpecTestBall.new
137 138
     assert_equal f.devel, f.active_spec
138  
-    assert_equal '0.2', f.version
  139
+    assert_version_equal '0.2', f.version
139 140
     assert_equal 'file:///foo.com/testball-0.2.tbz', f.url
140 141
     assert_equal CurlDownloadStrategy, f.download_strategy
141 142
     assert_instance_of CurlDownloadStrategy, f.downloader
@@ -146,7 +147,7 @@ def test_head_active_spec
146 147
     ARGV.push '--HEAD'
147 148
     f = SpecTestBall.new
148 149
     assert_equal f.head, f.active_spec
149  
-    assert_equal 'HEAD', f.version
  150
+    assert_version_equal 'HEAD', f.version
150 151
     assert_equal 'https://github.com/mxcl/homebrew.git', f.url
151 152
     assert_equal GitDownloadStrategy, f.download_strategy
152 153
     assert_instance_of GitDownloadStrategy, f.downloader
@@ -155,9 +156,9 @@ def test_head_active_spec
155 156
 
156 157
   def test_explicit_version_spec
157 158
     f = ExplicitVersionSpecTestBall.new
158  
-    assert_equal '0.3', f.version
159  
-    assert_equal '0.3', f.stable.version
160  
-    assert_equal '0.4', f.devel.version
  159
+    assert_version_equal '0.3', f.version
  160
+    assert_version_equal '0.3', f.stable.version
  161
+    assert_version_equal '0.4', f.devel.version
161 162
     assert f.stable.explicit_version?
162 163
     assert f.devel.explicit_version?
163 164
   end
@@ -183,7 +184,7 @@ def test_old_bottle_specs
183 184
 
184 185
       assert !f.bottle.explicit_version?
185 186
       assert_equal 0, f.bottle.revision
186  
-      assert_equal '0.1', f.bottle.version
  187
+      assert_version_equal '0.1', f.bottle.version
187 188
     else
188 189
       assert_nil f.bottle
189 190
     end
@@ -203,7 +204,7 @@ def test_head_only_specs
203 204
     assert_nil f.devel
204 205
 
205 206
     assert_equal f.head, f.active_spec
206  
-    assert_equal 'HEAD', f.version
  207
+    assert_version_equal 'HEAD', f.version
207 208
     assert_nil f.head.checksum
208 209
     assert_equal 'https://github.com/mxcl/homebrew.git', f.url
209 210
     assert_equal GitDownloadStrategy, f.download_strategy
@@ -220,7 +221,7 @@ def test_incomplete_stable_specs
220 221
     assert_nil f.devel
221 222
 
222 223
     assert_equal f.head, f.active_spec
223  
-    assert_equal 'HEAD', f.version
  224
+    assert_version_equal 'HEAD', f.version
224 225
     assert_nil f.head.checksum
225 226
     assert_equal 'https://github.com/mxcl/homebrew.git', f.url
226 227
     assert_equal GitDownloadStrategy, f.download_strategy
@@ -237,7 +238,7 @@ def test_head_only_with_version_specs
237 238
     assert_nil f.devel
238 239
 
239 240
     assert_equal f.head, f.active_spec
240  
-    assert_equal 'HEAD', f.version
  241
+    assert_version_equal 'HEAD', f.version
241 242
     assert_nil f.head.checksum
242 243
     assert_equal 'https://github.com/mxcl/homebrew.git', f.url
243 244
     assert_equal GitDownloadStrategy, f.download_strategy
19  Library/Homebrew/test/test_versions.rb
@@ -3,20 +3,6 @@
3 3
 require 'test/testball'
4 4
 require 'version'
5 5
 
6  
-module VersionAssertions
7  
-  def assert_version_detected expected, url
8  
-    assert_equal expected, Version.parse(url).to_s
9  
-  end
10  
-
11  
-  def assert_version_nil url
12  
-    assert_nil Version.parse(url)
13  
-  end
14  
-
15  
-  def assert_version_comparison a, comparison, b
16  
-    eval "assert Version.new(a) #{comparison} Version.new(b)"
17  
-  end
18  
-end
19  
-
20 6
 class TestBadVersion < TestBall
21 7
   def initialize name=nil
22 8
     @stable = SoftwareSpec.new
@@ -34,6 +20,9 @@ def test_version_comparisons
34 20
     assert_version_comparison '1.2.3', '>', '1.2.2'
35 21
     assert_version_comparison '1.2.3-p34', '>', '1.2.3-p33'
36 22
     assert_version_comparison '1.2.4', '<', '1.2.4.1'
  23
+    assert_version_comparison 'HEAD', '==', 'HEAD'
  24
+    assert_version_comparison 'HEAD', '>', '1.2.3'
  25
+    assert_version_comparison '1.2.3', '<', 'HEAD'
37 26
   end
38 27
 end
39 28
 
@@ -43,7 +32,7 @@ class VersionParsingTests < Test::Unit::TestCase
43 32
   def test_pathname_version
44 33
     d = HOMEBREW_CELLAR/'foo-0.1.9'
45 34
     d.mkpath
46  
-    assert_equal '0.1.9', d.version
  35
+    assert_version_equal '0.1.9', d.version
47 36
   end
48 37
 
49 38
   def test_no_version
18  Library/Homebrew/test/testing_env.rb
@@ -65,3 +65,21 @@ def shutup
65 65
 
66 66
 require 'extend/ENV'
67 67
 ENV.extend(HomebrewEnvExtension)
  68
+
  69
+module VersionAssertions
  70
+  def assert_version_equal expected, actual
  71
+    assert_equal Version.new(expected), actual
  72
+  end
  73
+
  74
+  def assert_version_detected expected, url
  75
+    assert_equal expected, Version.parse(url).to_s
  76
+  end
  77
+
  78
+  def assert_version_nil url
  79
+    assert_nil Version.parse(url)
  80
+  end
  81
+
  82
+  def assert_version_comparison a, comparison, b
  83
+    eval "assert Version.new(a) #{comparison} Version.new(b)"
  84
+  end
  85
+end

0 notes on commit 4affbab

Please sign in to comment.
Something went wrong with that request. Please try again.