diff options
| author | Mike McQuaid | 2016-09-05 21:37:02 +0100 |
|---|---|---|
| committer | Mike McQuaid | 2016-09-08 20:46:37 +0100 |
| commit | af8605ea4ba1d9856c055c8c76b447e030540e3f (patch) | |
| tree | d093b11340406c21a4b873a80effe3b068fd07d4 /Library/Homebrew/dev-cmd/tests.rb | |
| parent | 4f6bae46f9c0f7b713cdbb999318460135f423de (diff) | |
| download | brew-af8605ea4ba1d9856c055c8c76b447e030540e3f.tar.bz2 | |
Move developer-focused commands to dev-cmd.
Diffstat (limited to 'Library/Homebrew/dev-cmd/tests.rb')
| -rw-r--r-- | Library/Homebrew/dev-cmd/tests.rb | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/Library/Homebrew/dev-cmd/tests.rb b/Library/Homebrew/dev-cmd/tests.rb new file mode 100644 index 000000000..be8f72ace --- /dev/null +++ b/Library/Homebrew/dev-cmd/tests.rb @@ -0,0 +1,63 @@ +#: @hide_from_man_page +#: * `tests` [`-v`] [`--coverage`] [`--generic`] [`--no-compat`] [`--only=`<test_script/test_method>] [`--seed` <seed>] [`--trace`] [`--online`] [`--official-cmd-taps`]: +#: Run Homebrew's unit and integration tests. + +require "fileutils" +require "tap" + +module Homebrew + def tests + (HOMEBREW_LIBRARY/"Homebrew/test").cd do + ENV["HOMEBREW_NO_ANALYTICS_THIS_RUN"] = "1" + ENV["TESTOPTS"] = "-v" if ARGV.verbose? + 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 "coverage/.resultset.json" + end + + # 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" + end + + Homebrew.install_gem_setup_path! "bundler" + unless quiet_system("bundle", "check") + system "bundle", "install", "--path", "vendor/bundle" + end + + # Make it easier to reproduce test runs. + ENV["SEED"] = ARGV.next if ARGV.include? "--seed" + + args = [] + args << "--trace" if ARGV.include? "--trace" + if ARGV.value("only") + ENV["HOMEBREW_TESTS_ONLY"] = "1" + test_name, test_method = ARGV.value("only").split("/", 2) + args << "TEST=test_#{test_name}.rb" + args << "TESTOPTS=--name=test_#{test_method}" if test_method + end + args += ARGV.named.select { |v| v[/^TEST(OPTS)?=/] } + system "bundle", "exec", "rake", "test", *args + + Homebrew.failed = !$?.success? + + if (fs_leak_log = HOMEBREW_LIBRARY/"Homebrew/test/fs_leak_log").file? + 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 + end + end +end |
