2013-07-28 19:03:06 -04:00
|
|
|
# encoding: utf-8
|
|
|
|
|
2012-11-21 18:10:50 -05:00
|
|
|
module Mutant
|
2013-01-04 16:16:03 -05:00
|
|
|
|
|
|
|
# Abstract base class for killing strategies
|
2013-04-17 23:31:21 -04:00
|
|
|
class Strategy
|
2014-01-17 18:25:16 -05:00
|
|
|
include AbstractType, Adamantium::Flat, Equalizer.new
|
2012-12-10 18:17:19 -05:00
|
|
|
|
2014-01-17 18:15:42 -05:00
|
|
|
REGISTRY = {}
|
|
|
|
|
|
|
|
# Lookup strategy for name
|
|
|
|
#
|
|
|
|
# @param [String] name
|
|
|
|
#
|
|
|
|
# @return [Strategy]
|
|
|
|
# if found
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def self.lookup(name)
|
|
|
|
REGISTRY.fetch(name)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Register strategy
|
|
|
|
#
|
|
|
|
# @param [String] name
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def self.register(name)
|
|
|
|
REGISTRY[name] = self
|
|
|
|
end
|
|
|
|
private_class_method :register
|
|
|
|
|
2013-07-17 13:59:44 -04:00
|
|
|
# Perform strategy setup
|
2012-12-10 18:17:19 -05:00
|
|
|
#
|
2013-01-15 17:46:05 -05:00
|
|
|
# @return [self]
|
2012-12-10 18:17:19 -05:00
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2013-07-17 13:59:44 -04:00
|
|
|
def setup
|
2013-09-02 16:02:51 -04:00
|
|
|
self
|
2012-12-10 18:17:19 -05:00
|
|
|
end
|
|
|
|
|
2013-07-17 13:59:44 -04:00
|
|
|
# Perform strategy teardown
|
2012-12-10 18:17:19 -05:00
|
|
|
#
|
2013-01-15 17:46:05 -05:00
|
|
|
# @return [self]
|
2012-12-10 18:17:19 -05:00
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2013-07-17 13:59:44 -04:00
|
|
|
def teardown
|
2013-09-02 16:02:51 -04:00
|
|
|
self
|
2012-12-10 18:17:19 -05:00
|
|
|
end
|
2012-11-21 18:10:50 -05:00
|
|
|
|
2014-04-28 15:17:25 -04:00
|
|
|
# Return all available tests by strategy
|
|
|
|
#
|
|
|
|
# @return [Enumerable<Test>]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
abstract_method :all_tests
|
|
|
|
|
|
|
|
# Return killers for mutation
|
2012-11-21 18:10:50 -05:00
|
|
|
#
|
2012-12-12 16:31:14 -05:00
|
|
|
# @param [Mutation] mutation
|
2012-11-21 18:10:50 -05:00
|
|
|
#
|
2014-04-28 15:17:25 -04:00
|
|
|
# @return [Enumerable<Killer>]
|
2012-11-21 18:10:50 -05:00
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2014-04-28 15:17:25 -04:00
|
|
|
def killers(mutation)
|
|
|
|
tests(mutation).map do |test|
|
|
|
|
Killer.new(
|
|
|
|
mutation: mutation,
|
|
|
|
test: test
|
|
|
|
)
|
|
|
|
end
|
2012-11-21 18:10:50 -05:00
|
|
|
end
|
|
|
|
|
2014-04-28 15:17:25 -04:00
|
|
|
# Return tests for mutation
|
2012-12-07 10:55:53 -05:00
|
|
|
#
|
2014-04-28 15:17:25 -04:00
|
|
|
# TODO: This logic is now centralized but still fucked.
|
|
|
|
#
|
|
|
|
# @param [Mutation] mutation
|
|
|
|
#
|
|
|
|
# @return [Enumerable<Test>]
|
2012-12-07 10:55:53 -05:00
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2014-04-28 15:17:25 -04:00
|
|
|
def tests(mutation)
|
|
|
|
mutation.subject.match_prefixes.map do |match_expression|
|
|
|
|
tests = all_tests.select do |test|
|
|
|
|
test.subject_identification.start_with?(match_expression)
|
|
|
|
end
|
|
|
|
return tests if tests.any?
|
|
|
|
end
|
|
|
|
|
|
|
|
[]
|
2012-11-21 18:10:50 -05:00
|
|
|
end
|
2013-06-14 14:54:02 -04:00
|
|
|
|
2014-04-28 15:17:25 -04:00
|
|
|
private
|
|
|
|
|
2014-01-17 18:15:42 -05:00
|
|
|
# Null strategy that never kills a mutation
|
|
|
|
class Null < self
|
|
|
|
|
2014-04-28 15:17:25 -04:00
|
|
|
register('null')
|
2014-01-17 18:15:42 -05:00
|
|
|
|
2014-04-28 15:17:25 -04:00
|
|
|
# Return all tests
|
|
|
|
#
|
|
|
|
# @return [Enumerable<Test>]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def all_tests
|
|
|
|
[]
|
|
|
|
end
|
2014-01-17 18:15:42 -05:00
|
|
|
|
|
|
|
end # Null
|
|
|
|
|
2013-06-14 14:54:02 -04:00
|
|
|
end # Strategy
|
|
|
|
end # Mutant
|