2012-08-14 22:45:34 +02:00
|
|
|
module Mutant
|
2012-08-16 04:10:54 +02:00
|
|
|
# Runner that allows to mutate an entire project
|
2012-08-14 22:45:34 +02:00
|
|
|
class Runner
|
2012-11-21 20:49:23 +01:00
|
|
|
include Adamantium::Flat
|
2012-08-16 04:10:54 +02:00
|
|
|
extend MethodObject
|
2012-08-14 22:45:34 +02:00
|
|
|
|
2012-08-16 19:26:15 +02:00
|
|
|
# Return killers with errors
|
|
|
|
#
|
|
|
|
# @return [Enumerable<Killer>]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2012-10-26 11:24:29 +02:00
|
|
|
attr_reader :errors
|
2012-08-14 22:45:34 +02:00
|
|
|
|
2012-08-16 19:26:15 +02:00
|
|
|
# Test for failure
|
|
|
|
#
|
|
|
|
# @return [true]
|
|
|
|
# returns true when there are left mutations
|
|
|
|
#
|
|
|
|
# @return [false]
|
|
|
|
# returns false othewise
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2012-08-16 04:10:54 +02:00
|
|
|
def fail?
|
|
|
|
!errors.empty?
|
2012-08-14 22:45:34 +02:00
|
|
|
end
|
|
|
|
|
2012-11-21 22:28:08 +01:00
|
|
|
# Return config
|
|
|
|
#
|
|
|
|
# @return [Mutant::Config]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
attr_reader :config
|
|
|
|
|
2012-08-16 04:10:54 +02:00
|
|
|
private
|
2012-08-14 22:45:34 +02:00
|
|
|
|
2012-09-16 00:51:47 +02:00
|
|
|
# Initialize object
|
2012-08-16 19:26:15 +02:00
|
|
|
#
|
2012-11-21 20:49:23 +01:00
|
|
|
# @param [Config] config
|
2012-08-16 19:26:15 +02:00
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2012-11-21 20:49:23 +01:00
|
|
|
def initialize(config)
|
|
|
|
@config, @errors = config, []
|
2012-08-19 21:40:08 +02:00
|
|
|
|
2012-11-21 22:28:08 +01:00
|
|
|
reporter.config(config)
|
|
|
|
|
2012-08-14 22:45:34 +02:00
|
|
|
run
|
|
|
|
end
|
|
|
|
|
2012-11-21 22:28:08 +01:00
|
|
|
# Return reporter
|
|
|
|
#
|
|
|
|
# @return [Reporter]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def reporter
|
|
|
|
config.reporter
|
|
|
|
end
|
|
|
|
|
2012-08-16 19:26:15 +02:00
|
|
|
# Run mutation killers on subjects
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2012-08-16 04:10:54 +02:00
|
|
|
def run
|
2012-11-21 22:28:08 +01:00
|
|
|
config.matcher.each do |subject|
|
2012-08-16 04:10:54 +02:00
|
|
|
reporter.subject(subject)
|
2012-11-21 22:28:08 +01:00
|
|
|
run_subject(subject)
|
2012-08-14 22:45:34 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-08-16 19:26:15 +02:00
|
|
|
# Run mutation killers on subject
|
|
|
|
#
|
|
|
|
# @param [Subject] subject
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2012-08-16 04:10:54 +02:00
|
|
|
def run_subject(subject)
|
|
|
|
subject.each do |mutation|
|
2012-11-21 22:28:08 +01:00
|
|
|
next unless config.filter.match?(mutation)
|
2012-08-16 04:10:54 +02:00
|
|
|
reporter.mutation(mutation)
|
|
|
|
kill(mutation)
|
2012-08-14 22:45:34 +02:00
|
|
|
end
|
2012-08-16 04:10:54 +02:00
|
|
|
subject.reset
|
2012-08-14 22:45:34 +02:00
|
|
|
end
|
|
|
|
|
2012-08-16 19:26:15 +02:00
|
|
|
# Run killer on mutation
|
|
|
|
#
|
|
|
|
# @param [Mutation] mutation
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2012-08-16 04:10:54 +02:00
|
|
|
def kill(mutation)
|
2012-11-22 00:10:50 +01:00
|
|
|
killer = config.strategy.kill(mutation)
|
2012-08-16 04:10:54 +02:00
|
|
|
reporter.killer(killer)
|
|
|
|
if killer.fail?
|
|
|
|
@errors << killer
|
2012-08-14 22:45:34 +02:00
|
|
|
end
|
|
|
|
end
|
2012-08-29 13:37:28 +02:00
|
|
|
end
|
|
|
|
end
|