2012-08-16 04:09:14 +02:00
|
|
|
module Mutant
|
|
|
|
# Represent a mutated node with its subject
|
|
|
|
class Mutation
|
2013-07-28 19:04:42 +02:00
|
|
|
include AbstractType, Adamantium::Flat
|
|
|
|
include Concord::Public.new(:subject, :node)
|
2012-08-29 13:33:47 +02:00
|
|
|
|
2014-05-11 14:30:02 +00:00
|
|
|
CODE_DELIMITER = "\0".freeze
|
|
|
|
CODE_RANGE = (0..4).freeze
|
|
|
|
|
2012-08-16 04:09:14 +02:00
|
|
|
# Return mutated root node
|
|
|
|
#
|
2013-06-04 10:25:13 +02:00
|
|
|
# @return [Parser::AST::Node]
|
2012-08-16 04:09:14 +02:00
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def root
|
2012-10-26 11:24:29 +02:00
|
|
|
subject.root(node)
|
2012-08-16 04:09:14 +02:00
|
|
|
end
|
|
|
|
memoize :root
|
|
|
|
|
|
|
|
# Insert mutated node
|
|
|
|
#
|
2013-07-28 12:16:45 -07: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 22:20:48 +02:00
|
|
|
#
|
2012-08-16 04:09:14 +02:00
|
|
|
# @return [self]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def insert
|
2013-06-23 22:20:48 +02:00
|
|
|
subject.public?
|
2014-04-22 19:02:33 +00:00
|
|
|
Loader::Eval.call(root, subject)
|
2012-08-16 04:09:14 +02:00
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
# Return identification
|
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def identification
|
2014-05-11 14:38:07 +00:00
|
|
|
"#{self.class::SYMBOL}:#{subject.identification}:#{code}"
|
2012-08-29 13:33:47 +02:00
|
|
|
end
|
2014-05-11 14:38:07 +00:00
|
|
|
memoize :identification
|
2012-08-29 13:33:47 +02:00
|
|
|
|
|
|
|
# Return mutation code
|
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def code
|
2014-05-11 14:30:02 +00:00
|
|
|
sha1[CODE_RANGE]
|
2012-08-16 04:09:14 +02:00
|
|
|
end
|
2012-08-29 13:33:47 +02:00
|
|
|
memoize :code
|
2012-08-16 04:09:14 +02:00
|
|
|
|
|
|
|
# Return source
|
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def source
|
2013-06-21 23:52:57 +02:00
|
|
|
Unparser.unparse(node)
|
2012-08-16 04:09:14 +02:00
|
|
|
end
|
|
|
|
memoize :source
|
|
|
|
|
|
|
|
# Return original source
|
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def original_source
|
2012-08-20 17:53:41 +02:00
|
|
|
subject.source
|
2012-08-16 04:09:14 +02:00
|
|
|
end
|
|
|
|
|
2014-07-03 21:16:12 +00:00
|
|
|
# Test if mutation is killed by test report
|
|
|
|
#
|
|
|
|
# @param [Report::Test] test_report
|
2014-04-28 19:17:25 +00:00
|
|
|
#
|
|
|
|
# @return [Boolean]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2014-07-03 21:16:12 +00:00
|
|
|
def killed_by?(test_report)
|
|
|
|
self.class::SHOULD_PASS.equal?(test_report.passed)
|
2014-04-28 19:17:25 +00:00
|
|
|
end
|
|
|
|
|
2013-09-14 01:01:11 +02:00
|
|
|
private
|
|
|
|
|
|
|
|
# Return sha1 sum of source and subject identification
|
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def sha1
|
2014-05-11 14:30:02 +00:00
|
|
|
Digest::SHA1.hexdigest(subject.identification + CODE_DELIMITER + source)
|
2013-09-14 01:01:11 +02:00
|
|
|
end
|
|
|
|
memoize :sha1
|
|
|
|
|
2014-07-03 21:16:12 +00:00
|
|
|
# Evil mutation that should case mutations to fail tests
|
|
|
|
class Evil < self
|
|
|
|
|
|
|
|
SHOULD_PASS = false
|
|
|
|
SYMBOL = 'evil'.freeze
|
|
|
|
|
|
|
|
end # Evil
|
|
|
|
|
|
|
|
# Neutral mutation that should not cause mutations to fail tests
|
|
|
|
class Neutral < self
|
|
|
|
|
|
|
|
SYMBOL = 'neutral'.freeze
|
|
|
|
SHOULD_PASS = true
|
|
|
|
|
|
|
|
end # Neutral
|
|
|
|
|
|
|
|
# Noop mutation, special case of neutral
|
|
|
|
class Noop < self
|
|
|
|
|
|
|
|
SYMBOL = 'noop'.freeze
|
|
|
|
SHOULD_PASS = true
|
|
|
|
|
|
|
|
end # Noop
|
|
|
|
|
2013-06-04 10:25:13 +02:00
|
|
|
end # Mutation
|
|
|
|
end # Mutant
|