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


246
247
248
249
250
251
252
253
254
# File 'lib/test/unit.rb', line 246

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


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

def file
  @file
end

#ioObject (readonly)

Returns the value of attribute io


307
308
309
# File 'lib/test/unit.rb', line 307

def io
  @io
end

#loadpathObject

Returns the value of attribute loadpath


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

def loadpath
  @loadpath
end

#pidObject (readonly)

Returns the value of attribute pid


307
308
309
# File 'lib/test/unit.rb', line 307

def pid
  @pid
end

#real_fileObject

Returns the value of attribute real_file


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

def real_file
  @real_file
end

#statusObject

Returns the value of attribute status


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

def status
  @status
end

Class Method Details

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


239
240
241
242
243
244
# File 'lib/test/unit.rb', line 239

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


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

def close
  @io.close
  self
end

#died(*additional) ⇒ Object


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

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

  call_hook(:dead,*additional)
end

#hook(id, &block) ⇒ Object


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

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

#puts(*args) ⇒ Object


256
257
258
# File 'lib/test/unit.rb', line 256

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

#readObject


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

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

#run(task, type) ⇒ Object


260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# File 'lib/test/unit.rb', line 260

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


299
300
301
302
303
304
305
# File 'lib/test/unit.rb', line 299

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