From 17005b93abbc0e95c5bdf9bcee485f12f2a14778 Mon Sep 17 00:00:00 2001 From: danielnachun Date: Sun, 6 Mar 2022 21:55:54 -0800 Subject: [PATCH 1/2] software_spec.rb: add tag_to_cellar method --- Library/Homebrew/software_spec.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/software_spec.rb b/Library/Homebrew/software_spec.rb index 85012c9b4f..f6eb79b225 100644 --- a/Library/Homebrew/software_spec.rb +++ b/Library/Homebrew/software_spec.rb @@ -504,14 +504,19 @@ class BottleSpecification end end - sig { params(tag: Utils::Bottles::Tag).returns(T::Boolean) } - def compatible_locations?(tag: Utils::Bottles.tag) + sig { params(tag: Utils::Bottles::Tag).returns(T.any(Symbol, String)) } + def tag_to_cellar(tag = Utils::Bottles.tag) spec = collector.specification_for(tag) - cellar = if spec.present? + if spec.present? spec.cellar else tag.default_cellar end + end + + sig { params(tag: Utils::Bottles::Tag).returns(T::Boolean) } + def compatible_locations?(tag: Utils::Bottles.tag) + cellar = tag_to_cellar(tag) return true if [:any, :any_skip_relocation].include?(cellar) From 2c4ad58d16d6c137e3d26ff494450f3064364d02 Mon Sep 17 00:00:00 2001 From: danielnachun Date: Sun, 6 Mar 2022 21:56:41 -0800 Subject: [PATCH 2/2] test/software_spec/bottle_spec.rb: add unit tests --- Library/Homebrew/test/software_spec/bottle_spec.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Library/Homebrew/test/software_spec/bottle_spec.rb b/Library/Homebrew/test/software_spec/bottle_spec.rb index 01e45373fe..08910f8a96 100644 --- a/Library/Homebrew/test/software_spec/bottle_spec.rb +++ b/Library/Homebrew/test/software_spec/bottle_spec.rb @@ -41,6 +41,18 @@ describe BottleSpecification do end end + describe "#compatible_locations?" do + it "checks if the bottle cellar is relocatable" do + expect(bottle_spec.compatible_locations?).to be false + end + end + + describe "#tag_to_cellar" do + it "returns the cellar for a tag" do + expect(bottle_spec.tag_to_cellar).to eq Utils::Bottles.tag.default_cellar + end + end + %w[root_url rebuild].each do |method| specify "##{method}" do object = Object.new