free_mutant/lib/mutant/runner.rb

103 lines
1.8 KiB
Ruby
Raw Normal View History

2012-08-14 16:45:34 -04:00
module Mutant
# Runner that allows to mutate an entire project
2012-08-14 16:45:34 -04:00
class Runner
2012-10-15 08:36:15 -04:00
include Adamantium, Anima
extend MethodObject
2012-08-14 16:45:34 -04:00
attribute :matcher
attribute :killer
attribute :reporter
attribute :mutation_filter
2012-08-16 13:26:15 -04:00
# Return killers with errors
#
# @return [Enumerable<Killer>]
#
# @api private
#
attr_reader :errors
2012-08-14 16:45:34 -04:00
2012-08-16 13:26:15 -04:00
# Test for failure
#
# @return [true]
# returns true when there are left mutations
#
# @return [false]
# returns false othewise
#
# @api private
#
def fail?
!errors.empty?
2012-08-14 16:45:34 -04:00
end
private
2012-08-14 16:45:34 -04:00
# Initialize object
2012-08-16 13:26:15 -04:00
#
# @param [Hash] attributes
2012-08-16 13:26:15 -04:00
#
# @return [undefined]
#
# @api private
#
def initialize(attributes)
attributes[:reporter] ||= Reporter::Null
attributes[:mutation_filter] ||= Mutation::Filter::ALL
super(attributes)
@errors = []
2012-08-14 16:45:34 -04:00
run
end
2012-08-16 13:26:15 -04:00
# Run mutation killers on subjects
#
# @return [undefined]
#
# @api private
#
def run
matcher.each do |subject|
reporter.subject(subject)
#run_subject(subject)
2012-08-14 16:45:34 -04:00
end
end
2012-08-16 13:26:15 -04:00
# Run mutation killers on subject
#
# @param [Subject] subject
#
# @return [undefined]
#
# @api private
#
def run_subject(subject)
subject.each do |mutation|
reporter.mutation(mutation)
next unless @mutation_filter.match?(mutation)
reporter.mutation(mutation)
kill(mutation)
2012-08-14 16:45:34 -04:00
end
subject.reset
2012-08-14 16:45:34 -04:00
end
2012-08-16 13:26:15 -04:00
# Run killer on mutation
#
# @param [Mutation] mutation
#
# @return [undefined]
#
# @api private
#
def kill(mutation)
killer = @killer.run(mutation)
reporter.killer(killer)
if killer.fail?
@errors << killer
2012-08-14 16:45:34 -04:00
end
end
end
end