2015-11-19 07:54:27 -05:00
|
|
|
require "bundler"
|
2015-07-23 21:32:13 +01:00
|
|
|
require "testing_env"
|
2015-12-26 16:31:06 +08:00
|
|
|
require "core_formula_repository"
|
2016-01-04 23:14:58 +01:00
|
|
|
require "fileutils"
|
2015-07-23 21:32:13 +01:00
|
|
|
|
|
|
|
class IntegrationCommandTests < Homebrew::TestCase
|
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
|
2016-01-05 15:45:45 +01:00
|
|
|
-rintegration_mocks
|
2015-07-23 21:32:13 +01:00
|
|
|
]
|
|
|
|
cmd_args << "-rsimplecov" if ENV["HOMEBREW_TESTS_COVERAGE"]
|
|
|
|
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"
|
|
|
|
ENV["HOMEBREW_INTEGRATION_TEST"] = args.join " "
|
|
|
|
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)
|
|
|
|
assert_equal 0, $?.exitstatus
|
|
|
|
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)
|
|
|
|
assert_equal 1, $?.exitstatus
|
|
|
|
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
|
|
|
|
|
|
|
|
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-01-05 15:45:45 +01:00
|
|
|
def test_help
|
|
|
|
assert_match "Example usage:",
|
|
|
|
cmd("help")
|
|
|
|
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)
|
|
|
|
formula_file = CoreFormulaRepository.new.formula_dir/"testball.rb"
|
|
|
|
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
|
2015-12-16 20:57:31 +00:00
|
|
|
HOMEBREW_CACHE.cd do
|
2015-12-30 20:33:46 +00:00
|
|
|
assert_match(/testball-0\.1.*\.bottle\.tar\.gz/,
|
|
|
|
cmd_output("bottle", "--no-revision", "testball"))
|
2015-12-16 20:57:31 +00:00
|
|
|
end
|
|
|
|
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?
|
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")
|
|
|
|
end
|
2015-12-19 21:24:45 +08:00
|
|
|
|
|
|
|
def test_readall
|
|
|
|
repo = CoreFormulaRepository.new
|
|
|
|
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")
|
|
|
|
cmd("readall", "Homebrew/homebrew")
|
|
|
|
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"
|
|
|
|
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")
|
|
|
|
assert_match "1 tap", cmd("tap-info")
|
|
|
|
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")
|
|
|
|
ensure
|
|
|
|
Tap::TAP_DIRECTORY.rmtree
|
|
|
|
end
|
2016-01-04 23:14:58 +01:00
|
|
|
|
|
|
|
def test_missing
|
|
|
|
repo = CoreFormulaRepository.new
|
|
|
|
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-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
|