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


278
279
280
281
282
283
284
285
286
287
# File 'lib/test/unit.rb', line 278

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


354
355
356
# File 'lib/test/unit.rb', line 354

def file
  @file
end

#ioObject (readonly)

Returns the value of attribute io


353
354
355
# File 'lib/test/unit.rb', line 353

def io
  @io
end

#loadpathObject

Returns the value of attribute loadpath


354
355
356
# File 'lib/test/unit.rb', line 354

def loadpath
  @loadpath
end

#pidObject (readonly)

Returns the value of attribute pid


353
354
355
# File 'lib/test/unit.rb', line 353

def pid
  @pid
end

#quit_calledObject (readonly)

Returns the value of attribute quit_called


276
277
278
# File 'lib/test/unit.rb', line 276

def quit_called
  @quit_called
end

#real_fileObject

Returns the value of attribute real_file


354
355
356
# File 'lib/test/unit.rb', line 354

def real_file
  @real_file
end

#statusObject

Returns the value of attribute status


354
355
356
# File 'lib/test/unit.rb', line 354

def status
  @status
end

Class Method Details

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


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

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


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

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

#died(*additional) ⇒ Object


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

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

  call_hook(:dead,*additional)
end

#hook(id, &block) ⇒ Object


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

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

#killObject


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

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

#puts(*args) ⇒ Object


289
290
291
# File 'lib/test/unit.rb', line 289

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

#quitObject


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

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

#readObject


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

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

#run(task, type) ⇒ Object


293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# File 'lib/test/unit.rb', line 293

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


345
346
347
348
349
350
351
# File 'lib/test/unit.rb', line 345

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