require 'optparse' require 'parallel_tests/test/runner' module ParallelTest module CLI def self.run(argv) options = {} OptionParser.new do |opts| opts.banner = < 0 num_processes = ParallelTests.determine_number_of_processes(options[:count]) num_processes = num_processes * (options[:multiply] || 1) if options[:execute] runs = (0...num_processes).to_a results = if options[:non_parallel] runs.map do |i| ParallelTests::Test::Runner.execute_command(options[:execute], i, options) end else Parallel.map(runs, :in_processes => num_processes) do |i| ParallelTests::Test::Runner.execute_command(options[:execute], i, options) end end.flatten abort if results.any? { |r| r[:exit_status] != 0 } else lib, name, task = { 'test' => ["test", "test", "test"], 'spec' => ["spec", "spec", "spec"], 'features' => ["cucumber", "feature", "features"] }[options[:type]||'test'] require "parallel_tests/#{lib}/runner" klass = eval("ParallelTests::#{lib.capitalize}::Runner") start = Time.now tests_folder = task tests_folder = File.join(options[:root], tests_folder) unless options[:root].to_s.empty? groups = klass.tests_in_groups(options[:files] || tests_folder, num_processes, options) num_processes = groups.size #adjust processes to groups abort "no #{name}s found!" if groups.size == 0 num_tests = groups.inject(0) { |sum, item| sum + item.size } puts "#{num_processes} processes for #{num_tests} #{name}s, ~ #{num_tests / groups.size} #{name}s per process" test_results = Parallel.map(groups, :in_processes => num_processes) do |group| if group.empty? {:stdout => '', :exit_status => 0} else klass.run_tests(group, groups.index(group), options) end end #parse and print results results = klass.find_results(test_results.map { |result| result[:stdout] }*"") puts "" puts klass.summarize_results(results) #report total time taken puts "" puts "Took #{Time.now - start} seconds" #exit with correct status code so rake parallel:test && echo 123 works failed = test_results.any? { |result| result[:exit_status] != 0 } abort "#{name.capitalize}s Failed" if failed end end end end