Sha256: a7b0b005b2618df86e2a80eab825a20c627a0b7c49bac7c90d6bdfb449729582

Contents?: true

Size: 1.71 KB

Versions: 7

Compression:

Stored size: 1.71 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
          killer = @killer.new(strategy, mutation)
          Kernel.exit(killer.fail? ? 1 : 0)
        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

7 entries across 7 versions & 1 rubygems

Version Path
mutant-0.2.12 lib/mutant/killer/forking.rb
mutant-0.2.11 lib/mutant/killer/forking.rb
mutant-0.2.9 lib/mutant/killer/forking.rb
mutant-0.2.8 lib/mutant/killer/forking.rb
mutant-0.2.7 lib/mutant/killer/forking.rb
mutant-0.2.6 lib/mutant/killer/forking.rb
mutant-0.2.5 lib/mutant/killer/forking.rb