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
|
|
|
|
orig_stdout = MiniTest::Unit.output
|
|
|
|
i,o = IO.pipe
|
|
|
|
MiniTest::Unit.output = o
|
|
|
|
|
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
|
|
|
|
|
|
|
|
result = orig_run_suite(suite, type)
|
|
|
|
|
|
|
|
MiniTest::Unit.output = orig_stdout
|
|
|
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
|
|
|
|
Signal.trap(:INT,"IGNORE")
|
|
|
|
@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-03-01 07:54:39 -05:00
|
|
|
@stdout.puts "ready"
|
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
|
|
|
|
|
|
|
|
Test::Unit::Worker.new.run(ARGV)
|