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
|
|
|
|
2012-03-29 03:35:38 -04:00
|
|
|
alias orig_run_suite mini_run_suite
|
2011-02-21 22:36:38 -05:00
|
|
|
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)
|
2012-06-15 18:11:55 -04:00
|
|
|
@partial_report = []
|
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))
|
2012-06-19 05:22:01 -04:00
|
|
|
_report "p", buf
|
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
|
|
|
|
2012-06-15 18:11:55 -04:00
|
|
|
result << @partial_report
|
|
|
|
@partial_report = nil
|
2011-02-21 22:36:38 -05:00
|
|
|
result << [@errors-e,@failures-f,@skips-s]
|
|
|
|
result << ($: - @old_loadpath)
|
|
|
|
result << suite.name
|
|
|
|
|
|
|
|
begin
|
2012-06-19 05:22:01 -04:00
|
|
|
_report "done", Marshal.dump(result)
|
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
|
2012-03-11 04:28:48 -04:00
|
|
|
begin
|
|
|
|
@stdout = increment_io(STDOUT)
|
|
|
|
@stdin = increment_io(STDIN)
|
|
|
|
rescue
|
|
|
|
exit 2
|
|
|
|
end
|
|
|
|
exit 2 unless @stdout && @stdin
|
|
|
|
|
2011-03-01 07:54:39 -05:00
|
|
|
@stdout.sync = true
|
2012-06-19 05:22:01 -04:00
|
|
|
_report "ready!"
|
2011-03-01 07:54:39 -05:00
|
|
|
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 (.+?) (.+?)$/
|
2012-06-19 05:22:01 -04:00
|
|
|
_report "okay"
|
2011-02-21 22:36:38 -05:00
|
|
|
|
|
|
|
@options = @opts.dup
|
|
|
|
suites = MiniTest::Unit::TestCase.test_suites
|
|
|
|
|
|
|
|
begin
|
|
|
|
require $1
|
|
|
|
rescue LoadError
|
2012-06-19 05:22:01 -04:00
|
|
|
_report "after", Marshal.dump([$1, $!])
|
|
|
|
_report "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
|
2012-06-19 05:22:01 -04:00
|
|
|
_report "bye"
|
2011-05-22 20:10:49 -04:00
|
|
|
rescue Errno::EPIPE; end
|
|
|
|
exit
|
|
|
|
else
|
2012-06-19 05:22:01 -04:00
|
|
|
_report "ready"
|
2011-05-22 20:10:49 -04:00
|
|
|
end
|
2011-02-21 22:36:38 -05:00
|
|
|
when /^quit$/
|
|
|
|
begin
|
2012-06-19 05:22:01 -04:00
|
|
|
_report "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
|
2012-08-19 22:07:24 -04:00
|
|
|
trace = e.backtrace
|
|
|
|
err = ["#{trace.shift}: #{e.message} (#{e.class})"] + trace.map{|t| t.prepend("\t") }
|
|
|
|
|
|
|
|
_report "bye", Marshal.dump(err.join("\n"))
|
2011-02-21 22:36:38 -05:00
|
|
|
rescue Errno::EPIPE;end
|
|
|
|
exit
|
|
|
|
ensure
|
2012-03-11 04:28:48 -04:00
|
|
|
@stdin.close if @stdin
|
|
|
|
@stdout.close if @stdout
|
2011-02-21 22:36:38 -05:00
|
|
|
end
|
|
|
|
end
|
2012-06-15 18:11:55 -04:00
|
|
|
|
2012-06-19 05:22:01 -04:00
|
|
|
def _report(res, *args)
|
|
|
|
res = "#{res} #{args.pack("m0")}" unless args.empty?
|
|
|
|
@stdout.puts(res)
|
|
|
|
end
|
|
|
|
|
2012-06-15 18:11:55 -04:00
|
|
|
def puke(klass, meth, e)
|
2012-08-20 21:57:19 -04:00
|
|
|
@partial_report << [klass.name, meth, e.is_a?(MiniTest::Assertion) ? e : ProxyError.new(e)]
|
2012-06-15 18:11:55 -04:00
|
|
|
super
|
|
|
|
end
|
2011-02-21 22:36:38 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-06-18 21:12:02 -04:00
|
|
|
if $0 == __FILE__
|
|
|
|
module Test
|
|
|
|
module Unit
|
|
|
|
class TestCase < MiniTest::Unit::TestCase
|
2012-07-02 22:11:01 -04:00
|
|
|
undef on_parallel_worker?
|
2011-06-18 21:12:02 -04:00
|
|
|
def on_parallel_worker?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-06-28 16:11:19 -04:00
|
|
|
require 'rubygems'
|
|
|
|
class Gem::TestCase < MiniTest::Unit::TestCase
|
|
|
|
@@project_dir = File.expand_path('../../../..', __FILE__)
|
|
|
|
end
|
2011-06-18 21:12:02 -04:00
|
|
|
|
|
|
|
Test::Unit::Worker.new.run(ARGV)
|
|
|
|
end
|