Skip to content
Draft
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
72 changes: 45 additions & 27 deletions Library/Homebrew/test/cmd/install_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,48 +10,66 @@

it_behaves_like "parseable arguments"

it "installs a Formula", :integration_test do
setup_test_formula "testball1"
it "installs a Formula from bottle", :integration_test do
formula_name = "testball_bottle"
formula_prefix = HOMEBREW_CELLAR/formula_name/"0.1"
formula_prefix_regex = /#{Regexp.escape(formula_prefix)}/
option_file = formula_prefix/"foo/test"
bottle_file = formula_prefix/"bin/helloworld"

expect { brew "install", "testball1" }
.to output(%r{#{HOMEBREW_CELLAR}/testball1/0\.1}o).to_stdout
setup_test_formula formula_name

expect { brew "install", formula_name }
.to output(formula_prefix_regex).to_stdout
.and output(/✔︎.*/m).to_stderr
.and be_a_success
expect(testball1_rack/"0.1/foo/test").not_to be_a_file
expect(option_file).not_to be_a_file
expect(bottle_file).to be_a_file

uninstall_test_formula "testball1"
uninstall_test_formula formula_name

expect { brew "install", "testball1", "--with-foo" }
.to output(%r{#{HOMEBREW_CELLAR}/testball1/0\.1}o).to_stdout
expect { brew "install", "--ask", formula_name }
.to output(/.*Formula\s*\(1\):\s*#{formula_name}.*/).to_stdout
.and output(/✔︎.*/m).to_stderr
.and be_a_success
expect(testball1_rack/"0.1/foo/test").to be_a_file
expect(option_file).not_to be_a_file
expect(bottle_file).to be_a_file

uninstall_test_formula "testball1"
uninstall_test_formula formula_name

expect { brew "install", "testball1", "--debug-symbols", "--build-from-source" }
.to output(%r{#{HOMEBREW_CELLAR}/testball1/0\.1}o).to_stdout
.and output(/✔︎.*/m).to_stderr
.and be_a_success
expect(testball1_rack/"0.1/bin/test").to be_a_file
expect(testball1_rack/"0.1/bin/test.dSYM/Contents/Resources/DWARF/test").to be_a_file if OS.mac?
expect(HOMEBREW_CACHE/"Sources/testball1").to be_a_directory
expect { brew "install", formula_name, { "HOMEBREW_FORBIDDEN_FORMULAE" => formula_name } }
.to not_to_output(formula_prefix_regex).to_stdout
.and output(/#{formula_name} was forbidden/).to_stderr
.and be_a_failure
expect(formula_prefix).not_to exist
end

it "installs a Formula from source", :integration_test do
formula_name = "testball2"
formula_prefix = HOMEBREW_CELLAR/formula_name/"0.1"
formula_prefix_regex = /#{Regexp.escape(formula_prefix)}/
option_file = formula_prefix/"foo/test"
always_built_file = formula_prefix/"bin/test"

uninstall_test_formula "testball1"
setup_test_formula formula_name

expect { brew "install", "--ask", "testball1" }
.to output(/.*Formula\s*\(1\):\s*testball1.*/).to_stdout
expect { brew "install", formula_name, "--with-foo" }
.to output(formula_prefix_regex).to_stdout
.and output(/✔︎.*/m).to_stderr
.and be_a_success
expect(testball1_rack/"0.1/bin/test").to be_a_file
expect(option_file).to be_a_file
expect(always_built_file).to be_a_file

uninstall_test_formula "testball1"
uninstall_test_formula formula_name

expect { brew "install", "testball1", { "HOMEBREW_FORBIDDEN_FORMULAE" => "testball1" } }
.to not_to_output(%r{#{HOMEBREW_CELLAR}/testball1/0\.1}o).to_stdout
.and output(/testball1 was forbidden/).to_stderr
.and be_a_failure
expect(testball1_rack).not_to exist
expect { brew "install", formula_name, "--debug-symbols", "--build-from-source" }
.to output(formula_prefix_regex).to_stdout
.and output(/✔︎.*/m).to_stderr
.and be_a_success
expect(option_file).not_to be_a_file
expect(always_built_file).to be_a_file
expect(formula_prefix/"bin/test.dSYM/Contents/Resources/DWARF/test").to be_a_file if OS.mac?
expect(HOMEBREW_CACHE/"Sources/#{formula_name}").to be_a_directory
end

it "installs a keg-only Formula", :integration_test do
Expand Down
35 changes: 19 additions & 16 deletions Library/Homebrew/test/cmd/reinstall_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,35 @@
it_behaves_like "parseable arguments"

it "reinstalls a Formula", :aggregate_failures, :integration_test do
setup_test_formula "testball", tab_attributes: { installed_on_request: true }
formula_name = "testball_bottle"
formula_prefix = HOMEBREW_CELLAR/formula_name/"0.1"
formula_bin = formula_prefix/"bin"

testball_bin = HOMEBREW_CELLAR/"testball/0.1/bin"
expect(testball_bin).not_to exist
setup_test_formula formula_name, tab_attributes: { installed_on_request: true }
Keg.new(formula_prefix).link

expect { brew "reinstall", "testball" }
.to output(/Reinstalling testball/).to_stdout
expect(formula_bin).not_to exist

expect { brew "reinstall", "--verbose", formula_name }
.to output(/Reinstalling #{formula_name}/).to_stdout
.and output(/✔︎.*/m).to_stderr
.and be_a_success
expect(testball_bin).to exist
expect(formula_bin).to exist

FileUtils.rm_r(testball_bin)
FileUtils.rm_r(formula_bin)

expect { brew "reinstall", "--ask", "testball" }
.to output(/.*Formula\s*\(1\):\s*testball.*/).to_stdout
expect { brew "reinstall", "--ask", formula_name }
.to output(/.*Formula\s*\(1\):\s*#{formula_name}.*/).to_stdout
.and output(/✔︎.*/m).to_stderr
.and be_a_success
expect(testball_bin).to exist
expect(formula_bin).to exist

FileUtils.rm_r(testball_bin)
FileUtils.rm_r(formula_bin)

expect { brew "reinstall", "testball", { "HOMEBREW_FORBIDDEN_FORMULAE" => "testball" } }
.to not_to_output(%r{#{HOMEBREW_CELLAR}/testball/0\.1}o).to_stdout
.and output(/testball was forbidden/).to_stderr
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(testball_bin).not_to exist
expect(formula_bin).not_to exist
end
end
43 changes: 22 additions & 21 deletions Library/Homebrew/test/cmd/upgrade_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,50 +10,51 @@
it_behaves_like "parseable arguments"

it "upgrades a Formula", :integration_test do
setup_test_formula "testball"
formula_name = "testball_bottle"
formula_rack = HOMEBREW_CELLAR/formula_name

testball_rack = HOMEBREW_CELLAR/"testball"
setup_test_formula formula_name

(testball_rack/"0.0.1/foo").mkpath
(formula_rack/"0.0.1/foo").mkpath

expect { brew "upgrade" }.to be_a_success

expect(testball_rack/"0.1").to be_a_directory
expect(testball_rack/"0.0.1").not_to exist
expect(formula_rack/"0.1").to be_a_directory
expect(formula_rack/"0.0.1").not_to exist

uninstall_test_formula "testball"
uninstall_test_formula formula_name

# links newer version when upgrade was interrupted
(testball_rack/"0.1/foo").mkpath
(formula_rack/"0.1/foo").mkpath

expect { brew "upgrade" }.to be_a_success

expect(testball_rack/"0.1").to be_a_directory
expect(HOMEBREW_PREFIX/"opt/testball").to be_a_symlink
expect(HOMEBREW_PREFIX/"var/homebrew/linked/testball").to be_a_symlink
expect(formula_rack/"0.1").to be_a_directory
expect(HOMEBREW_PREFIX/"opt/#{formula_name}").to be_a_symlink
expect(HOMEBREW_PREFIX/"var/homebrew/linked/#{formula_name}").to be_a_symlink

uninstall_test_formula "testball"
uninstall_test_formula formula_name

# upgrades with asking for user prompts
(testball_rack/"0.0.1/foo").mkpath
(formula_rack/"0.0.1/foo").mkpath

expect { brew "upgrade", "--ask" }
.to output(/.*Formula\s*\(1\):\s*testball.*/).to_stdout
.to output(/.*Formula\s*\(1\):\s*#{formula_name}.*/).to_stdout
.and output(/✔︎.*/m).to_stderr

expect(testball_rack/"0.1").to be_a_directory
expect(testball_rack/"0.0.1").not_to exist
expect(formula_rack/"0.1").to be_a_directory
expect(formula_rack/"0.0.1").not_to exist

uninstall_test_formula "testball"
uninstall_test_formula formula_name

# refuses to upgrade a forbidden formula
(testball_rack/"0.0.1/foo").mkpath
(formula_rack/"0.0.1/foo").mkpath

expect { brew "upgrade", "testball", { "HOMEBREW_FORBIDDEN_FORMULAE" => "testball" } }
.to not_to_output(%r{#{HOMEBREW_CELLAR}/testball/0\.1}o).to_stdout
.and output(/testball was forbidden/).to_stderr
expect { brew "upgrade", formula_name, { "HOMEBREW_FORBIDDEN_FORMULAE" => formula_name } }
.to not_to_output(%r{#{formula_rack}/0\.1}o).to_stdout
.and output(/#{formula_name} was forbidden/).to_stderr
.and be_a_failure
expect(testball_rack/"0.1").not_to exist
expect(formula_rack/"0.1").not_to exist
end

it_behaves_like "reinstall_pkgconf_if_needed"
Expand Down
1 change: 1 addition & 0 deletions Library/Homebrew/test/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
HOMEBREW_LOCKS,
HOMEBREW_LOGS,
HOMEBREW_TEMP,
HOMEBREW_TEMP_CELLAR,
HOMEBREW_ALIASES,
].freeze

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ def setup_test_formula(name, content = nil, tap: CoreTap.instance,
else
TEST_FIXTURE_DIR/"tarballs/#{prefix}-0.1.tbz"
end
bottle_block ||= <<~RUBY if name == "testball_bottle"
bottle do
root_url "file://#{TEST_FIXTURE_DIR}/bottles"
sha256 cellar: :any_skip_relocation, all: "d7b9f4e8bf83608b71fe958a99f19f2e5e68bb2582965d32e41759c24f1aef97"
end
RUBY
content = <<~RUBY
desc "Some test"
homepage "https://brew.sh/#{name}"
Expand Down
Loading