Sha256: 76f79bd3b34b40081c196f8161b33cfbc00e9308c915d6982e4f21aca2a107c3

Contents?: true

Size: 1.78 KB

Versions: 6

Compression:

Stored size: 1.78 KB

Contents

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

      # Return killer type
      #
      # @return [String]
      #
      # @api private
      #
      def type
        @killer.type
      end

    private

      # Run killer
      #
      # @return [true] 
      #   if mutant was killed
      #
      # @return [false]
      #   otherwise
      #
      # @api private
      #
      def run
        fork do
          begin
            killer = @killer.new(strategy, mutation)
            Kernel.exit(killer.fail? ? 1 : 0)
          rescue
            Kernel.exit(1)
          end
        end

        status = Process.wait2.last
        status.exitstatus.zero?
      end
    end

    # A killer that executes other killer in forked environemnts
    class Forking < self
      include Equalizer.new(:killer)

      # Return killer
      #
      # @return [Killer]
      #
      # @api private
      #
      attr_reader :killer

      # Initalize killer
      #
      # @param [Killer] killer
      #   the killer that will be used
      #
      # @return [undefined]
      #
      # @api private
      #
      def initialize(killer)
        @killer = killer
      end

      # Return killer instance
      #
      # @param [Strategy] strategy
      # @param [Mutation] mutation
      #
      # @return [Killer::Forked]
      #
      # @api private
      #
      def new(strategy, mutation)
        Forked.new(killer, strategy, mutation)
      end

    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
mutant-0.2.20 lib/mutant/killer/forking.rb
mutant-0.2.17 lib/mutant/killer/forking.rb
mutant-0.2.16 lib/mutant/killer/forking.rb
mutant-0.2.15 lib/mutant/killer/forking.rb
mutant-0.2.14 lib/mutant/killer/forking.rb
mutant-0.2.13 lib/mutant/killer/forking.rb