aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/test/test_versions.rb4
-rw-r--r--Library/Homebrew/version.rb2
2 files changed, 6 insertions, 0 deletions
diff --git a/Library/Homebrew/test/test_versions.rb b/Library/Homebrew/test/test_versions.rb
index 6f85fe7a0..3e1c97b03 100644
--- a/Library/Homebrew/test/test_versions.rb
+++ b/Library/Homebrew/test/test_versions.rb
@@ -145,6 +145,10 @@ class VersionComparisonTests < Homebrew::TestCase
assert_operator version("2-p194"), :<, version("2.1-p195")
end
+ def test_comparing_against_nil
+ assert_operator version("2.1.0-p194"), :>, nil
+ 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 57a9c11a5..56ffc9a64 100644
--- a/Library/Homebrew/version.rb
+++ b/Library/Homebrew/version.rb
@@ -213,6 +213,8 @@ class Version
end
def <=>(other)
+ return 1 if other.nil?
+
return unless other.is_a?(Version)
return 0 if version == other.version
return 1 if head? && !other.head?