free_mutant/lib/mutant/killer/forked.rb

49 lines
934 B
Ruby
Raw Normal View History

2013-01-15 23:46:05 +01:00
module Mutant
class Killer
# Killer that executes other killer in forked environment
class Forked < self
# Initialize object
#
# @param [Killer] killer
# @param [Strategy] strategy
# @param [Mutation] mutation
#
# @api private
#
def initialize(killer, strategy, mutation)
@killer = killer
super(strategy, mutation)
end
private
# Run killer
#
2013-04-17 20:31:21 -07:00
# @return [true]
2013-01-15 23:46:05 +01:00
# if mutant was killed
#
# @return [false]
# otherwise
#
# @api private
#
def run
fork do
begin
killer = @killer.new(strategy, mutation)
2013-04-17 18:58:44 -07:00
Kernel.exit(killer.success? ? 0 : 1)
2013-01-15 23:46:05 +01:00
rescue
Kernel.exit(1)
end
end
status = Process.wait2.last
status.exitstatus.zero?
end
2013-06-14 20:54:02 +02:00
end # Forked
end # Killer
end # Mutant