2012-07-26 19:25:23 +02:00
|
|
|
module Mutant
|
2012-11-21 22:28:08 +01:00
|
|
|
# Subject of a mutation
|
2012-08-01 18:34:03 +02:00
|
|
|
class Subject
|
2013-07-28 19:05:17 +02:00
|
|
|
include AbstractType, Adamantium::Flat, Enumerable
|
2014-07-03 21:16:12 +00:00
|
|
|
include Concord::Public.new(:config, :context, :node)
|
2012-07-26 19:25:23 +02:00
|
|
|
|
2013-07-15 01:17:15 +02:00
|
|
|
# Return mutations
|
2012-07-26 19:25:23 +02:00
|
|
|
#
|
2013-07-15 01:17:15 +02:00
|
|
|
# @return [Enumerable<Mutation>]
|
2014-07-03 21:16:12 +00:00
|
|
|
# @return [undefined]
|
2012-12-11 00:17:19 +01:00
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2013-07-15 01:17:15 +02:00
|
|
|
def mutations
|
2014-07-05 23:32:07 +00:00
|
|
|
mutations = [neutral_mutation]
|
2013-07-15 01:17:15 +02:00
|
|
|
generate_mutations(mutations)
|
|
|
|
mutations
|
2012-12-11 00:17:19 +01:00
|
|
|
end
|
2013-07-15 01:17:15 +02:00
|
|
|
memoize :mutations
|
2012-12-11 00:17:19 +01:00
|
|
|
|
2012-12-14 19:53:37 +01:00
|
|
|
# Return source path
|
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def source_path
|
|
|
|
context.source_path
|
|
|
|
end
|
|
|
|
|
2014-07-03 21:16:12 +00:00
|
|
|
# Return tests for mutation
|
|
|
|
#
|
|
|
|
# @return [Array<Test>]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def tests
|
|
|
|
match_expressions.each do |match_expression|
|
|
|
|
tests = config.integration.all_tests.select do |test|
|
|
|
|
match_expression.prefix?(test.expression)
|
|
|
|
end
|
|
|
|
return tests if tests.any?
|
|
|
|
end
|
|
|
|
|
|
|
|
EMPTY_ARRAY
|
|
|
|
end
|
|
|
|
memoize :tests
|
|
|
|
|
2014-03-14 21:34:21 +00:00
|
|
|
# Prepare the subject for the insertion of mutation
|
|
|
|
#
|
|
|
|
# @return [self]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def prepare
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
2012-12-14 19:53:37 +01:00
|
|
|
# Return source line
|
|
|
|
#
|
|
|
|
# @return [Fixnum]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def source_line
|
2013-06-14 20:23:46 +02:00
|
|
|
node.location.expression.line
|
2012-12-14 19:53:37 +01:00
|
|
|
end
|
|
|
|
|
2013-06-22 23:08:32 -07:00
|
|
|
# Return subject identification
|
2012-07-26 19:25:23 +02:00
|
|
|
#
|
2012-08-16 04:10:54 +02:00
|
|
|
# @return [String]
|
2012-07-26 19:25:23 +02:00
|
|
|
#
|
|
|
|
# @api private
|
2012-07-31 04:10:37 +02:00
|
|
|
#
|
2012-08-16 04:10:54 +02:00
|
|
|
def identification
|
2014-06-28 20:47:46 +00:00
|
|
|
"#{expression.syntax}:#{source_path}:#{source_line}"
|
2012-07-26 19:25:23 +02:00
|
|
|
end
|
2012-08-16 04:10:54 +02:00
|
|
|
memoize :identification
|
2012-07-26 19:25:23 +02:00
|
|
|
|
2012-08-16 04:10:54 +02:00
|
|
|
# Return source representation of ast
|
2012-08-14 12:27:56 +02:00
|
|
|
#
|
2013-06-21 23:52:57 +02:00
|
|
|
# @return [String]
|
2012-08-14 12:27:56 +02:00
|
|
|
#
|
|
|
|
# @api private
|
2013-04-17 20:31:21 -07:00
|
|
|
#
|
2012-08-16 04:10:54 +02:00
|
|
|
def source
|
2013-06-21 23:52:57 +02:00
|
|
|
Unparser.unparse(node)
|
2012-08-14 12:27:56 +02:00
|
|
|
end
|
2012-08-16 04:10:54 +02:00
|
|
|
memoize :source
|
2012-08-14 12:27:56 +02:00
|
|
|
|
2013-08-04 18:49:42 +02:00
|
|
|
# Return match expression
|
2013-01-13 22:25:49 +01:00
|
|
|
#
|
2014-06-28 20:47:46 +00:00
|
|
|
# @return [Expression]
|
2013-01-13 22:25:49 +01:00
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2014-06-28 20:47:46 +00:00
|
|
|
abstract_method :expression
|
2013-08-04 18:49:42 +02:00
|
|
|
|
2014-06-28 20:47:46 +00:00
|
|
|
# Return match expressions
|
2013-08-04 18:49:42 +02:00
|
|
|
#
|
2014-06-28 20:47:46 +00:00
|
|
|
# @return [Enumerable<Expression>]
|
2013-08-04 18:49:42 +02:00
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2014-10-08 15:16:05 +00:00
|
|
|
abstract_method :match_expressions
|
2013-08-04 18:49:42 +02:00
|
|
|
|
|
|
|
private
|
2013-01-13 22:25:49 +01:00
|
|
|
|
2013-07-05 00:54:50 +02:00
|
|
|
# Return neutral mutation
|
|
|
|
#
|
|
|
|
# @return [Mutation::Neutral]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2014-07-05 23:32:07 +00:00
|
|
|
def neutral_mutation
|
|
|
|
Mutation::Neutral.new(self, node)
|
2013-07-05 00:54:50 +02:00
|
|
|
end
|
|
|
|
|
2013-07-15 01:17:15 +02:00
|
|
|
# Generate mutations
|
|
|
|
#
|
|
|
|
# @param [#<<] emitter
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2014-07-05 23:32:07 +00:00
|
|
|
def generate_mutations(emitter)
|
|
|
|
Mutator.each(node) do |mutant|
|
|
|
|
emitter << Mutation::Evil.new(self, mutant)
|
|
|
|
end
|
|
|
|
end
|
2013-07-15 01:17:15 +02:00
|
|
|
|
2013-06-04 10:25:13 +02:00
|
|
|
end # Subject
|
|
|
|
end # Mutant
|