From 176c82516f4d81d29d8354e99273afc8cd889338 Mon Sep 17 00:00:00 2001 From: Alyssa Ross <hi@alyssa.is> Date: Tue, 20 Sep 2016 00:02:04 +0100 Subject: [PATCH] cask-tests: run in parallel --- Library/Homebrew/cask/Gemfile | 1 + Library/Homebrew/cask/Gemfile.lock | 4 +++ Library/Homebrew/cask/Rakefile | 31 +------------------- Library/Homebrew/cask/cmd/brew-cask-tests.rb | 23 +++++++++++---- 4 files changed, 24 insertions(+), 35 deletions(-) diff --git a/Library/Homebrew/cask/Gemfile b/Library/Homebrew/cask/Gemfile index af1c8d3bc6..e252b5f3d9 100644 --- a/Library/Homebrew/cask/Gemfile +++ b/Library/Homebrew/cask/Gemfile @@ -16,6 +16,7 @@ group :test do gem "minitest", "5.4.1" gem "minitest-reporters" gem "mocha", "1.1.0", require: false + gem "parallel_tests" gem "rspec", "~> 3.0.0" gem "rspec-its", require: false gem "rspec-wait", require: false diff --git a/Library/Homebrew/cask/Gemfile.lock b/Library/Homebrew/cask/Gemfile.lock index c9c2b5cca9..fa5dcf9a99 100644 --- a/Library/Homebrew/cask/Gemfile.lock +++ b/Library/Homebrew/cask/Gemfile.lock @@ -23,6 +23,9 @@ GEM ruby-progressbar mocha (1.1.0) metaclass (~> 0.0.1) + parallel (1.9.0) + parallel_tests (2.9.0) + parallel parser (2.3.1.2) ast (~> 2.2) powerpack (0.1.1) @@ -80,6 +83,7 @@ DEPENDENCIES minitest (= 5.4.1) minitest-reporters mocha (= 1.1.0) + parallel_tests pry pry-byebug rake diff --git a/Library/Homebrew/cask/Rakefile b/Library/Homebrew/cask/Rakefile index 25deee4071..c30b2f6717 100644 --- a/Library/Homebrew/cask/Rakefile +++ b/Library/Homebrew/cask/Rakefile @@ -6,40 +6,11 @@ homebrew_repo = `brew --repository`.chomp $LOAD_PATH.unshift(File.expand_path("#{homebrew_repo}/Library/Homebrew")) $LOAD_PATH.unshift(File.expand_path("../lib", __FILE__)) -namespace :test do - Rake::TestTask.new(:minitest) do |t| - # TODO: setting the --seed here is an ugly temporary hack, to remain only - # until test-suite glitches are fixed. - ENV["TESTOPTS"] = "--seed=14830" if ENV["TRAVIS"] - t.pattern = "test/**/*_test.rb" - t.libs << "test" - end - - RSpec::Core::RakeTask.new(:rspec) - - desc "Run tests for minitest and RSpec with coverage" - task :coverage do - ENV["HOMEBREW_TESTS_COVERAGE"] = "1" - - Rake::Task[:test].invoke - - if ENV["CODECOV_TOKEN"] - require "simplecov" - require "codecov" - formatter = SimpleCov::Formatter::Codecov.new - formatter.format(SimpleCov::ResultMerger.merged_result) - end - end -end - -desc "Run tests for minitest and RSpec" -task test: ["test:minitest", "test:rspec"] - RuboCop::RakeTask.new(:rubocop) do |t| t.options = ["--force-exclusion"] end -task default: [:test, :rubocop] +task default: [:rubocop] desc "Open a REPL for debugging and experimentation" task :console do diff --git a/Library/Homebrew/cask/cmd/brew-cask-tests.rb b/Library/Homebrew/cask/cmd/brew-cask-tests.rb index 92ef3ddd90..20f3430473 100755 --- a/Library/Homebrew/cask/cmd/brew-cask-tests.rb +++ b/Library/Homebrew/cask/cmd/brew-cask-tests.rb @@ -1,5 +1,9 @@ require "English" +def run_tests(executable, files, args = []) + system "bundle", "exec", executable, "--", *args, "--", *files +end + repo_root = Pathname(__FILE__).realpath.parent.parent repo_root.cd do ENV["HOMEBREW_NO_ANALYTICS_THIS_RUN"] = "1" @@ -9,12 +13,21 @@ repo_root.cd do system "bundle", "install", "--path", "vendor/bundle" end - test_task = "test" - %w[rspec minitest coverage].each do |subtask| - next unless ARGV.flag?("--#{subtask}") - test_task = "test:#{subtask}" + rspec = ARGV.flag?("--rspec") || !ARGV.flag?("--minitest") + minitest = ARGV.flag?("--minitest") || !ARGV.flag?("--rspec") + + ENV["TESTOPTS"] = "--seed=14830" if ENV["TRAVIS"] + ENV["HOMEBREW_TESTS_COVERAGE"] = "1" if ARGV.flag?("--coverage") + + run_tests "parallel_rspec", Dir["spec/**/*_spec.rb"] if rspec + run_tests "parallel_test", Dir["test/**/*_test.rb"] if minitest + + if ENV["CODECOV_TOKEN"] + require "simplecov" + require "codecov" + formatter = SimpleCov::Formatter::Codecov.new + formatter.format(SimpleCov::ResultMerger.merged_result) end - system "bundle", "exec", "rake", test_task Homebrew.failed = !$CHILD_STATUS.success? end -- GitLab