aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew
diff options
context:
space:
mode:
Diffstat (limited to 'Library/Homebrew')
-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)