diff --git a/Library/Homebrew/test/cmd/install_spec.rb b/Library/Homebrew/test/cmd/install_spec.rb new file mode 100644 index 0000000000..c1240a30e0 --- /dev/null +++ b/Library/Homebrew/test/cmd/install_spec.rb @@ -0,0 +1,243 @@ +describe "brew install", :integration_test do + it "installs Formulae" do + setup_test_formula "testball1" + + expect { brew "install", "testball1", "--head" } + .to output(/Specify `\-\-HEAD`/).to_stderr + .and not_to_output.to_stdout + .and be_a_failure + + expect { brew "install", "testball1", "--HEAD" } + .to output(/No head is defined/).to_stderr + .and not_to_output.to_stdout + .and be_a_failure + + expect { brew "install", "testball1", "--devel" } + .to output(/No devel block/).to_stderr + .and not_to_output.to_stdout + .and be_a_failure + + expect { brew "install", "testball1" } + .to output(%r{#{HOMEBREW_CELLAR}/testball1/0\.1}).to_stdout + .and not_to_output.to_stderr + .and be_a_success + + expect { brew "install", "testball1" } + .to output(/testball1\-0\.1 already installed/).to_stderr + .and not_to_output.to_stdout + .and be_a_success + + expect { brew "install", "macruby" } + .to output(/MacRuby is not packaged/).to_stderr + .and not_to_output.to_stdout + .and be_a_failure + + expect { brew "install", "formula" } + .to output(/No available formula/).to_stderr + .and output(/Searching for similarly named formulae/).to_stdout + .and be_a_failure + + expect { brew "install", "testball" } + .to output(/This similarly named formula was found/).to_stdout + .and output(/No available formula/).to_stderr + .and be_a_failure + + setup_test_formula "testball2" + expect { brew "install", "testball" } + .to output(/These similarly named formulae were found/).to_stdout + .and output(/No available formula/).to_stderr + .and be_a_failure + + install_and_rename_coretap_formula "testball1", "testball2" + expect { brew "install", "testball2" } + .to output(/testball1 already installed, it's just not migrated/).to_stderr + .and output(/You can migrate formula with `brew migrate testball2`/).to_stdout + .and be_a_success + end + + specify "install failures" do + path = setup_test_formula "testball1", <<-EOS.undent + version "1.0" + EOS + + expect { brew "install", "testball1" } + .to output(%r{#{HOMEBREW_CELLAR}/testball1/1\.0}).to_stdout + .and not_to_output.to_stderr + .and be_a_success + + FileUtils.rm path + setup_test_formula "testball1", <<-EOS.undent + version "2.0" + + devel do + url "#{Formulary.factory("testball1").stable.url}" + sha256 "#{TESTBALL_SHA256}" + version "3.0" + end + EOS + + expect { brew "install", "testball1" } + .to output(/first `brew unlink testball1`/).to_stderr + .and not_to_output.to_stdout + .and be_a_failure + + expect { brew "unlink", "testball1" } + .to output(%r{#{HOMEBREW_CELLAR}/testball1/1\.0}).to_stdout + .and not_to_output.to_stderr + .and be_a_success + + expect { brew "install", "testball1", "--devel" } + .to output(%r{#{HOMEBREW_CELLAR}/testball1/3\.0}).to_stdout + .and not_to_output.to_stderr + .and be_a_success + + expect { brew "unlink", "testball1" } + .to output(%r{#{HOMEBREW_CELLAR}/testball1/3\.0}).to_stdout + .and not_to_output.to_stderr + .and be_a_success + + expect { brew "install", "testball1" } + .to output(%r{#{HOMEBREW_CELLAR}/testball1/2\.0}).to_stdout + .and not_to_output.to_stderr + .and be_a_success + + shutup do + expect { brew "switch", "testball1", "3.0" }.to be_a_success + end + + expect { brew "install", "testball1" } + .to output(/already installed, however linked version is/).to_stderr + .and output(/`brew switch testball1 2.0`/).to_stdout + .and be_a_success + + expect { brew "unlink", "testball1" } + .to output(%r{#{HOMEBREW_CELLAR}/testball1/3\.0}).to_stdout + .and not_to_output.to_stderr + .and be_a_success + + expect { brew "install", "testball1" } + .to output(/just not linked/).to_stderr + .and not_to_output.to_stdout + .and be_a_success + end + + it "can install keg-only Formulae" do + path_keg_only = setup_test_formula "testball1", <<-EOS.undent + version "1.0" + + keg_only "test reason" + EOS + + expect { brew "install", "testball1" } + .to output(%r{#{HOMEBREW_CELLAR}/testball1/1\.0}).to_stdout + .and not_to_output.to_stderr + .and be_a_success + + FileUtils.rm path_keg_only + setup_test_formula "testball1", <<-EOS.undent + version "2.0" + + keg_only "test reason" + EOS + + expect { brew "install", "testball1" } + .to output(/keg-only and another version is linked to opt/).to_stderr + .and output(/Use `brew install --force`/).to_stdout + .and be_a_success + + expect { brew "install", "testball1", "--force" } + .to output(%r{#{HOMEBREW_CELLAR}/testball1/2\.0}).to_stdout + .and not_to_output.to_stderr + .and be_a_success + end + + it "can install HEAD Formulae" do + repo_path = HOMEBREW_CACHE.join("repo") + repo_path.join("bin").mkpath + + repo_path.cd do + shutup do + system "git", "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 + end + + setup_test_formula "testball1", <<-EOS.undent + version "1.0" + + head "file://#{repo_path}", :using => :git + + def install + prefix.install Dir["*"] + end + EOS + + # 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" } + .to output(%r{#{HOMEBREW_CELLAR}/testball1/HEAD\-d5eb689}).to_stdout + .and output(/Cloning into/).to_stderr + .and be_a_success + + expect { brew "install", "testball1", "--HEAD", "--ignore-dependencies" } + .to output(/testball1\-HEAD\-d5eb689 already installed/).to_stderr + .and not_to_output.to_stdout + .and be_a_success + + expect { brew "unlink", "testball1" } + .to output(%r{#{HOMEBREW_CELLAR}/testball1/HEAD\-d5eb689}).to_stdout + .and not_to_output.to_stderr + .and be_a_success + + expect { brew "install", "testball1" } + .to output(%r{#{HOMEBREW_CELLAR}/testball1/1\.0}).to_stdout + .and not_to_output.to_stderr + .and be_a_success + end + + it "ignores invalid options" do + setup_test_formula "testball1" + expect { brew "install", "testball1", "--with-fo" } + .to output(/testball1: this formula has no \-\-with\-fo option so it will be ignored!/).to_stderr + .and output(/Downloading file/).to_stdout + .and be_a_success + end + + it "succeeds when a non-fatal requirement isn't satisfied" do + setup_test_formula "testball1", <<-EOS.undent + class NonFatalRequirement < Requirement + satisfy { false } + end + + depends_on NonFatalRequirement + EOS + + # FIXME: This should output to STDERR. + expect { brew "install", "testball1" } + .to output(/NonFatalRequirement unsatisfied!/).to_stdout + .and not_to_output.to_stderr + .and be_a_success + end + + it "fails when a fatal requirement isn't satisfied" do + setup_test_formula "testball1", <<-EOS.undent + class FatalRequirement < Requirement + fatal true + satisfy { false } + end + + depends_on FatalRequirement + EOS + + # FIXME: This should output to STDERR. + expect { brew "install", "testball1" } + .to output(/FatalRequirement unsatisfied!/).to_stdout + .and output(/An unsatisfied requirement failed this build./).to_stderr + .and be_a_failure + end +end diff --git a/Library/Homebrew/test/cmd/reinstall_spec.rb b/Library/Homebrew/test/cmd/reinstall_spec.rb index 74d36bbb81..63584e6be6 100644 --- a/Library/Homebrew/test/cmd/reinstall_spec.rb +++ b/Library/Homebrew/test/cmd/reinstall_spec.rb @@ -1,9 +1,6 @@ require "extend/ENV" describe "brew reinstall", :integration_test do - let(:bin) { (HOMEBREW_PREFIX/"bin").realpath } - let(:path) { "#{bin}#{File::PATH_SEPARATOR}#{ENV["PATH"]}" } - before(:each) do setup_test_formula "testball" @@ -17,7 +14,7 @@ describe "brew reinstall", :integration_test do expect(foo_dir).to exist foo_dir.rmtree - expect { brew "reinstall", "testball", "PATH" => path } + expect { brew "reinstall", "testball" } .to output(/Reinstalling testball --with-foo/).to_stdout .and not_to_output.to_stderr .and be_a_success @@ -26,7 +23,7 @@ describe "brew reinstall", :integration_test do end it "reinstalls a Formula even when one of the options is invalid" do - expect { brew "reinstall", "testball", "--with-fo", "PATH" => path } + expect { brew "reinstall", "testball", "--with-fo" } .to output(/Reinstalling testball --with-foo/).to_stdout .and output(/testball: this formula has no \-\-with-fo option so it will be ignored!/).to_stderr .and be_a_success diff --git a/Library/Homebrew/test/install_test.rb b/Library/Homebrew/test/install_test.rb deleted file mode 100644 index da6c1863f5..0000000000 --- a/Library/Homebrew/test/install_test.rb +++ /dev/null @@ -1,136 +0,0 @@ -require "testing_env" - -class IntegrationCommandTestInstall < IntegrationCommandTestCase - def test_install - setup_test_formula "testball1" - assert_match "Specify `--HEAD`", cmd_fail("install", "testball1", "--head") - assert_match "No head is defined", cmd_fail("install", "testball1", "--HEAD") - assert_match "No devel block", cmd_fail("install", "testball1", "--devel") - assert_match "#{HOMEBREW_CELLAR}/testball1/0.1", cmd("install", "testball1") - assert_match "testball1-0.1 already installed", cmd("install", "testball1") - assert_match "MacRuby is not packaged", cmd_fail("install", "macruby") - assert_match "No available formula", cmd_fail("install", "formula") - assert_match "This similarly named formula was found", - cmd_fail("install", "testball") - - setup_test_formula "testball2" - assert_match "These similarly named formulae were found", - cmd_fail("install", "testball") - - install_and_rename_coretap_formula "testball1", "testball2" - assert_match "testball1 already installed, it's just not migrated", - cmd("install", "testball2") - end - - def test_install_failures - path = setup_test_formula "testball1", "version \"1.0\"" - devel_content = <<-EOS.undent - version "3.0" - devel do - url "#{Formulary.factory("testball1").stable.url}" - sha256 "#{TESTBALL_SHA256}" - version "2.0" - end - EOS - - assert_match "#{HOMEBREW_CELLAR}/testball1/1.0", cmd("install", "testball1") - - FileUtils.rm path - setup_test_formula "testball1", devel_content - - assert_match "first `brew unlink testball1`", cmd_fail("install", "testball1") - assert_match "#{HOMEBREW_CELLAR}/testball1/1.0", cmd("unlink", "testball1") - assert_match "#{HOMEBREW_CELLAR}/testball1/2.0", cmd("install", "testball1", "--devel") - assert_match "#{HOMEBREW_CELLAR}/testball1/2.0", cmd("unlink", "testball1") - assert_match "#{HOMEBREW_CELLAR}/testball1/3.0", cmd("install", "testball1") - - cmd("switch", "testball1", "2.0") - assert_match "already installed, however linked version is", - cmd("install", "testball1") - assert_match "#{HOMEBREW_CELLAR}/testball1/2.0", cmd("unlink", "testball1") - assert_match "just not linked", cmd("install", "testball1") - end - - def test_install_keg_only_outdated - path_keg_only = setup_test_formula "testball1", <<-EOS.undent - version "1.0" - keg_only "test reason" - EOS - - assert_match "#{HOMEBREW_CELLAR}/testball1/1.0", cmd("install", "testball1") - - FileUtils.rm path_keg_only - setup_test_formula "testball1", <<-EOS.undent - version "2.0" - keg_only "test reason" - EOS - - assert_match "keg-only and another version is linked to opt", - cmd("install", "testball1") - - assert_match "#{HOMEBREW_CELLAR}/testball1/2.0", - cmd("install", "testball1", "--force") - end - - def test_install_head_installed - repo_path = HOMEBREW_CACHE.join("repo") - repo_path.join("bin").mkpath - - repo_path.cd do - shutup do - system "git", "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 - end - - setup_test_formula "testball1", <<-EOS.undent - version "1.0" - head "file://#{repo_path}", :using => :git - def install - prefix.install Dir["*"] - end - EOS - - # 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. - assert_match "#{HOMEBREW_CELLAR}/testball1/HEAD-d5eb689", cmd("install", "testball1", "--HEAD", "--ignore-dependencies") - assert_match "testball1-HEAD-d5eb689 already installed", - cmd("install", "testball1", "--HEAD", "--ignore-dependencies") - assert_match "#{HOMEBREW_CELLAR}/testball1/HEAD-d5eb689", cmd("unlink", "testball1") - assert_match "#{HOMEBREW_CELLAR}/testball1/1.0", cmd("install", "testball1") - end - - def test_install_with_invalid_option - setup_test_formula "testball1" - assert_match "testball1: this formula has no --with-fo option so it will be ignored!", - cmd("install", "testball1", "--with-fo") - end - - def test_install_with_nonfatal_requirement - setup_test_formula "testball1", <<-EOS.undent - class NonFatalRequirement < Requirement - satisfy { false } - end - depends_on NonFatalRequirement - EOS - message = "NonFatalRequirement unsatisfied!" - assert_equal 1, cmd("install", "testball1").scan(message).size - end - - def test_install_with_fatal_requirement - setup_test_formula "testball1", <<-EOS.undent - class FatalRequirement < Requirement - fatal true - satisfy { false } - end - depends_on FatalRequirement - EOS - message = "FatalRequirement unsatisfied!" - assert_equal 1, cmd_fail("install", "testball1").scan(message).size - end -end 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 fc7b49fa4d..2eb98826aa 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 @@ -63,7 +63,15 @@ RSpec.shared_context "integration test" do def brew(*args) env = args.last.is_a?(Hash) ? args.pop : {} + # Avoid warnings when HOMEBREW_PREFIX/bin is not in PATH. + path = [ + env["PATH"], + (HOMEBREW_PREFIX/"bin").realpath.to_s, + ENV["PATH"], + ].compact.join(File::PATH_SEPARATOR) + env.merge!( + "PATH" => path, "HOMEBREW_BREW_FILE" => HOMEBREW_PREFIX/"bin/brew", "HOMEBREW_INTEGRATION_TEST" => command_id_from_args(args), "HOMEBREW_TEST_TMPDIR" => TEST_TMPDIR,