diff options
| author | Naoto Kaneko | 2017-02-27 14:23:53 +0900 |
|---|---|---|
| committer | Naoto Kaneko | 2017-02-27 14:23:53 +0900 |
| commit | 928eaca26720fd38b07c1e7df3f9f567477d48db (patch) | |
| tree | c08fd030cca960e74bab72b59ce057684e554334 /Library/Homebrew/test/cmd | |
| parent | ccc9b2dc6dc27026673db3c8871c691be9541342 (diff) | |
| parent | e3f4701f385c286a2cc72c5d07870cc9a6ce0bf4 (diff) | |
| download | brew-928eaca26720fd38b07c1e7df3f9f567477d48db.tar.bz2 | |
Merge branch 'master' into exclude-executable-metafiles
Added tests in keg_test and pathname_test was
moved into keg_spec and pathname_spec.
Diffstat (limited to 'Library/Homebrew/test/cmd')
48 files changed, 1372 insertions, 0 deletions
diff --git a/Library/Homebrew/test/cmd/--cache_spec.rb b/Library/Homebrew/test/cmd/--cache_spec.rb new file mode 100644 index 000000000..fb3c9cee6 --- /dev/null +++ b/Library/Homebrew/test/cmd/--cache_spec.rb @@ -0,0 +1,15 @@ +describe "brew --cache", :integration_test do + it "print the location of Homebrew's cache when no argument is given" do + expect { brew "--cache" } + .to output("#{HOMEBREW_CACHE}\n").to_stdout + .and not_to_output.to_stderr + .and be_a_success + end + + it "prints all cache files for a given Formula" do + expect { brew "--cache", testball } + .to output(%r{#{HOMEBREW_CACHE}/testball-}).to_stdout + .and not_to_output.to_stderr + .and be_a_success + end +end diff --git a/Library/Homebrew/test/cmd/--cellar_spec.rb b/Library/Homebrew/test/cmd/--cellar_spec.rb new file mode 100644 index 000000000..6c8d7dea6 --- /dev/null +++ b/Library/Homebrew/test/cmd/--cellar_spec.rb @@ -0,0 +1,15 @@ +describe "brew --cellar", :integration_test do + it "print the location of Homebrew's Cellar when no argument is given" do + expect { brew "--cellar" } + .to output("#{HOMEBREW_CELLAR}\n").to_stdout + .and not_to_output.to_stderr + .and be_a_success + end + + it "returns the Cellar subdirectory for a given Formula" do + expect { brew "--cellar", testball } + .to output(%r{#{HOMEBREW_CELLAR}/testball}).to_stdout + .and not_to_output.to_stderr + .and be_a_success + end +end diff --git a/Library/Homebrew/test/cmd/--env_spec.rb b/Library/Homebrew/test/cmd/--env_spec.rb new file mode 100644 index 000000000..7dd84132a --- /dev/null +++ b/Library/Homebrew/test/cmd/--env_spec.rb @@ -0,0 +1,44 @@ +describe "brew --env", :integration_test do + it "prints the Homebrew build environment variables" do + expect { brew "--env" } + .to output(/CMAKE_PREFIX_PATH="#{Regexp.escape(HOMEBREW_PREFIX)}[:"]/).to_stdout + .and not_to_output.to_stderr + .and be_a_success + end + + describe "--shell=bash" do + it "prints the Homebrew build environment variables in Bash syntax" do + expect { brew "--env", "--shell=bash" } + .to output(/export CMAKE_PREFIX_PATH="#{Regexp.quote(HOMEBREW_PREFIX.to_s)}"/).to_stdout + .and not_to_output.to_stderr + .and be_a_success + end + end + + describe "--shell=fish" do + it "prints the Homebrew build environment variables in Fish syntax" do + expect { brew "--env", "--shell=fish" } + .to output(/set [-]gx CMAKE_PREFIX_PATH "#{Regexp.quote(HOMEBREW_PREFIX.to_s)}"/).to_stdout + .and not_to_output.to_stderr + .and be_a_success + end + end + + describe "--shell=tcsh" do + it "prints the Homebrew build environment variables in Tcsh syntax" do + expect { brew "--env", "--shell=tcsh" } + .to output(/setenv CMAKE_PREFIX_PATH #{Regexp.quote(HOMEBREW_PREFIX.to_s)};/).to_stdout + .and not_to_output.to_stderr + .and be_a_success + end + end + + describe "--plain" do + it "prints the Homebrew build environment variables without quotes" do + expect { brew "--env", "--plain" } + .to output(/CMAKE_PREFIX_PATH: #{Regexp.quote(HOMEBREW_PREFIX)}/).to_stdout + .and not_to_output.to_stderr + .and be_a_success + end + end +end diff --git a/Library/Homebrew/test/cmd/--prefix_spec.rb b/Library/Homebrew/test/cmd/--prefix_spec.rb new file mode 100644 index 000000000..80ef73a97 --- /dev/null +++ b/Library/Homebrew/test/cmd/--prefix_spec.rb @@ -0,0 +1,15 @@ +describe "brew --prefix", :integration_test do + it "prints the Homebrew prefix when no argument is given" do + expect { brew "--prefix" } + .to output("#{HOMEBREW_PREFIX}\n").to_stdout + .and not_to_output.to_stderr + .and be_a_success + end + + it "prints a given Formula's prefix" do + expect { brew "--prefix", testball } + .to output(%r{#{HOMEBREW_CELLAR}/testball}).to_stdout + .and not_to_output.to_stderr + .and be_a_success + end +end diff --git a/Library/Homebrew/test/cmd/--repository_spec.rb b/Library/Homebrew/test/cmd/--repository_spec.rb new file mode 100644 index 000000000..d3e531f7b --- /dev/null +++ b/Library/Homebrew/test/cmd/--repository_spec.rb @@ -0,0 +1,15 @@ +describe "brew --repository", :integration_test do + it "prints the path of the Homebrew repository" do + expect { brew "--repository" } + .to output("#{HOMEBREW_REPOSITORY}\n").to_stdout + .and not_to_output.to_stderr + .and be_a_success + end + + it "prints the path of a given Tap" do + expect { brew "--repository", "foo/bar" } + .to output("#{HOMEBREW_LIBRARY}/Taps/foo/homebrew-bar\n").to_stdout + .and not_to_output.to_stderr + .and be_a_success + end +end diff --git a/Library/Homebrew/test/cmd/--version_spec.rb b/Library/Homebrew/test/cmd/--version_spec.rb new file mode 100644 index 000000000..8992629d7 --- /dev/null +++ b/Library/Homebrew/test/cmd/--version_spec.rb @@ -0,0 +1,8 @@ +describe "brew --version", :integration_test do + it "prints the Homebrew version" do + expect { brew "--version" } + .to output(/^Homebrew #{Regexp.escape(HOMEBREW_VERSION.to_s)}\n/).to_stdout + .and not_to_output.to_stderr + .and be_a_success + end +end diff --git a/Library/Homebrew/test/cmd/bundle_spec.rb b/Library/Homebrew/test/cmd/bundle_spec.rb new file mode 100644 index 000000000..755f9ab3d --- /dev/null +++ b/Library/Homebrew/test/cmd/bundle_spec.rb @@ -0,0 +1,24 @@ +describe "brew bundle", :integration_test, :needs_test_cmd_taps do + describe "check" do + it "checks if a Brewfile's dependencies are satisfied" do + setup_remote_tap "homebrew/bundle" + + HOMEBREW_REPOSITORY.cd do + shutup do + system "git", "init" + system "git", "commit", "--allow-empty", "-m", "This is a test commit" + end + end + + Dir.mktmpdir do |path| + FileUtils.touch "#{path}/Brewfile" + Dir.chdir path do + expect { brew "bundle", "check" } + .to output("The Brewfile's dependencies are satisfied.\n").to_stdout + .and not_to_output.to_stderr + .and be_a_success + end + end + end + end +end diff --git a/Library/Homebrew/test/cmd/cask_spec.rb b/Library/Homebrew/test/cmd/cask_spec.rb new file mode 100644 index 000000000..e46843cab --- /dev/null +++ b/Library/Homebrew/test/cmd/cask_spec.rb @@ -0,0 +1,8 @@ +describe "brew cask", :integration_test, :needs_macos, :needs_official_cmd_taps do + describe "list" do + it "returns a list of installed Casks" do + setup_remote_tap("caskroom/cask") + expect { brew "cask", "list" }.to be_a_success + end + end +end diff --git a/Library/Homebrew/test/cmd/cat_spec.rb b/Library/Homebrew/test/cmd/cat_spec.rb new file mode 100644 index 000000000..8c230abee --- /dev/null +++ b/Library/Homebrew/test/cmd/cat_spec.rb @@ -0,0 +1,11 @@ +describe "brew cat", :integration_test do + it "prints the content of a given Formula" do + formula_file = setup_test_formula "testball" + content = formula_file.read + + expect { brew "cat", "testball" } + .to output(content).to_stdout + .and not_to_output.to_stderr + .and be_a_success + end +end diff --git a/Library/Homebrew/test/cmd/cleanup_spec.rb b/Library/Homebrew/test/cmd/cleanup_spec.rb new file mode 100644 index 000000000..9e2cf493f --- /dev/null +++ b/Library/Homebrew/test/cmd/cleanup_spec.rb @@ -0,0 +1,12 @@ +describe "brew cleanup", :integration_test do + describe "--prune=all" do + it "removes all files in Homebrew's cache" do + (HOMEBREW_CACHE/"test").write "test" + + expect { brew "cleanup", "--prune=all" } + .to output(%r{#{Regexp.escape(HOMEBREW_CACHE)}/test}).to_stdout + .and not_to_output.to_stderr + .and be_a_success + end + end +end diff --git a/Library/Homebrew/test/cmd/command_spec.rb b/Library/Homebrew/test/cmd/command_spec.rb new file mode 100644 index 000000000..5d6a67b70 --- /dev/null +++ b/Library/Homebrew/test/cmd/command_spec.rb @@ -0,0 +1,13 @@ +describe "brew command", :integration_test do + it "returns the file for a given command" do + expect { brew "command", "info" } + .to output(%r{#{Regexp.escape(HOMEBREW_LIBRARY_PATH)}/cmd/info.rb}).to_stdout + .and be_a_success + end + + it "fails when the given command is unknown" do + expect { brew "command", "does-not-exist" } + .to output(/Unknown command/).to_stderr + .and be_a_failure + end +end diff --git a/Library/Homebrew/test/cmd/commands_spec.rb b/Library/Homebrew/test/cmd/commands_spec.rb new file mode 100644 index 000000000..f42072956 --- /dev/null +++ b/Library/Homebrew/test/cmd/commands_spec.rb @@ -0,0 +1,7 @@ +describe "brew commands", :integration_test do + it "prints a list of all available commands" do + expect { brew "commands" } + .to output(/Built-in commands/).to_stdout + .and be_a_success + end +end diff --git a/Library/Homebrew/test/cmd/config_spec.rb b/Library/Homebrew/test/cmd/config_spec.rb new file mode 100644 index 000000000..7687fcdc7 --- /dev/null +++ b/Library/Homebrew/test/cmd/config_spec.rb @@ -0,0 +1,8 @@ +describe "brew config", :integration_test do + it "prints information about the current Homebrew configuration" do + expect { brew "config" } + .to output(/HOMEBREW_VERSION: #{HOMEBREW_VERSION}/).to_stdout + .and not_to_output.to_stderr + .and be_a_success + end +end diff --git a/Library/Homebrew/test/cmd/custom-external-command_spec.rb b/Library/Homebrew/test/cmd/custom-external-command_spec.rb new file mode 100644 index 000000000..8ccc21fa7 --- /dev/null +++ b/Library/Homebrew/test/cmd/custom-external-command_spec.rb @@ -0,0 +1,21 @@ +describe "brew custom-external-command", :integration_test do + it "is supported" do + Dir.mktmpdir do |path| + path = Pathname.new(path) + + cmd = "custom-external-command-#{rand}" + file = path/"brew-#{cmd}" + + file.write <<-EOS.undent + #!/bin/sh + echo 'I am #{cmd}.' + EOS + FileUtils.chmod "+x", file + + expect { brew cmd, "PATH" => "#{path}#{File::PATH_SEPARATOR}#{ENV["PATH"]}" } + .to output("I am #{cmd}.\n").to_stdout + .and not_to_output.to_stderr + .and be_a_success + end + end +end diff --git a/Library/Homebrew/test/cmd/desc_spec.rb b/Library/Homebrew/test/cmd/desc_spec.rb new file mode 100644 index 000000000..b09819d81 --- /dev/null +++ b/Library/Homebrew/test/cmd/desc_spec.rb @@ -0,0 +1,40 @@ +describe "brew desc", :integration_test do + let(:desc_cache) { HOMEBREW_CACHE/"desc_cache.json" } + + it "shows a given Formula's description" do + setup_test_formula "testball" + + expect { brew "desc", "testball" } + .to output("testball: Some test\n").to_stdout + .and not_to_output.to_stderr + .and be_a_success + end + + it "fails when both --search and --name are specified" do + expect { brew "desc", "--search", "--name" } + .to output(/Pick one, and only one/).to_stderr + .and not_to_output.to_stdout + .and be_a_failure + end + + describe "--search" do + it "fails when no search term is given" do + expect { brew "desc", "--search" } + .to output(/You must provide a search term/).to_stderr + .and not_to_output.to_stdout + .and be_a_failure + end + end + + describe "--description" do + it "creates a description cache" do + expect(desc_cache).not_to exist + + shutup do + expect { brew "desc", "--description", "testball" }.to be_a_success + end + + expect(desc_cache).to exist + end + end +end diff --git a/Library/Homebrew/test/cmd/doctor_spec.rb b/Library/Homebrew/test/cmd/doctor_spec.rb new file mode 100644 index 000000000..530adcd98 --- /dev/null +++ b/Library/Homebrew/test/cmd/doctor_spec.rb @@ -0,0 +1,6 @@ +describe "brew doctor", :integration_test do + specify "check_integration_test" do + expect { brew "doctor", "check_integration_test" } + .to output(/This is an integration test/).to_stderr + end +end diff --git a/Library/Homebrew/test/cmd/fetch_spec.rb b/Library/Homebrew/test/cmd/fetch_spec.rb new file mode 100644 index 000000000..111d9f85c --- /dev/null +++ b/Library/Homebrew/test/cmd/fetch_spec.rb @@ -0,0 +1,13 @@ +describe "brew fetch", :integration_test do + it "downloads the Formula's URL" do + setup_test_formula "testball" + + expect(HOMEBREW_CACHE/"testball-0.1.tbz").not_to exist + + shutup do + expect { brew "fetch", "testball" }.to be_a_success + end + + expect(HOMEBREW_CACHE/"testball-0.1.tbz").to exist + end +end diff --git a/Library/Homebrew/test/cmd/help_spec.rb b/Library/Homebrew/test/cmd/help_spec.rb new file mode 100644 index 000000000..6d94d7444 --- /dev/null +++ b/Library/Homebrew/test/cmd/help_spec.rb @@ -0,0 +1,47 @@ +describe "brew", :integration_test do + it "prints help when no argument is given" do + expect { brew } + .to output(/Example usage:\n/).to_stderr + .and be_a_failure + end + + describe "help" do + it "prints help" do + expect { brew "help" } + .to output(/Example usage:\n/).to_stdout + .and be_a_success + end + + it "prints help for a documented Ruby command" do + expect { brew "help", "cat" } + .to output(/^brew cat/).to_stdout + .and be_a_success + end + + it "prints help for a documented shell command" do + expect { brew "help", "update" } + .to output(/^brew update/).to_stdout + .and be_a_success + end + + it "prints help for a documented Ruby developer command" do + expect { brew "help", "update-test" } + .to output(/^brew update-test/).to_stdout + .and be_a_success + end + + it "fails when given an unknown command" do + expect { brew "help", "command-that-does-not-exist" } + .to output(/Unknown command: command-that-does-not-exist/).to_stderr + .and be_a_failure + end + end + + describe "cat" do + it "prints help when no argument is given" do + expect { brew "cat" } + .to output(/^brew cat/).to_stderr + .and be_a_failure + end + end +end diff --git a/Library/Homebrew/test/cmd/home_spec.rb b/Library/Homebrew/test/cmd/home_spec.rb new file mode 100644 index 000000000..5a4070492 --- /dev/null +++ b/Library/Homebrew/test/cmd/home_spec.rb @@ -0,0 +1,17 @@ +describe "brew home", :integration_test do + it "opens the Homebrew homepage when no argument is given" do + expect { brew "home", "HOMEBREW_BROWSER" => "echo" } + .to output("#{HOMEBREW_WWW}\n").to_stdout + .and not_to_output.to_stderr + .and be_a_success + end + + it "opens the homepage for a given Formula" do + setup_test_formula "testball" + + expect { brew "home", "testball", "HOMEBREW_BROWSER" => "echo" } + .to output("#{Formula["testball"].homepage}\n").to_stdout + .and not_to_output.to_stderr + .and be_a_success + end +end diff --git a/Library/Homebrew/test/cmd/info_spec.rb b/Library/Homebrew/test/cmd/info_spec.rb new file mode 100644 index 000000000..8deef3d23 --- /dev/null +++ b/Library/Homebrew/test/cmd/info_spec.rb @@ -0,0 +1,30 @@ +require "cmd/info" + +describe "brew info", :integration_test do + it "prints information about a given Formula" do + setup_test_formula "testball" + + expect { brew "info", "testball" } + .to output(/testball: stable 0.1/).to_stdout + .and not_to_output.to_stderr + .and be_a_success + end +end + +describe Homebrew do + let(:remote) { "https://github.com/Homebrew/homebrew-core" } + + specify "::github_remote_path" do + expect(subject.github_remote_path(remote, "Formula/git.rb")) + .to eq("https://github.com/Homebrew/homebrew-core/blob/master/Formula/git.rb") + + expect(subject.github_remote_path("#{remote}.git", "Formula/git.rb")) + .to eq("https://github.com/Homebrew/homebrew-core/blob/master/Formula/git.rb") + + expect(subject.github_remote_path("git@github.com:user/repo", "foo.rb")) + .to eq("https://github.com/user/repo/blob/master/foo.rb") + + expect(subject.github_remote_path("https://mywebsite.com", "foo/bar.rb")) + .to eq("https://mywebsite.com/foo/bar.rb") + end +end diff --git a/Library/Homebrew/test/cmd/install_spec.rb b/Library/Homebrew/test/cmd/install_spec.rb new file mode 100644 index 000000000..c1240a30e --- /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/irb_spec.rb b/Library/Homebrew/test/cmd/irb_spec.rb new file mode 100644 index 000000000..44410fabe --- /dev/null +++ b/Library/Homebrew/test/cmd/irb_spec.rb @@ -0,0 +1,24 @@ +describe "brew irb", :integration_test do + it "starts an interactive Homebrew shell session" do + setup_test_formula "testball" + + irb_test = HOMEBREW_TEMP/"irb-test.rb" + irb_test.write <<-EOS.undent + "testball".f + :testball.f + exit + EOS + + expect { brew "irb", irb_test } + .to output(/Interactive Homebrew Shell/).to_stdout + .and not_to_output.to_stderr + .and be_a_success + end + + specify "--examples" do + expect { brew "irb", "--examples" } + .to output(/'v8'\.f # => instance of the v8 formula/).to_stdout + .and not_to_output.to_stderr + .and be_a_success + end +end diff --git a/Library/Homebrew/test/cmd/leaves_spec.rb b/Library/Homebrew/test/cmd/leaves_spec.rb new file mode 100644 index 000000000..cd93d7e3d --- /dev/null +++ b/Library/Homebrew/test/cmd/leaves_spec.rb @@ -0,0 +1,23 @@ +describe "brew leaves", :integration_test do + it "prints all Formulae that are not dependencies of other Formulae" do + setup_test_formula "foo" + setup_test_formula "bar" + + expect { brew "leaves" } + .to be_a_success + .and not_to_output.to_stdout + .and not_to_output.to_stderr + + (HOMEBREW_CELLAR/"foo/0.1/somedir").mkpath + expect { brew "leaves" } + .to output("foo\n").to_stdout + .and not_to_output.to_stderr + .and be_a_success + + (HOMEBREW_CELLAR/"bar/0.1/somedir").mkpath + expect { brew "leaves" } + .to output("bar\n").to_stdout + .and not_to_output.to_stderr + .and be_a_success + end +end diff --git a/Library/Homebrew/test/cmd/link_spec.rb b/Library/Homebrew/test/cmd/link_spec.rb new file mode 100644 index 000000000..7b85c96dc --- /dev/null +++ b/Library/Homebrew/test/cmd/link_spec.rb @@ -0,0 +1,56 @@ +describe "brew link", :integration_test do + it "fails when no argument is given" do + expect { brew "link" } + .to output(/This command requires a keg argument/).to_stderr + .and not_to_output.to_stdout + .and be_a_failure + end + + it "does not fail if the given Formula is already linked" do + setup_test_formula "testball1" + + shutup do + expect { brew "install", "testball1" }.to be_a_success + expect { brew "link", "testball1" }.to be_a_success + end + end + + it "links a given Formula" do + setup_test_formula "testball1" + + shutup do + expect { brew "install", "testball1" }.to be_a_success + expect { brew "unlink", "testball1" }.to be_a_success + end + + expect { brew "link", "--dry-run", "testball1" } + .to output(/Would link/).to_stdout + .and not_to_output.to_stderr + .and be_a_success + + expect { brew "link", "--dry-run", "--overwrite", "testball1" } + .to output(/Would remove/).to_stdout + .and not_to_output.to_stderr + .and be_a_success + + expect { brew "link", "testball1" } + .to output(/Linking/).to_stdout + .and not_to_output.to_stderr + .and be_a_success + end + + it "refuses to link keg-only Formulae" do + setup_test_formula "testball1", <<-EOS.undent + keg_only "just because" + EOS + + shutup do + expect { brew "install", "testball1" }.to be_a_success + end + + expect { brew "link", "testball1" } + .to output(/testball1 is keg-only/).to_stderr + .and output(/Note that doing so can interfere with building software\./).to_stdout + .and be_a_success + end +end diff --git a/Library/Homebrew/test/cmd/linkapps_spec.rb b/Library/Homebrew/test/cmd/linkapps_spec.rb new file mode 100644 index 000000000..42118a215 --- /dev/null +++ b/Library/Homebrew/test/cmd/linkapps_spec.rb @@ -0,0 +1,24 @@ +describe "brew linkapps", :integration_test do + let(:home_dir) { @home_dir = Pathname.new(Dir.mktmpdir) } + let(:apps_dir) { home_dir/"Applications" } + + after(:each) do + home_dir.rmtree unless @home_dir.nil? + end + + it "symlinks applications" do + apps_dir.mkpath + + setup_test_formula "testball" + + source_app = HOMEBREW_CELLAR/"testball/0.1/TestBall.app" + source_app.mkpath + + expect { brew "linkapps", "--local", "HOME" => home_dir } + .to output(/Linking: #{Regexp.escape(source_app)}/).to_stdout + .and output(/`brew linkapps` has been deprecated/).to_stderr + .and be_a_success + + expect(apps_dir/"TestBall.app").to be_a_symlink + end +end diff --git a/Library/Homebrew/test/cmd/list_spec.rb b/Library/Homebrew/test/cmd/list_spec.rb new file mode 100644 index 000000000..df7394d7b --- /dev/null +++ b/Library/Homebrew/test/cmd/list_spec.rb @@ -0,0 +1,14 @@ +describe "brew list", :integration_test do + let(:formulae) { %w[bar foo qux] } + + it "prints all installed Formulae" do + formulae.each do |f| + (HOMEBREW_CELLAR/f/"1.0/somedir").mkpath + end + + expect { brew "list" } + .to output("#{formulae.join("\n")}\n").to_stdout + .and not_to_output.to_stderr + .and be_a_success + end +end diff --git a/Library/Homebrew/test/cmd/log_spec.rb b/Library/Homebrew/test/cmd/log_spec.rb new file mode 100644 index 000000000..bdbca8912 --- /dev/null +++ b/Library/Homebrew/test/cmd/log_spec.rb @@ -0,0 +1,41 @@ +describe "brew log", :integration_test do + it "shows the Git log for the Homebrew repository when no argument is given" do + HOMEBREW_REPOSITORY.cd do + shutup do + system "git", "init" + system "git", "commit", "--allow-empty", "-m", "This is a test commit" + end + end + + expect { brew "log" } + .to output(/This is a test commit/).to_stdout + .and not_to_output.to_stderr + .and be_a_success + end + + it "shows the Git log for a given Formula" do + setup_test_formula "testball" + + core_tap = CoreTap.new + core_tap.path.cd do + shutup do + system "git", "init" + system "git", "add", "--all" + system "git", "commit", "-m", "This is a test commit for Testball" + end + end + + core_tap_url = "file://#{core_tap.path}" + shallow_tap = Tap.fetch("homebrew", "shallow") + shutup do + system "git", "clone", "--depth=1", core_tap_url, shallow_tap.path + end + + expect { brew "log", "#{shallow_tap}/testball" } + .to output(/This is a test commit for Testball/).to_stdout + .and output(/Warning: The git repository is a shallow clone/).to_stderr + .and be_a_success + + expect(shallow_tap.path/".git/shallow").to exist, "A shallow clone should have been created." + end +end diff --git a/Library/Homebrew/test/cmd/migrate_spec.rb b/Library/Homebrew/test/cmd/migrate_spec.rb new file mode 100644 index 000000000..18c94fa01 --- /dev/null +++ b/Library/Homebrew/test/cmd/migrate_spec.rb @@ -0,0 +1,46 @@ +describe "brew migrate", :integration_test do + before(:each) do + setup_test_formula "testball1" + setup_test_formula "testball2" + end + + it "fails when no argument is given" do + expect { brew "migrate" } + .to output(/Invalid usage/).to_stderr + .and not_to_output.to_stdout + .and be_a_failure + end + + it "fails when a given Formula doesn't exist" do + expect { brew "migrate", "testball" } + .to output(/No available formula with the name "testball"/).to_stderr + .and not_to_output.to_stdout + .and be_a_failure + end + + it "fails if a given Formula doesn't replace another one" do + expect { brew "migrate", "testball1" } + .to output(/testball1 doesn't replace any formula/).to_stderr + .and not_to_output.to_stdout + .and be_a_failure + end + + it "migrates a renamed Formula" do + install_and_rename_coretap_formula "testball1", "testball2" + + expect { brew "migrate", "testball1" } + .to output(/Migrating testball1 to testball2/).to_stdout + .and not_to_output.to_stderr + .and be_a_success + end + + it "fails if a given Formula is not installed" do + install_and_rename_coretap_formula "testball1", "testball2" + (HOMEBREW_CELLAR/"testball1").rmtree + + expect { brew "migrate", "testball1" } + .to output(/Error: No such keg/).to_stderr + .and not_to_output.to_stdout + .and be_a_failure + end +end diff --git a/Library/Homebrew/test/cmd/missing_spec.rb b/Library/Homebrew/test/cmd/missing_spec.rb new file mode 100644 index 000000000..4668e72e0 --- /dev/null +++ b/Library/Homebrew/test/cmd/missing_spec.rb @@ -0,0 +1,41 @@ +describe "brew missing", :integration_test do + before(:each) do + setup_test_formula "foo" + setup_test_formula "bar" + end + + def make_prefix(name) + (HOMEBREW_CELLAR/name/"1.0").mkpath + end + + it "prints missing dependencies" do + make_prefix "bar" + + expect { brew "missing" } + .to output("foo\n").to_stdout + .and not_to_output.to_stderr + .and be_a_success + end + + it "prints nothing if all dependencies are installed" do + make_prefix "foo" + make_prefix "bar" + + expect { brew "missing" } + .to be_a_success + .and not_to_output.to_stdout + .and not_to_output.to_stderr + end + + describe "--hide=" do + it "pretends that the specified Formulae are not installed" do + make_prefix "foo" + make_prefix "bar" + + expect { brew "missing", "--hide=foo" } + .to output("bar: foo\n").to_stdout + .and not_to_output.to_stderr + .and be_a_success + end + end +end diff --git a/Library/Homebrew/test/cmd/options_spec.rb b/Library/Homebrew/test/cmd/options_spec.rb new file mode 100644 index 000000000..33fe8b107 --- /dev/null +++ b/Library/Homebrew/test/cmd/options_spec.rb @@ -0,0 +1,12 @@ +describe "brew options", :integration_test do + it "prints a given Formula's options" do + setup_test_formula "testball", <<-EOS.undent + depends_on "bar" => :recommended + EOS + + expect { brew "options", "testball" } + .to output("--with-foo\n\tBuild with foo\n--without-bar\n\tBuild without bar support\n\n").to_stdout + .and not_to_output.to_stderr + .and be_a_success + end +end diff --git a/Library/Homebrew/test/cmd/outdated_spec.rb b/Library/Homebrew/test/cmd/outdated_spec.rb new file mode 100644 index 000000000..2ce0825e8 --- /dev/null +++ b/Library/Homebrew/test/cmd/outdated_spec.rb @@ -0,0 +1,11 @@ +describe "brew outdated", :integration_test do + it "prints outdated Formulae" do + setup_test_formula "testball" + (HOMEBREW_CELLAR/"testball/0.0.1/foo").mkpath + + expect { brew "outdated" } + .to output("testball\n").to_stdout + .and not_to_output.to_stderr + .and be_a_success + end +end diff --git a/Library/Homebrew/test/cmd/pin_spec.rb b/Library/Homebrew/test/cmd/pin_spec.rb new file mode 100644 index 000000000..9ffc052c3 --- /dev/null +++ b/Library/Homebrew/test/cmd/pin_spec.rb @@ -0,0 +1,13 @@ +describe "brew pin", :integration_test do + it "pins a Formula's version" do + setup_test_formula "testball" + (HOMEBREW_CELLAR/"testball/0.0.1/foo").mkpath + + shutup do + expect { brew "pin", "testball" }.to be_a_success + expect { brew "upgrade" }.to be_a_success + end + + expect(HOMEBREW_CELLAR/"testball/0.1").not_to be_a_directory + end +end diff --git a/Library/Homebrew/test/cmd/prune_spec.rb b/Library/Homebrew/test/cmd/prune_spec.rb new file mode 100644 index 000000000..c5a9df70c --- /dev/null +++ b/Library/Homebrew/test/cmd/prune_spec.rb @@ -0,0 +1,28 @@ +describe "brew prune", :integration_test do + it "removes empty directories and broken symlinks" do + share = (HOMEBREW_PREFIX/"share") + + (share/"pruneable/directory/here").mkpath + (share/"notpruneable/file").write "I'm here" + FileUtils.ln_s "/i/dont/exist/no/really/i/dont", share/"pruneable_symlink" + + expect { brew "prune", "--dry-run" } + .to output(%r{Would remove \(empty directory\): .*/pruneable/directory/here}).to_stdout + .and not_to_output.to_stderr + .and be_a_success + + expect { brew "prune" } + .to output(/Pruned 1 symbolic links and 3 directories/).to_stdout + .and not_to_output.to_stderr + .and be_a_success + + expect(share/"pruneable").not_to be_a_directory + expect(share/"notpruneable").to be_a_directory + expect(share/"pruneable_symlink").not_to be_a_symlink + + expect { brew "prune", "--verbose" } + .to output(/Nothing pruned/).to_stdout + .and not_to_output.to_stderr + .and be_a_success + end +end diff --git a/Library/Homebrew/test/cmd/readall_spec.rb b/Library/Homebrew/test/cmd/readall_spec.rb new file mode 100644 index 000000000..9165e0cb0 --- /dev/null +++ b/Library/Homebrew/test/cmd/readall_spec.rb @@ -0,0 +1,20 @@ +describe "brew readall", :integration_test do + it "imports all Formulae for a given Tap" do + formula_file = setup_test_formula "testball" + + alias_file = CoreTap.new.alias_dir/"foobar" + alias_file.parent.mkpath + + FileUtils.ln_s formula_file, alias_file + + expect { brew "readall", "--aliases", "--syntax" } + .to be_a_success + .and not_to_output.to_stdout + .and not_to_output.to_stderr + + expect { brew "readall", "homebrew/core" } + .to be_a_success + .and not_to_output.to_stdout + .and not_to_output.to_stderr + end +end diff --git a/Library/Homebrew/test/cmd/reinstall_spec.rb b/Library/Homebrew/test/cmd/reinstall_spec.rb new file mode 100644 index 000000000..63584e6be --- /dev/null +++ b/Library/Homebrew/test/cmd/reinstall_spec.rb @@ -0,0 +1,44 @@ +require "extend/ENV" + +describe "brew reinstall", :integration_test do + before(:each) do + setup_test_formula "testball" + + shutup do + expect { brew "install", "testball", "--with-foo" }.to be_a_success + end + end + + it "reinstalls a Formula" do + foo_dir = HOMEBREW_CELLAR/"testball/0.1/foo" + expect(foo_dir).to exist + foo_dir.rmtree + + expect { brew "reinstall", "testball" } + .to output(/Reinstalling testball --with-foo/).to_stdout + .and not_to_output.to_stderr + .and be_a_success + + expect(foo_dir).to exist + end + + it "reinstalls a Formula even when one of the options is invalid" do + 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 + end + + it "refuses to reinstall a pinned Formula, but doesn't fail" do + (HOMEBREW_CELLAR/"testball/0.1").mkpath + HOMEBREW_PINNED_KEGS.mkpath + FileUtils.ln_s HOMEBREW_CELLAR/"testball/0.1", HOMEBREW_PINNED_KEGS/"testball" + + expect { brew "reinstall", "testball" } + .to output(/testball is pinned. You must unpin it to reinstall./).to_stderr + .and not_to_output.to_stdout + .and be_a_success + + HOMEBREW_PINNED_KEGS.rmtree + end +end diff --git a/Library/Homebrew/test/cmd/search_spec.rb b/Library/Homebrew/test/cmd/search_spec.rb new file mode 100644 index 000000000..06b7073d8 --- /dev/null +++ b/Library/Homebrew/test/cmd/search_spec.rb @@ -0,0 +1,57 @@ +describe "brew search", :integration_test do + before(:each) do + setup_test_formula "testball" + end + + it "lists all available Formulae when no argument is given" do + expect { brew "search" } + .to output(/testball/).to_stdout + .and not_to_output.to_stderr + .and be_a_success + end + + it "supports searching by name" do + expect { brew "search", "testball" } + .to output(/testball/).to_stdout + .and not_to_output.to_stderr + .and be_a_success + end + + it "supports searching a fully-qualified name " do + expect { brew "search", "homebrew/homebrew-core/testball" } + .to output(/testball/).to_stdout + .and not_to_output.to_stderr + .and be_a_success + end + + describe "--desc" do + let(:desc_cache) { HOMEBREW_CACHE/"desc_cache.json" } + + it "supports searching in descriptions and creates a description cache" do + expect(desc_cache).not_to exist + + expect { brew "search", "--desc", "Some test" } + .to output(/testball/).to_stdout + .and not_to_output.to_stderr + .and be_a_success + + expect(desc_cache).to exist + end + end + + { + "macports" => "https://www.macports.org/ports.php?by=name&substr=testball", + "fink" => "http://pdb.finkproject.org/pdb/browse.php?summary=testball", + "debian" => "https://packages.debian.org/search?keywords=testball&searchon=names&suite=all§ion=all", + "opensuse" => "https://software.opensuse.org/search?q=testball", + "fedora" => "https://admin.fedoraproject.org/pkgdb/packages/%2Atestball%2A/", + "ubuntu" => "http://packages.ubuntu.com/search?keywords=testball&searchon=names&suite=all§ion=all", + }.each do |flag, url| + specify "--#{flag}" do + expect { brew "search", "--#{flag}", "testball", "HOMEBREW_BROWSER" => "echo" } + .to output("#{url}\n").to_stdout + .and not_to_output.to_stderr + .and be_a_success + end + end +end diff --git a/Library/Homebrew/test/cmd/services_spec.rb b/Library/Homebrew/test/cmd/services_spec.rb new file mode 100644 index 000000000..c456fea17 --- /dev/null +++ b/Library/Homebrew/test/cmd/services_spec.rb @@ -0,0 +1,10 @@ +describe "brew services", :integration_test, :needs_macos, :needs_official_cmd_taps do + it "allows controlling services" do + setup_remote_tap "homebrew/services" + + expect { brew "services", "list" } + .to output("Warning: No services available to control with `brew services`\n").to_stderr + .and not_to_output.to_stdout + .and be_a_success + end +end diff --git a/Library/Homebrew/test/cmd/sh_spec.rb b/Library/Homebrew/test/cmd/sh_spec.rb new file mode 100644 index 000000000..5260ddb75 --- /dev/null +++ b/Library/Homebrew/test/cmd/sh_spec.rb @@ -0,0 +1,8 @@ +describe "brew sh", :integration_test do + it "runs a shell with the Homebrew environment" do + expect { brew "sh", "SHELL" => which("true") } + .to output(/Your shell has been configured/).to_stdout + .and not_to_output.to_stderr + .and be_a_success + end +end diff --git a/Library/Homebrew/test/cmd/switch_spec.rb b/Library/Homebrew/test/cmd/switch_spec.rb new file mode 100644 index 000000000..c27c96c14 --- /dev/null +++ b/Library/Homebrew/test/cmd/switch_spec.rb @@ -0,0 +1,34 @@ +describe "brew switch", :integration_test do + it "allows switching between Formula versions" do + expect { brew "switch" } + .to output(/Usage: brew switch <name> <version>/).to_stderr + .and not_to_output.to_stdout + .and be_a_failure + + expect { brew "switch", "testball", "0.1" } + .to output(/testball not found/).to_stderr + .and not_to_output.to_stdout + .and be_a_failure + + setup_test_formula "testball", <<-EOS.undent + keg_only "just because" + EOS + + shutup do + expect { brew "install", "testball" }.to be_a_success + end + + testball_rack = HOMEBREW_CELLAR/"testball" + FileUtils.cp_r testball_rack/"0.1", testball_rack/"0.2" + + expect { brew "switch", "testball", "0.2" } + .to output(/link created/).to_stdout + .and not_to_output.to_stderr + .and be_a_success + + expect { brew "switch", "testball", "0.3" } + .to output("Versions available: 0.1, 0.2\n").to_stdout + .and output(/testball does not have a version "0.3"/).to_stderr + .and be_a_failure + end +end diff --git a/Library/Homebrew/test/cmd/tap-new_spec.rb b/Library/Homebrew/test/cmd/tap-new_spec.rb new file mode 100644 index 000000000..ea4b8aa73 --- /dev/null +++ b/Library/Homebrew/test/cmd/tap-new_spec.rb @@ -0,0 +1,10 @@ +describe "brew tap-new", :integration_test do + it "initializes a new Tap with a ReadMe file" do + expect { brew "tap-new", "homebrew/foo", "--verbose" } + .to be_a_success + .and not_to_output.to_stdout + .and not_to_output.to_stderr + + expect(HOMEBREW_LIBRARY/"Taps/homebrew/homebrew-foo/README.md").to exist + end +end diff --git a/Library/Homebrew/test/cmd/uninstall_spec.rb b/Library/Homebrew/test/cmd/uninstall_spec.rb new file mode 100644 index 000000000..65f69e802 --- /dev/null +++ b/Library/Homebrew/test/cmd/uninstall_spec.rb @@ -0,0 +1,12 @@ +describe "brew uninstall", :integration_test do + it "uninstalls a given Formula" do + shutup do + expect { brew "install", testball }.to be_a_success + end + + expect { brew "uninstall", "--force", testball } + .to output(/Uninstalling testball/).to_stdout + .and not_to_output.to_stderr + .and be_a_success + end +end diff --git a/Library/Homebrew/test/cmd/unlink_spec.rb b/Library/Homebrew/test/cmd/unlink_spec.rb new file mode 100644 index 000000000..5961651fe --- /dev/null +++ b/Library/Homebrew/test/cmd/unlink_spec.rb @@ -0,0 +1,14 @@ +describe "brew unlink", :integration_test do + it "unlinks a Formula" do + setup_test_formula "testball" + + shutup do + expect { brew "install", "testball" }.to be_a_success + end + + expect { brew "unlink", "--dry-run", "testball" } + .to output(/Would remove/).to_stdout + .and not_to_output.to_stderr + .and be_a_success + end +end diff --git a/Library/Homebrew/test/cmd/unlinkapps_spec.rb b/Library/Homebrew/test/cmd/unlinkapps_spec.rb new file mode 100644 index 000000000..1e21bd851 --- /dev/null +++ b/Library/Homebrew/test/cmd/unlinkapps_spec.rb @@ -0,0 +1,24 @@ +describe "brew unlinkapps", :integration_test do + let(:home_dir) { @home_dir = Pathname.new(Dir.mktmpdir) } + let(:apps_dir) { home_dir/"Applications" } + + after(:each) do + home_dir.rmtree unless @home_dir.nil? + end + + it "unlinks symlinked applications" do + apps_dir.mkpath + + setup_test_formula "testball" + + source_app = HOMEBREW_CELLAR/"testball/0.1/TestBall.app" + source_app.mkpath + + FileUtils.ln_s source_app, apps_dir/"TestBall.app" + + expect { brew "unlinkapps", "--local", "HOME" => home_dir } + .to output(%r{Unlinking: #{Regexp.escape(apps_dir)}/TestBall.app}).to_stdout + .and output(/`brew unlinkapps` has been deprecated/).to_stderr + .and be_a_success + end +end diff --git a/Library/Homebrew/test/cmd/unpack_spec.rb b/Library/Homebrew/test/cmd/unpack_spec.rb new file mode 100644 index 000000000..244fc0852 --- /dev/null +++ b/Library/Homebrew/test/cmd/unpack_spec.rb @@ -0,0 +1,16 @@ +describe "brew unpack", :integration_test do + it "unpacks a given Formula's archive" do + setup_test_formula "testball" + + Dir.mktmpdir do |path| + path = Pathname.new(path) + + shutup do + expect { brew "unpack", "testball", "--destdir=#{path}" } + .to be_a_success + end + + expect(path/"testball-0.1").to be_a_directory + end + end +end diff --git a/Library/Homebrew/test/cmd/unpin_spec.rb b/Library/Homebrew/test/cmd/unpin_spec.rb new file mode 100644 index 000000000..4f14626d8 --- /dev/null +++ b/Library/Homebrew/test/cmd/unpin_spec.rb @@ -0,0 +1,14 @@ +describe "brew unpin", :integration_test do + it "unpins a Formula's version" do + setup_test_formula "testball" + (HOMEBREW_CELLAR/"testball/0.0.1/foo").mkpath + + shutup do + expect { brew "pin", "testball" }.to be_a_success + expect { brew "unpin", "testball" }.to be_a_success + expect { brew "upgrade" }.to be_a_success + end + + expect(HOMEBREW_CELLAR/"testball/0.1").to be_a_directory + end +end diff --git a/Library/Homebrew/test/cmd/update-report_spec.rb b/Library/Homebrew/test/cmd/update-report_spec.rb new file mode 100644 index 000000000..3665e3c78 --- /dev/null +++ b/Library/Homebrew/test/cmd/update-report_spec.rb @@ -0,0 +1,127 @@ +require "cmd/update-report" +require "formula_versions" +require "yaml" + +describe Reporter do + def perform_update(fixture_name = "") + allow(Formulary).to receive(:factory).and_return(double(pkg_version: "1.0")) + allow(FormulaVersions).to receive(:new).and_return(double(formula_at_revision: "2.0")) + + diff = YAML.load_file("#{TEST_FIXTURE_DIR}/updater_fixture.yaml")[fixture_name] + allow(subject).to receive(:diff).and_return(diff || "") + + hub.add(subject) if subject.updated? + end + + let(:reporter_class) do + Class.new(described_class) do + def initialize(tap) + @tap = tap + + ENV["HOMEBREW_UPDATE_BEFORE#{repo_var}"] = "12345678" + ENV["HOMEBREW_UPDATE_AFTER#{repo_var}"] = "abcdef00" + + super(tap) + end + end + end + subject { reporter_class.new(tap) } + let(:tap) { CoreTap.new } + let(:hub) { ReporterHub.new } + + specify "without revision variable" do + ENV.delete_if { |k, _v| k.start_with? "HOMEBREW_UPDATE" } + + expect { + described_class.new(tap) + }.to raise_error(Reporter::ReporterRevisionUnsetError) + end + + specify "without any changes" do + perform_update + expect(hub).to be_empty + end + + specify "without Formula changes" do + perform_update("update_git_diff_output_without_formulae_changes") + + expect(hub.select_formula(:M)).to be_empty + expect(hub.select_formula(:A)).to be_empty + expect(hub.select_formula(:D)).to be_empty + end + + specify "with Formula changes" do + perform_update("update_git_diff_output_with_formulae_changes") + + expect(hub.select_formula(:M)).to eq(%w[xar yajl]) + expect(hub.select_formula(:A)).to eq(%w[antiword bash-completion ddrescue dict lua]) + end + + specify "with removed Formulae" do + perform_update("update_git_diff_output_with_removed_formulae") + + expect(hub.select_formula(:D)).to eq(%w[libgsasl]) + end + + specify "with changed file type" do + perform_update("update_git_diff_output_with_changed_filetype") + + expect(hub.select_formula(:M)).to eq(%w[elixir]) + expect(hub.select_formula(:A)).to eq(%w[libbson]) + expect(hub.select_formula(:D)).to eq(%w[libgsasl]) + end + + specify "with renamed Formula" do + allow(tap).to receive(:formula_renames).and_return("cv" => "progress") + perform_update("update_git_diff_output_with_formula_rename") + + expect(hub.select_formula(:A)).to be_empty + expect(hub.select_formula(:D)).to be_empty + expect(hub.select_formula(:R)).to eq([["cv", "progress"]]) + end + + context "when updating a Tap other than the core Tap" do + let(:tap) { Tap.new("foo", "bar") } + + before(:each) do + (tap.path/"Formula").mkpath + end + + after(:each) do + tap.path.parent.rmtree + end + + specify "with restructured Tap" do + perform_update("update_git_diff_output_with_restructured_tap") + + expect(hub.select_formula(:A)).to be_empty + expect(hub.select_formula(:D)).to be_empty + expect(hub.select_formula(:R)).to be_empty + end + + specify "with renamed Formula and restructured Tap" do + allow(tap).to receive(:formula_renames).and_return("xchat" => "xchat2") + perform_update("update_git_diff_output_with_formula_rename_and_restructuring") + + expect(hub.select_formula(:A)).to be_empty + expect(hub.select_formula(:D)).to be_empty + expect(hub.select_formula(:R)).to eq([%w[foo/bar/xchat foo/bar/xchat2]]) + end + + specify "with simulated 'homebrew/php' restructuring" do + perform_update("update_git_diff_simulate_homebrew_php_restructuring") + + expect(hub.select_formula(:A)).to be_empty + expect(hub.select_formula(:D)).to be_empty + expect(hub.select_formula(:R)).to be_empty + end + + specify "with Formula changes" do + perform_update("update_git_diff_output_with_tap_formulae_changes") + + expect(hub.select_formula(:A)).to eq(%w[foo/bar/lua]) + expect(hub.select_formula(:M)).to eq(%w[foo/bar/git]) + expect(hub.select_formula(:D)).to be_empty + end + end +end diff --git a/Library/Homebrew/test/cmd/upgrade_spec.rb b/Library/Homebrew/test/cmd/upgrade_spec.rb new file mode 100644 index 000000000..84f5c09f4 --- /dev/null +++ b/Library/Homebrew/test/cmd/upgrade_spec.rb @@ -0,0 +1,12 @@ +describe "brew upgrade", :integration_test do + it "upgrades a Formula to the latest version" do + setup_test_formula "testball" + (HOMEBREW_CELLAR/"testball/0.0.1/foo").mkpath + + shutup do + expect { brew "upgrade" }.to be_a_success + end + + expect(HOMEBREW_CELLAR/"testball/0.1").to be_a_directory + end +end diff --git a/Library/Homebrew/test/cmd/uses_spec.rb b/Library/Homebrew/test/cmd/uses_spec.rb new file mode 100644 index 000000000..2a6f48cb7 --- /dev/null +++ b/Library/Homebrew/test/cmd/uses_spec.rb @@ -0,0 +1,25 @@ +describe "brew uses", :integration_test do + it "prints the Formulae a given Formula is used by" do + setup_test_formula "foo" + setup_test_formula "bar" + setup_test_formula "baz", <<-EOS.undent + url "https://example.com/baz-1.0" + depends_on "bar" + EOS + + expect { brew "uses", "baz" } + .to be_a_success + .and not_to_output.to_stdout + .and not_to_output.to_stderr + + expect { brew "uses", "bar" } + .to output("baz\n").to_stdout + .and not_to_output.to_stderr + .and be_a_success + + expect { brew "uses", "--recursive", "foo" } + .to output(/(bar\nbaz|baz\nbar)/).to_stdout + .and not_to_output.to_stderr + .and be_a_success + end +end |
