2013-04-29 05:50:12 +08:00
|
|
|
require 'bundler'
|
2012-10-14 03:39:00 +08:00
|
|
|
require 'bundler/setup'
|
2013-04-05 16:08:51 +08:00
|
|
|
|
2014-02-23 07:24:56 +08:00
|
|
|
# force some environment variables
|
|
|
|
ENV['HOMEBREW_NO_EMOJI']='1'
|
|
|
|
|
2014-02-02 01:47:05 +08:00
|
|
|
# set some Homebrew constants used in our code
|
|
|
|
HOMEBREW_BREW_FILE = '/usr/local/bin/brew'
|
2012-10-14 03:39:00 +08:00
|
|
|
|
|
|
|
# add cask lib to load path
|
|
|
|
brew_cask_path = Pathname.new(File.expand_path(__FILE__+'/../../'))
|
|
|
|
casks_path = brew_cask_path.join('casks')
|
|
|
|
lib_path = brew_cask_path.join('lib')
|
|
|
|
|
|
|
|
$:.push(lib_path)
|
|
|
|
|
2013-04-05 04:24:01 +08:00
|
|
|
# add homebrew to load path
|
|
|
|
homebrew_path = Pathname(`brew --prefix`.chomp)
|
2014-03-02 00:40:54 +08:00
|
|
|
homebrew_path = Pathname('/usr/local') unless homebrew_path.exist?
|
2012-10-14 03:39:00 +08:00
|
|
|
$:.push(homebrew_path.join('Library', 'Homebrew'))
|
|
|
|
|
|
|
|
# require homebrew testing env
|
|
|
|
require 'test/testing_env'
|
|
|
|
|
2012-10-14 05:17:27 +08:00
|
|
|
# making homebrew's cache dir allows us to actually download casks in tests
|
|
|
|
HOMEBREW_CACHE.mkpath
|
2014-02-05 22:42:36 +08:00
|
|
|
HOMEBREW_CACHE.join('Casks').mkpath
|
2012-10-14 05:17:27 +08:00
|
|
|
|
2012-10-14 03:39:00 +08:00
|
|
|
# must be called after testing_env so at_exit hooks are in proper order
|
|
|
|
require 'minitest/autorun'
|
2013-04-05 16:08:51 +08:00
|
|
|
require 'minitest-colorize'
|
2012-10-14 03:39:00 +08:00
|
|
|
|
2013-07-06 18:35:14 +08:00
|
|
|
# Force mocha to patch MiniTest since we have both loaded thanks to homebrew's testing_env
|
|
|
|
require 'mocha/api'
|
|
|
|
require 'mocha/integration/mini_test'
|
|
|
|
Mocha::Integration::MiniTest.activate
|
|
|
|
|
2012-10-14 03:39:00 +08:00
|
|
|
# our baby
|
|
|
|
require 'cask'
|
|
|
|
|
2013-04-05 16:08:51 +08:00
|
|
|
# look for casks in testcasks by default
|
2013-04-05 05:55:07 +08:00
|
|
|
Cask.default_tap = 'phinze-testcasks'
|
|
|
|
|
2013-04-07 06:14:04 +08:00
|
|
|
# our own testy caskroom
|
|
|
|
Cask.caskroom = HOMEBREW_PREFIX.join('TestCaskroom')
|
|
|
|
|
2012-11-22 05:51:03 +08:00
|
|
|
class TestHelper
|
|
|
|
# helper for test casks to reference local files easily
|
|
|
|
def self.local_binary(name)
|
2013-04-05 16:08:51 +08:00
|
|
|
path = File.expand_path(File.join(File.dirname(__FILE__), 'support', 'binaries', name))
|
2012-11-22 05:51:03 +08:00
|
|
|
"file://#{path}"
|
|
|
|
end
|
2012-11-25 10:13:57 +08:00
|
|
|
|
|
|
|
def self.test_cask
|
2013-04-08 03:28:42 +08:00
|
|
|
Cask.load('basic-cask')
|
2012-11-25 10:13:57 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.fake_fetcher
|
|
|
|
Cask::FakeFetcher
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.fake_response_for(*args)
|
|
|
|
Cask::FakeFetcher.fake_response_for(*args)
|
|
|
|
end
|
2013-04-08 01:46:35 +08:00
|
|
|
|
|
|
|
def self.must_output(test, lambda, expected)
|
|
|
|
out, err = test.capture_subprocess_io do
|
|
|
|
lambda.call
|
|
|
|
end
|
|
|
|
|
2013-04-29 00:08:54 +08:00
|
|
|
if expected.is_a? Regexp
|
|
|
|
(out+err).chomp.must_match expected
|
|
|
|
else
|
|
|
|
(out+err).chomp.must_equal expected.gsub(/^ */, '')
|
|
|
|
end
|
2013-04-08 01:46:35 +08:00
|
|
|
end
|
2013-04-05 12:49:43 +08:00
|
|
|
|
|
|
|
def self.valid_alias?(candidate)
|
|
|
|
return false unless candidate.symlink?
|
|
|
|
candidate.readlink.exist?
|
|
|
|
end
|
2013-09-23 22:32:46 +08:00
|
|
|
|
|
|
|
def self.install_without_artifacts(cask)
|
|
|
|
Cask::Installer.new(cask).tap do |i|
|
|
|
|
shutup { i.download }
|
2013-10-20 05:17:45 +08:00
|
|
|
i.extract_primary_container
|
2013-09-23 22:32:46 +08:00
|
|
|
end
|
|
|
|
end
|
2012-11-25 10:13:57 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
require 'support/fake_fetcher'
|
2013-11-30 00:58:46 +08:00
|
|
|
require 'support/fake_dirs'
|
2013-04-29 02:56:26 +08:00
|
|
|
require 'support/fake_system_command'
|
2013-05-12 12:30:28 +08:00
|
|
|
require 'support/cleanup'
|
2013-10-25 03:52:55 +08:00
|
|
|
require 'support/never_sudo_system_command'
|
2013-06-13 03:09:16 +08:00
|
|
|
require 'tmpdir'
|
2013-10-25 03:52:55 +08:00
|
|
|
require 'tempfile'
|
2012-11-25 10:13:57 +08:00
|
|
|
|
2012-11-22 05:51:03 +08:00
|
|
|
# pretend like we installed the cask tap
|
|
|
|
project_root = Pathname.new(File.expand_path("#{File.dirname(__FILE__)}/../"))
|
|
|
|
taps_dest = HOMEBREW_LIBRARY/"Taps"
|
|
|
|
|
2014-02-02 01:20:28 +08:00
|
|
|
# create directories
|
2012-11-22 05:51:03 +08:00
|
|
|
taps_dest.mkdir
|
2014-02-02 01:20:28 +08:00
|
|
|
HOMEBREW_PREFIX.join('bin').mkdir
|
2012-11-22 05:51:03 +08:00
|
|
|
|
|
|
|
FileUtils.ln_s project_root, taps_dest/"phinze-cask"
|
|
|
|
|
2013-04-08 03:28:42 +08:00
|
|
|
# Common superclass for tests casks for when we need to filter them out
|
|
|
|
class TestCask < Cask; end
|
|
|
|
|
2014-02-02 01:20:28 +08:00
|
|
|
# jack in some optional utilities
|
|
|
|
FileUtils.ln_s '/usr/local/bin/cabextract', HOMEBREW_PREFIX.join('bin/cabextract')
|
2014-02-04 00:42:15 +08:00
|
|
|
FileUtils.ln_s '/usr/local/bin/unar', HOMEBREW_PREFIX.join('bin/unar')
|
|
|
|
FileUtils.ln_s '/usr/local/bin/lsar', HOMEBREW_PREFIX.join('bin/lsar')
|
2014-02-02 01:20:28 +08:00
|
|
|
|
2012-11-22 05:51:03 +08:00
|
|
|
# also jack in some test casks
|
|
|
|
FileUtils.ln_s project_root/'test'/'support', taps_dest/"phinze-testcasks"
|