Class: Test::Unit::Runner::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/test/unit.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io, pid, status) ⇒ Worker

Returns a new instance of Worker.



272
273
274
275
276
277
278
279
280
281
# 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

Instance Attribute Details

#fileObject

Returns the value of attribute file



348
349
350
# File 'lib/test/unit.rb', line 348

def file
  @file
end

#ioObject (readonly)

Returns the value of attribute io



347
348
349
# File 'lib/test/unit.rb', line 347

def io
  @io
end

#loadpathObject

Returns the value of attribute loadpath



348
349
350
# File 'lib/test/unit.rb', line 348

def loadpath
  @loadpath
end

#pidObject (readonly)

Returns the value of attribute pid



347
348
349
# File 'lib/test/unit.rb', line 347

def pid
  @pid
end

#quit_calledObject (readonly)

Returns the value of attribute quit_called



270
271
272
# File 'lib/test/unit.rb', line 270

def quit_called
  @quit_called
end

#real_fileObject

Returns the value of attribute real_file



348
349
350
# File 'lib/test/unit.rb', line 348

def real_file
  @real_file
end

#statusObject

Returns the value of attribute status



348
349
350
# File 'lib/test/unit.rb', line 348

def status
  @status
end

Class Method Details

.launch(ruby, args = []) ⇒ Object



263
264
265
266
267
268
# 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

Instance Method Details

#closeObject



314
315
316
317
318
# File 'lib/test/unit.rb', line 314

def close
  @io.close unless @io.closed?
  self
rescue IOError
end

#died(*additional) ⇒ Object



332
333
334
335
336
337
# File 'lib/test/unit.rb', line 332

def died(*additional)
  @status = :quit
  @io.close

  call_hook(:dead,*additional)
end

#hook(id, &block) ⇒ Object



303
304
305
306
307
# File 'lib/test/unit.rb', line 303

def hook(id,&block)
  @hooks[id] ||= []
  @hooks[id] << block
  self
end

#killObject



327
328
329
330
# File 'lib/test/unit.rb', line 327

def kill
  Process.kill(:KILL, @pid)
rescue Errno::ESRCH
end

#puts(*args) ⇒ Object



283
284
285
# File 'lib/test/unit.rb', line 283

def puts(*args)
  @io.puts(*args)
end

#quitObject



320
321
322
323
324
325
# File 'lib/test/unit.rb', line 320

def quit
  return if @io.closed?
  @quit_called = true
  @io.puts "quit"
  @io.close
end

#readObject



309
310
311
312
# File 'lib/test/unit.rb', line 309

def read
  res = (@status == :quit) ? @io.read : @io.gets
  res && res.chomp
end

#run(task, type) ⇒ Object



287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
# 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_sObject



339
340
341
342
343
344
345
# File 'lib/test/unit.rb', line 339

def to_s
  if @file
    "#{@pid}=#{@file}"
  else
    "#{@pid}:#{@status.to_s.ljust(7)}"
  end
end