diff --git a/Library/Homebrew/test/cask/cask_spec.rb b/Library/Homebrew/test/cask/cask_spec.rb index be59b6df8e..f52ba3cb66 100644 --- a/Library/Homebrew/test/cask/cask_spec.rb +++ b/Library/Homebrew/test/cask/cask_spec.rb @@ -211,4 +211,64 @@ describe Cask::Cask, :cask do end end end + + describe "#to_hash_with_variations" do + let!(:original_macos_version) { MacOS.full_version.to_s } + let(:expected_variations) { + <<~JSON + { + "arm64_big_sur": { + "url": "file://#{TEST_FIXTURE_DIR}/cask/caffeine/1.2.0/arm.zip", + "version": "1.2.0", + "sha256": "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b" + }, + "monterey": { + "url": "file://#{TEST_FIXTURE_DIR}/cask/caffeine/1.2.3/intel.zip" + }, + "big_sur": { + "url": "file://#{TEST_FIXTURE_DIR}/cask/caffeine/1.2.0/intel.zip", + "version": "1.2.0", + "sha256": "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b" + }, + "catalina": { + "url": "file://#{TEST_FIXTURE_DIR}/cask/caffeine/1.0.0/intel.zip", + "version": "1.0.0", + "sha256": "1866dfa833b123bb8fe7fa7185ebf24d28d300d0643d75798bc23730af734216" + }, + "mojave": { + "url": "file://#{TEST_FIXTURE_DIR}/cask/caffeine/1.0.0/intel.zip", + "version": "1.0.0", + "sha256": "1866dfa833b123bb8fe7fa7185ebf24d28d300d0643d75798bc23730af734216" + } + } + JSON + } + + before do + # Use a more limited symbols list to shorten the variations hash + symbols = { + monterey: "12", + big_sur: "11", + catalina: "10.15", + mojave: "10.14", + } + stub_const("MacOSVersions::SYMBOLS", symbols) + + # For consistency, always run on Monterey and ARM + MacOS.full_version = "12" + allow(Hardware::CPU).to receive(:type).and_return(:arm) + end + + after do + MacOS.full_version = original_macos_version + end + + it "returns the correct variations hash" do + c = Cask::CaskLoader.load("multiple-versions") + h = c.to_hash_with_variations + + expect(h).to be_a(Hash) + expect(JSON.pretty_generate(h["variations"])).to eq expected_variations.strip + end + end end diff --git a/Library/Homebrew/test/cask/cmd/list_spec.rb b/Library/Homebrew/test/cask/cmd/list_spec.rb index 988083e39c..86704bc041 100644 --- a/Library/Homebrew/test/cask/cmd/list_spec.rb +++ b/Library/Homebrew/test/cask/cmd/list_spec.rb @@ -120,9 +120,7 @@ describe Cask::Cmd::List, :cask do }, "conflicts_with": null, "container": null, - "auto_updates": null, - "variations": { - } + "auto_updates": null }, { "token": "local-transmission", @@ -151,9 +149,7 @@ describe Cask::Cmd::List, :cask do }, "conflicts_with": null, "container": null, - "auto_updates": null, - "variations": { - } + "auto_updates": null }, { "token": "multiple-versions", @@ -185,32 +181,7 @@ describe Cask::Cmd::List, :cask do }, "conflicts_with": null, "container": null, - "auto_updates": null, - "variations": { - "arm64_big_sur": { - "url": "file://#{TEST_FIXTURE_DIR}/cask/caffeine/1.2.0/arm.zip", - "version": "1.2.0", - "sha256": "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b" - }, - "monterey": { - "url": "file://#{TEST_FIXTURE_DIR}/cask/caffeine/1.2.3/intel.zip" - }, - "big_sur": { - "url": "file://#{TEST_FIXTURE_DIR}/cask/caffeine/1.2.0/intel.zip", - "version": "1.2.0", - "sha256": "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b" - }, - "catalina": { - "url": "file://#{TEST_FIXTURE_DIR}/cask/caffeine/1.0.0/intel.zip", - "version": "1.0.0", - "sha256": "1866dfa833b123bb8fe7fa7185ebf24d28d300d0643d75798bc23730af734216" - }, - "mojave": { - "url": "file://#{TEST_FIXTURE_DIR}/cask/caffeine/1.0.0/intel.zip", - "version": "1.0.0", - "sha256": "1866dfa833b123bb8fe7fa7185ebf24d28d300d0643d75798bc23730af734216" - } - } + "auto_updates": null }, { "token": "third-party-cask", @@ -239,9 +210,7 @@ describe Cask::Cmd::List, :cask do }, "conflicts_with": null, "container": null, - "auto_updates": null, - "variations": { - } + "auto_updates": null } ] EOS diff --git a/Library/Homebrew/test/formula_spec.rb b/Library/Homebrew/test/formula_spec.rb index e47a197361..d4904f4a7f 100644 --- a/Library/Homebrew/test/formula_spec.rb +++ b/Library/Homebrew/test/formula_spec.rb @@ -905,6 +905,99 @@ describe Formula do expect(h["versions"]["bottle"]).to be_truthy end + describe "#to_hash_with_variations" do + let(:formula_path) { CoreTap.new.formula_dir/"foo-variations.rb" } + let(:formula_content) do + <<~RUBY + class FooVariations < Formula + url "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz" + sha256 TESTBALL_SHA256 + + on_intel do + depends_on "intel-formula" + end + + on_big_sur do + depends_on "big-sur-formula" + end + + on_catalina :or_older do + depends_on "catalina-or-older-formula" + end + + on_linux do + depends_on "linux-formula" + end + end + RUBY + end + let(:expected_variations) { + <<~JSON + { + "arm64_big_sur": { + "dependencies": [ + "big-sur-formula" + ] + }, + "monterey": { + "dependencies": [ + "intel-formula" + ] + }, + "big_sur": { + "dependencies": [ + "intel-formula", + "big-sur-formula" + ] + }, + "catalina": { + "dependencies": [ + "intel-formula", + "catalina-or-older-formula" + ] + }, + "mojave": { + "dependencies": [ + "intel-formula", + "catalina-or-older-formula" + ] + }, + "x86_64_linux": { + "dependencies": [ + "intel-formula", + "linux-formula" + ] + } + } + JSON + } + + before do + # Use a more limited symbols list to shorten the variations hash + symbols = { + monterey: "12", + big_sur: "11", + catalina: "10.15", + mojave: "10.14", + } + stub_const("MacOSVersions::SYMBOLS", symbols) + + # For consistency, always run on Monterey and ARM + MacOS.full_version = "12" + allow(Hardware::CPU).to receive(:type).and_return(:arm) + + formula_path.dirname.mkpath + formula_path.write formula_content + end + + it "returns the correct variations hash" do + h = Formulary.factory("foo-variations").to_hash_with_variations + + expect(h).to be_a(Hash) + expect(JSON.pretty_generate(h["variations"])).to eq expected_variations.strip + end + end + specify "#to_recursive_bottle_hash" do f1 = formula "foo" do url "foo-1.0" diff --git a/Library/Homebrew/test/utils/bottles/tag_spec.rb b/Library/Homebrew/test/utils/bottles/tag_spec.rb index d99e9af5aa..256c592635 100644 --- a/Library/Homebrew/test/utils/bottles/tag_spec.rb +++ b/Library/Homebrew/test/utils/bottles/tag_spec.rb @@ -62,7 +62,7 @@ describe Utils::Bottles::Tag do expect(tag.valid_combination?).to be false end - it "returns false for arm archs and linux " do + it "returns false for arm archs and linux" do tag = described_class.new(system: :linux, arch: :arm64) expect(tag.valid_combination?).to be false tag = described_class.new(system: :linux, arch: :arm)