Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Replace version strings with Version objects

  • Loading branch information...
commit 4affbabfb7aef915f716531ad0a39eff04ff9933 1 parent 7cfc6be
Jack Nagel jacknagel authored
2  Library/Formula/bash.rb
View
@@ -10,7 +10,7 @@ class Bash < Formula
depends_on 'readline'
def patches
- patch_level = version.split('.').last.to_i
+ patch_level = version.to_s.split('.').last.to_i
{'p0' => (1..patch_level).map { |i| "http://ftpmirror.gnu.org/bash/bash-4.2-patches/bash42-%03d" % i }}
end
2  Library/Formula/lua.rb
View
@@ -53,7 +53,7 @@ def install
# this ensures that this symlinking for lua starts at lib/lua/5.1 and not
# below that, thus making luarocks work
- (HOMEBREW_PREFIX/"lib/lua"/version.split('.')[0..1].join('.')).mkpath
+ (HOMEBREW_PREFIX/"lib/lua"/version.to_s.split('.')[0..1].join('.')).mkpath
system "make", "macosx", "INSTALL_TOP=#{prefix}", "INSTALL_MAN=#{man1}"
system "make", "install", "INSTALL_TOP=#{prefix}", "INSTALL_MAN=#{man1}"
2  Library/Formula/shapelib.rb
View
@@ -25,7 +25,7 @@ def install
include.install 'shapefil.h'
cd lib do
- ln_s "libshp.#{version}.dylib", "libshp.#{version.split('.').first}.dylib"
+ ln_s "libshp.#{version}.dylib", "libshp.#{version.to_s.split('.').first}.dylib"
ln_s "libshp.#{version}.dylib", "libshp.dylib"
end
end
2  Library/Formula/sip.rb
View
@@ -28,7 +28,7 @@ def install
else
sip_version = version
end
- inreplace 'build.py', /@SIP_VERSION@/, (sip_version.gsub '.', ',')
+ inreplace 'build.py', /@SIP_VERSION@/, (sip_version.to_s.gsub '.', ',')
system "python", "build.py", "prepare"
# Set --destdir such that the python modules will be in the HOMEBREWPREFIX/lib/pythonX.Y/site-packages
2  Library/Homebrew/cmd/diy.rb
View
@@ -21,7 +21,7 @@ def diy
end
end
- prefix = HOMEBREW_CELLAR+name+version
+ prefix = HOMEBREW_CELLAR/name/version
if File.file? 'CMakeLists.txt'
puts "-DCMAKE_INSTALL_PREFIX=#{prefix}"
2  Library/Homebrew/cmd/versions.rb
View
@@ -13,7 +13,7 @@ def versions
else
f.versions do |version, sha|
print Tty.white.to_s
- print "#{version.ljust(8)} "
+ print "#{version.to_s.ljust(8)} "
print Tty.reset.to_s
puts "git checkout #{sha} #{f.pretty_relative_path}"
end
3  Library/Homebrew/extend/pathname.rb
View
@@ -163,8 +163,7 @@ def abv
def version
require 'version'
- version = Version.parse(self)
- version.to_s unless version.nil?
+ Version.parse(self)
end
def compression_type
4 Library/Homebrew/formula.rb
View
@@ -108,7 +108,7 @@ def installed_prefix
def prefix
validate_variable :name
validate_variable :version
- HOMEBREW_CELLAR+@name+@version
+ HOMEBREW_CELLAR/@name/@version
end
def rack; prefix.parent end
@@ -543,7 +543,7 @@ def patch
def validate_variable name
v = instance_variable_get("@#{name}")
- raise "Invalid @#{name}" if v.to_s.empty? or v =~ /\s/
+ raise "Invalid @#{name}" if v.to_s.empty? or v.to_s =~ /\s/
end
def set_instance_variable(type)
13 Library/Homebrew/formula_support.rb
View
@@ -1,5 +1,6 @@
require 'download_strategy'
require 'checksums'
+require 'version'
class SoftwareSpec
attr_reader :checksum, :mirrors, :specs
@@ -58,12 +59,12 @@ def url val=nil, specs=nil
end
def version val=nil
- unless val.nil?
- @version = val
+ if val.nil?
+ @version ||= Version.parse(@url)
+ else
+ @version = Version.new(val)
@explicit_version = true
end
- @version ||= Pathname.new(@url).version
- return @version
end
def mirror val
@@ -73,7 +74,7 @@ def mirror val
end
class HeadSoftwareSpec < SoftwareSpec
- def initialize url=nil, version='HEAD'
+ def initialize url=nil, version=Version.new(:HEAD)
super
end
@@ -120,7 +121,7 @@ def url val=nil
# as accessor for @version to preserve the interface
def version val=nil
if val.nil?
- return @version ||= Pathname.new(@url).version
+ return @version ||= Version.parse(@url)
else
@revision = val
end
12 Library/Homebrew/test/test_bucket.rb
View
@@ -22,6 +22,8 @@ def initialize
# separate TestCase classes.
class BeerTasting < Test::Unit::TestCase
+ include VersionAssertions
+
def test_supported_compressed_types
assert_nothing_raised do
MockFormula.new 'test-0.1.tar.gz'
@@ -129,12 +131,6 @@ def test_my_float_assumptions
assert_equal 10.7, f+0.1
end
- def test_pathname_version
- d=HOMEBREW_CELLAR+'foo-0.1.9'
- d.mkpath
- assert_equal '0.1.9', d.version
- end
-
def test_pathname_plus_yeast
nostdout do
assert_nothing_raised do
@@ -176,12 +172,12 @@ def test_pathname_properties
assert_equal '.tar.gz', foo1.extname
assert_equal 'foo-0.1', foo1.stem
- assert_equal '0.1', foo1.version
+ assert_version_equal '0.1', foo1.version
foo1 = HOMEBREW_CACHE/'foo-0.1.cpio.gz'
assert_equal '.cpio.gz', foo1.extname
assert_equal 'foo-0.1', foo1.stem
- assert_equal '0.1', foo1.version
+ assert_version_equal '0.1', foo1.version
end
class MockMockFormula < Struct.new(:name); end
29 Library/Homebrew/test/test_formula.rb
View
@@ -10,6 +10,7 @@ class MostlyAbstractFormula < Formula
end
class FormulaTests < Test::Unit::TestCase
+ include VersionAssertions
def test_prefix
nostdout do
@@ -65,7 +66,7 @@ def test_formula_specs
assert_equal 'http://example.com', f.homepage
assert_equal 'file:///foo.com/testball-0.1.tbz', f.url
assert_equal 1, f.mirrors.length
- assert_equal '0.1', f.version
+ assert_version_equal '0.1', f.version
assert_equal f.stable, f.active_spec
assert_equal CurlDownloadStrategy, f.download_strategy
assert_instance_of CurlDownloadStrategy, f.downloader
@@ -124,10 +125,10 @@ def test_formula_specs
assert !f.stable.explicit_version?
assert !f.bottle.explicit_version?
assert !f.devel.explicit_version?
- assert_equal '0.1', f.stable.version
- assert_equal '0.1', f.bottle.version
- assert_equal '0.2', f.devel.version
- assert_equal 'HEAD', f.head.version
+ assert_version_equal '0.1', f.stable.version
+ assert_version_equal '0.1', f.bottle.version
+ assert_version_equal '0.2', f.devel.version
+ assert_version_equal 'HEAD', f.head.version
assert_equal 0, f.bottle.revision
end
@@ -135,7 +136,7 @@ def test_devel_active_spec
ARGV.push '--devel'
f = SpecTestBall.new
assert_equal f.devel, f.active_spec
- assert_equal '0.2', f.version
+ assert_version_equal '0.2', f.version
assert_equal 'file:///foo.com/testball-0.2.tbz', f.url
assert_equal CurlDownloadStrategy, f.download_strategy
assert_instance_of CurlDownloadStrategy, f.downloader
@@ -146,7 +147,7 @@ def test_head_active_spec
ARGV.push '--HEAD'
f = SpecTestBall.new
assert_equal f.head, f.active_spec
- assert_equal 'HEAD', f.version
+ assert_version_equal 'HEAD', f.version
assert_equal 'https://github.com/mxcl/homebrew.git', f.url
assert_equal GitDownloadStrategy, f.download_strategy
assert_instance_of GitDownloadStrategy, f.downloader
@@ -155,9 +156,9 @@ def test_head_active_spec
def test_explicit_version_spec
f = ExplicitVersionSpecTestBall.new
- assert_equal '0.3', f.version
- assert_equal '0.3', f.stable.version
- assert_equal '0.4', f.devel.version
+ assert_version_equal '0.3', f.version
+ assert_version_equal '0.3', f.stable.version
+ assert_version_equal '0.4', f.devel.version
assert f.stable.explicit_version?
assert f.devel.explicit_version?
end
@@ -183,7 +184,7 @@ def test_old_bottle_specs
assert !f.bottle.explicit_version?
assert_equal 0, f.bottle.revision
- assert_equal '0.1', f.bottle.version
+ assert_version_equal '0.1', f.bottle.version
else
assert_nil f.bottle
end
@@ -203,7 +204,7 @@ def test_head_only_specs
assert_nil f.devel
assert_equal f.head, f.active_spec
- assert_equal 'HEAD', f.version
+ assert_version_equal 'HEAD', f.version
assert_nil f.head.checksum
assert_equal 'https://github.com/mxcl/homebrew.git', f.url
assert_equal GitDownloadStrategy, f.download_strategy
@@ -220,7 +221,7 @@ def test_incomplete_stable_specs
assert_nil f.devel
assert_equal f.head, f.active_spec
- assert_equal 'HEAD', f.version
+ assert_version_equal 'HEAD', f.version
assert_nil f.head.checksum
assert_equal 'https://github.com/mxcl/homebrew.git', f.url
assert_equal GitDownloadStrategy, f.download_strategy
@@ -237,7 +238,7 @@ def test_head_only_with_version_specs
assert_nil f.devel
assert_equal f.head, f.active_spec
- assert_equal 'HEAD', f.version
+ assert_version_equal 'HEAD', f.version
assert_nil f.head.checksum
assert_equal 'https://github.com/mxcl/homebrew.git', f.url
assert_equal GitDownloadStrategy, f.download_strategy
19 Library/Homebrew/test/test_versions.rb
View
@@ -3,20 +3,6 @@
require 'test/testball'
require 'version'
-module VersionAssertions
- def assert_version_detected expected, url
- assert_equal expected, Version.parse(url).to_s
- end
-
- def assert_version_nil url
- assert_nil Version.parse(url)
- end
-
- def assert_version_comparison a, comparison, b
- eval "assert Version.new(a) #{comparison} Version.new(b)"
- end
-end
-
class TestBadVersion < TestBall
def initialize name=nil
@stable = SoftwareSpec.new
@@ -34,6 +20,9 @@ def test_version_comparisons
assert_version_comparison '1.2.3', '>', '1.2.2'
assert_version_comparison '1.2.3-p34', '>', '1.2.3-p33'
assert_version_comparison '1.2.4', '<', '1.2.4.1'
+ assert_version_comparison 'HEAD', '==', 'HEAD'
+ assert_version_comparison 'HEAD', '>', '1.2.3'
+ assert_version_comparison '1.2.3', '<', 'HEAD'
end
end
@@ -43,7 +32,7 @@ class VersionParsingTests < Test::Unit::TestCase
def test_pathname_version
d = HOMEBREW_CELLAR/'foo-0.1.9'
d.mkpath
- assert_equal '0.1.9', d.version
+ assert_version_equal '0.1.9', d.version
end
def test_no_version
18 Library/Homebrew/test/testing_env.rb
View
@@ -65,3 +65,21 @@ def shutup
require 'extend/ENV'
ENV.extend(HomebrewEnvExtension)
+
+module VersionAssertions
+ def assert_version_equal expected, actual
+ assert_equal Version.new(expected), actual
+ end
+
+ def assert_version_detected expected, url
+ assert_equal expected, Version.parse(url).to_s
+ end
+
+ def assert_version_nil url
+ assert_nil Version.parse(url)
+ end
+
+ def assert_version_comparison a, comparison, b
+ eval "assert Version.new(a) #{comparison} Version.new(b)"
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.