Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Library/Homebrew/test/bundle/installer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 6 additions & 7 deletions Library/Homebrew/test/cask/artifact/alt_target_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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 }
Expand Down
10 changes: 6 additions & 4 deletions Library/Homebrew/test/cask/artifact/bashcompletion_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
10 changes: 6 additions & 4 deletions Library/Homebrew/test/cask/artifact/fishlcompletion_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 0 additions & 4 deletions Library/Homebrew/test/cask/artifact/uninstall_no_zap_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
10 changes: 6 additions & 4 deletions Library/Homebrew/test/cask/artifact/zshcompletion_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
12 changes: 4 additions & 8 deletions Library/Homebrew/test/cask/cask_loader/from_api_loader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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") }

Expand Down Expand Up @@ -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") }

Expand Down Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions Library/Homebrew/test/cmd/help_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 1 addition & 17 deletions Library/Homebrew/test/cmd/reinstall_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
8 changes: 1 addition & 7 deletions Library/Homebrew/test/cmd/tab_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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
Expand Down
9 changes: 8 additions & 1 deletion Library/Homebrew/test/cmd/unlink_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment thread
Copilot marked this conversation as resolved.
(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
Expand Down
49 changes: 30 additions & 19 deletions Library/Homebrew/test/dev-cmd/test_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
22 changes: 13 additions & 9 deletions Library/Homebrew/test/patching_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Comment thread
MikeMcQuaid marked this conversation as resolved.
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
Expand Down
6 changes: 3 additions & 3 deletions Library/Homebrew/test/system_command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading