Merge pull request #10955 from reitermarkus/bundle-version-comparison
Fix `BundleVersion` comparison when one part is `nil`.
This commit is contained in:
commit
3bfa59bd2f
@ -10,6 +10,8 @@ module Homebrew
|
|||||||
class BundleVersion
|
class BundleVersion
|
||||||
extend T::Sig
|
extend T::Sig
|
||||||
|
|
||||||
|
include Comparable
|
||||||
|
|
||||||
extend SystemCommand::Mixin
|
extend SystemCommand::Mixin
|
||||||
|
|
||||||
sig { params(info_plist_path: Pathname).returns(T.nilable(T.attached_class)) }
|
sig { params(info_plist_path: Pathname).returns(T.nilable(T.attached_class)) }
|
||||||
@ -55,10 +57,15 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
def <=>(other)
|
def <=>(other)
|
||||||
[version, short_version].map { |v| v&.yield_self(&Version.public_method(:new)) } <=>
|
[version, short_version].map { |v| v&.yield_self(&Version.public_method(:new)) || Version::NULL } <=>
|
||||||
[other.version, other.short_version].map { |v| v&.yield_self(&Version.public_method(:new)) }
|
[other.version, other.short_version].map { |v| v&.yield_self(&Version.public_method(:new)) || Version::NULL }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def ==(other)
|
||||||
|
instance_of?(other.class) && short_version == other.short_version && version == other.version
|
||||||
|
end
|
||||||
|
alias eql? ==
|
||||||
|
|
||||||
# Create a nicely formatted version (on a best effort basis).
|
# Create a nicely formatted version (on a best effort basis).
|
||||||
sig { returns(String) }
|
sig { returns(String) }
|
||||||
def nice_version
|
def nice_version
|
||||||
|
@ -26,4 +26,10 @@ describe Homebrew::BundleVersion do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#<=>" do
|
||||||
|
it "does not fail when a `version` is nil" do
|
||||||
|
expect(described_class.new("1.06", nil)).to be < described_class.new("1.12", "1.12")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user