From 46cb7f28472114c99a7207c890b14ec696d3e8d5 Mon Sep 17 00:00:00 2001 From: Rylan Polster Date: Tue, 25 Jun 2024 00:15:41 -0400 Subject: [PATCH] Update tests --- Library/Homebrew/test/cask/cask_spec.rb | 76 +++++ Library/Homebrew/test/cask/tab_spec.rb | 275 ++++++++++++++++++ Library/Homebrew/test/cmd/deps_spec.rb | 2 +- Library/Homebrew/test/cmd/untap_spec.rb | 2 +- Library/Homebrew/test/cmd/uses_spec.rb | 2 +- Library/Homebrew/test/formula_spec.rb | 12 +- .../test/installed_dependents_spec.rb | 2 +- .../fixtures/cask/Casks/many-artifacts.rb | 32 ++ .../cask/Casks/with-depends-on-everything.rb | 15 + .../test/support/fixtures/cask_receipt.json | 53 ++++ .../test/support/fixtures/receipt.json | 17 +- .../spec/shared_context/integration_test.rb | 2 +- Library/Homebrew/test/tab_spec.rb | 73 +++-- Library/Homebrew/test/uninstall_spec.rb | 2 +- 14 files changed, 527 insertions(+), 38 deletions(-) create mode 100644 Library/Homebrew/test/cask/tab_spec.rb create mode 100644 Library/Homebrew/test/support/fixtures/cask/Casks/many-artifacts.rb create mode 100644 Library/Homebrew/test/support/fixtures/cask/Casks/with-depends-on-everything.rb create mode 100644 Library/Homebrew/test/support/fixtures/cask_receipt.json diff --git a/Library/Homebrew/test/cask/cask_spec.rb b/Library/Homebrew/test/cask/cask_spec.rb index 701a58a2041cd..17e6b5c9beda5 100644 --- a/Library/Homebrew/test/cask/cask_spec.rb +++ b/Library/Homebrew/test/cask/cask_spec.rb @@ -212,6 +212,82 @@ end end + describe "#artifacts_list" do + subject(:cask) { Cask::CaskLoader.load("many-artifacts") } + + it "returns all artifacts when no options are given" do + expected_artifacts = [ + { "uninstall_preflight" => nil }, + { "preflight" => nil }, + { uninstall: [{ + rmdir: "#{TEST_TMPDIR}/empty_directory_path", + trash: ["#{TEST_TMPDIR}/foo", "#{TEST_TMPDIR}/bar"], + }] }, + { pkg: ["ManyArtifacts/ManyArtifacts.pkg"] }, + { app: ["ManyArtifacts/ManyArtifacts.app"] }, + { "uninstall_postflight" => nil }, + { "postflight" => nil }, + { zap: [{ + rmdir: ["~/Library/Caches/ManyArtifacts", "~/Library/Application Support/ManyArtifacts"], + trash: "~/Library/Logs/ManyArtifacts.log", + }] }, + ] + + expect(cask.artifacts_list).to eq(expected_artifacts) + end + + it "skips flight blocks when compact is true" do + expected_artifacts = [ + { uninstall: [{ + rmdir: "#{TEST_TMPDIR}/empty_directory_path", + trash: ["#{TEST_TMPDIR}/foo", "#{TEST_TMPDIR}/bar"], + }] }, + { pkg: ["ManyArtifacts/ManyArtifacts.pkg"] }, + { app: ["ManyArtifacts/ManyArtifacts.app"] }, + { zap: [{ + rmdir: ["~/Library/Caches/ManyArtifacts", "~/Library/Application Support/ManyArtifacts"], + trash: "~/Library/Logs/ManyArtifacts.log", + }] }, + ] + + expect(cask.artifacts_list(compact: true)).to eq(expected_artifacts) + end + + it "returns only uninstall artifacts when uninstall_only is true" do + expected_artifacts = [ + { "uninstall_preflight" => nil }, + { uninstall: [{ + rmdir: "#{TEST_TMPDIR}/empty_directory_path", + trash: ["#{TEST_TMPDIR}/foo", "#{TEST_TMPDIR}/bar"], + }] }, + { app: ["ManyArtifacts/ManyArtifacts.app"] }, + { "uninstall_postflight" => nil }, + { zap: [{ + rmdir: ["~/Library/Caches/ManyArtifacts", "~/Library/Application Support/ManyArtifacts"], + trash: "~/Library/Logs/ManyArtifacts.log", + }] }, + ] + + expect(cask.artifacts_list(uninstall_only: true)).to eq(expected_artifacts) + end + + it "skips flight blocks and returns only uninstall artifacts when compact and uninstall_only are true" do + expected_artifacts = [ + { uninstall: [{ + rmdir: "#{TEST_TMPDIR}/empty_directory_path", + trash: ["#{TEST_TMPDIR}/foo", "#{TEST_TMPDIR}/bar"], + }] }, + { app: ["ManyArtifacts/ManyArtifacts.app"] }, + { zap: [{ + rmdir: ["~/Library/Caches/ManyArtifacts", "~/Library/Application Support/ManyArtifacts"], + trash: "~/Library/Logs/ManyArtifacts.log", + }] }, + ] + + expect(cask.artifacts_list(compact: true, uninstall_only: true)).to eq(expected_artifacts) + end + end + describe "#to_h" do let(:expected_json) { (TEST_FIXTURE_DIR/"cask/everything.json").read.strip } diff --git a/Library/Homebrew/test/cask/tab_spec.rb b/Library/Homebrew/test/cask/tab_spec.rb new file mode 100644 index 0000000000000..e6eeabef94225 --- /dev/null +++ b/Library/Homebrew/test/cask/tab_spec.rb @@ -0,0 +1,275 @@ +# frozen_string_literal: true + +require "cask" + +RSpec.describe Cask::Tab, :cask do + matcher :be_installed_as_dependency do + match do |actual| + actual.installed_as_dependency == true + end + end + + matcher :be_installed_on_request do + match do |actual| + actual.installed_on_request == true + end + end + + matcher :be_loaded_from_api do + match do |actual| + actual.loaded_from_api == true + end + end + + matcher :have_uninstall_flight_blocks do + match do |actual| + actual.uninstall_flight_blocks == true + end + end + + subject(:tab) do + described_class.new( + "homebrew_version" => HOMEBREW_VERSION, + "loaded_from_api" => false, + "uninstall_flight_blocks" => true, + "installed_as_dependency" => false, + "installed_on_request" => true, + "time" => time, + "runtime_dependencies" => { + "cask" => [{ "full_name" => "bar", "version" => "2.0", "declared_directly" => false }], + }, + "source" => { + "path" => CoreCaskTap.instance.path.to_s, + "tap" => CoreCaskTap.instance.to_s, + "tap_git_head" => "8b79aa759500f0ffdf65a23e12950cbe3bf8fe17", + "version" => "1.2.3", + }, + "arch" => Hardware::CPU.arch, + "uninstall_artifacts" => [{ "app" => ["Foo.app"] }], + "built_on" => DevelopmentTools.build_system_info, + ) + end + + let(:time) { Time.now.to_i } + + let(:f) { formula { url "foo-1.0" } } + let(:f_tab_path) { f.prefix/"INSTALL_RECEIPT.json" } + let(:f_tab_content) { (TEST_FIXTURE_DIR/"receipt.json").read } + + specify "defaults" do + stub_const("HOMEBREW_VERSION", "4.3.7") + + tab = described_class.empty + + expect(tab.homebrew_version).to eq(HOMEBREW_VERSION) + expect(tab).not_to be_installed_as_dependency + expect(tab).not_to be_installed_on_request + expect(tab).not_to be_loaded_from_api + expect(tab).not_to have_uninstall_flight_blocks + expect(tab.tap).to be_nil + expect(tab.time).to be_nil + expect(tab.runtime_dependencies).to be_nil + expect(tab.source["path"]).to be_nil + end + + specify "#runtime_dependencies" do + tab = described_class.new + expect(tab.runtime_dependencies).to be_nil + + tab.runtime_dependencies = {} + expect(tab.runtime_dependencies).not_to be_nil + + tab.runtime_dependencies = { + "cask" => [{ "full_name" => "bar", "version" => "2.0", "declared_directly" => false }], + } + expect(tab.runtime_dependencies).not_to be_nil + end + + specify "::runtime_deps_hash" do + cask = Cask::CaskLoader.load("with-depends-on-everything") + + unar = instance_double(Formula, full_name: "unar", version: "1.2", revision: 0, pkg_version: "1.2") + expect(Formulary).to receive(:factory).with("unar", { warn: false }).and_return(unar) + + expected_hash = { + arch: [{ type: :intel, bits: 64 }, { type: :arm, bits: 64 }], + cask: [ + { "full_name"=>"local-caffeine", "version"=>"1.2.3", "declared_directly"=>true }, + { "full_name"=>"local-transmission", "version"=>"2.61", "declared_directly"=>true }, + ], + formula: [ + { "full_name"=>"unar", "version"=>"1.2", "revision"=>0, "pkg_version"=>"1.2", "declared_directly"=>true }, + ], + macos: MacOSRequirement.new([:el_capitan], comparator: ">="), + } + + runtime_deps_hash = described_class.runtime_deps_hash(cask, cask.depends_on) + tab = described_class.new + tab.runtime_dependencies = runtime_deps_hash + expect(tab.runtime_dependencies).to eql(expected_hash) + end + + specify "other attributes" do + expect(tab.tap.name).to eq("homebrew/cask") + expect(tab.time).to eq(time) + expect(tab).not_to be_loaded_from_api + expect(tab).to have_uninstall_flight_blocks + expect(tab).not_to be_installed_as_dependency + expect(tab).to be_installed_on_request + expect(tab).not_to be_loaded_from_api + end + + describe "::from_file" do + it "parses a cask Tab from a file" do + path = Pathname.new("#{TEST_FIXTURE_DIR}/cask_receipt.json") + tab = described_class.from_file(path) + source_path = "/opt/homebrew/Library/Taps/homebrew/homebrew-cask/Casks/f/foo.rb" + runtime_dependencies = { + "cask" => [ + { + "full_name" => "bar", + "version" => "2.0", + "declared_directly" => true, + }, + ], + "formula" => [ + { + "full_name" => "baz", + "version" => "3.0", + "revision" => 0, + "pkg_version" => "3.0", + "declared_directly" => true, + }, + ], + "macos" => { + ">=" => [ + "12", + ], + }, + } + + expect(tab).not_to be_loaded_from_api + expect(tab).to have_uninstall_flight_blocks + expect(tab).not_to be_installed_as_dependency + expect(tab).to be_installed_on_request + expect(tab.time).to eq(Time.at(1_719_289_256).to_i) + expect(tab.runtime_dependencies).to eq(runtime_dependencies) + expect(tab.source["path"]).to eq(source_path) + expect(tab.version).to eq("1.2.3") + expect(tab.tap.name).to eq("homebrew/cask") + end + end + + describe "::from_file_content" do + it "parses a cask Tab from a file" do + path = Pathname.new("#{TEST_FIXTURE_DIR}/cask_receipt.json") + tab = described_class.from_file_content(path.read, path) + source_path = "/opt/homebrew/Library/Taps/homebrew/homebrew-cask/Casks/f/foo.rb" + runtime_dependencies = { + "cask" => [ + { + "full_name" => "bar", + "version" => "2.0", + "declared_directly" => true, + }, + ], + "formula" => [ + { + "full_name" => "baz", + "version" => "3.0", + "revision" => 0, + "pkg_version" => "3.0", + "declared_directly" => true, + }, + ], + "macos" => { + ">=" => [ + "12", + ], + }, + } + + expect(tab).not_to be_loaded_from_api + expect(tab).to have_uninstall_flight_blocks + expect(tab).not_to be_installed_as_dependency + expect(tab).to be_installed_on_request + expect(tab.tabfile).to eq(path) + expect(tab.time).to eq(Time.at(1_719_289_256).to_i) + expect(tab.runtime_dependencies).to eq(runtime_dependencies) + expect(tab.source["path"]).to eq(source_path) + expect(tab.version).to eq("1.2.3") + expect(tab.tap.name).to eq("homebrew/cask") + end + + it "raises a parse exception message including the Tab filename" do + expect { described_class.from_file_content("''", "cask_receipt.json") }.to raise_error( + JSON::ParserError, + /receipt.json:/, + ) + end + end + + describe "::create" do + it "creates a cask Tab" do + cask = Cask::CaskLoader.load("local-caffeine") + + tab = described_class.create(cask) + expect(tab).not_to be_loaded_from_api + expect(tab).not_to have_uninstall_flight_blocks + expect(tab).not_to be_installed_as_dependency + expect(tab).not_to be_installed_on_request + expect(tab.source).to eq({ + "path" => "#{CoreCaskTap.instance.path}/Casks/local-caffeine.rb", + "tap" => CoreCaskTap.instance.name, + "tap_git_head" => nil, + "version" => "1.2.3", + }) + expect(tab.runtime_dependencies).to eq({}) + expect(tab.uninstall_artifacts).to eq([{ app: ["Caffeine.app"] }]) + end + end + + describe "::for_cask" do + let(:cask) { Cask::CaskLoader.load("local-transmission") } + let(:cask_tab_path) { cask.metadata_main_container_path/AbstractTab::FILENAME } + let(:cask_tab_content) { (TEST_FIXTURE_DIR/"cask_receipt.json").read } + + it "creates a Tab for a given cask" do + tab = described_class.for_cask(cask) + expect(tab.source["path"]).to eq(cask.sourcefile_path.to_s) + end + + it "creates a Tab for a given cask with existing Tab" do + cask_tab_path.dirname.mkpath + cask_tab_path.write cask_tab_content + + tab = described_class.for_cask(cask) + expect(tab.tabfile).to eq(cask_tab_path) + end + + it "can create a Tab for a non-existent cask" do + cask_tab_path.dirname.mkpath + + tab = described_class.for_cask(cask) + expect(tab.tabfile).to be_nil + end + end + + specify "#to_json" do + json_tab = described_class.new(JSON.parse(tab.to_json)) + expect(json_tab.homebrew_version).to eq(tab.homebrew_version) + expect(json_tab.loaded_from_api).to eq(tab.loaded_from_api) + expect(json_tab.uninstall_flight_blocks).to eq(tab.uninstall_flight_blocks) + expect(json_tab.installed_as_dependency).to eq(tab.installed_as_dependency) + expect(json_tab.installed_on_request).to eq(tab.installed_on_request) + expect(json_tab.time).to eq(tab.time) + expect(json_tab.runtime_dependencies).to eq(tab.runtime_dependencies) + expect(json_tab.source["path"]).to eq(tab.source["path"]) + expect(json_tab.tap).to eq(tab.tap) + expect(json_tab.source["tap_git_head"]).to eq(tab.source["tap_git_head"]) + expect(json_tab.version).to eq(tab.version) + expect(json_tab.arch).to eq(tab.arch.to_s) + expect(json_tab.uninstall_artifacts).to eq(tab.uninstall_artifacts) + expect(json_tab.built_on["os"]).to eq(tab.built_on["os"]) + end +end diff --git a/Library/Homebrew/test/cmd/deps_spec.rb b/Library/Homebrew/test/cmd/deps_spec.rb index a4ccf274de7b9..80edb9433737b 100644 --- a/Library/Homebrew/test/cmd/deps_spec.rb +++ b/Library/Homebrew/test/cmd/deps_spec.rb @@ -32,7 +32,7 @@ # Mock `Formula#any_version_installed?` by creating the tab in a plausible keg directory keg_dir = HOMEBREW_CELLAR/"installed"/"1.0" keg_dir.mkpath - touch keg_dir/Tab::FILENAME + touch keg_dir/AbstractTab::FILENAME expect { brew "deps", "baz", "--include-test", "--missing", "--skip-recommended" } .to be_a_success diff --git a/Library/Homebrew/test/cmd/untap_spec.rb b/Library/Homebrew/test/cmd/untap_spec.rb index bc5d286724d67..fb1d3a77b0e5c 100644 --- a/Library/Homebrew/test/cmd/untap_spec.rb +++ b/Library/Homebrew/test/cmd/untap_spec.rb @@ -33,7 +33,7 @@ def load_formula(name:, with_formula_file: false, mock_install: false) keg_path = HOMEBREW_CELLAR/name/"1.2.3" keg_path.mkpath - tab_path = keg_path/Tab::FILENAME + tab_path = keg_path/AbstractTab::FILENAME tab_path.write <<~JSON { "source": { diff --git a/Library/Homebrew/test/cmd/uses_spec.rb b/Library/Homebrew/test/cmd/uses_spec.rb index 83199c30fcfca..92d27df77812b 100644 --- a/Library/Homebrew/test/cmd/uses_spec.rb +++ b/Library/Homebrew/test/cmd/uses_spec.rb @@ -36,7 +36,7 @@ %w[foo installed].each do |formula_name| keg_dir = HOMEBREW_CELLAR/formula_name/"1.0" keg_dir.mkpath - touch keg_dir/Tab::FILENAME + touch keg_dir/AbstractTab::FILENAME end expect { brew "uses", "foo", "--eval-all", "--include-optional", "--missing", "--recursive" } diff --git a/Library/Homebrew/test/formula_spec.rb b/Library/Homebrew/test/formula_spec.rb index 6fc08f61d1215..e85d970cc3a03 100644 --- a/Library/Homebrew/test/formula_spec.rb +++ b/Library/Homebrew/test/formula_spec.rb @@ -264,7 +264,7 @@ prefix = HOMEBREW_CELLAR/f.name/"0.1" prefix.mkpath - FileUtils.touch prefix/Tab::FILENAME + FileUtils.touch prefix/AbstractTab::FILENAME expect(f).to have_any_version_installed end @@ -279,7 +279,7 @@ oldname_prefix.mkpath oldname_tab = Tab.empty - oldname_tab.tabfile = oldname_prefix/Tab::FILENAME + oldname_tab.tabfile = oldname_prefix/AbstractTab::FILENAME oldname_tab.write expect(f).not_to need_migration @@ -346,7 +346,7 @@ head_prefix.mkpath tab = Tab.empty - tab.tabfile = head_prefix/Tab::FILENAME + tab.tabfile = head_prefix/AbstractTab::FILENAME tab.source["versions"] = { "stable" => "1.0" } tab.write @@ -378,7 +378,7 @@ prefix.mkpath tab = Tab.empty - tab.tabfile = prefix/Tab::FILENAME + tab.tabfile = prefix/AbstractTab::FILENAME tab.source_modified_time = stamp tab.write end @@ -1106,7 +1106,7 @@ class FooVariations < Formula prefix = f.prefix(version) prefix.mkpath tab = Tab.empty - tab.tabfile = prefix/Tab::FILENAME + tab.tabfile = prefix/AbstractTab::FILENAME tab.source_modified_time = 1 tab.write end @@ -1340,7 +1340,7 @@ def pour_bottle? def setup_tab_for_prefix(prefix, options = {}) prefix.mkpath tab = Tab.empty - tab.tabfile = prefix/Tab::FILENAME + tab.tabfile = prefix/AbstractTab::FILENAME tab.source["path"] = options[:path].to_s if options[:path] tab.source["tap"] = options[:tap] if options[:tap] tab.source["versions"] = options[:versions] if options[:versions] diff --git a/Library/Homebrew/test/installed_dependents_spec.rb b/Library/Homebrew/test/installed_dependents_spec.rb index 4bcbd383c44f4..35823954eea38 100644 --- a/Library/Homebrew/test/installed_dependents_spec.rb +++ b/Library/Homebrew/test/installed_dependents_spec.rb @@ -61,7 +61,7 @@ def alter_tab(keg) def tab_dependencies(keg, deps, homebrew_version: "1.1.6") alter_tab(keg) do |tab| tab.homebrew_version = homebrew_version - tab.tabfile = keg/Tab::FILENAME + tab.tabfile = keg/AbstractTab::FILENAME tab.runtime_dependencies = deps end end diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/many-artifacts.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/many-artifacts.rb new file mode 100644 index 0000000000000..a488fd35f1d96 --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/many-artifacts.rb @@ -0,0 +1,32 @@ +cask "many-artifacts" do + version "1.2.3" + sha256 "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b" + + url "file://#{TEST_FIXTURE_DIR}/cask/ManyArtifacts.zip" + homepage "https://brew.sh/many-artifacts" + + app "ManyArtifacts/ManyArtifacts.app" + pkg "ManyArtifacts/ManyArtifacts.pkg" + + preflight do + # do nothing + end + + postflight do + # do nothing + end + + uninstall_preflight do + # do nothing + end + + uninstall_postflight do + # do nothing + end + + uninstall trash: ["#{TEST_TMPDIR}/foo", "#{TEST_TMPDIR}/bar"], + rmdir: "#{TEST_TMPDIR}/empty_directory_path" + + zap trash: "~/Library/Logs/ManyArtifacts.log", + rmdir: ["~/Library/Caches/ManyArtifacts", "~/Library/Application Support/ManyArtifacts"] +end diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-depends-on-everything.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-depends-on-everything.rb new file mode 100644 index 0000000000000..85570a7b002c8 --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-depends-on-everything.rb @@ -0,0 +1,15 @@ +cask "with-depends-on-everything" do + version "1.2.3" + sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94" + + url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip" + homepage "https://brew.sh/with-depends-on-everything" + + depends_on arch: [:intel, :arm64] + depends_on cask: "local-caffeine" + depends_on cask: "local-transmission" + depends_on formula: "unar" + depends_on macos: ">= :el_capitan" + + app "Caffeine.app" +end diff --git a/Library/Homebrew/test/support/fixtures/cask_receipt.json b/Library/Homebrew/test/support/fixtures/cask_receipt.json new file mode 100644 index 0000000000000..e6ca53b9bbbfe --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/cask_receipt.json @@ -0,0 +1,53 @@ +{ + "homebrew_version": "4.3.7", + "loaded_from_api": false, + "uninstall_flight_blocks": true, + "installed_as_dependency": false, + "installed_on_request": true, + "time": 1719289256, + "runtime_dependencies": { + "cask": [ + { + "full_name": "bar", + "version": "2.0", + "declared_directly": true + } + ], + "formula": [ + { + "full_name": "baz", + "version": "3.0", + "revision": 0, + "pkg_version": "3.0", + "declared_directly": true + } + ], + "macos": { + ">=": [ + "12" + ] + } + }, + "source": { + "path": "/opt/homebrew/Library/Taps/homebrew/homebrew-cask/Casks/f/foo.rb", + "tap": "homebrew/cask", + "tap_git_head": "8b79aa759500f0ffdf65a23e12950cbe3bf8fe17", + "version": "1.2.3" + }, + "arch": "arm64", + "uninstall_artifacts": [ + { + "app": [ + "Foo.app" + ] + } + ], + "built_on": { + "os": "Macintosh", + "os_version": "macOS 14", + "cpu_family": "arm_firestorm_icestorm", + "xcode": "15.4", + "clt": "15.3.0.0.1.1708646388", + "preferred_perl": "5.34" + } +} diff --git a/Library/Homebrew/test/support/fixtures/receipt.json b/Library/Homebrew/test/support/fixtures/receipt.json index 6907ae040c5a2..c51ec4d08f182 100644 --- a/Library/Homebrew/test/support/fixtures/receipt.json +++ b/Library/Homebrew/test/support/fixtures/receipt.json @@ -10,6 +10,9 @@ ], "built_as_bottle": false, "poured_from_bottle": true, + "loaded_from_api": false, + "installed_as_dependency": false, + "installed_on_request": true, "changed_files": [ "INSTALL_RECEIPT.json", "bin/foo" @@ -27,12 +30,12 @@ } ], "source": { - "path": "/usr/local/Library/Taps/homebrew/homebrew-core/Formula/foo.rb", - "tap": "homebrew/core", - "spec": "stable", - "versions": { - "stable": "2.14", - "head": "HEAD-0000000" - } + "path": "/usr/local/Library/Taps/homebrew/homebrew-core/Formula/foo.rb", + "tap": "homebrew/core", + "spec": "stable", + "versions": { + "stable": "2.14", + "head": "HEAD-0000000" + } } } diff --git a/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb b/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb index c11c4e4d4df9d..0132ceebb7951 100644 --- a/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb +++ b/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb @@ -191,7 +191,7 @@ class #{Formulary.class_s(name)} < Formula keg.mkpath tab = Tab.for_name(name) - tab.tabfile ||= keg/Tab::FILENAME + tab.tabfile ||= keg/AbstractTab::FILENAME tab_attributes.each do |key, value| tab.instance_variable_set(:"@#{key}", value) end diff --git a/Library/Homebrew/test/tab_spec.rb b/Library/Homebrew/test/tab_spec.rb index 961f9c0e5cded..6f968305f10db 100644 --- a/Library/Homebrew/test/tab_spec.rb +++ b/Library/Homebrew/test/tab_spec.rb @@ -18,20 +18,40 @@ end end + matcher :be_installed_as_dependency do + match do |actual| + actual.installed_as_dependency == true + end + end + + matcher :be_installed_on_request do + match do |actual| + actual.installed_on_request == true + end + end + + matcher :be_loaded_from_api do + match do |actual| + actual.loaded_from_api == true + end + end + subject(:tab) do described_class.new( - "homebrew_version" => HOMEBREW_VERSION, - "used_options" => used_options.as_flags, - "unused_options" => unused_options.as_flags, - "built_as_bottle" => false, - "poured_from_bottle" => true, - "changed_files" => [], - "time" => time, - "source_modified_time" => 0, - "compiler" => "clang", - "stdlib" => "libcxx", - "runtime_dependencies" => [], - "source" => { + "homebrew_version" => HOMEBREW_VERSION, + "used_options" => used_options.as_flags, + "unused_options" => unused_options.as_flags, + "built_as_bottle" => false, + "poured_from_bottle" => true, + "installed_as_dependency" => false, + "installed_on_request" => true, + "changed_files" => [], + "time" => time, + "source_modified_time" => 0, + "compiler" => "clang", + "stdlib" => "libcxx", + "runtime_dependencies" => [], + "source" => { "tap" => CoreTap.instance.to_s, "path" => CoreTap.instance.path.to_s, "spec" => "stable", @@ -40,8 +60,8 @@ "head" => "HEAD-1111111", }, }, - "arch" => Hardware::CPU.arch, - "built_on" => DevelopmentTools.build_system_info, + "arch" => Hardware::CPU.arch, + "built_on" => DevelopmentTools.build_system_info, ) end @@ -65,6 +85,9 @@ expect(tab.changed_files).to be_nil expect(tab).not_to be_built_as_bottle expect(tab).not_to be_poured_from_bottle + expect(tab).not_to be_installed_as_dependency + expect(tab).not_to be_installed_on_request + expect(tab).not_to be_loaded_from_api expect(tab).to be_stable expect(tab).not_to be_head expect(tab.tap).to be_nil @@ -156,10 +179,13 @@ expect(tab.time).to eq(time) expect(tab).not_to be_built_as_bottle expect(tab).to be_poured_from_bottle + expect(tab).not_to be_installed_as_dependency + expect(tab).to be_installed_on_request + expect(tab).not_to be_loaded_from_api end describe "::from_file" do - it "parses a Tab from a file" do + it "parses a formula Tab from a file" do path = Pathname.new("#{TEST_FIXTURE_DIR}/receipt.json") tab = described_class.from_file(path) source_path = "/usr/local/Library/Taps/homebrew/homebrew-core/Formula/foo.rb" @@ -171,6 +197,9 @@ expect(tab.changed_files).to eq(changed_files) expect(tab).not_to be_built_as_bottle expect(tab).to be_poured_from_bottle + expect(tab).not_to be_installed_as_dependency + expect(tab).to be_installed_on_request + expect(tab).not_to be_loaded_from_api expect(tab).to be_stable expect(tab).not_to be_head expect(tab.tap.name).to eq("homebrew/core") @@ -186,7 +215,7 @@ end describe "::from_file_content" do - it "parses a Tab from a file" do + it "parses a formula Tab from a file" do path = Pathname.new("#{TEST_FIXTURE_DIR}/receipt.json") tab = described_class.from_file_content(path.read, path) source_path = "/usr/local/Library/Taps/homebrew/homebrew-core/Formula/foo.rb" @@ -198,6 +227,9 @@ expect(tab.changed_files).to eq(changed_files) expect(tab).not_to be_built_as_bottle expect(tab).to be_poured_from_bottle + expect(tab).not_to be_installed_as_dependency + expect(tab).to be_installed_on_request + expect(tab).not_to be_loaded_from_api expect(tab).to be_stable expect(tab).not_to be_head expect(tab.tap.name).to eq("homebrew/core") @@ -211,7 +243,7 @@ expect(tab.source["path"]).to eq(source_path) end - it "can parse an old Tab file" do + it "can parse an old formula Tab file" do path = Pathname.new("#{TEST_FIXTURE_DIR}/receipt_old.json") tab = described_class.from_file_content(path.read, path) @@ -219,6 +251,9 @@ expect(tab.unused_options.sort).to eq(unused_options.sort) expect(tab).not_to be_built_as_bottle expect(tab).to be_poured_from_bottle + expect(tab).not_to be_installed_as_dependency + expect(tab).not_to be_installed_on_request + expect(tab).not_to be_loaded_from_api expect(tab).to be_stable expect(tab).not_to be_head expect(tab.tap.name).to eq("homebrew/core") @@ -238,7 +273,7 @@ end describe "::create" do - it "creates a Tab" do + it "creates a formula Tab" do # < 1.1.7 runtime dependencies were wrong so are ignored stub_const("HOMEBREW_VERSION", "1.1.7") @@ -277,7 +312,7 @@ expect(tab.source["path"]).to eq(f.path.to_s) end - it "can create a Tab from an alias" do + it "can create a formula Tab from an alias" do alias_path = CoreTap.instance.alias_dir/"bar" f = formula(alias_path:) { url "foo-1.0" } compiler = DevelopmentTools.default_compiler diff --git a/Library/Homebrew/test/uninstall_spec.rb b/Library/Homebrew/test/uninstall_spec.rb index e4cc7d1f9191d..530a687310cb0 100644 --- a/Library/Homebrew/test/uninstall_spec.rb +++ b/Library/Homebrew/test/uninstall_spec.rb @@ -33,7 +33,7 @@ tab = Tab.empty tab.homebrew_version = "1.1.6" - tab.tabfile = dependent_formula.latest_installed_prefix/Tab::FILENAME + tab.tabfile = dependent_formula.latest_installed_prefix/AbstractTab::FILENAME tab.runtime_dependencies = [ { "full_name" => "dependency", "version" => "1" }, ]