2017-02-25 17:37:57 -05:00
|
|
|
#: * `tests` [`-v`] [`--coverage`] [`--generic`] [`--no-compat`] [`--only=`<test_script>`:`<test_method>] [`--seed` <seed>] [`--trace`] [`--online`] [`--official-cmd-taps`]:
|
2016-06-26 23:00:10 -07:00
|
|
|
#: Run Homebrew's unit and integration tests.
|
|
|
|
|
2016-01-18 15:33:59 +01:00
|
|
|
require "fileutils"
|
2016-07-04 17:05:37 +01:00
|
|
|
require "tap"
|
2016-01-18 15:33:59 +01:00
|
|
|
|
2014-06-18 22:41:47 -05:00
|
|
|
module Homebrew
|
2016-09-26 01:44:51 +02:00
|
|
|
module_function
|
|
|
|
|
2017-02-10 21:21:57 +01:00
|
|
|
def run_tests(executable, files, args = [])
|
|
|
|
opts = []
|
|
|
|
opts << "--serialize-stdout" if ENV["CI"]
|
|
|
|
|
|
|
|
system "bundle", "exec", executable, *opts, "--", *args, "--", *files
|
|
|
|
|
|
|
|
return if $?.success?
|
|
|
|
Homebrew.failed = true
|
|
|
|
end
|
|
|
|
|
2012-04-16 16:44:11 -05:00
|
|
|
def tests
|
2016-10-21 08:57:39 +02:00
|
|
|
HOMEBREW_LIBRARY_PATH.cd do
|
2016-10-01 09:49:06 +01:00
|
|
|
ENV.delete "HOMEBREW_VERBOSE"
|
|
|
|
ENV.delete "VERBOSE"
|
2017-02-10 21:21:57 +01:00
|
|
|
ENV.delete("HOMEBREW_CASK_OPTS")
|
2016-07-04 18:26:44 +01:00
|
|
|
ENV["HOMEBREW_NO_ANALYTICS_THIS_RUN"] = "1"
|
2016-09-10 09:50:40 +01:00
|
|
|
ENV["HOMEBREW_DEVELOPER"] = "1"
|
2015-01-02 12:42:02 +00:00
|
|
|
ENV["TESTOPTS"] = "-v" if ARGV.verbose?
|
2015-07-22 17:09:23 +08:00
|
|
|
ENV["HOMEBREW_NO_COMPAT"] = "1" if ARGV.include? "--no-compat"
|
2016-05-08 17:12:14 +01:00
|
|
|
ENV["HOMEBREW_TEST_GENERIC_OS"] = "1" if ARGV.include? "--generic"
|
2016-07-04 13:32:58 +01:00
|
|
|
ENV["HOMEBREW_NO_GITHUB_API"] = "1" unless ARGV.include? "--online"
|
2016-07-04 18:26:44 +01:00
|
|
|
if ARGV.include? "--official-cmd-taps"
|
|
|
|
ENV["HOMEBREW_TEST_OFFICIAL_CMD_TAPS"] = "1"
|
|
|
|
end
|
|
|
|
|
2016-01-18 15:33:59 +01:00
|
|
|
if ARGV.include? "--coverage"
|
|
|
|
ENV["HOMEBREW_TESTS_COVERAGE"] = "1"
|
2016-09-19 23:00:58 +01:00
|
|
|
FileUtils.rm_f "test/coverage/.resultset.json"
|
2016-01-18 15:33:59 +01:00
|
|
|
end
|
2015-12-23 00:34:19 +01:00
|
|
|
|
2016-10-29 15:31:47 +02:00
|
|
|
ENV["BUNDLE_GEMFILE"] = "#{HOMEBREW_LIBRARY_PATH}/test/Gemfile"
|
|
|
|
ENV["BUNDLE_PATH"] = "#{HOMEBREW_LIBRARY_PATH}/vendor/bundle"
|
2016-09-19 23:00:58 +01:00
|
|
|
|
2016-01-04 14:54:09 +01:00
|
|
|
# Override author/committer as global settings might be invalid and thus
|
|
|
|
# will cause silent failure during the setup of dummy Git repositories.
|
|
|
|
%w[AUTHOR COMMITTER].each do |role|
|
|
|
|
ENV["GIT_#{role}_NAME"] = "brew tests"
|
|
|
|
ENV["GIT_#{role}_EMAIL"] = "brew-tests@localhost"
|
2017-01-22 20:54:37 +00:00
|
|
|
ENV["GIT_#{role}_DATE"] = "Sun Jan 22 19:59:13 2017 +0000"
|
2016-01-04 14:54:09 +01:00
|
|
|
end
|
|
|
|
|
2015-01-02 12:42:02 +00:00
|
|
|
Homebrew.install_gem_setup_path! "bundler"
|
2015-12-23 00:34:19 +01:00
|
|
|
unless quiet_system("bundle", "check")
|
2016-10-29 15:31:47 +02:00
|
|
|
system "bundle", "install"
|
2015-12-23 00:34:19 +01:00
|
|
|
end
|
|
|
|
|
2016-01-20 06:39:57 +01:00
|
|
|
# Make it easier to reproduce test runs.
|
|
|
|
ENV["SEED"] = ARGV.next if ARGV.include? "--seed"
|
|
|
|
|
2017-02-10 21:21:57 +01:00
|
|
|
files = Dir.glob("test/**/*_{spec,test}.rb")
|
2017-02-27 12:56:33 +11:00
|
|
|
.reject { |p| p =~ %r{^test/vendor/bundle} }
|
2017-02-21 06:17:06 +01:00
|
|
|
.reject { |p| !OS.mac? && p =~ %r{^test/(os/mac|cask)(/.*|_(test|spec)\.rb)$} }
|
2016-09-20 14:57:08 +01:00
|
|
|
|
2017-02-10 21:21:57 +01:00
|
|
|
test_args = []
|
|
|
|
test_args << "--trace" if ARGV.include? "--trace"
|
2016-09-20 14:57:08 +01:00
|
|
|
|
2016-01-20 07:06:09 +01:00
|
|
|
if ARGV.value("only")
|
2016-10-21 08:57:39 +02:00
|
|
|
test_name, test_method = ARGV.value("only").split(":", 2)
|
2017-02-10 21:21:57 +01:00
|
|
|
files = Dir.glob("test/{#{test_name},#{test_name}/**/*}_{spec,test}.rb")
|
|
|
|
test_args << "--name=test_#{test_method}" if test_method
|
2016-01-20 07:06:09 +01:00
|
|
|
end
|
2016-09-20 14:57:08 +01:00
|
|
|
|
2017-02-10 21:21:57 +01:00
|
|
|
test_files = files.select { |p| p.end_with?("_test.rb") }
|
|
|
|
spec_files = files.select { |p| p.end_with?("_spec.rb") }
|
|
|
|
|
|
|
|
test_args += ARGV.named.select { |v| v[/^TEST(OPTS)?=/] }
|
|
|
|
run_tests "parallel_test", test_files, test_args
|
|
|
|
|
|
|
|
spec_args = [
|
|
|
|
"--color",
|
|
|
|
"-I", HOMEBREW_LIBRARY_PATH/"test",
|
|
|
|
"--require", "spec_helper",
|
|
|
|
"--format", "progress",
|
|
|
|
"--format", "ParallelTests::RSpec::RuntimeLogger",
|
|
|
|
"--out", "tmp/parallel_runtime_rspec.log"
|
|
|
|
]
|
2017-02-21 21:55:11 +01:00
|
|
|
spec_args << "--tag" << "~needs_macos" unless OS.mac?
|
|
|
|
|
2017-02-10 21:21:57 +01:00
|
|
|
run_tests "parallel_rspec", spec_files, spec_args
|
2015-12-23 00:34:19 +01:00
|
|
|
|
2016-10-24 23:11:23 +02:00
|
|
|
if (fs_leak_log = HOMEBREW_LIBRARY_PATH/"tmp/fs_leak.log").file?
|
2015-07-22 16:04:59 +08:00
|
|
|
fs_leak_log_content = fs_leak_log.read
|
|
|
|
unless fs_leak_log_content.empty?
|
|
|
|
opoo "File leak is detected"
|
|
|
|
puts fs_leak_log_content
|
|
|
|
Homebrew.failed = true
|
|
|
|
end
|
|
|
|
end
|
2012-04-16 16:44:11 -05:00
|
|
|
end
|
|
|
|
end
|
2012-03-25 00:49:18 +11:00
|
|
|
end
|