free_mutant/lib/mutant/killer/forked.rb

47 lines
920 B
Ruby
Raw Normal View History

# encoding: utf-8
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
pid = fork do
killer = @killer.new(strategy, mutation)
exit(killer.killed? ? CLI::EXIT_SUCCESS : CLI::EXIT_FAILURE)
2013-01-15 23:46:05 +01:00
end
status = Process.wait2(pid).last
status.exited? && status.success?
2013-01-15 23:46:05 +01:00
end
2013-06-14 20:54:02 +02:00
end # Forked
end # Killer
end # Mutant