free_mutant/lib/mutant/mutation.rb

118 lines
2.1 KiB
Ruby
Raw Normal View History

# 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-15 22:09:14 -04:00
# Return mutated root node
#
# @return [Parser::AST::Node]
2012-08-15 22:09:14 -04:00
#
# @api private
#
def root
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?
# Indicate if a killer should treat a kill as problematic
#
# @return [true]
# if killing is unexpected
#
# @return [false]
# if killing is expected
#
# @api private
#
abstract_method :should_survive?
2012-08-15 22:09:14 -04:00
# Insert mutated node
#
# 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?
Loader::Eval.run(root, subject)
2012-08-15 22:09:14 -04:00
self
end
# Return identification
#
# @return [String]
#
# @api private
#
def identification
"#{subject.identification}:#{code}"
end
memoize :identification
# Return mutation code
#
# @return [String]
#
# @api private
#
def code
sha1[0..4]
2012-08-15 22:09:14 -04:00
end
memoize :code
2012-08-15 22:09:14 -04:00
# Return sha1 sum of source and subject identification
2012-08-15 22:09:14 -04:00
#
# @return [String]
#
# @api private
#
def sha1
Digest::SHA1.hexdigest(subject.identification + 0.chr + source)
2012-08-15 22:09:14 -04:00
end
memoize :sha1
# Return source
#
# @return [String]
#
# @api private
#
def source
Unparser.unparse(node)
2012-08-15 22:09:14 -04:00
end
memoize :source
# Return original source
#
# @return [String]
#
# @api private
#
def original_source
subject.source
2012-08-15 22:09:14 -04:00
end
end # Mutation
end # Mutant