class Test::Unit::Runner::Worker
Attributes
file[RW]
io[R]
loadpath[RW]
pid[R]
quit_called[R]
real_file[RW]
status[RW]
Public Class Methods
launch(ruby,args=[])
click to toggle source
# File lib/test/unit.rb, line 263 def self.launch(ruby,args=[]) io = IO.popen([*ruby, "#{File.dirname(__FILE__)}/unit/parallel.rb", *args], "rb+") new(io, io.pid, :waiting) end
new(io, pid, status)
click to toggle source
# File lib/test/unit.rb, line 272 def initialize(io, pid, status) @io = io @pid = pid @status = status @file = nil @real_file = nil @loadpath = [] @hooks = {} @quit_called = false end
Public Instance Methods
close()
click to toggle source
# File lib/test/unit.rb, line 314 def close @io.close unless @io.closed? self rescue IOError end
died(*additional)
click to toggle source
# File lib/test/unit.rb, line 332 def died(*additional) @status = :quit @io.close call_hook(:dead,*additional) end
hook(id,&block)
click to toggle source
# File lib/test/unit.rb, line 303 def hook(id,&block) @hooks[id] ||= [] @hooks[id] << block self end
kill()
click to toggle source
# File lib/test/unit.rb, line 327 def kill Process.kill(:KILL, @pid) rescue Errno::ESRCH end
puts(*args)
click to toggle source
# File lib/test/unit.rb, line 283 def puts(*args) @io.puts(*args) end
quit()
click to toggle source
# File lib/test/unit.rb, line 320 def quit return if @io.closed? @quit_called = true @io.puts "quit" @io.close end
read()
click to toggle source
# File lib/test/unit.rb, line 309 def read res = (@status == :quit) ? @io.read : @io.gets res && res.chomp end
run(task,type)
click to toggle source
# File lib/test/unit.rb, line 287 def run(task,type) @file = File.basename(task, ".rb") @real_file = task begin puts "loadpath #{[Marshal.dump($:-@loadpath)].pack("m0")}" @loadpath = $:.dup puts "run #{task} #{type}" @status = :prepare rescue Errno::EPIPE died rescue IOError raise unless ["stream closed","closed stream"].include? $!.message died end end
to_s()
click to toggle source
# File lib/test/unit.rb, line 339 def to_s if @file "#{@pid}=#{@file}" else "#{@pid}:#{@status.to_s.ljust(7)}" end end
Private Instance Methods
call_hook(id,*additional)
click to toggle source
# File lib/test/unit.rb, line 352 def call_hook(id,*additional) @hooks[id] ||= [] @hooks[id].each{|hook| hook[self,additional] } self end