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
|
2013-01-21 22:59:50 +01:00
|
|
|
include Adamantium::Flat, Equalizer.new(:config)
|
2012-08-16 04:10:54 +02:00
|
|
|
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
|
|
|
|
|
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)
|
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
|
|
|
|
|
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
|
2013-01-21 23:54:25 +01:00
|
|
|
reporter.start(config)
|
2013-01-15 23:46:05 +01:00
|
|
|
util = strategy
|
|
|
|
util.setup
|
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
|
2013-01-15 23:46:05 +01:00
|
|
|
util.teardown
|
2013-01-21 23:54:25 +01:00
|
|
|
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
|
|
|
|
#
|
2012-08-16 04:10:54 +02:00
|
|
|
def run_subject(subject)
|
2013-01-15 23:46:05 +01:00
|
|
|
return unless test_noop(subject)
|
2012-08-16 04:10:54 +02:00
|
|
|
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
|
|
|
|
end
|
|
|
|
|
2013-01-15 23:46:05 +01:00
|
|
|
# Test noop mutation
|
2012-12-11 00:17:19 +01:00
|
|
|
#
|
|
|
|
# @return [true]
|
2013-01-15 23:46:05 +01:00
|
|
|
# if noop mutation is alive
|
2012-12-11 00:17:19 +01:00
|
|
|
#
|
|
|
|
# @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)
|
2012-12-11 00:23:44 +01:00
|
|
|
return false
|
2012-12-11 00:17:19 +01:00
|
|
|
end
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2012-08-16 19:26:15 +02:00
|
|
|
# Run killer on mutation
|
|
|
|
#
|
|
|
|
# @param [Mutation] mutation
|
|
|
|
#
|
2012-12-11 00:17:19 +01:00
|
|
|
# @return [true]
|
2013-01-15 23:46:05 +01:00
|
|
|
# if killer was successful
|
2012-12-11 00:17:19 +01:00
|
|
|
#
|
|
|
|
# @return [false]
|
|
|
|
# otherwise
|
2012-08-16 19:26:15 +02:00
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2012-08-16 04:10:54 +02:00
|
|
|
def kill(mutation)
|
2012-12-11 00:17:19 +01:00
|
|
|
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
|
2012-12-11 00:17:19 +01:00
|
|
|
|
|
|
|
# Return killer for mutation
|
|
|
|
#
|
|
|
|
# @return [Killer]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def killer(mutation)
|
2013-01-15 23:46:05 +01:00
|
|
|
strategy.kill(mutation)
|
2012-12-11 00:17:19 +01:00
|
|
|
end
|
2012-08-29 13:37:28 +02:00
|
|
|
end
|
|
|
|
end
|