2011-02-21 22:36:38 -05:00
|
|
|
require 'test/unit'
|
|
|
|
|
|
|
|
module Test
|
|
|
|
module Unit
|
|
|
|
class Worker < Runner
|
|
|
|
class << self
|
|
|
|
undef autorun
|
|
|
|
end
|
2011-02-26 09:51:35 -05:00
|
|
|
|
2011-02-21 22:36:38 -05:00
|
|
|
alias orig_run_suite _run_suite
|
|
|
|
undef _run_suite
|
|
|
|
undef _run_suites
|
2011-02-23 09:08:25 -05:00
|
|
|
undef run
|
2011-02-21 22:36:38 -05:00
|
|
|
|
2011-03-02 00:29:52 -05:00
|
|
|
def increment_io(orig)
|
2011-03-01 08:05:17 -05:00
|
|
|
*rest, io = 32.times.inject([orig.dup]){|ios, | ios << ios.last.dup }
|
2011-03-01 07:54:39 -05:00
|
|
|
rest.each(&:close)
|
|
|
|
io
|
|
|
|
end
|
|
|
|
|
2011-03-02 00:29:52 -05:00
|
|
|
def _run_suites(suites, type)
|
2011-02-21 22:36:38 -05:00
|
|
|
suites.map do |suite|
|
2011-03-21 17:42:23 -04:00
|
|
|
_run_suite(suite, type)
|
2011-02-21 22:36:38 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def _run_suite(suite, type)
|
|
|
|
r = report.dup
|
2011-06-03 07:48:47 -04:00
|
|
|
orig_testout = MiniTest::Unit.output
|
2011-02-21 22:36:38 -05:00
|
|
|
i,o = IO.pipe
|
2011-06-03 07:48:47 -04:00
|
|
|
|
2011-02-21 22:36:38 -05:00
|
|
|
MiniTest::Unit.output = o
|
2011-06-03 07:48:47 -04:00
|
|
|
orig_stdin, orig_stdout = $stdin, $stdout
|
2011-02-21 22:36:38 -05:00
|
|
|
|
2011-02-26 02:17:59 -05:00
|
|
|
th = Thread.new do
|
2011-02-21 22:36:38 -05:00
|
|
|
begin
|
2011-02-26 02:17:59 -05:00
|
|
|
while buf = (self.verbose ? i.gets : i.read(5))
|
2011-03-01 07:54:39 -05:00
|
|
|
@stdout.puts "p #{[buf].pack("m").gsub("\n","")}"
|
2011-02-21 22:36:38 -05:00
|
|
|
end
|
|
|
|
rescue IOError
|
|
|
|
rescue Errno::EPIPE
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
e, f, s = @errors, @failures, @skips
|
|
|
|
|
2011-05-22 20:10:49 -04:00
|
|
|
begin
|
|
|
|
result = orig_run_suite(suite, type)
|
|
|
|
rescue Interrupt
|
|
|
|
@need_exit = true
|
|
|
|
result = [nil,nil]
|
|
|
|
end
|
2011-02-21 22:36:38 -05:00
|
|
|
|
2011-06-03 07:48:47 -04:00
|
|
|
MiniTest::Unit.output = orig_testout
|
|
|
|
$stdin = orig_stdin
|
|
|
|
$stdout = orig_stdout
|
2011-02-21 22:36:38 -05:00
|
|
|
|
|
|
|
o.close
|
|
|
|
begin
|
|
|
|
th.join
|
|
|
|
rescue IOError
|
|
|
|
raise unless ["stream closed","closed stream"].include? $!.message
|
|
|
|
end
|
2011-02-23 09:08:25 -05:00
|
|
|
i.close
|
2011-02-21 22:36:38 -05:00
|
|
|
|
|
|
|
result << (report - r)
|
|
|
|
result << [@errors-e,@failures-f,@skips-s]
|
|
|
|
result << ($: - @old_loadpath)
|
|
|
|
result << suite.name
|
|
|
|
|
|
|
|
begin
|
2011-03-01 07:54:39 -05:00
|
|
|
@stdout.puts "done #{[Marshal.dump(result)].pack("m").gsub("\n","")}"
|
2011-02-21 22:36:38 -05:00
|
|
|
rescue Errno::EPIPE; end
|
|
|
|
return result
|
|
|
|
ensure
|
|
|
|
MiniTest::Unit.output = orig_stdout
|
2011-06-03 07:48:47 -04:00
|
|
|
$stdin = orig_stdin
|
|
|
|
$stdout = orig_stdout
|
2011-02-21 22:36:38 -05:00
|
|
|
o.close if o && !o.closed?
|
|
|
|
i.close if i && !i.closed?
|
|
|
|
end
|
|
|
|
|
|
|
|
def run(args = [])
|
|
|
|
process_args args
|
|
|
|
@@stop_auto_run = true
|
|
|
|
@opts = @options.dup
|
2011-05-22 20:10:49 -04:00
|
|
|
@need_exit = false
|
2011-02-21 22:36:38 -05:00
|
|
|
|
|
|
|
@old_loadpath = []
|
|
|
|
begin
|
2011-03-02 00:29:52 -05:00
|
|
|
@stdout = increment_io(STDOUT)
|
|
|
|
@stdin = increment_io(STDIN)
|
2011-03-01 07:54:39 -05:00
|
|
|
@stdout.sync = true
|
|
|
|
@stdout.puts "ready"
|
|
|
|
while buf = @stdin.gets
|
2011-02-21 22:36:38 -05:00
|
|
|
case buf.chomp
|
|
|
|
when /^loadpath (.+?)$/
|
|
|
|
@old_loadpath = $:.dup
|
|
|
|
$:.push(*Marshal.load($1.unpack("m")[0].force_encoding("ASCII-8BIT"))).uniq!
|
|
|
|
when /^run (.+?) (.+?)$/
|
2011-03-01 07:54:39 -05:00
|
|
|
@stdout.puts "okay"
|
2011-02-21 22:36:38 -05:00
|
|
|
|
|
|
|
@options = @opts.dup
|
|
|
|
suites = MiniTest::Unit::TestCase.test_suites
|
|
|
|
|
|
|
|
begin
|
|
|
|
require $1
|
|
|
|
rescue LoadError
|
2011-03-01 07:54:39 -05:00
|
|
|
@stdout.puts "after #{[Marshal.dump([$1, $!])].pack("m").gsub("\n","")}"
|
|
|
|
@stdout.puts "ready"
|
2011-02-21 22:36:38 -05:00
|
|
|
next
|
|
|
|
end
|
|
|
|
_run_suites MiniTest::Unit::TestCase.test_suites-suites, $2.to_sym
|
|
|
|
|
2011-05-22 20:10:49 -04:00
|
|
|
if @need_exit
|
|
|
|
begin
|
|
|
|
@stdout.puts "bye"
|
|
|
|
rescue Errno::EPIPE; end
|
|
|
|
exit
|
|
|
|
else
|
|
|
|
@stdout.puts "ready"
|
|
|
|
end
|
2011-02-21 22:36:38 -05:00
|
|
|
when /^quit$/
|
|
|
|
begin
|
2011-03-01 07:54:39 -05:00
|
|
|
@stdout.puts "bye"
|
2011-02-21 22:36:38 -05:00
|
|
|
rescue Errno::EPIPE; end
|
|
|
|
exit
|
|
|
|
end
|
|
|
|
end
|
2011-02-26 02:17:59 -05:00
|
|
|
rescue Errno::EPIPE
|
2011-02-21 22:36:38 -05:00
|
|
|
rescue Exception => e
|
|
|
|
begin
|
2011-03-01 07:54:39 -05:00
|
|
|
@stdout.puts "bye #{[Marshal.dump(e)].pack("m").gsub("\n","")}"
|
2011-02-21 22:36:38 -05:00
|
|
|
rescue Errno::EPIPE;end
|
|
|
|
exit
|
|
|
|
ensure
|
2011-03-01 07:54:39 -05:00
|
|
|
@stdin.close
|
|
|
|
@stdout.close
|
2011-02-21 22:36:38 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-06-18 21:12:02 -04:00
|
|
|
if $0 == __FILE__
|
|
|
|
module Test
|
|
|
|
module Unit
|
|
|
|
class TestCase < MiniTest::Unit::TestCase
|
|
|
|
def on_parallel_worker?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
Test::Unit::Worker.new.run(ARGV)
|
|
|
|
end
|