Don't raise when converting the tag to a version fails

This commit is contained in:
Jack Nagel 2014-07-16 21:11:48 -05:00
parent 596f3ba0a0
commit 28f0e5c4fd
2 changed files with 17 additions and 1 deletions

View File

@ -114,10 +114,16 @@ class BottleCollector
# so the same bottle can target multiple OSs.
# Not used in core, used in taps.
def find_or_later_tag(tag)
begin
tag_version = MacOS::Version.from_symbol(tag)
rescue ArgumentError
return
end
keys.find do |key|
if key.to_s.end_with?("_or_later")
later_tag = key.to_s[/(\w+)_or_later$/, 1].to_sym
MacOS::Version.from_symbol(later_tag) <= MacOS::Version.from_symbol(tag)
MacOS::Version.from_symbol(later_tag) <= tag_version
end
end
end

View File

@ -20,6 +20,16 @@ class BottleCollectorTests < Homebrew::TestCase
assert_nil checksum_for(:foo)
end
def test_collector_returns_nil_for_no_match
@collector[:lion] = "foo"
assert_nil checksum_for(:foo)
end
def test_collector_returns_nil_for_no_match_when_later_tag_present
@collector[:lion_or_later] = "foo"
assert_nil checksum_for(:foo)
end
def test_collector_finds_or_later_tags
@collector[:lion_or_later] = "foo"
assert_equal ['foo', :lion_or_later], checksum_for(:mountain_lion)