diff --git a/Library/Homebrew/test/cmd/install_spec.rb b/Library/Homebrew/test/cmd/install_spec.rb index f0eb4a2755550..7086c28c6376a 100644 --- a/Library/Homebrew/test/cmd/install_spec.rb +++ b/Library/Homebrew/test/cmd/install_spec.rb @@ -6,98 +6,118 @@ RSpec.describe Homebrew::Cmd::InstallCmd do include FileUtils - let(:testball1_rack) { HOMEBREW_CELLAR/"testball1" } - it_behaves_like "parseable arguments" - it "installs a Formula", :integration_test do - setup_test_formula "testball1" - - expect { brew "install", "testball1" } - .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/foo/test").not_to be_a_file - - uninstall_test_formula "testball1" - - expect { brew "install", "testball1", "--with-foo" } - .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/foo/test").to be_a_file - - uninstall_test_formula "testball1" - - 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 - - uninstall_test_formula "testball1" - - expect { brew "install", "--ask", "testball1" } - .to output(/.*Formula\s*\(1\):\s*testball1.*/).to_stdout - .and output(/✔︎.*/m).to_stderr - .and be_a_success - expect(testball1_rack/"0.1/bin/test").to be_a_file - - uninstall_test_formula "testball1" + context "when using a bottle" do + let(:formula_name) { "testball_bottle" } + let(:formula_prefix) { HOMEBREW_CELLAR/formula_name/"0.1" } + let(:formula_prefix_regex) { /#{Regexp.escape(formula_prefix)}/o } + let(:option_file) { formula_prefix/"foo/test" } + let(:bottle_file) { formula_prefix/"bin/helloworld" } + + it "installs a Formula", :integration_test do + 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(option_file).not_to be_a_file + expect(bottle_file).to be_a_file + + uninstall_test_formula formula_name + + 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(option_file).not_to be_a_file + expect(bottle_file).to be_a_file + + uninstall_test_formula formula_name + + 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 - 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 + it "installs a keg-only Formula", :integration_test do + setup_test_formula formula_name, <<~RUBY + keg_only "test reason" + RUBY + + expect { brew "install", formula_name } + .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(bottle_file).to be_a_file + expect(HOMEBREW_PREFIX/"bin/helloworld").not_to be_a_file + end end - it "installs a keg-only Formula", :integration_test do - setup_test_formula "testball1", <<~RUBY - version "1.0" - - keg_only "test reason" - RUBY + context "when building from source" do + let(:formula_name) { "testball1" } + + it "installs a Formula", :integration_test do + formula_prefix = HOMEBREW_CELLAR/formula_name/"0.1" + formula_prefix_regex = /#{Regexp.escape(formula_prefix)}/o + option_file = formula_prefix/"foo/test" + always_built_file = formula_prefix/"bin/test" + + setup_test_formula formula_name + + expect { brew "install", formula_name, "--with-foo" } + .to output(formula_prefix_regex).to_stdout + .and output(/✔︎.*/m).to_stderr + .and be_a_success + expect(option_file).to be_a_file + expect(always_built_file).to be_a_file + + uninstall_test_formula formula_name + + 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 - expect { brew "install", "testball1" } - .to output(%r{#{testball1_rack}/1\.0}o).to_stdout - .and output(/✔︎.*/m).to_stderr - .and be_a_success - expect(testball1_rack/"1.0/foo/test").not_to be_a_file - end + it "installs a HEAD Formula", :integration_test do + testball1_prefix = HOMEBREW_CELLAR/"testball1/HEAD-d5eb689" + repo_path = HOMEBREW_CACHE/"repo" + (repo_path/"bin").mkpath + + repo_path.cd do + system "git", "-c", "init.defaultBranch=master", "init" + system "git", "remote", "add", "origin", "https://github.com/Homebrew/homebrew-foo" + FileUtils.touch "bin/something.bin" + FileUtils.touch "README" + system "git", "add", "--all" + system "git", "commit", "-m", "Initial repo commit" + end - it "installs a HEAD Formula", :integration_test do - repo_path = HOMEBREW_CACHE/"repo" - (repo_path/"bin").mkpath - - repo_path.cd do - system "git", "-c", "init.defaultBranch=master", "init" - system "git", "remote", "add", "origin", "https://github.com/Homebrew/homebrew-foo" - FileUtils.touch "bin/something.bin" - FileUtils.touch "README" - system "git", "add", "--all" - system "git", "commit", "-m", "Initial repo commit" - end + setup_test_formula "testball1", <<~RUBY + version "1.0" - setup_test_formula "testball1", <<~RUBY - version "1.0" + head "file://#{repo_path}", using: :git - head "file://#{repo_path}", :using => :git + def install + prefix.install Dir["*"] + end + RUBY - def install - prefix.install Dir["*"] - end - RUBY - - # Ignore dependencies, because we'll try to resolve requirements in build.rb - # and there will be the git requirement, but we cannot instantiate git - # formula since we only have testball1 formula. - expect { brew "install", "testball1", "--HEAD", "--ignore-dependencies", "HOMEBREW_DOWNLOAD_CONCURRENCY" => "1" } - .to output(%r{#{testball1_rack}/HEAD-d5eb689}o).to_stdout - .and output(/Cloning into/).to_stderr - .and be_a_success - expect(testball1_rack/"HEAD-d5eb689/foo/test").not_to be_a_file + expect { brew "install", formula_name, "--HEAD", "HOMEBREW_DOWNLOAD_CONCURRENCY" => "1" } + .to output(/#{Regexp.escape(testball1_prefix)}/o).to_stdout + .and output(/Cloning into/).to_stderr + .and be_a_success + expect(testball1_prefix/"foo/test").not_to be_a_file + expect(testball1_prefix/"bin/something.bin").to be_a_file + end end end diff --git a/Library/Homebrew/test/cmd/reinstall_spec.rb b/Library/Homebrew/test/cmd/reinstall_spec.rb index 0bcca0ca5ab99..4866651e989e5 100644 --- a/Library/Homebrew/test/cmd/reinstall_spec.rb +++ b/Library/Homebrew/test/cmd/reinstall_spec.rb @@ -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", 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 diff --git a/Library/Homebrew/test/cmd/upgrade_spec.rb b/Library/Homebrew/test/cmd/upgrade_spec.rb index 32544fca77718..045bd22cd2f69 100644 --- a/Library/Homebrew/test/cmd/upgrade_spec.rb +++ b/Library/Homebrew/test/cmd/upgrade_spec.rb @@ -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" diff --git a/Library/Homebrew/test/spec_helper.rb b/Library/Homebrew/test/spec_helper.rb index 45f1af07517c0..613ee0173368f 100644 --- a/Library/Homebrew/test/spec_helper.rb +++ b/Library/Homebrew/test/spec_helper.rb @@ -66,6 +66,7 @@ HOMEBREW_LOCKS, HOMEBREW_LOGS, HOMEBREW_TEMP, + HOMEBREW_TEMP_CELLAR, HOMEBREW_ALIASES, ].freeze diff --git a/Library/Homebrew/test/support/fixtures/bottles/testball_bottle-0.1.all.bottle.tar.gz b/Library/Homebrew/test/support/fixtures/bottles/testball_bottle-0.1.all.bottle.tar.gz new file mode 120000 index 0000000000000..3e989830ba206 --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/bottles/testball_bottle-0.1.all.bottle.tar.gz @@ -0,0 +1 @@ +testball_bottle-0.1.yosemite.bottle.tar.gz \ No newline at end of file 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 d7df0f163788e..5a0e716d7d9be 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 @@ -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}"