2013-07-28 19:03:06 -04:00
|
|
|
# encoding: utf-8
|
|
|
|
|
2013-02-02 10:32:13 -05:00
|
|
|
module Mutant
|
|
|
|
class Runner
|
|
|
|
# Mutation runner
|
|
|
|
class Mutation < self
|
2014-05-22 21:03:09 -04:00
|
|
|
include Equalizer.new(:config, :mutation, :tests)
|
2013-02-02 10:32:13 -05:00
|
|
|
|
2013-07-14 19:17:15 -04:00
|
|
|
register Mutant::Mutation
|
|
|
|
|
2013-09-02 14:35:01 -04:00
|
|
|
# Return mutation
|
|
|
|
#
|
|
|
|
# @return [Mutation]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
attr_reader :mutation
|
|
|
|
|
2014-04-28 15:17:25 -04:00
|
|
|
# Return killers
|
2013-02-02 10:32:13 -05:00
|
|
|
#
|
2014-05-22 23:15:36 -04:00
|
|
|
# @return [Enumerable<Runner::Killer>]
|
2013-02-02 10:32:13 -05:00
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2014-04-28 15:17:25 -04:00
|
|
|
attr_reader :killers
|
2013-02-02 10:32:13 -05:00
|
|
|
|
|
|
|
# Initialize object
|
|
|
|
#
|
2013-03-27 10:52:02 -04:00
|
|
|
# @param [Config] config
|
2013-02-02 10:32:13 -05:00
|
|
|
# @param [Mutation] mutation
|
2014-05-22 21:03:09 -04:00
|
|
|
# @param [Enumerable<Test>] tests
|
2013-02-02 10:32:13 -05:00
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2014-05-22 21:03:09 -04:00
|
|
|
def initialize(config, mutation, tests)
|
|
|
|
@mutation, @tests = mutation, tests
|
2013-02-02 10:32:13 -05:00
|
|
|
super(config)
|
2014-05-22 21:26:04 -04:00
|
|
|
@stop = config.fail_fast && !success?
|
2013-02-02 10:32:13 -05:00
|
|
|
end
|
|
|
|
|
2013-03-27 10:52:02 -04:00
|
|
|
# Test if mutation was handeled successfully
|
|
|
|
#
|
|
|
|
# @return [true]
|
|
|
|
# if successful
|
|
|
|
#
|
|
|
|
# @return [false]
|
|
|
|
# otherwise
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def success?
|
2014-04-28 15:17:25 -04:00
|
|
|
killers.any?(&:success?)
|
2013-03-27 10:52:02 -04:00
|
|
|
end
|
|
|
|
|
2013-02-02 10:32:13 -05:00
|
|
|
private
|
|
|
|
|
|
|
|
# Perform operation
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def run
|
2014-05-27 12:43:16 -04:00
|
|
|
@killers = []
|
|
|
|
|
|
|
|
killers = @tests.map do |test|
|
2014-05-22 21:03:09 -04:00
|
|
|
Mutant::Killer.new(
|
|
|
|
mutation: mutation,
|
|
|
|
test: test
|
|
|
|
)
|
2014-05-27 12:43:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
killers.each do |killer|
|
|
|
|
runner = visit(killer)
|
|
|
|
@killers << runner
|
|
|
|
return if runner.mutation_dead?
|
|
|
|
end
|
2013-02-02 10:32:13 -05:00
|
|
|
end
|
|
|
|
|
2013-06-14 14:54:02 -04:00
|
|
|
end # Mutation
|
|
|
|
end # Runner
|
|
|
|
end # Mutant
|