2018-09-12 14:21:24 +00:00
|
|
|
# frozen_string_literal: true
|
2018-09-12 13:15:43 +00:00
|
|
|
|
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
|
|
|
|
|
2015-07-03 15:21:39 +00:00
|
|
|
# Identification string
|
2012-08-16 04:09:14 +02:00
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
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
|
|
|
|
2015-07-03 15:21:39 +00:00
|
|
|
# Mutation code
|
2012-08-29 13:33:47 +02:00
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
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
|
|
|
|
2015-07-03 15:21:39 +00:00
|
|
|
# Normalized mutation source
|
2012-08-16 04:09:14 +02:00
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
def source
|
2013-06-21 23:52:57 +02:00
|
|
|
Unparser.unparse(node)
|
2012-08-16 04:09:14 +02:00
|
|
|
end
|
|
|
|
memoize :source
|
|
|
|
|
2015-07-03 15:21:39 +00:00
|
|
|
# Normalized original source
|
2012-08-16 04:09:14 +02:00
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
def original_source
|
2012-08-20 17:53:41 +02:00
|
|
|
subject.source
|
2012-08-16 04:09:14 +02:00
|
|
|
end
|
|
|
|
|
2014-10-23 11:37:53 +00:00
|
|
|
# Test if mutation is killed by test reports
|
2014-07-03 21:16:12 +00:00
|
|
|
#
|
2015-12-21 00:28:27 +00:00
|
|
|
# @param [Result::Test] test_result
|
2014-04-28 19:17:25 +00:00
|
|
|
#
|
|
|
|
# @return [Boolean]
|
2014-11-27 16:34:08 +00:00
|
|
|
def self.success?(test_result)
|
|
|
|
self::TEST_PASS_SUCCESS.equal?(test_result.passed)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Insert mutated node
|
2014-10-23 11:37:53 +00:00
|
|
|
#
|
2015-11-21 22:02:51 +00:00
|
|
|
# @param kernel [Kernel]
|
|
|
|
#
|
2014-11-27 16:34:08 +00:00
|
|
|
# @return [self]
|
2015-11-21 22:02:51 +00:00
|
|
|
def insert(kernel)
|
2014-11-27 16:34:08 +00:00
|
|
|
subject.prepare
|
2015-11-21 22:02:51 +00:00
|
|
|
Loader.call(
|
|
|
|
binding: TOPLEVEL_BINDING,
|
|
|
|
kernel: kernel,
|
|
|
|
node: root,
|
|
|
|
subject: subject
|
|
|
|
)
|
2014-11-27 16:34:08 +00:00
|
|
|
self
|
|
|
|
end
|
2013-09-14 01:01:11 +02:00
|
|
|
|
2014-12-22 15:42:21 +00:00
|
|
|
private
|
|
|
|
|
2015-07-03 15:21:39 +00:00
|
|
|
# SHA1 sum of source and subject identification
|
2013-09-14 01:01:11 +02:00
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
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
|
|
|
|
|
2015-07-03 15:21:39 +00:00
|
|
|
# Mutated root node
|
2014-11-17 20:31:12 +00:00
|
|
|
#
|
|
|
|
# @return [Parser::AST::Node]
|
|
|
|
def root
|
2014-11-17 21:40:39 +00:00
|
|
|
subject.context.root(node)
|
2014-11-17 20:31:12 +00:00
|
|
|
end
|
|
|
|
|
2014-07-03 21:16:12 +00:00
|
|
|
# Evil mutation that should case mutations to fail tests
|
|
|
|
class Evil < self
|
|
|
|
|
2014-11-27 16:34:08 +00:00
|
|
|
SYMBOL = 'evil'.freeze
|
|
|
|
TEST_PASS_SUCCESS = false
|
2014-07-03 21:16:12 +00:00
|
|
|
|
|
|
|
end # Evil
|
|
|
|
|
|
|
|
# Neutral mutation that should not cause mutations to fail tests
|
|
|
|
class Neutral < self
|
|
|
|
|
2014-11-27 16:34:08 +00:00
|
|
|
SYMBOL = 'neutral'.freeze
|
|
|
|
TEST_PASS_SUCCESS = true
|
2014-07-03 21:16:12 +00:00
|
|
|
|
|
|
|
end # Neutral
|
|
|
|
|
|
|
|
# Noop mutation, special case of neutral
|
2014-10-23 11:37:53 +00:00
|
|
|
class Noop < Neutral
|
2014-07-03 21:16:12 +00:00
|
|
|
|
2014-11-27 16:34:08 +00:00
|
|
|
SYMBOL = 'noop'.freeze
|
|
|
|
TEST_PASS_SUCCESS = true
|
2014-07-03 21:16:12 +00:00
|
|
|
|
|
|
|
end # Noop
|
|
|
|
|
2013-06-04 10:25:13 +02:00
|
|
|
end # Mutation
|
|
|
|
end # Mutant
|