free_mutant/lib/mutant/subject.rb

154 lines
2.7 KiB
Ruby
Raw Normal View History

module Mutant
# Subject of a mutation
2012-08-01 12:34:03 -04:00
class Subject
2013-07-28 13:05:17 -04:00
include AbstractType, Adamantium::Flat, Enumerable
include Concord::Public.new(:config, :context, :node)
# Return mutations
#
# @return [Enumerable<Mutation>]
# @return [undefined]
#
# @api private
#
def mutations
2014-07-05 19:32:07 -04:00
mutations = [neutral_mutation]
generate_mutations(mutations)
mutations
end
memoize :mutations
# Return source path
#
# @return [String]
#
# @api private
#
def source_path
context.source_path
end
# Return tests for mutation
#
# TODO: This logic is now centralized but still fucked.
#
# @param [Mutation] 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
# Prepare the subject for the insertion of mutation
#
# @return [self]
#
# @api private
#
def prepare
self
end
# Return source line
#
# @return [Fixnum]
#
# @api private
#
def source_line
2013-06-14 14:23:46 -04:00
node.location.expression.line
end
2013-06-23 02:08:32 -04:00
# Return subject identification
#
# @return [String]
#
# @api private
#
def identification
"#{expression.syntax}:#{source_path}:#{source_line}"
end
memoize :identification
# Return source representation of ast
#
# @return [String]
#
# @api private
2013-04-17 23:31:21 -04:00
#
def source
Unparser.unparse(node)
end
memoize :source
2012-08-14 16:45:34 -04:00
# Return root AST for node
#
# @param [Parser::AST::Node] node
2012-08-14 16:45:34 -04:00
#
# @return [Parser::AST::Node]
2012-08-14 16:45:34 -04:00
#
# @api private
#
def root(node)
context.root(node)
end
# Return match expression
2013-01-13 16:25:49 -05:00
#
# @return [Expression]
2013-01-13 16:25:49 -05:00
#
# @api private
#
abstract_method :expression
# Return match expressions
#
# @return [Enumerable<Expression>]
#
# @api private
#
def match_expressions
[expression].concat(context.match_expressions)
end
memoize :match_expressions
private
2013-01-13 16:25:49 -05:00
# Return neutral mutation
#
# @return [Mutation::Neutral]
#
# @api private
#
2014-07-05 19:32:07 -04:00
def neutral_mutation
Mutation::Neutral.new(self, node)
end
# Generate mutations
#
# @param [#<<] emitter
#
# @return [undefined]
#
# @api private
#
2014-07-05 19:32:07 -04:00
def generate_mutations(emitter)
Mutator.each(node) do |mutant|
emitter << Mutation::Evil.new(self, mutant)
end
end
end # Subject
end # Mutant