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 identification
|
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
def identification
|
2014-05-11 10:38:07 -04:00
|
|
|
"#{self.class::SYMBOL}:#{subject.identification}:#{code}"
|
2012-08-29 07:33:47 -04:00
|
|
|
end
|
2014-05-11 10:38:07 -04:00
|
|
|
memoize :identification
|
2012-08-29 07:33:47 -04:00
|
|
|
|
|
|
|
# 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-10-23 07:37:53 -04:00
|
|
|
# Test if mutation is killed by test reports
|
2014-07-03 17:16:12 -04:00
|
|
|
#
|
2014-10-23 07:37:53 -04:00
|
|
|
# @param [Array<Report::Test>] test_reports
|
2014-04-28 15:17:25 -04:00
|
|
|
#
|
|
|
|
# @return [Boolean]
|
|
|
|
#
|
|
|
|
# @api private
|
2014-11-27 11:34:08 -05:00
|
|
|
def self.success?(test_result)
|
|
|
|
self::TEST_PASS_SUCCESS.equal?(test_result.passed)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Insert mutated node
|
2014-10-23 07:37:53 -04:00
|
|
|
#
|
2014-11-27 11:34:08 -05: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.
|
|
|
|
#
|
|
|
|
# @return [self]
|
2014-10-23 07:37:53 -04:00
|
|
|
#
|
|
|
|
# @api private
|
2014-11-27 11:34:08 -05:00
|
|
|
def insert
|
|
|
|
subject.public?
|
|
|
|
subject.prepare
|
|
|
|
Loader::Eval.call(root, subject)
|
|
|
|
self
|
|
|
|
end
|
2013-09-13 19:01:11 -04:00
|
|
|
|
2014-12-22 10:42:21 -05:00
|
|
|
private
|
|
|
|
|
2013-09-13 19:01:11 -04:00
|
|
|
# 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
|
|
|
|
|
2014-11-17 15:31:12 -05:00
|
|
|
# Return mutated root node
|
|
|
|
#
|
|
|
|
# @return [Parser::AST::Node]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
def root
|
2014-11-17 16:40:39 -05:00
|
|
|
subject.context.root(node)
|
2014-11-17 15:31:12 -05:00
|
|
|
end
|
|
|
|
|
2014-07-03 17:16:12 -04:00
|
|
|
# Evil mutation that should case mutations to fail tests
|
|
|
|
class Evil < self
|
|
|
|
|
2014-11-27 11:34:08 -05:00
|
|
|
SYMBOL = 'evil'.freeze
|
|
|
|
TEST_PASS_SUCCESS = false
|
2014-07-03 17:16:12 -04:00
|
|
|
|
|
|
|
end # Evil
|
|
|
|
|
|
|
|
# Neutral mutation that should not cause mutations to fail tests
|
|
|
|
class Neutral < self
|
|
|
|
|
2014-11-27 11:34:08 -05:00
|
|
|
SYMBOL = 'neutral'.freeze
|
|
|
|
TEST_PASS_SUCCESS = true
|
2014-07-03 17:16:12 -04:00
|
|
|
|
|
|
|
end # Neutral
|
|
|
|
|
|
|
|
# Noop mutation, special case of neutral
|
2014-10-23 07:37:53 -04:00
|
|
|
class Noop < Neutral
|
2014-07-03 17:16:12 -04:00
|
|
|
|
2014-11-27 11:34:08 -05:00
|
|
|
SYMBOL = 'noop'.freeze
|
|
|
|
TEST_PASS_SUCCESS = true
|
2014-07-03 17:16:12 -04:00
|
|
|
|
|
|
|
end # Noop
|
|
|
|
|
2013-06-04 04:25:13 -04:00
|
|
|
end # Mutation
|
|
|
|
end # Mutant
|