2013-07-28 19:03:06 -04:00
|
|
|
# encoding: utf-8
|
|
|
|
|
2012-08-15 22:09:14 -04:00
|
|
|
module Mutant
|
|
|
|
# Represent a mutated node with its subject
|
|
|
|
class Mutation
|
2013-07-28 13:04:42 -04:00
|
|
|
include AbstractType, Adamantium::Flat
|
|
|
|
include Concord::Public.new(:subject, :node)
|
2012-08-29 07:33:47 -04:00
|
|
|
|
2014-05-11 10:30:02 -04:00
|
|
|
CODE_DELIMITER = "\0".freeze
|
|
|
|
CODE_RANGE = (0..4).freeze
|
|
|
|
|
2012-08-15 22:09:14 -04:00
|
|
|
# Return mutated root node
|
|
|
|
#
|
2013-06-04 04:25:13 -04:00
|
|
|
# @return [Parser::AST::Node]
|
2012-08-15 22:09:14 -04:00
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def root
|
2012-10-26 05:24:29 -04:00
|
|
|
subject.root(node)
|
2012-08-15 22:09:14 -04:00
|
|
|
end
|
|
|
|
memoize :root
|
|
|
|
|
2013-01-15 17:46:05 -05:00
|
|
|
# Test if killer is successful
|
|
|
|
#
|
|
|
|
# @param [Killer] killer
|
|
|
|
#
|
|
|
|
# @return [true]
|
|
|
|
# if killer is successful
|
|
|
|
#
|
|
|
|
# @return [false]
|
|
|
|
# otherwise
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
abstract_method :success?
|
|
|
|
|
2012-08-15 22:09:14 -04:00
|
|
|
# Insert mutated node
|
|
|
|
#
|
2013-07-28 15:16:45 -04:00
|
|
|
# FIXME: Cache subject visibility in a better way! Ideally dont mutate it
|
|
|
|
# implicitly. Also subject.public? should NOT be a public interface it
|
|
|
|
# is a detail of method mutations.
|
2013-06-23 16:20:48 -04:00
|
|
|
#
|
2012-08-15 22:09:14 -04:00
|
|
|
# @return [self]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def insert
|
2013-06-23 16:20:48 -04:00
|
|
|
subject.public?
|
2014-04-22 15:02:33 -04:00
|
|
|
Loader::Eval.call(root, subject)
|
2012-08-15 22:09:14 -04:00
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
# Return identification
|
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def identification
|
2012-08-29 07:33:47 -04:00
|
|
|
"#{subject.identification}:#{code}"
|
|
|
|
end
|
|
|
|
|
|
|
|
# Return mutation code
|
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def code
|
2014-05-11 10:30:02 -04:00
|
|
|
sha1[CODE_RANGE]
|
2012-08-15 22:09:14 -04:00
|
|
|
end
|
2012-08-29 07:33:47 -04:00
|
|
|
memoize :code
|
2012-08-15 22:09:14 -04:00
|
|
|
|
|
|
|
# Return source
|
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def source
|
2013-06-21 17:52:57 -04:00
|
|
|
Unparser.unparse(node)
|
2012-08-15 22:09:14 -04:00
|
|
|
end
|
|
|
|
memoize :source
|
|
|
|
|
|
|
|
# Return original source
|
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def original_source
|
2012-08-20 11:53:41 -04:00
|
|
|
subject.source
|
2012-08-15 22:09:14 -04:00
|
|
|
end
|
|
|
|
|
2014-04-28 15:17:25 -04:00
|
|
|
# Test if test should fail under mutation
|
|
|
|
#
|
|
|
|
# @return [Boolean]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def should_fail?
|
|
|
|
self.class::SHOULD_FAIL
|
|
|
|
end
|
|
|
|
|
2013-09-13 19:01:11 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
# Return sha1 sum of source and subject identification
|
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def sha1
|
2014-05-11 10:30:02 -04:00
|
|
|
Digest::SHA1.hexdigest(subject.identification + CODE_DELIMITER + source)
|
2013-09-13 19:01:11 -04:00
|
|
|
end
|
|
|
|
memoize :sha1
|
|
|
|
|
2013-06-04 04:25:13 -04:00
|
|
|
end # Mutation
|
|
|
|
end # Mutant
|