2015-11-19 07:54:27 -05:00
|
|
|
require "bundler"
|
2015-07-23 21:32:13 +01:00
|
|
|
require "testing_env"
|
2016-01-04 23:14:58 +01:00
|
|
|
require "fileutils"
|
2016-01-30 14:12:07 +01:00
|
|
|
require "pathname"
|
2016-06-02 09:17:05 +02:00
|
|
|
require "formula"
|
2015-07-23 21:32:13 +01:00
|
|
|
|
|
|
|
class IntegrationCommandTests < Homebrew::TestCase
|
2016-01-20 06:16:10 +01:00
|
|
|
def setup
|
|
|
|
@cmd_id_index = 0 # Assign unique IDs to invocations of `cmd_output`.
|
2016-02-02 23:37:42 -08:00
|
|
|
(HOMEBREW_PREFIX/"bin").mkpath
|
|
|
|
FileUtils.touch HOMEBREW_PREFIX/"bin/brew"
|
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
(HOMEBREW_PREFIX/"bin").rmtree
|
2016-01-20 06:16:10 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def cmd_id_from_args(args)
|
|
|
|
args_pretty = args.join(" ").gsub(TEST_TMPDIR, "@TMPDIR@")
|
|
|
|
test_pretty = "#{self.class.name}\##{name}.#{@cmd_id_index += 1}"
|
|
|
|
"[#{test_pretty}] brew #{args_pretty}"
|
|
|
|
end
|
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
def cmd_output(*args)
|
2016-01-04 23:14:51 +01:00
|
|
|
# 1.8-compatible way of writing def cmd_output(*args, **env)
|
|
|
|
env = args.last.is_a?(Hash) ? args.pop : {}
|
2015-07-23 21:32:13 +01:00
|
|
|
cmd_args = %W[
|
2015-08-03 13:09:07 +01:00
|
|
|
-W0
|
|
|
|
-I#{HOMEBREW_LIBRARY_PATH}/test/lib
|
|
|
|
-rconfig
|
2015-07-23 21:32:13 +01:00
|
|
|
]
|
2016-01-28 00:02:01 +01:00
|
|
|
if ENV["HOMEBREW_TESTS_COVERAGE"]
|
|
|
|
# This is needed only because we currently use a patched version of
|
|
|
|
# simplecov, and gems installed through git are not available without
|
|
|
|
# requiring bundler/setup first. See also the comment in test/Gemfile.
|
|
|
|
# Remove this line when we'll switch back to a stable simplecov release.
|
|
|
|
cmd_args << "-rbundler/setup"
|
|
|
|
cmd_args << "-rsimplecov"
|
|
|
|
end
|
2016-02-06 18:40:40 +01:00
|
|
|
cmd_args << "-rintegration_mocks"
|
2015-07-23 21:32:13 +01:00
|
|
|
cmd_args << (HOMEBREW_LIBRARY_PATH/"../brew.rb").resolved_path.to_s
|
|
|
|
cmd_args += args
|
|
|
|
Bundler.with_original_env do
|
|
|
|
ENV["HOMEBREW_BREW_FILE"] = HOMEBREW_PREFIX/"bin/brew"
|
2016-01-20 06:16:10 +01:00
|
|
|
ENV["HOMEBREW_INTEGRATION_TEST"] = cmd_id_from_args(args)
|
2015-07-23 21:32:13 +01:00
|
|
|
ENV["HOMEBREW_TEST_TMPDIR"] = TEST_TMPDIR
|
2016-01-04 23:14:51 +01:00
|
|
|
env.each_pair { |k,v| ENV[k] = v }
|
|
|
|
|
2015-12-26 16:31:06 +08:00
|
|
|
read, write = IO.pipe
|
|
|
|
begin
|
|
|
|
pid = fork do
|
|
|
|
read.close
|
|
|
|
$stdout.reopen(write)
|
|
|
|
$stderr.reopen(write)
|
|
|
|
write.close
|
|
|
|
exec RUBY_PATH, *cmd_args
|
|
|
|
end
|
|
|
|
write.close
|
|
|
|
read.read.chomp
|
|
|
|
ensure
|
|
|
|
Process.wait(pid)
|
|
|
|
read.close
|
|
|
|
end
|
2015-07-23 21:32:13 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
def cmd(*args)
|
2015-07-23 21:32:13 +01:00
|
|
|
output = cmd_output(*args)
|
2016-05-08 17:12:31 +01:00
|
|
|
status = $?.exitstatus
|
|
|
|
puts "\n#{output}" if status != 0
|
|
|
|
assert_equal 0, status
|
2015-07-23 21:32:13 +01:00
|
|
|
output
|
|
|
|
end
|
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
def cmd_fail(*args)
|
2015-07-23 21:32:13 +01:00
|
|
|
output = cmd_output(*args)
|
2016-05-08 17:12:31 +01:00
|
|
|
status = $?.exitstatus
|
|
|
|
$stderr.puts "\n#{output}" if status != 1
|
|
|
|
assert_equal 1, status
|
2015-07-23 21:32:13 +01:00
|
|
|
output
|
|
|
|
end
|
|
|
|
|
|
|
|
def testball
|
|
|
|
"#{File.expand_path("..", __FILE__)}/testball.rb"
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_prefix
|
|
|
|
assert_equal HOMEBREW_PREFIX.to_s,
|
|
|
|
cmd("--prefix")
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_version
|
2015-07-18 21:55:50 -07:00
|
|
|
assert_match HOMEBREW_VERSION.to_s,
|
2015-07-23 21:32:13 +01:00
|
|
|
cmd("--version")
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_cache
|
|
|
|
assert_equal HOMEBREW_CACHE.to_s,
|
|
|
|
cmd("--cache")
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_cache_formula
|
|
|
|
assert_match %r{#{HOMEBREW_CACHE}/testball-},
|
|
|
|
cmd("--cache", testball)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_cellar
|
|
|
|
assert_equal HOMEBREW_CELLAR.to_s,
|
|
|
|
cmd("--cellar")
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_cellar_formula
|
|
|
|
assert_match "#{HOMEBREW_CELLAR}/testball",
|
|
|
|
cmd("--cellar", testball)
|
|
|
|
end
|
|
|
|
|
2016-05-08 17:11:57 +01:00
|
|
|
def test_cleanup
|
|
|
|
assert_equal HOMEBREW_CACHE.to_s,
|
|
|
|
cmd("cleanup")
|
|
|
|
end
|
|
|
|
|
2015-07-23 21:32:13 +01:00
|
|
|
def test_env
|
2015-09-05 14:33:56 +08:00
|
|
|
assert_match %r{CMAKE_PREFIX_PATH="#{HOMEBREW_PREFIX}[:"]},
|
2015-07-23 21:32:13 +01:00
|
|
|
cmd("--env")
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_prefix_formula
|
|
|
|
assert_match "#{HOMEBREW_CELLAR}/testball",
|
|
|
|
cmd("--prefix", testball)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_repository
|
|
|
|
assert_match HOMEBREW_REPOSITORY.to_s,
|
|
|
|
cmd("--repository")
|
|
|
|
end
|
2015-12-16 20:57:31 +00:00
|
|
|
|
2016-03-23 16:33:40 +08:00
|
|
|
def test_repository
|
|
|
|
assert_match "#{HOMEBREW_LIBRARY}/Taps/foo/homebrew-bar",
|
|
|
|
cmd("--repository", "foo/bar")
|
|
|
|
end
|
|
|
|
|
2016-01-05 15:45:45 +01:00
|
|
|
def test_help
|
2016-04-19 08:50:03 +02:00
|
|
|
assert_match "Example usage:\n",
|
|
|
|
cmd_fail # Generic help (empty argument list).
|
|
|
|
assert_match "Unknown command: command-that-does-not-exist",
|
|
|
|
cmd_fail("help", "command-that-does-not-exist")
|
|
|
|
assert_match(/^brew cat /,
|
|
|
|
cmd_fail("cat")) # Missing formula argument triggers help.
|
|
|
|
|
|
|
|
assert_match "Example usage:\n",
|
|
|
|
cmd("help") # Generic help.
|
|
|
|
assert_match(/^brew cat /,
|
|
|
|
cmd("help", "cat")) # Internal command (documented, Ruby).
|
|
|
|
assert_match(/^brew update /,
|
|
|
|
cmd("help", "update")) # Internal command (documented, Shell).
|
2016-05-30 21:44:35 +01:00
|
|
|
if ARGV.homebrew_developer?
|
|
|
|
assert_match "Example usage:\n",
|
|
|
|
cmd("help", "test-bot") # Internal developer command (undocumented).
|
|
|
|
end
|
2016-01-05 15:45:45 +01:00
|
|
|
end
|
|
|
|
|
2016-01-15 15:48:37 +01:00
|
|
|
def test_config
|
|
|
|
assert_match "HOMEBREW_VERSION: #{HOMEBREW_VERSION}",
|
|
|
|
cmd("config")
|
|
|
|
end
|
|
|
|
|
2015-12-16 20:57:31 +00:00
|
|
|
def test_install
|
|
|
|
assert_match "#{HOMEBREW_CELLAR}/testball/0.1", cmd("install", testball)
|
|
|
|
ensure
|
|
|
|
cmd("uninstall", "--force", testball)
|
|
|
|
cmd("cleanup", "--force", "--prune=all")
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_bottle
|
|
|
|
cmd("install", "--build-bottle", testball)
|
2015-12-26 16:31:06 +08:00
|
|
|
assert_match "Formula not from core or any taps",
|
|
|
|
cmd_fail("bottle", "--no-revision", testball)
|
2016-03-07 18:04:25 +08:00
|
|
|
formula_file = CoreTap.new.formula_dir/"testball.rb"
|
2015-12-26 16:31:06 +08:00
|
|
|
formula_file.write <<-EOS.undent
|
|
|
|
class Testball < Formula
|
2015-12-30 20:37:22 +00:00
|
|
|
url "https://example.com/testball-0.1.tar.gz"
|
2015-12-26 16:31:06 +08:00
|
|
|
end
|
|
|
|
EOS
|
2016-02-10 19:29:40 +08:00
|
|
|
# `brew bottle` should not fail with dead symlink
|
2016-05-01 14:55:45 +02:00
|
|
|
# https://github.com/Homebrew/legacy-homebrew/issues/49007
|
2016-02-10 19:29:40 +08:00
|
|
|
(HOMEBREW_CELLAR/"testball/0.1").cd do
|
|
|
|
FileUtils.ln_s "not-exist", "symlink"
|
|
|
|
end
|
2016-02-06 18:40:12 +01:00
|
|
|
assert_match(/testball-0\.1.*\.bottle\.tar\.gz/,
|
|
|
|
cmd_output("bottle", "--no-revision", "testball"))
|
2015-12-16 20:57:31 +00:00
|
|
|
ensure
|
2015-12-26 16:31:06 +08:00
|
|
|
cmd("uninstall", "--force", "testball")
|
2015-12-16 20:57:31 +00:00
|
|
|
cmd("cleanup", "--force", "--prune=all")
|
2016-01-04 13:41:38 +01:00
|
|
|
formula_file.unlink unless formula_file.nil?
|
2016-02-07 12:25:14 +01:00
|
|
|
FileUtils.rm_f Dir["testball-0.1*.bottle.tar.gz"]
|
2015-12-16 20:57:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_uninstall
|
2015-12-26 16:31:06 +08:00
|
|
|
cmd("install", testball)
|
2015-12-16 20:57:31 +00:00
|
|
|
assert_match "Uninstalling testball", cmd("uninstall", "--force", testball)
|
|
|
|
ensure
|
|
|
|
cmd("cleanup", "--force", "--prune=all")
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_cleanup
|
|
|
|
(HOMEBREW_CACHE/"test").write "test"
|
|
|
|
assert_match "#{HOMEBREW_CACHE}/test", cmd("cleanup", "--prune=all")
|
2016-01-27 22:38:03 +01:00
|
|
|
ensure
|
2016-01-27 23:02:41 +01:00
|
|
|
FileUtils.rm_f HOMEBREW_CACHE/"test"
|
2015-12-16 20:57:31 +00:00
|
|
|
end
|
2015-12-19 21:24:45 +08:00
|
|
|
|
|
|
|
def test_readall
|
2016-03-07 18:04:25 +08:00
|
|
|
repo = CoreTap.new
|
2015-12-19 21:24:45 +08:00
|
|
|
formula_file = repo.formula_dir/"foo.rb"
|
|
|
|
formula_file.write <<-EOS.undent
|
|
|
|
class Foo < Formula
|
|
|
|
url "https://example.com/foo-1.0.tar.gz"
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
alias_file = repo.alias_dir/"bar"
|
|
|
|
alias_file.parent.mkpath
|
|
|
|
FileUtils.ln_s formula_file, alias_file
|
|
|
|
cmd("readall", "--aliases", "--syntax")
|
2016-05-01 14:59:39 +02:00
|
|
|
cmd("readall", "homebrew/core")
|
2015-12-19 21:24:45 +08:00
|
|
|
ensure
|
2016-01-04 23:14:58 +01:00
|
|
|
formula_file.unlink unless formula_file.nil?
|
2015-12-19 21:24:45 +08:00
|
|
|
repo.alias_dir.rmtree
|
|
|
|
end
|
2015-12-19 21:54:42 +08:00
|
|
|
|
|
|
|
def test_tap
|
|
|
|
path = Tap::TAP_DIRECTORY/"homebrew/homebrew-foo"
|
|
|
|
path.mkpath
|
|
|
|
path.cd do
|
|
|
|
shutup do
|
|
|
|
system "git", "init"
|
|
|
|
system "git", "remote", "add", "origin", "https://github.com/Homebrew/homebrew-foo"
|
2016-02-26 17:18:30 +08:00
|
|
|
FileUtils.touch "readme"
|
2015-12-19 21:54:42 +08:00
|
|
|
system "git", "add", "--all"
|
|
|
|
system "git", "commit", "-m", "init"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match "homebrew/foo", cmd("tap")
|
|
|
|
assert_match "homebrew/versions", cmd("tap", "--list-official")
|
2016-02-26 19:43:49 +08:00
|
|
|
assert_match "2 taps", cmd("tap-info")
|
2015-12-19 21:54:42 +08:00
|
|
|
assert_match "https://github.com/Homebrew/homebrew-foo", cmd("tap-info", "homebrew/foo")
|
|
|
|
assert_match "https://github.com/Homebrew/homebrew-foo", cmd("tap-info", "--json=v1", "--installed")
|
|
|
|
assert_match "Pinned homebrew/foo", cmd("tap-pin", "homebrew/foo")
|
|
|
|
assert_match "homebrew/foo", cmd("tap", "--list-pinned")
|
|
|
|
assert_match "Unpinned homebrew/foo", cmd("tap-unpin", "homebrew/foo")
|
|
|
|
assert_match "Tapped", cmd("tap", "homebrew/bar", path/".git")
|
|
|
|
assert_match "Untapped", cmd("untap", "homebrew/bar")
|
2016-02-26 17:18:30 +08:00
|
|
|
assert_equal "", cmd("tap", "homebrew/bar", path/".git", "-q", "--full")
|
|
|
|
assert_match "Untapped", cmd("untap", "homebrew/bar")
|
2015-12-19 21:54:42 +08:00
|
|
|
ensure
|
2016-02-26 19:43:49 +08:00
|
|
|
path.rmtree
|
2015-12-19 21:54:42 +08:00
|
|
|
end
|
2016-01-04 23:14:58 +01:00
|
|
|
|
|
|
|
def test_missing
|
2016-03-07 18:04:25 +08:00
|
|
|
repo = CoreTap.new
|
2016-01-04 23:14:58 +01:00
|
|
|
foo_file = repo.formula_dir/"foo.rb"
|
|
|
|
foo_file.write <<-EOS.undent
|
|
|
|
class Foo < Formula
|
2016-01-09 19:11:34 +08:00
|
|
|
url "https://example.com/foo-1.0"
|
2016-01-04 23:14:58 +01:00
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
|
|
|
bar_file = repo.formula_dir/"bar.rb"
|
|
|
|
bar_file.write <<-EOS.undent
|
|
|
|
class Bar < Formula
|
2016-01-09 19:11:34 +08:00
|
|
|
url "https://example.com/bar-1.0"
|
2016-01-04 23:14:58 +01:00
|
|
|
depends_on "foo"
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
2016-01-09 19:11:34 +08:00
|
|
|
(HOMEBREW_CELLAR/"bar/1.0").mkpath
|
2016-01-04 23:14:58 +01:00
|
|
|
assert_match "foo", cmd("missing")
|
|
|
|
ensure
|
2016-01-09 19:11:34 +08:00
|
|
|
(HOMEBREW_CELLAR/"bar").rmtree
|
|
|
|
foo_file.unlink
|
|
|
|
bar_file.unlink
|
2016-01-04 23:14:58 +01:00
|
|
|
end
|
|
|
|
|
2016-01-05 15:45:45 +01:00
|
|
|
def test_doctor
|
|
|
|
assert_match "This is an integration test",
|
|
|
|
cmd_fail("doctor", "check_integration_test")
|
2016-01-04 23:14:58 +01:00
|
|
|
end
|
|
|
|
|
2016-01-15 15:48:37 +01:00
|
|
|
def test_command
|
|
|
|
assert_equal "#{HOMEBREW_LIBRARY_PATH}/cmd/info.rb",
|
|
|
|
cmd("command", "info")
|
|
|
|
|
|
|
|
assert_match "Unknown command",
|
|
|
|
cmd_fail("command", "I-don't-exist")
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_commands
|
|
|
|
assert_match "Built-in commands",
|
|
|
|
cmd("commands")
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_cat
|
2016-03-07 18:04:25 +08:00
|
|
|
formula_file = CoreTap.new.formula_dir/"testball.rb"
|
2016-01-15 15:48:37 +01:00
|
|
|
content = <<-EOS.undent
|
|
|
|
class Testball < Formula
|
|
|
|
url "https://example.com/testball-0.1.tar.gz"
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
formula_file.write content
|
|
|
|
|
|
|
|
assert_equal content.chomp, cmd("cat", "testball")
|
|
|
|
ensure
|
|
|
|
formula_file.unlink
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_desc
|
2016-03-07 18:04:25 +08:00
|
|
|
formula_file = CoreTap.new.formula_dir/"testball.rb"
|
2016-02-03 15:23:01 +01:00
|
|
|
formula_file.write <<-EOS.undent
|
2016-01-15 15:48:37 +01:00
|
|
|
class Testball < Formula
|
|
|
|
desc "Some test"
|
|
|
|
url "https://example.com/testball-0.1.tar.gz"
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
|
|
|
assert_equal "testball: Some test", cmd("desc", "testball")
|
|
|
|
ensure
|
|
|
|
formula_file.unlink
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_edit
|
|
|
|
(HOMEBREW_REPOSITORY/".git").mkpath
|
2016-03-07 18:04:25 +08:00
|
|
|
formula_file = CoreTap.new.formula_dir/"testball.rb"
|
2016-02-03 15:23:01 +01:00
|
|
|
formula_file.write <<-EOS.undent
|
2016-01-15 15:48:37 +01:00
|
|
|
class Testball < Formula
|
|
|
|
url "https://example.com/testball-0.1.tar.gz"
|
|
|
|
# something here
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
|
|
|
assert_match "# something here",
|
2016-01-17 13:07:46 -08:00
|
|
|
cmd("edit", "testball", {"HOMEBREW_EDITOR" => "/bin/cat"})
|
2016-01-15 15:48:37 +01:00
|
|
|
ensure
|
|
|
|
formula_file.unlink
|
|
|
|
(HOMEBREW_REPOSITORY/".git").unlink
|
|
|
|
end
|
|
|
|
|
2016-01-20 00:29:14 +01:00
|
|
|
def test_sh
|
|
|
|
assert_match "Your shell has been configured",
|
|
|
|
cmd("sh", {"SHELL" => "/usr/bin/true"})
|
2016-01-20 01:33:20 +01:00
|
|
|
end
|
2016-01-19 23:53:28 +01:00
|
|
|
|
|
|
|
def test_info
|
2016-03-07 18:04:25 +08:00
|
|
|
formula_file = CoreTap.new.formula_dir/"testball.rb"
|
2016-02-03 15:23:01 +01:00
|
|
|
formula_file.write <<-EOS.undent
|
2016-01-19 23:53:28 +01:00
|
|
|
class Testball < Formula
|
|
|
|
url "https://example.com/testball-0.1.tar.gz"
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
|
|
|
assert_match "testball: stable 0.1",
|
|
|
|
cmd("info", "testball")
|
|
|
|
ensure
|
|
|
|
formula_file.unlink
|
2016-01-20 00:29:14 +01:00
|
|
|
end
|
|
|
|
|
2016-01-20 01:33:20 +01:00
|
|
|
def test_tap_readme
|
|
|
|
assert_match "brew install homebrew/foo/<formula>",
|
|
|
|
cmd("tap-readme", "foo", "--verbose")
|
|
|
|
readme = HOMEBREW_LIBRARY/"Taps/homebrew/homebrew-foo/README.md"
|
|
|
|
assert readme.exist?, "The README should be created"
|
|
|
|
ensure
|
2016-02-26 19:43:49 +08:00
|
|
|
(HOMEBREW_LIBRARY/"Taps/homebrew/homebrew-foo").rmtree
|
2016-01-20 01:33:20 +01:00
|
|
|
end
|
|
|
|
|
2016-01-30 14:12:07 +01:00
|
|
|
def test_unpack
|
2016-03-07 18:04:25 +08:00
|
|
|
formula_file = CoreTap.new.formula_dir/"testball.rb"
|
2016-02-03 15:23:01 +01:00
|
|
|
formula_file.write <<-EOS.undent
|
2016-01-30 14:12:07 +01:00
|
|
|
class Testball < Formula
|
|
|
|
url "file://#{File.expand_path("..", __FILE__)}/tarballs/testball-0.1.tbz"
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
|
|
|
mktmpdir do |path|
|
|
|
|
cmd "unpack", "testball", "--destdir=#{path}"
|
|
|
|
assert File.directory?("#{path}/testball-0.1"),
|
|
|
|
"The tarball should be unpacked"
|
|
|
|
end
|
|
|
|
ensure
|
2016-02-02 23:10:37 -08:00
|
|
|
FileUtils.rm_f HOMEBREW_CACHE/"testball-0.1.tbz"
|
2016-01-30 14:12:07 +01:00
|
|
|
formula_file.unlink
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_options
|
2016-03-07 18:04:25 +08:00
|
|
|
formula_file = CoreTap.new.formula_dir/"testball.rb"
|
2016-02-03 15:23:01 +01:00
|
|
|
formula_file.write <<-EOS.undent
|
2016-01-30 14:12:07 +01:00
|
|
|
class Testball < Formula
|
|
|
|
url "file://#{File.expand_path("..", __FILE__)}/tarballs/testball-0.1.tbz"
|
|
|
|
option "with-foo", "foobar"
|
|
|
|
depends_on "bar" => :recommended
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
|
|
|
assert_equal "--with-foo\n\tfoobar\n--without-bar\n\tBuild without bar support",
|
|
|
|
cmd_output("options", "testball").chomp
|
|
|
|
ensure
|
|
|
|
formula_file.unlink
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_outdated
|
2016-03-07 18:04:25 +08:00
|
|
|
formula_file = CoreTap.new.formula_dir/"testball.rb"
|
2016-02-03 15:23:01 +01:00
|
|
|
formula_file.write <<-EOS.undent
|
2016-01-30 14:12:07 +01:00
|
|
|
class Testball < Formula
|
|
|
|
url "file://#{File.expand_path("..", __FILE__)}/tarballs/testball-0.1.tbz"
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
(HOMEBREW_CELLAR/"testball/0.0.1/foo").mkpath
|
|
|
|
|
|
|
|
assert_equal "testball", cmd("outdated")
|
|
|
|
ensure
|
|
|
|
formula_file.unlink
|
|
|
|
FileUtils.rm_rf HOMEBREW_CELLAR/"testball"
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_upgrade
|
2016-03-07 18:04:25 +08:00
|
|
|
formula_file = CoreTap.new.formula_dir/"testball.rb"
|
2016-02-03 15:23:01 +01:00
|
|
|
formula_file.write <<-EOS.undent
|
2016-01-30 14:12:07 +01:00
|
|
|
class Testball < Formula
|
|
|
|
url "file://#{File.expand_path("..", __FILE__)}/tarballs/testball-0.1.tbz"
|
|
|
|
sha256 "#{TESTBALL_SHA256}"
|
|
|
|
|
|
|
|
def install
|
|
|
|
prefix.install Dir["*"]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
|
|
|
(HOMEBREW_CELLAR/"testball/0.0.1/foo").mkpath
|
|
|
|
|
|
|
|
cmd("upgrade")
|
2016-04-20 01:42:14 +02:00
|
|
|
assert((HOMEBREW_CELLAR/"testball/0.1").directory?,
|
|
|
|
"The latest version directory should be created")
|
2016-01-30 14:12:07 +01:00
|
|
|
ensure
|
|
|
|
formula_file.unlink
|
|
|
|
cmd("uninstall", "--force", testball)
|
|
|
|
cmd("cleanup", "--force", "--prune=all")
|
|
|
|
end
|
|
|
|
|
2016-01-31 12:56:15 +01:00
|
|
|
def test_linkapps
|
|
|
|
home = mktmpdir
|
|
|
|
apps_dir = Pathname.new(home).join("Applications")
|
|
|
|
apps_dir.mkpath
|
|
|
|
|
2016-03-07 18:04:25 +08:00
|
|
|
formula_file = CoreTap.new.formula_dir/"testball.rb"
|
2016-02-03 15:23:01 +01:00
|
|
|
formula_file.write <<-EOS.undent
|
2016-01-31 12:56:15 +01:00
|
|
|
class Testball < Formula
|
|
|
|
url "https://example.com/testball-0.1.tar.gz"
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
|
|
|
source_dir = HOMEBREW_CELLAR/"testball/0.1/TestBall.app"
|
|
|
|
source_dir.mkpath
|
2016-02-07 10:59:38 +01:00
|
|
|
assert_match "Linking: #{source_dir}",
|
2016-01-31 12:56:15 +01:00
|
|
|
cmd("linkapps", "--local", {"HOME" => home})
|
|
|
|
ensure
|
|
|
|
formula_file.unlink
|
|
|
|
FileUtils.rm_rf apps_dir
|
|
|
|
(HOMEBREW_CELLAR/"testball").rmtree
|
|
|
|
end
|
|
|
|
|
2016-01-30 14:12:07 +01:00
|
|
|
def test_unlinkapps
|
2016-01-31 12:56:15 +01:00
|
|
|
home = mktmpdir
|
|
|
|
apps_dir = Pathname.new(home).join("Applications")
|
2016-01-30 14:12:07 +01:00
|
|
|
apps_dir.mkpath
|
|
|
|
|
2016-03-07 18:04:25 +08:00
|
|
|
formula_file = CoreTap.new.formula_dir/"testball.rb"
|
2016-02-03 15:23:01 +01:00
|
|
|
formula_file.write <<-EOS.undent
|
2016-01-30 14:12:07 +01:00
|
|
|
class Testball < Formula
|
|
|
|
url "https://example.com/testball-0.1.tar.gz"
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
|
|
|
source_app = (HOMEBREW_CELLAR/"testball/0.1/TestBall.app")
|
|
|
|
source_app.mkpath
|
|
|
|
|
|
|
|
FileUtils.ln_s source_app, "#{apps_dir}/TestBall.app"
|
|
|
|
|
2016-02-07 10:59:38 +01:00
|
|
|
assert_match "Unlinking: #{apps_dir}/TestBall.app",
|
2016-01-31 12:56:15 +01:00
|
|
|
cmd("unlinkapps", "--local", {"HOME" => home})
|
2016-01-30 14:12:07 +01:00
|
|
|
ensure
|
|
|
|
formula_file.unlink
|
|
|
|
apps_dir.rmtree
|
|
|
|
(HOMEBREW_CELLAR/"testball").rmtree
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_pin_unpin
|
2016-03-07 18:04:25 +08:00
|
|
|
formula_file = CoreTap.new.formula_dir/"testball.rb"
|
2016-02-03 15:23:01 +01:00
|
|
|
formula_file.write <<-EOS.undent
|
2016-01-30 14:12:07 +01:00
|
|
|
class Testball < Formula
|
|
|
|
url "file://#{File.expand_path("..", __FILE__)}/tarballs/testball-0.1.tbz"
|
|
|
|
sha256 "#{TESTBALL_SHA256}"
|
|
|
|
|
|
|
|
def install
|
|
|
|
prefix.install Dir["*"]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
(HOMEBREW_CELLAR/"testball/0.0.1/foo").mkpath
|
|
|
|
|
|
|
|
cmd("pin", "testball")
|
|
|
|
cmd("upgrade")
|
2016-04-20 01:42:14 +02:00
|
|
|
refute((HOMEBREW_CELLAR/"testball/0.1").directory?,
|
|
|
|
"The latest version directory should NOT be created")
|
2016-01-30 14:12:07 +01:00
|
|
|
|
|
|
|
cmd("unpin", "testball")
|
|
|
|
cmd("upgrade")
|
2016-04-20 01:42:14 +02:00
|
|
|
assert((HOMEBREW_CELLAR/"testball/0.1").directory?,
|
|
|
|
"The latest version directory should be created")
|
2016-01-30 14:12:07 +01:00
|
|
|
ensure
|
|
|
|
formula_file.unlink
|
|
|
|
cmd("uninstall", "--force", testball)
|
|
|
|
cmd("cleanup", "--force", "--prune=all")
|
|
|
|
end
|
|
|
|
|
2016-01-31 12:56:15 +01:00
|
|
|
def test_reinstall
|
2016-03-07 18:04:25 +08:00
|
|
|
formula_file = CoreTap.new.formula_dir/"testball.rb"
|
2016-02-03 15:23:01 +01:00
|
|
|
formula_file.write <<-EOS.undent
|
2016-01-31 12:56:15 +01:00
|
|
|
class Testball < Formula
|
|
|
|
url "file://#{File.expand_path("..", __FILE__)}/tarballs/testball-0.1.tbz"
|
|
|
|
sha256 "#{TESTBALL_SHA256}"
|
|
|
|
|
|
|
|
option "with-foo", "build with foo"
|
|
|
|
|
|
|
|
def install
|
|
|
|
(prefix/"foo"/"test").write("test") if build.with? "foo"
|
|
|
|
prefix.install Dir["*"]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
|
|
|
cmd("install", "testball", "--with-foo")
|
|
|
|
foo_dir = HOMEBREW_CELLAR/"testball/0.1/foo"
|
|
|
|
assert foo_dir.exist?
|
|
|
|
foo_dir.rmtree
|
|
|
|
assert_match "Reinstalling testball with --with-foo",
|
|
|
|
cmd("reinstall", "testball")
|
|
|
|
assert foo_dir.exist?
|
|
|
|
ensure
|
|
|
|
formula_file.unlink
|
|
|
|
cmd("uninstall", "--force", "testball")
|
|
|
|
cmd("cleanup", "--force", "--prune=all")
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_home
|
|
|
|
assert_equal HOMEBREW_WWW,
|
|
|
|
cmd("home", {"HOMEBREW_BROWSER" => "echo"})
|
2016-06-01 16:26:32 -07:00
|
|
|
|
|
|
|
formula_file = CoreTap.new.formula_dir/"testball.rb"
|
|
|
|
formula_file.write <<-EOS.undent
|
|
|
|
class Testball < Formula
|
|
|
|
desc "Some test"
|
|
|
|
homepage "https://example.com/testball"
|
|
|
|
url "https://example.com/testball-0.1.tar.gz"
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
|
|
|
assert_equal Formula["testball"].homepage,
|
|
|
|
cmd("home", "testball", {"HOMEBREW_BROWSER" => "echo"})
|
|
|
|
ensure
|
|
|
|
formula_file.unlink
|
2016-01-31 12:56:15 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_list
|
|
|
|
formulae = %w[bar foo qux]
|
|
|
|
formulae.each do |f|
|
|
|
|
(HOMEBREW_CELLAR/"#{f}/1.0/somedir").mkpath
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal formulae.join("\n"),
|
|
|
|
cmd("list")
|
|
|
|
ensure
|
|
|
|
formulae.each do |f|
|
|
|
|
(HOMEBREW_CELLAR/"#{f}").rmtree
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_create
|
|
|
|
url = "file://#{File.expand_path("..", __FILE__)}/tarballs/testball-0.1.tbz"
|
|
|
|
cmd("create", url, {"HOMEBREW_EDITOR" => "/bin/cat"})
|
|
|
|
|
2016-03-07 18:04:25 +08:00
|
|
|
formula_file = CoreTap.new.formula_dir/"testball.rb"
|
2016-01-31 12:56:15 +01:00
|
|
|
assert formula_file.exist?, "The formula source should have been created"
|
|
|
|
assert_match %(sha256 "#{TESTBALL_SHA256}"), formula_file.read
|
|
|
|
ensure
|
|
|
|
formula_file.unlink
|
|
|
|
cmd("cleanup", "--force", "--prune=all")
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_fetch
|
2016-03-07 18:04:25 +08:00
|
|
|
formula_file = CoreTap.new.formula_dir/"testball.rb"
|
2016-02-03 15:23:01 +01:00
|
|
|
formula_file.write <<-EOS.undent
|
2016-01-31 12:56:15 +01:00
|
|
|
class Testball < Formula
|
|
|
|
url "file://#{File.expand_path("..", __FILE__)}/tarballs/testball-0.1.tbz"
|
|
|
|
sha256 "#{TESTBALL_SHA256}"
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
|
|
|
cmd("fetch", "testball")
|
2016-04-20 01:42:14 +02:00
|
|
|
assert((HOMEBREW_CACHE/"testball-0.1.tbz").exist?,
|
|
|
|
"The tarball should have been cached")
|
2016-01-31 12:56:15 +01:00
|
|
|
ensure
|
|
|
|
formula_file.unlink
|
|
|
|
cmd("cleanup", "--force", "--prune=all")
|
|
|
|
end
|
|
|
|
|
2016-02-03 15:36:40 +01:00
|
|
|
def test_deps
|
2016-03-07 18:04:25 +08:00
|
|
|
formula_dir = CoreTap.new.formula_dir
|
2016-02-03 15:36:40 +01:00
|
|
|
formula_file1 = formula_dir/"testball1.rb"
|
|
|
|
formula_file2 = formula_dir/"testball2.rb"
|
|
|
|
formula_file3 = formula_dir/"testball3.rb"
|
|
|
|
formula_file1.write <<-EOS.undent
|
|
|
|
class Testball1 < Formula
|
|
|
|
url "https://example.com/testball1-0.1.tar.gz"
|
|
|
|
depends_on "testball2"
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
formula_file2.write <<-EOS.undent
|
|
|
|
class Testball2 < Formula
|
|
|
|
url "https://example.com/testball2-0.1.tar.gz"
|
|
|
|
depends_on "testball3"
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
formula_file3.write <<-EOS.undent
|
|
|
|
class Testball3 < Formula
|
|
|
|
url "https://example.com/testball3-0.1.tar.gz"
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
|
|
|
assert_equal "testball2\ntestball3", cmd("deps", "testball1")
|
|
|
|
assert_equal "testball3", cmd("deps", "testball2")
|
|
|
|
assert_equal "", cmd("deps", "testball3")
|
|
|
|
|
|
|
|
ensure
|
|
|
|
formula_file1.unlink
|
|
|
|
formula_file2.unlink
|
|
|
|
formula_file3.unlink
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_uses
|
2016-03-07 18:04:25 +08:00
|
|
|
formula_dir = CoreTap.new.formula_dir
|
2016-02-03 15:36:40 +01:00
|
|
|
formula_file1 = formula_dir/"testball1.rb"
|
|
|
|
formula_file2 = formula_dir/"testball2.rb"
|
|
|
|
formula_file3 = formula_dir/"testball3.rb"
|
|
|
|
formula_file1.write <<-EOS.undent
|
|
|
|
class Testball1 < Formula
|
|
|
|
url "https://example.com/testball1-0.1.tar.gz"
|
|
|
|
depends_on "testball2"
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
formula_file2.write <<-EOS.undent
|
|
|
|
class Testball2 < Formula
|
|
|
|
url "https://example.com/testball2-0.1.tar.gz"
|
|
|
|
depends_on "testball3"
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
formula_file3.write <<-EOS.undent
|
|
|
|
class Testball3 < Formula
|
|
|
|
url "https://example.com/testball3-0.1.tar.gz"
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
|
|
|
assert_equal "testball1\ntestball2", cmd("uses", "--recursive", "testball3")
|
|
|
|
assert_equal "testball2", cmd("uses", "testball3")
|
|
|
|
assert_equal "", cmd("uses", "testball1")
|
|
|
|
ensure
|
|
|
|
formula_file1.unlink
|
|
|
|
formula_file2.unlink
|
|
|
|
formula_file3.unlink
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_log
|
|
|
|
FileUtils.cd HOMEBREW_REPOSITORY do
|
|
|
|
shutup do
|
|
|
|
system "git", "init"
|
|
|
|
system "git", "commit", "--allow-empty", "-m", "This is a test commit"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
assert_match "This is a test commit", cmd("log")
|
|
|
|
ensure
|
|
|
|
(HOMEBREW_REPOSITORY/".git").rmtree
|
|
|
|
end
|
|
|
|
|
2016-02-07 12:47:40 +01:00
|
|
|
def test_leaves
|
2016-03-07 18:04:25 +08:00
|
|
|
formula_dir = CoreTap.new.formula_dir
|
2016-02-07 12:47:40 +01:00
|
|
|
formula_file1 = formula_dir/"testball1.rb"
|
|
|
|
formula_file2 = formula_dir/"testball2.rb"
|
|
|
|
formula_file1.write <<-EOS.undent
|
|
|
|
class Testball1 < Formula
|
|
|
|
url "https://example.com/testball1-0.1.tar.gz"
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
formula_file2.write <<-EOS.undent
|
|
|
|
class Testball2 < Formula
|
|
|
|
url "https://example.com/testball2-0.1.tar.gz"
|
|
|
|
depends_on "testball1"
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
assert_equal "", cmd("leaves")
|
|
|
|
|
|
|
|
(HOMEBREW_CELLAR/"testball1/0.1/somedir").mkpath
|
|
|
|
assert_equal "testball1", cmd("leaves")
|
|
|
|
|
|
|
|
(HOMEBREW_CELLAR/"testball2/0.1/somedir").mkpath
|
|
|
|
assert_equal "testball2", cmd("leaves")
|
|
|
|
ensure
|
|
|
|
(HOMEBREW_CELLAR/"testball1").rmtree
|
|
|
|
(HOMEBREW_CELLAR/"testball2").rmtree
|
|
|
|
formula_file1.unlink
|
|
|
|
formula_file2.unlink
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_prune
|
|
|
|
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"
|
|
|
|
|
|
|
|
assert_match %r{Would remove \(empty directory\): .*/pruneable/directory/here},
|
|
|
|
cmd("prune", "--dry-run")
|
|
|
|
assert_match "Pruned 1 symbolic links and 3 directories",
|
|
|
|
cmd("prune")
|
2016-04-20 01:42:14 +02:00
|
|
|
refute((share/"pruneable").directory?)
|
|
|
|
assert((share/"notpruneable").directory?)
|
|
|
|
refute((share/"pruneable_symlink").symlink?)
|
2016-02-07 12:47:40 +01:00
|
|
|
|
2016-04-02 18:16:03 +02:00
|
|
|
# Inexact match because only if ~/Applications exists, will this output one
|
|
|
|
# more line with contents `No apps unlinked from /Users/<user/Applications`.
|
|
|
|
assert_match "Nothing pruned\nNo apps unlinked from /Applications",
|
2016-02-07 12:47:40 +01:00
|
|
|
cmd("prune", "--verbose")
|
|
|
|
ensure
|
|
|
|
share.rmtree
|
|
|
|
end
|
|
|
|
|
2016-01-05 15:45:45 +01:00
|
|
|
def test_custom_command
|
2016-01-04 23:14:58 +01:00
|
|
|
mktmpdir do |path|
|
2016-01-05 15:45:45 +01:00
|
|
|
cmd = "int-test-#{rand}"
|
|
|
|
file = "#{path}/brew-#{cmd}"
|
|
|
|
|
|
|
|
File.open(file, "w") { |f| f.write "#!/bin/sh\necho 'I am #{cmd}'\n" }
|
|
|
|
FileUtils.chmod 0777, file
|
2016-01-04 23:14:58 +01:00
|
|
|
|
2016-01-05 15:45:45 +01:00
|
|
|
assert_match "I am #{cmd}",
|
|
|
|
cmd(cmd, {"PATH" => "#{path}#{File::PATH_SEPARATOR}#{ENV["PATH"]}"})
|
2016-01-04 23:14:58 +01:00
|
|
|
end
|
|
|
|
end
|
2015-07-23 21:32:13 +01:00
|
|
|
end
|