diff --git a/Library/Homebrew/test/bundle/installer_spec.rb b/Library/Homebrew/test/bundle/installer_spec.rb index edf2520d10260..318910a429020 100644 --- a/Library/Homebrew/test/bundle/installer_spec.rb +++ b/Library/Homebrew/test/bundle/installer_spec.rb @@ -163,9 +163,7 @@ it "does not trust unqualified `trusted: true` names" do trusted_formula_entry = Homebrew::Bundle::Dsl::Entry.new(:brew, "mysql", { trusted: true }) - expect(Homebrew::Trust).not_to receive(:trust!) - - described_class.install!([trusted_formula_entry], quiet: true) + expect(Homebrew::Bundle::Trust.entries([trusted_formula_entry])).to be_empty end it "skips fetching formulae from fully qualified untapped taps" do diff --git a/Library/Homebrew/test/cask/artifact/alt_target_spec.rb b/Library/Homebrew/test/cask/artifact/alt_target_spec.rb index f660d360f849e..f985177faf696 100644 --- a/Library/Homebrew/test/cask/artifact/alt_target_spec.rb +++ b/Library/Homebrew/test/cask/artifact/alt_target_spec.rb @@ -10,15 +10,12 @@ artifact.install_phase(command: NeverSudoSystemCommand, force: false) end end - let(:source_path) { cask.staged_path.join("Caffeine.app") } let(:target_path) { Pathname(cask.config.appdir).join("AnotherName.app") } - before do - InstallHelper.install_without_artifacts(cask) - end - it "installs the given apps using the proper target directory" do + source_path.mkpath + expect(source_path).to be_a_directory expect(target_path).not_to exist @@ -41,7 +38,7 @@ it "installs the given apps using the proper target directory" do appsubdir = cask.staged_path.join("subdir").tap(&:mkpath) - FileUtils.mv(source_path, appsubdir) + (appsubdir/"Caffeine.app").mkpath install_phase @@ -51,8 +48,9 @@ end it "only uses apps when they are specified" do + source_path.mkpath staged_app_copy = source_path.sub("Caffeine.app", "Caffeine Deluxe.app") - FileUtils.cp_r source_path, staged_app_copy + staged_app_copy.mkpath install_phase @@ -64,6 +62,7 @@ end it "avoids clobbering an existing app by moving over it" do + source_path.mkpath target_path.mkpath expect { install_phase } diff --git a/Library/Homebrew/test/cask/artifact/bashcompletion_spec.rb b/Library/Homebrew/test/cask/artifact/bashcompletion_spec.rb index 566b18bc658ee..57a3ff2baa1f2 100644 --- a/Library/Homebrew/test/cask/artifact/bashcompletion_spec.rb +++ b/Library/Homebrew/test/cask/artifact/bashcompletion_spec.rb @@ -19,14 +19,13 @@ let(:full_source_path) { cask.staged_path.join("test.bash-completion") } let(:full_target_path) { cask.config.bash_completion.join("test") } - before do - InstallHelper.install_without_artifacts(cask) - end - context "with completion" do let(:cask_token) { "with-shellcompletion" } it "links the completion to the proper directory" do + source_path.dirname.mkpath + source_path.write "" + install_phase.call expect(File).to be_identical target_path, source_path @@ -37,6 +36,9 @@ let(:cask_token) { "with-shellcompletion-long" } it "links the completion to the proper directory" do + full_source_path.dirname.mkpath + full_source_path.write "" + install_phase.call expect(File).to be_identical full_target_path, full_source_path diff --git a/Library/Homebrew/test/cask/artifact/fishlcompletion_spec.rb b/Library/Homebrew/test/cask/artifact/fishlcompletion_spec.rb index aec2aeafb8e29..36454ee647eac 100644 --- a/Library/Homebrew/test/cask/artifact/fishlcompletion_spec.rb +++ b/Library/Homebrew/test/cask/artifact/fishlcompletion_spec.rb @@ -19,12 +19,11 @@ let(:full_source_path) { cask.staged_path.join("test.fish-completion") } let(:full_target_path) { cask.config.fish_completion.join("test.fish") } - before do - InstallHelper.install_without_artifacts(cask) - end - context "with completion" do it "links the completion to the proper directory" do + source_path.dirname.mkpath + source_path.write "" + install_phase.call expect(File).to be_identical target_path, source_path @@ -35,6 +34,9 @@ let(:cask_token) { "with-shellcompletion-long" } it "links the completion to the proper directory" do + full_source_path.dirname.mkpath + full_source_path.write "" + install_phase.call expect(File).to be_identical full_target_path, full_source_path diff --git a/Library/Homebrew/test/cask/artifact/uninstall_no_zap_spec.rb b/Library/Homebrew/test/cask/artifact/uninstall_no_zap_spec.rb index 2550aafd08220..d9d7e5212100e 100644 --- a/Library/Homebrew/test/cask/artifact/uninstall_no_zap_spec.rb +++ b/Library/Homebrew/test/cask/artifact/uninstall_no_zap_spec.rb @@ -8,10 +8,6 @@ cask.artifacts.find { |a| a.is_a?(described_class) } end - before do - InstallHelper.install_without_artifacts(cask) - end - describe "#uninstall_phase" do subject { zap_artifact } diff --git a/Library/Homebrew/test/cask/artifact/zshcompletion_spec.rb b/Library/Homebrew/test/cask/artifact/zshcompletion_spec.rb index b79a4bd583f5a..a83d8bc195974 100644 --- a/Library/Homebrew/test/cask/artifact/zshcompletion_spec.rb +++ b/Library/Homebrew/test/cask/artifact/zshcompletion_spec.rb @@ -19,12 +19,11 @@ let(:full_source_path) { cask.staged_path.join("test.zsh-completion") } let(:full_target_path) { cask.config.zsh_completion.join("_test") } - before do - InstallHelper.install_without_artifacts(cask) - end - context "with completion" do it "links the completion to the proper directory" do + source_path.dirname.mkpath + source_path.write "" + install_phase.call expect(File).to be_identical target_path, source_path @@ -35,6 +34,9 @@ let(:cask_token) { "with-shellcompletion-long" } it "links the completion to the proper directory" do + full_source_path.dirname.mkpath + full_source_path.write "" + install_phase.call expect(File).to be_identical full_target_path, full_source_path diff --git a/Library/Homebrew/test/cask/cask_loader/from_api_loader_spec.rb b/Library/Homebrew/test/cask/cask_loader/from_api_loader_spec.rb index 371f057f7e707..004d467558273 100644 --- a/Library/Homebrew/test/cask/cask_loader/from_api_loader_spec.rb +++ b/Library/Homebrew/test/cask/cask_loader/from_api_loader_spec.rb @@ -84,10 +84,6 @@ .and have_attributes(token: api_token) end - it "returns nil for full name with invalid tap" do - expect(described_class.try_new("homebrew/foo/#{api_token}")).to be_nil - end - context "with core tap migration renames" do let(:foo_tap) { Tap.fetch("homebrew", "foo") } @@ -140,10 +136,6 @@ .and have_attributes(token: internal_api_token) end - it "returns nil for full name with invalid tap" do - expect(described_class.try_new("homebrew/foo/#{internal_api_token}")).to be_nil - end - context "with core tap migration renames" do let(:foo_tap) { Tap.fetch("homebrew", "foo") } @@ -180,6 +172,10 @@ end end end + + it "returns nil for full name with invalid tap" do + expect(described_class.try_new("homebrew/foo/test-opera")).to be_nil + end end describe "#load" do diff --git a/Library/Homebrew/test/cmd/help_spec.rb b/Library/Homebrew/test/cmd/help_spec.rb index a81fb776e2465..d428d130eded1 100644 --- a/Library/Homebrew/test/cmd/help_spec.rb +++ b/Library/Homebrew/test/cmd/help_spec.rb @@ -104,9 +104,7 @@ def run; end .to output(%r{trusthelp/foo}).to_stderr .and be_a_failure - expect { brew "trust", "--command", "trusthelp/foo/hello-trust-tap", trust_env.dup } - .to output(%r{Trusted command: trusthelp/foo/hello-trust-tap}).to_stdout - .and be_a_success + with_env(trust_env) { Homebrew::Trust.trust!(:command, "trusthelp/foo/hello-trust-tap") } expect { brew "help", "hello-trust-tap", require_trust_env.dup } .to output(%r{^From tap: trusthelp/foo$}).to_stdout diff --git a/Library/Homebrew/test/cmd/reinstall_spec.rb b/Library/Homebrew/test/cmd/reinstall_spec.rb index 60de489f730a6..82ad3c51c9fdf 100644 --- a/Library/Homebrew/test/cmd/reinstall_spec.rb +++ b/Library/Homebrew/test/cmd/reinstall_spec.rb @@ -127,7 +127,7 @@ cmd.run end - it "reinstalls a Formula", :aggregate_failures, :integration_test do + it "reinstalls a Formula", :integration_test do formula_name = "testball_bottle" formula_prefix = HOMEBREW_CELLAR/formula_name/"0.1" formula_bin = formula_prefix/"bin" @@ -142,21 +142,5 @@ .and output(/✔︎.*/m).to_stderr .and be_a_success expect(formula_bin).to exist - - FileUtils.rm_r(formula_bin) - - expect { brew "reinstall", formula_name } - .to output(/.*Would reinstall 1 formula:\s*#{formula_name}.*/).to_stdout - .and output(/✔︎.*/m).to_stderr - .and be_a_success - expect(formula_bin).to exist - - FileUtils.rm_r(formula_bin) - - expect { brew "reinstall", formula_name, { "HOMEBREW_FORBIDDEN_FORMULAE" => formula_name } } - .to not_to_output(/#{Regexp.escape(formula_prefix)}/o).to_stdout - .and output(/#{formula_name} was forbidden/).to_stderr - .and be_a_failure - expect(formula_bin).not_to exist end end diff --git a/Library/Homebrew/test/cmd/tab_spec.rb b/Library/Homebrew/test/cmd/tab_spec.rb index a538a232416f2..31936b1b6948b 100644 --- a/Library/Homebrew/test/cmd/tab_spec.rb +++ b/Library/Homebrew/test/cmd/tab_spec.rb @@ -20,7 +20,7 @@ def cask_installed_on_request?(cask) it_behaves_like "parseable arguments" - it "marks or unmarks a formula as installed on request", :integration_test do + it "marks a formula as installed on request", :integration_test do setup_test_formula "foo", tab_attributes: { "installed_on_request" => false } foo = Formula["foo"] @@ -30,12 +30,6 @@ def cask_installed_on_request?(cask) .and output(/foo is now marked as installed on request/).to_stdout .and not_to_output.to_stderr expect(installed_on_request?(foo)).to be true - - expect { brew "tab", "--no-installed-on-request", "foo" } - .to be_a_success - .and output(/foo is now marked as not installed on request/).to_stdout - .and not_to_output.to_stderr - expect(installed_on_request?(foo)).to be false end it "marks or unmarks a cask as installed on request with a missing tab", :cask do diff --git a/Library/Homebrew/test/cmd/unlink_spec.rb b/Library/Homebrew/test/cmd/unlink_spec.rb index 87c38fb282341..6455989f1001d 100644 --- a/Library/Homebrew/test/cmd/unlink_spec.rb +++ b/Library/Homebrew/test/cmd/unlink_spec.rb @@ -8,7 +8,14 @@ it_behaves_like "parseable arguments" it "unlinks a Formula", :integration_test do - install_test_formula "testball" + setup_test_formula "testball", tab_attributes: { installed_on_request: true } + formula_prefix = Formula["testball"].prefix + (formula_prefix/"bin").mkpath + (formula_prefix/"bin/test").write "test" + (HOMEBREW_PREFIX/"bin").mkpath + (HOMEBREW_PREFIX/"bin/test").make_relative_symlink(formula_prefix/"bin/test") + HOMEBREW_LINKED_KEGS.mkpath + (HOMEBREW_LINKED_KEGS/"testball").make_relative_symlink(formula_prefix) expect { brew "unlink", "testball" } .to output(/Unlinking /).to_stdout diff --git a/Library/Homebrew/test/dev-cmd/test_spec.rb b/Library/Homebrew/test/dev-cmd/test_spec.rb index f2c161bf91244..0c50bd829c8df 100644 --- a/Library/Homebrew/test/dev-cmd/test_spec.rb +++ b/Library/Homebrew/test/dev-cmd/test_spec.rb @@ -9,13 +9,22 @@ it_behaves_like "parseable arguments" it "tests a given Formula", :integration_test do - with_env(HOMEBREW_NO_INSTALL_FROM_API: "1") do - install_test_formula "testball", <<~'RUBY' - test do - assert_equal "test", shell_output("#{bin}/test") - end - RUBY - end + skip "Nested sandboxing is not supported." if Sandbox.nested_sandbox? + + setup_test_formula "testball", <<~'RUBY', tab_attributes: { installed_on_request: true } + test do + assert_equal "test", shell_output("#{bin}/test") + end + RUBY + formula_prefix = Formula["testball"].prefix + (formula_prefix/"bin").mkpath + (formula_prefix/"bin/test").write <<~SH + #!/bin/sh + printf test + SH + (formula_prefix/"bin/test").chmod 0755 + HOMEBREW_LINKED_KEGS.mkpath + (HOMEBREW_LINKED_KEGS/"testball").make_relative_symlink(formula_prefix) expect { brew "test", "--verbose", "testball", "HOMEBREW_NO_INSTALL_FROM_API" => "1" } .to output(/Testing testball/).to_stdout @@ -24,19 +33,21 @@ end it "blocks network access when test phase is offline", :integration_test do - if Sandbox.available? - with_env(HOMEBREW_NO_INSTALL_FROM_API: "1") do - install_test_formula "testball_offline_test", <<~RUBY - deny_network_access! :test - test do - system "curl", "example.org" - end - RUBY + skip "Sandbox not available." unless Sandbox.available? + skip "Nested sandboxing is not supported." if Sandbox.nested_sandbox? + + formula_name = "testball_offline_test" + setup_test_formula formula_name, <<~RUBY, tab_attributes: { installed_on_request: true } + deny_network_access! :test + test do + system "curl", "example.org" end + RUBY + HOMEBREW_LINKED_KEGS.mkpath + (HOMEBREW_LINKED_KEGS/formula_name).make_relative_symlink(Formula[formula_name].prefix) - expect { brew "test", "--verbose", "testball_offline_test", "HOMEBREW_NO_INSTALL_FROM_API" => "1" } - .to output(/curl: \(6\) Could not resolve host: example\.org/).to_stdout - .and be_a_failure - end + expect { brew "test", "--verbose", formula_name, "HOMEBREW_NO_INSTALL_FROM_API" => "1" } + .to output(/curl: \(6\) Could not resolve host: example\.org/).to_stdout + .and be_a_failure end end diff --git a/Library/Homebrew/test/patching_spec.rb b/Library/Homebrew/test/patching_spec.rb index 9a34496e2d7a5..9d85790e667a1 100644 --- a/Library/Homebrew/test/patching_spec.rb +++ b/Library/Homebrew/test/patching_spec.rb @@ -260,15 +260,19 @@ def formula(name = "formula_name", path: Formulary.core_path(name), spec: :stabl end specify "single_patch_dsl_with_strip_with_apply" do - expect( - formula do - patch :p1 do - url "file://#{tarball_fixture("testball-0.1-patches.tgz")}" - sha256 tarball_fixture_sha256("testball-0.1-patches.tgz") - apply "noop-a.diff" - end - end, - ).to be_patched + external_patch = formula do + patch :p1 do + url "file://#{tarball_fixture("testball-0.1-patches.tgz")}" + sha256 tarball_fixture_sha256("testball-0.1-patches.tgz") + apply "noop-a.diff" + end + end.stable.patches.last + + expect(external_patch).to have_attributes(strip: :p1, patch_files: ["noop-a.diff"]) + external_patch.fetch + external_patch.resource.unpack do + expect(Pathname.pwd/external_patch.patch_files.fetch(0)).to be_a_file + end end specify "single_patch_dsl_with_incorrect_strip" do diff --git a/Library/Homebrew/test/system_command_spec.rb b/Library/Homebrew/test/system_command_spec.rb index eee2d1174131c..a331d0ae64d19 100644 --- a/Library/Homebrew/test/system_command_spec.rb +++ b/Library/Homebrew/test/system_command_spec.rb @@ -374,17 +374,17 @@ # Ignore SIGINT. end - described_class.run! "sleep", args: [5] + described_class.run! "sleep", args: [1] exit! end - sleep 1 + sleep 0.1 Process.kill("INT", pid) Process.waitpid(pid) - expect(Time.now - start_time).to be >= 5 + expect(Time.now - start_time).to be >= 1 end end end