free_mutant/lib/mutant/runner.rb

152 lines
2.5 KiB
Ruby
Raw Normal View History

2012-08-14 22:45:34 +02:00
module Mutant
# 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
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
#
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
#
def fail?
!errors.empty?
2012-08-14 22:45:34 +02:00
end
# Return config
#
# @return [Mutant::Config]
#
# @api private
#
attr_reader :config
private
2012-08-14 22:45:34 +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, []
reporter.config(config)
2012-08-14 22:45:34 +02:00
run
2012-11-22 02:51:16 +01:00
reporter.errors(@errors)
2012-08-14 22:45:34 +02:00
end
# 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
#
def run
config.matcher.each do |subject|
reporter.subject(subject)
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
#
def run_subject(subject)
return unless noop(subject)
subject.each do |mutation|
next unless config.filter.match?(mutation)
reporter.mutation(mutation)
kill(mutation)
2012-08-14 22:45:34 +02:00
end
end
# Test for noop mutation
#
# @param [Subject] subject
#
# @return [true]
# if noop mutation is okay
#
# @return [false]
# otherwise
#
# @api private
#
def noop(subject)
killer = killer(subject.noop)
reporter.noop(killer)
unless killer.fail?
@errors << killer
return false
end
true
end
2012-08-16 19:26:15 +02:00
# Run killer on mutation
#
# @param [Mutation] mutation
#
# @return [true]
# if killer was unsuccessful
#
# @return [false]
# otherwise
2012-08-16 19:26:15 +02:00
#
# @api private
#
def kill(mutation)
killer = killer(mutation)
reporter.killer(killer)
if killer.fail?
@errors << killer
2012-08-14 22:45:34 +02:00
end
end
# Return killer for mutation
#
# @return [Killer]
#
# @api private
#
def killer(mutation)
config.strategy.kill(mutation)
end
end
end