Sha256: 917bcca00730bca3c6eccd368ac87523226ceac2372c3018dd6c90bf12c22f17

Contents?: true

Size: 1.85 KB

Versions: 5

Compression:

Stored size: 1.85 KB

Contents

module Mutant
  # Runner that allows to mutate an entire project
  class Runner
    include Adamantium::Flat
    extend MethodObject

    # Return killers with errors
    #
    # @return [Enumerable<Killer>]
    #
    # @api private
    #
    attr_reader :errors

    # Test for failure
    #
    # @return [true]
    #   returns true when there are left mutations
    #
    # @return [false]
    #   returns false othewise
    #
    # @api private
    #
    def fail?
      !errors.empty?
    end

    # Return config
    #
    # @return [Mutant::Config]
    #
    # @api private
    #
    attr_reader :config

  private

    # Initialize object
    #
    # @param [Config] config
    #
    # @return [undefined]
    #
    # @api private
    #
    def initialize(config)
      @config, @errors = config, []

      reporter.config(config)

      run

      reporter.errors(@errors)
    end

    # Return reporter
    #
    # @return [Reporter]
    #
    # @api private
    #
    def reporter
      config.reporter
    end

    # Run mutation killers on subjects
    #
    # @return [undefined]
    #
    # @api private
    #
    def run
      config.matcher.each do |subject|
        reporter.subject(subject)
        run_subject(subject)
      end
    end

    # Run mutation killers on subject
    #
    # @param [Subject] subject
    #
    # @return [undefined]
    #
    # @api private
    #
    def run_subject(subject)
      subject.each do |mutation|
        next unless config.filter.match?(mutation)
        reporter.mutation(mutation)
        kill(mutation)
      end
    end

    # Run killer on mutation
    #
    # @param [Mutation] mutation
    #
    # @return [undefined]
    #
    # @api private
    #
    def kill(mutation)
      killer = config.strategy.kill(mutation)
      reporter.killer(killer)
      if killer.fail?
        @errors << killer
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
mutant-0.2.4 lib/mutant/runner.rb
mutant-0.2.3 lib/mutant/runner.rb
mutant-0.2.2 lib/mutant/runner.rb
mutant-0.2.1 lib/mutant/runner.rb
mutant-0.2.0 lib/mutant/runner.rb