aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorMisty De Meo2016-11-03 16:47:18 -0700
committerMisty De Meo2016-11-10 15:08:36 -0800
commit16529a4de5c24f62574ba0b7dbc033f5323e7afb (patch)
tree1465b37796723c6985abafa0d157f10d10664e9b /Library
parentb6acb9cb47817631a69fba31a4cab2cae30da01b (diff)
downloadbrew-16529a4de5c24f62574ba0b7dbc033f5323e7afb.tar.bz2
Version: allow coercing non-versions in comparisons
These are needed due to the raw string and fixnum comparisons which exist for legacy reasons, for instance compiler version and build comparisons.
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/test/test_versions.rb5
-rw-r--r--Library/Homebrew/version.rb5
2 files changed, 10 insertions, 0 deletions
diff --git a/Library/Homebrew/test/test_versions.rb b/Library/Homebrew/test/test_versions.rb
index 3e1c97b03..a6e922178 100644
--- a/Library/Homebrew/test/test_versions.rb
+++ b/Library/Homebrew/test/test_versions.rb
@@ -149,6 +149,11 @@ class VersionComparisonTests < Homebrew::TestCase
assert_operator version("2.1.0-p194"), :>, nil
end
+ def test_comparing_against_strings
+ assert_operator version("2.1.0-p194"), :==, "2.1.0-p194"
+ assert_operator version("1"), :==, 1
+ end
+
def test_comparison_returns_nil_for_non_version
v = version("1.0")
assert_nil v <=> Object.new
diff --git a/Library/Homebrew/version.rb b/Library/Homebrew/version.rb
index 56ffc9a64..f5fdb0966 100644
--- a/Library/Homebrew/version.rb
+++ b/Library/Homebrew/version.rb
@@ -213,6 +213,11 @@ class Version
end
def <=>(other)
+ # Needed to retain API compatibility with older string comparisons
+ # for compiler versions, etc.
+ other = Version.new(other) if other.is_a? String
+ # Used by the *_build_version comparisons, which formerly returned Fixnum
+ other = Version.new(other.to_s) if other.is_a? Integer
return 1 if other.nil?
return unless other.is_a?(Version)