diff --git a/bin/turbo_rspec b/bin/turbo_rspec index 0d966017dd8..e0af6b31e50 100755 --- a/bin/turbo_rspec +++ b/bin/turbo_rspec @@ -6,6 +6,7 @@ require 'optparse' requires = [] formatters = [] +verbose = false OptionParser.new do |opts| opts.on("-r", "--require PATH", "Require a file.") do |filename| @@ -28,6 +29,10 @@ OptionParser.new do |opts| end formatters.last[:outputs] << filename end + + opts.on("-v", "--verbose", "More output") do + verbose = true + end end.parse!(ARGV) requires.each { |f| require(f) } @@ -45,4 +50,8 @@ formatters.each do |formatter| end end -TurboTests::Runner.run(formatters, ARGV.empty? ? ["spec"] : ARGV) +TurboTests::Runner.run( + formatters: formatters, + files: ARGV.empty? ? ["spec"] : ARGV, + verbose: verbose +) diff --git a/lib/tasks/turbo.rake b/lib/tasks/turbo.rake index 48c5a91b7f7..e78b2f22a3a 100644 --- a/lib/tasks/turbo.rake +++ b/lib/tasks/turbo.rake @@ -3,5 +3,8 @@ task 'turbo:spec' => :test do |t| require './lib/turbo_tests' - TurboTests::Runner.run([{ name: 'progress', outputs: ['-'] }], ['spec']) + TurboTests::Runner.run( + formatters: [{ name: 'progress', outputs: ['-'] }], + files: ['spec'] + ) end diff --git a/lib/turbo_tests/runner.rb b/lib/turbo_tests/runner.rb index 9f9b78d1b6c..650e5fed284 100644 --- a/lib/turbo_tests/runner.rb +++ b/lib/turbo_tests/runner.rb @@ -2,15 +2,30 @@ module TurboTests class Runner - def self.run(formatter_config, files, start_time = Time.now) - reporter = Reporter.from_config(formatter_config, start_time) + def self.run(opts = {}) + files = opts[:files] + formatters = opts[:formatters] + start_time = opts.fetch(:start_time) { Time.now } + verbose = opts.fetch(:verbose, false) - new(reporter, files).run + if verbose + STDERR.puts "VERBOSE" + end + + reporter = Reporter.from_config(formatters, start_time) + + new( + reporter: reporter, + files: files, + verbose: verbose + ).run end - def initialize(reporter, files) - @reporter = reporter - @files = files + def initialize(opts) + @reporter = opts[:reporter] + @files = opts[:files] + @verbose = opts[:verbose] + @messages = Queue.new @threads = [] end @@ -61,14 +76,24 @@ module TurboTests rescue Errno::EEXIST end - _stdin, stdout, stderr, _wait_thr = - Open3.popen3( - { 'TEST_ENV_NUMBER' => process_num.to_s }, - "bundle", "exec", "rspec", - "-f", "TurboTests::JsonRowsFormatter", - "-o", "tmp/test-pipes/subprocess-#{process_num}", - *tests - ) + env = { 'TEST_ENV_NUMBER' => process_num.to_s } + command = [ + "bundle", "exec", "rspec", + "-f", "TurboTests::JsonRowsFormatter", + "-o", "tmp/test-pipes/subprocess-#{process_num}", + *tests + ] + + if @verbose + command_str = [ + env.map { |k, v| "#{k}=#{v}" }.join(' '), + command.join(' ') + ].join(' ') + + STDERR.puts "Process #{process_num}: #{command_str}" + end + + _stdin, stdout, stderr, _wait_thr = Open3.popen3(env, *command) @threads << Thread.new do