2012-08-14 16:45:34 -04:00
|
|
|
module Mutant
|
2012-08-15 22:10:54 -04:00
|
|
|
# Runner that allows to mutate an entire project
|
2012-08-14 16:45:34 -04:00
|
|
|
class Runner
|
2012-11-02 21:12:33 -04:00
|
|
|
include Adamantium::Flat, Anima
|
2012-08-15 22:10:54 -04:00
|
|
|
extend MethodObject
|
2012-08-14 16:45:34 -04:00
|
|
|
|
2012-08-16 13:26:15 -04:00
|
|
|
# Return killers with errors
|
|
|
|
#
|
|
|
|
# @return [Enumerable<Killer>]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2012-10-26 05:24:29 -04:00
|
|
|
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
|
|
|
|
#
|
2012-08-15 22:10:54 -04:00
|
|
|
def fail?
|
|
|
|
!errors.empty?
|
2012-08-14 16:45:34 -04:00
|
|
|
end
|
|
|
|
|
2012-08-15 22:10:54 -04:00
|
|
|
private
|
2012-08-14 16:45:34 -04:00
|
|
|
|
2012-09-15 18:51:47 -04:00
|
|
|
# Initialize object
|
2012-08-16 13:26:15 -04:00
|
|
|
#
|
2012-09-15 18:51:47 -04:00
|
|
|
# @param [Hash] attributes
|
2012-08-16 13:26:15 -04:00
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2012-09-15 18:51:47 -04:00
|
|
|
def initialize(attributes)
|
|
|
|
attributes[:reporter] ||= Reporter::Null
|
|
|
|
attributes[:mutation_filter] ||= Mutation::Filter::ALL
|
|
|
|
|
|
|
|
super(attributes)
|
|
|
|
|
2012-08-15 22:10:54 -04:00
|
|
|
@errors = []
|
2012-08-19 15:40:08 -04:00
|
|
|
|
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
|
|
|
|
#
|
2012-08-15 22:10:54 -04:00
|
|
|
def run
|
2012-09-15 18:51:47 -04:00
|
|
|
matcher.each do |subject|
|
2012-08-15 22:10:54 -04:00
|
|
|
reporter.subject(subject)
|
2012-10-26 05:24:29 -04:00
|
|
|
#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
|
|
|
|
#
|
2012-08-15 22:10:54 -04:00
|
|
|
def run_subject(subject)
|
|
|
|
subject.each do |mutation|
|
2012-10-26 05:24:29 -04:00
|
|
|
reporter.mutation(mutation)
|
2012-08-29 07:37:28 -04:00
|
|
|
next unless @mutation_filter.match?(mutation)
|
2012-08-15 22:10:54 -04:00
|
|
|
reporter.mutation(mutation)
|
|
|
|
kill(mutation)
|
2012-08-14 16:45:34 -04:00
|
|
|
end
|
2012-08-15 22:10:54 -04:00
|
|
|
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
|
|
|
|
#
|
2012-08-15 22:10:54 -04:00
|
|
|
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
|
2012-08-29 07:37:28 -04:00
|
|
|
end
|
|
|
|
end
|