Raise errors on invalid symbol/block combinations

This commit is contained in:
Rylan Polster 2021-05-17 15:33:09 -04:00
parent fb3bfbb65c
commit 69e29a358b
No known key found for this signature in database
GPG Key ID: 46A744940CFF4D64
2 changed files with 32 additions and 2 deletions

View File

@ -2924,8 +2924,13 @@ class Formula
def pour_bottle?(reason: nil, &block)
@pour_bottle_check = PourBottleCheck.new(self)
if reason == :clt_required
block = lambda do |_|
if reason.present? && block.present?
raise ArgumentError, "Do not pass both a reason and a block to `pour_bottle?`"
end
block ||= case reason
when :clt_required
lambda do |_|
on_macos do
T.cast(self, PourBottleCheck).reason(+<<~EOS)
The bottle needs the Apple Command Line Tools to be installed.
@ -2935,6 +2940,8 @@ class Formula
T.cast(self, PourBottleCheck).satisfy { MacOS::CLT.installed? }
end
end
else
raise ArgumentError, "Invalid `pour_bottle?` reason" if reason.present?
end
@pour_bottle_check.instance_eval(&block)

View File

@ -1021,6 +1021,29 @@ describe Formula do
expect(f).to pour_bottle
end
it "throws an error if passed both a symbol and a block" do
expect do
formula "foo" do
url "foo-1.0"
pour_bottle? reason: :clt_required do
reason "true reason"
satisfy { true }
end
end
end.to raise_error(ArgumentError, "Do not pass both a reason and a block to `pour_bottle?`")
end
it "throws an error if passed an invalid symbol" do
expect do
formula "foo" do
url "foo-1.0"
pour_bottle? reason: :foo
end
end.to raise_error(ArgumentError, "Invalid `pour_bottle?` reason")
end
end
describe "alias changes" do