formula: tweak preset pour_bottle? symbols

Let's rename `reason` to `requirement` so the preset symbol can just be
`:clt`. See Homebrew/homebrew-core#77509.
This commit is contained in:
Carlo Cabrera 2021-05-19 02:18:43 +01:00
parent 2e9d4ffa15
commit 3c34c13056
No known key found for this signature in database
GPG Key ID: C74D447FC549A1D0
2 changed files with 17 additions and 17 deletions

View File

@ -2920,16 +2920,16 @@ class Formula
# the {Formula} will be built from source and `reason` will be printed.
#
# Alternatively, a preset reason can be passed as a symbol:
# <pre>pour_bottle? reason: :clt_required</pre>
def pour_bottle?(reason: nil, &block)
# <pre>pour_bottle? requirement: :clt</pre>
def pour_bottle?(requirement: nil, &block)
@pour_bottle_check = PourBottleCheck.new(self)
if reason.present? && block.present?
raise ArgumentError, "Do not pass both a reason and a block to `pour_bottle?`"
if requirement.present? && block.present?
raise ArgumentError, "Do not pass both a requirement and a block to `pour_bottle?`"
end
block ||= case reason
when :clt_required
block ||= case requirement
when :clt
lambda do |_|
on_macos do
T.cast(self, PourBottleCheck).reason(+<<~EOS)
@ -2941,7 +2941,7 @@ class Formula
end
end
else
raise ArgumentError, "Invalid `pour_bottle?` reason" if reason.present?
raise ArgumentError, "Invalid `pour_bottle?` requirement" if requirement.present?
end
@pour_bottle_check.instance_eval(&block)

View File

@ -996,37 +996,37 @@ describe Formula do
expect(f).to pour_bottle
end
it "returns false with `reason: :clt_required` on macOS", :needs_macos do
it "returns false with `requirement: :clt` on macOS", :needs_macos do
# Pretend CLT is not installed
allow(MacOS::CLT).to receive(:installed?).and_return(false)
f = formula "foo" do
url "foo-1.0"
pour_bottle? reason: :clt_required
pour_bottle? requirement: :clt
end
expect(f).not_to pour_bottle
end
it "returns true with `reason: :clt_required` on macOS", :needs_macos do
it "returns true with `requirement: :clt` on macOS", :needs_macos do
# Pretend CLT is installed
allow(MacOS::CLT).to receive(:installed?).and_return(true)
f = formula "foo" do
url "foo-1.0"
pour_bottle? reason: :clt_required
pour_bottle? requirement: :clt
end
expect(f).to pour_bottle
end
it "returns true with `reason: :clt_required` on Linux", :needs_linux do
it "returns true with `requirement: :clt` on Linux", :needs_linux do
f = formula "foo" do
url "foo-1.0"
pour_bottle? reason: :clt_required
pour_bottle? requirement: :clt
end
expect(f).to pour_bottle
@ -1037,12 +1037,12 @@ describe Formula do
formula "foo" do
url "foo-1.0"
pour_bottle? reason: :clt_required do
pour_bottle? requirement: :clt 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.to raise_error(ArgumentError, "Do not pass both a requirement and a block to `pour_bottle?`")
end
it "throws an error if passed an invalid symbol" do
@ -1050,9 +1050,9 @@ describe Formula do
formula "foo" do
url "foo-1.0"
pour_bottle? reason: :foo
pour_bottle? requirement: :foo
end
end.to raise_error(ArgumentError, "Invalid `pour_bottle?` reason")
end.to raise_error(ArgumentError, "Invalid `pour_bottle?` requirement")
end
end