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.



251
252
253
254
255
256
257
258
259
# File 'lib/test/unit.rb', line 251

def initialize(io, pid, status)
  @io = io
  @pid = pid
  @status = status
  @file = nil
  @real_file = nil
  @loadpath = []
  @hooks = {}
end

Instance Attribute Details

#fileObject

Returns the value of attribute file.



313
314
315
# File 'lib/test/unit.rb', line 313

def file
  @file
end

#ioObject (readonly)

Returns the value of attribute io.



312
313
314
# File 'lib/test/unit.rb', line 312

def io
  @io
end

#loadpathObject

Returns the value of attribute loadpath.



313
314
315
# File 'lib/test/unit.rb', line 313

def loadpath
  @loadpath
end

#pidObject (readonly)

Returns the value of attribute pid.



312
313
314
# File 'lib/test/unit.rb', line 312

def pid
  @pid
end

#real_fileObject

Returns the value of attribute real_file.



313
314
315
# File 'lib/test/unit.rb', line 313

def real_file
  @real_file
end

#statusObject

Returns the value of attribute status.



313
314
315
# File 'lib/test/unit.rb', line 313

def status
  @status
end

Class Method Details

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



245
246
247
248
249
# File 'lib/test/unit.rb', line 245

def self.launch(ruby,args=[])
  args = [ruby, "#{File.dirname(__FILE__)}/unit/parallel.rb", args].flatten
  io = IO.popen(args, "rb+")
  new(io, io.pid, :waiting)
end

Instance Method Details

#closeObject



292
293
294
295
# File 'lib/test/unit.rb', line 292

def close
  @io.close
  self
end

#died(*additional) ⇒ Object



297
298
299
300
301
302
# File 'lib/test/unit.rb', line 297

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

  call_hook(:dead,*additional)
end

#hook(id, &block) ⇒ Object



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

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

#puts(*args) ⇒ Object



261
262
263
# File 'lib/test/unit.rb', line 261

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

#readObject



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

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

#run(task, type) ⇒ Object



265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# File 'lib/test/unit.rb', line 265

def run(task,type)
  @file = File.basename(task).gsub(/\.rb/,"")
  @real_file = task
  begin
    puts "loadpath #{[Marshal.dump($:-@loadpath)].pack("m").gsub("\n","")}"
    @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



304
305
306
307
308
309
310
# File 'lib/test/unit.rb', line 304

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