free_mutant/lib/mutant/runner.rb

147 lines
2.4 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
2013-01-21 22:59:50 +01:00
include Adamantium::Flat, Equalizer.new(:config)
extend MethodObject
2012-08-14 22:45:34 +02:00
2013-01-21 23:53:25 +01:00
# Test for succcess
2012-08-16 19:26:15 +02:00
#
# @return [true]
2013-01-21 23:53:25 +01:00
# when there are subjects and no failures
2012-08-16 19:26:15 +02:00
#
# @return [false]
2013-01-21 23:53:25 +01:00
# otherwise
2012-08-16 19:26:15 +02:00
#
# @api private
#
2013-01-21 23:53:25 +01:00
def success?
reporter.success?
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)
2013-01-15 23:46:05 +01:00
@config = config
2012-08-14 22:45:34 +02:00
run
2013-01-15 23:46:05 +01:00
end
# Return strategy
#
# @return [Strategy]
#
# @api private
#
def strategy
config.strategy
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
reporter.start(config)
2013-01-15 23:46:05 +01:00
util = strategy
util.setup
config.matcher.each do |subject|
reporter.subject(subject)
run_subject(subject)
2012-08-14 22:45:34 +02:00
end
2013-01-15 23:46:05 +01:00
util.teardown
reporter.stop
2012-08-14 22:45:34 +02:00
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)
2013-01-15 23:46:05 +01:00
return unless test_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
2013-01-15 23:46:05 +01:00
# Test noop mutation
#
# @return [true]
2013-01-15 23:46:05 +01:00
# if noop mutation is alive
#
# @return [false]
# otherwise
#
# @api private
#
2013-01-15 23:46:05 +01:00
def test_noop(subject)
noop = subject.noop
unless kill(noop)
reporter.noop(noop)
return false
end
true
end
2012-08-16 19:26:15 +02:00
# Run killer on mutation
#
# @param [Mutation] mutation
#
# @return [true]
2013-01-15 23:46:05 +01:00
# if killer was successful
#
# @return [false]
# otherwise
2012-08-16 19:26:15 +02:00
#
# @api private
#
def kill(mutation)
killer = killer(mutation)
2013-01-15 23:46:05 +01:00
reporter.report_killer(killer)
killer.success?
2012-08-14 22:45:34 +02:00
end
# Return killer for mutation
#
# @return [Killer]
#
# @api private
#
def killer(mutation)
2013-01-15 23:46:05 +01:00
strategy.kill(mutation)
end
end
end