mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
94 lines
2.8 KiB
Ruby
94 lines
2.8 KiB
Ruby
#: * `tests` [`-v`] [`--coverage`] [`--generic`] [`--no-compat`] [`--only=`<test_script>`:`<line_number>] [`--seed` <seed>] [`--online`] [`--official-cmd-taps`]:
|
|
#: Run Homebrew's unit and integration tests.
|
|
|
|
require "fileutils"
|
|
require "tap"
|
|
|
|
module Homebrew
|
|
module_function
|
|
|
|
def tests
|
|
HOMEBREW_LIBRARY_PATH.cd do
|
|
ENV.delete("HOMEBREW_VERBOSE")
|
|
ENV.delete("VERBOSE")
|
|
ENV.delete("HOMEBREW_CASK_OPTS")
|
|
ENV["HOMEBREW_NO_ANALYTICS_THIS_RUN"] = "1"
|
|
ENV["HOMEBREW_DEVELOPER"] = "1"
|
|
ENV["HOMEBREW_NO_COMPAT"] = "1" if ARGV.include? "--no-compat"
|
|
ENV["HOMEBREW_TEST_GENERIC_OS"] = "1" if ARGV.include? "--generic"
|
|
ENV["HOMEBREW_NO_GITHUB_API"] = "1" unless ARGV.include? "--online"
|
|
|
|
if ARGV.include? "--official-cmd-taps"
|
|
ENV["HOMEBREW_TEST_OFFICIAL_CMD_TAPS"] = "1"
|
|
end
|
|
|
|
if ARGV.include? "--coverage"
|
|
ENV["HOMEBREW_TESTS_COVERAGE"] = "1"
|
|
FileUtils.rm_f "test/coverage/.resultset.json"
|
|
end
|
|
|
|
ENV["BUNDLE_GEMFILE"] = "#{HOMEBREW_LIBRARY_PATH}/test/Gemfile"
|
|
|
|
# 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"
|
|
ENV["GIT_#{role}_DATE"] = "Sun Jan 22 19:59:13 2017 +0000"
|
|
end
|
|
|
|
Homebrew.install_gem_setup_path! "bundler"
|
|
unless quiet_system("bundle", "check")
|
|
system "bundle", "install"
|
|
end
|
|
|
|
parallel = true
|
|
|
|
files = if ARGV.value("only")
|
|
test_name, line = ARGV.value("only").split(":", 2)
|
|
|
|
if line.nil?
|
|
Dir.glob("test/{#{test_name},#{test_name}/**/*}_spec.rb")
|
|
else
|
|
parallel = false
|
|
["test/#{test_name}_spec.rb:#{line}"]
|
|
end
|
|
else
|
|
Dir.glob("test/**/*_spec.rb").reject { |p| p =~ %r{^test/vendor/bundle/} }
|
|
end
|
|
|
|
opts = []
|
|
|
|
if ENV["CI"]
|
|
opts << "--combine-stderr"
|
|
opts << "--serialize-stdout"
|
|
end
|
|
|
|
args = [
|
|
"--color",
|
|
"-I", HOMEBREW_LIBRARY_PATH/"test",
|
|
"--require", "spec_helper",
|
|
"--format", "progress",
|
|
"--format", "ParallelTests::RSpec::RuntimeLogger",
|
|
"--out", "tmp/parallel_runtime_rspec.log"
|
|
]
|
|
|
|
args << "--seed" << ARGV.next if ARGV.include? "--seed"
|
|
|
|
unless OS.mac?
|
|
args << "--tag" << "~needs_macos"
|
|
files = files.reject { |p| p =~ %r{^test/(os/mac|cask)(/.*|_spec\.rb)$} }
|
|
end
|
|
|
|
if parallel
|
|
system "bundle", "exec", "parallel_rspec", *opts, "--", *args, "--", *files
|
|
else
|
|
system "bundle", "exec", "rspec", *args, "--", *files
|
|
end
|
|
|
|
return if $?.success?
|
|
Homebrew.failed = true
|
|
end
|
|
end
|
|
end
|