2014-07-03 17:16:12 -04:00
|
|
|
module Mutant
|
|
|
|
# Namespace and mixon module for results
|
|
|
|
module Result
|
|
|
|
|
|
|
|
# Coverage mixin
|
|
|
|
module Coverage
|
2015-07-21 16:08:55 -04:00
|
|
|
FULL_COVERAGE = Rational(1).freeze
|
|
|
|
private_constant(*constants(false))
|
2014-07-03 17:16:12 -04:00
|
|
|
|
2015-07-03 11:21:39 -04:00
|
|
|
# Observed coverage
|
2014-07-03 17:16:12 -04:00
|
|
|
#
|
|
|
|
# @return [Rational]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
def coverage
|
2015-07-21 16:08:55 -04:00
|
|
|
if amount_mutation_results.zero?
|
|
|
|
FULL_COVERAGE
|
|
|
|
else
|
|
|
|
Rational(amount_mutations_killed, amount_mutation_results)
|
|
|
|
end
|
2014-07-03 17:16:12 -04:00
|
|
|
end
|
2014-07-11 18:27:24 -04:00
|
|
|
end # Coverage
|
2014-07-03 17:16:12 -04:00
|
|
|
|
|
|
|
# Class level mixin
|
|
|
|
module ClassMethods
|
|
|
|
|
2014-07-10 18:56:01 -04:00
|
|
|
# Generate a sum method from name and collection
|
2014-07-03 17:16:12 -04:00
|
|
|
#
|
|
|
|
# @param [Symbol] name
|
|
|
|
# the attribute name on collection item and method name to use
|
|
|
|
#
|
|
|
|
# @param [Symbol] collection
|
|
|
|
# the attribute name used to receive collection
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
def sum(name, collection)
|
|
|
|
define_method(name) do
|
|
|
|
public_send(collection).map(&name).reduce(0, :+)
|
|
|
|
end
|
2014-12-07 15:42:10 -05:00
|
|
|
memoize(name)
|
2014-07-03 17:16:12 -04:00
|
|
|
end
|
2014-07-11 18:27:24 -04:00
|
|
|
end # ClassMethods
|
|
|
|
|
2015-07-21 16:08:55 -04:00
|
|
|
private_constant(*constants(false))
|
|
|
|
|
2015-07-03 11:21:39 -04:00
|
|
|
# Mutant overhead running mutatet tests
|
|
|
|
#
|
|
|
|
# This is NOT the overhead of mutation testing, just an engine specific
|
|
|
|
# measurement for the efficiency of the parellelization engine, kill
|
|
|
|
# isolation etc.
|
2014-07-03 17:16:12 -04:00
|
|
|
#
|
|
|
|
# @return [Float]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
def overhead
|
|
|
|
runtime - killtime
|
|
|
|
end
|
|
|
|
|
|
|
|
# Hook called when module gets included
|
|
|
|
#
|
2014-08-07 12:00:31 -04:00
|
|
|
# @param [Class, Module] host
|
2014-07-03 17:16:12 -04:00
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
def self.included(host)
|
|
|
|
host.class_eval do
|
2014-10-23 07:37:53 -04:00
|
|
|
include Adamantium, Anima::Update
|
2014-07-03 17:16:12 -04:00
|
|
|
extend ClassMethods
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Env result object
|
|
|
|
class Env
|
2014-10-07 20:10:58 -04:00
|
|
|
include Coverage, Result, Anima.new(:runtime, :env, :subject_results)
|
2014-07-03 17:16:12 -04:00
|
|
|
|
2014-07-17 09:59:25 -04:00
|
|
|
# Test if run is successful
|
2014-07-03 17:16:12 -04:00
|
|
|
#
|
|
|
|
# @return [Boolean]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
def success?
|
2015-03-05 23:46:03 -05:00
|
|
|
coverage.eql?(env.config.expected_coverage)
|
2014-07-03 17:16:12 -04:00
|
|
|
end
|
|
|
|
memoize :success?
|
|
|
|
|
2015-07-03 11:21:39 -04:00
|
|
|
# Failed subject results
|
2014-07-03 17:16:12 -04:00
|
|
|
#
|
|
|
|
# @return [Array<Result::Subject>]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
def failed_subject_results
|
|
|
|
subject_results.reject(&:success?)
|
|
|
|
end
|
|
|
|
|
2014-07-17 09:59:25 -04:00
|
|
|
sum :amount_mutation_results, :subject_results
|
2014-07-03 17:16:12 -04:00
|
|
|
sum :amount_mutations_alive, :subject_results
|
|
|
|
sum :amount_mutations_killed, :subject_results
|
|
|
|
sum :killtime, :subject_results
|
|
|
|
|
2015-07-03 11:21:39 -04:00
|
|
|
# Amount of mutations
|
2014-10-23 07:37:53 -04:00
|
|
|
#
|
|
|
|
# @return [Fixnum]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
def amount_mutations
|
|
|
|
env.mutations.length
|
|
|
|
end
|
|
|
|
|
2015-07-03 11:21:39 -04:00
|
|
|
# Amount of subjects
|
2014-07-03 17:16:12 -04:00
|
|
|
#
|
|
|
|
# @return [Fixnum]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
def amount_subjects
|
|
|
|
env.subjects.length
|
|
|
|
end
|
|
|
|
|
|
|
|
end # Env
|
|
|
|
|
|
|
|
# Test result
|
|
|
|
class Test
|
2014-08-11 02:52:10 -04:00
|
|
|
include Result, Anima.new(
|
2014-11-27 11:34:08 -05:00
|
|
|
:tests,
|
2014-07-03 17:16:12 -04:00
|
|
|
:output,
|
|
|
|
:passed,
|
|
|
|
:runtime
|
|
|
|
)
|
|
|
|
end # Test
|
|
|
|
|
|
|
|
# Subject result
|
|
|
|
class Subject
|
2014-12-22 12:54:18 -05:00
|
|
|
include Coverage, Result, Anima.new(:subject, :tests, :mutation_results)
|
2014-07-03 17:16:12 -04:00
|
|
|
|
|
|
|
sum :killtime, :mutation_results
|
2014-10-23 07:37:53 -04:00
|
|
|
sum :runtime, :mutation_results
|
2014-07-03 17:16:12 -04:00
|
|
|
|
|
|
|
# Test if subject was processed successful
|
|
|
|
#
|
|
|
|
# @return [Boolean]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
def success?
|
|
|
|
alive_mutation_results.empty?
|
|
|
|
end
|
|
|
|
|
2014-10-23 07:37:53 -04:00
|
|
|
# Test if runner should continue on subject
|
|
|
|
#
|
|
|
|
# @return [Boolean]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
def continue?
|
|
|
|
mutation_results.all?(&:success?)
|
|
|
|
end
|
|
|
|
|
2015-07-03 11:21:39 -04:00
|
|
|
# Killed mutations
|
2014-07-03 17:16:12 -04:00
|
|
|
#
|
|
|
|
# @return [Array<Result::Mutation>]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
def alive_mutation_results
|
|
|
|
mutation_results.reject(&:success?)
|
|
|
|
end
|
|
|
|
memoize :alive_mutation_results
|
|
|
|
|
2015-07-03 11:21:39 -04:00
|
|
|
# Amount of mutations
|
2014-07-17 09:59:25 -04:00
|
|
|
#
|
|
|
|
# @return [Fixnum]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
def amount_mutation_results
|
|
|
|
mutation_results.length
|
|
|
|
end
|
|
|
|
|
2015-07-03 11:21:39 -04:00
|
|
|
# Amount of mutations
|
2014-07-03 17:16:12 -04:00
|
|
|
#
|
|
|
|
# @return [Fixnum]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
def amount_mutations
|
|
|
|
subject.mutations.length
|
|
|
|
end
|
|
|
|
|
2015-07-03 11:21:39 -04:00
|
|
|
# Number of killed mutations
|
2014-07-03 17:16:12 -04:00
|
|
|
#
|
|
|
|
# @return [Fixnum]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
def amount_mutations_killed
|
|
|
|
killed_mutation_results.length
|
|
|
|
end
|
|
|
|
|
2015-07-03 11:21:39 -04:00
|
|
|
# Number of alive mutations
|
2014-07-03 17:16:12 -04:00
|
|
|
#
|
|
|
|
# @return [Fixnum]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
def amount_mutations_alive
|
2014-07-17 09:59:25 -04:00
|
|
|
alive_mutation_results.length
|
2014-07-03 17:16:12 -04:00
|
|
|
end
|
|
|
|
|
2015-07-03 11:21:39 -04:00
|
|
|
# Alive mutations
|
2014-07-03 17:16:12 -04:00
|
|
|
#
|
|
|
|
# @return [Array<Result::Mutation>]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
def killed_mutation_results
|
|
|
|
mutation_results.select(&:success?)
|
|
|
|
end
|
|
|
|
memoize :killed_mutation_results
|
|
|
|
|
|
|
|
end # Subject
|
|
|
|
|
|
|
|
# Mutation result
|
|
|
|
class Mutation
|
2014-12-07 16:51:53 -05:00
|
|
|
include Result, Anima.new(:mutation, :test_result)
|
2014-10-23 07:37:53 -04:00
|
|
|
|
2015-07-03 11:21:39 -04:00
|
|
|
# The runtime
|
2014-10-23 07:37:53 -04:00
|
|
|
#
|
2014-11-27 11:34:08 -05:00
|
|
|
# @return [Float]
|
2014-10-23 07:37:53 -04:00
|
|
|
#
|
|
|
|
# @api private
|
2014-11-27 11:34:08 -05:00
|
|
|
def runtime
|
|
|
|
test_result.runtime
|
2014-10-23 07:37:53 -04:00
|
|
|
end
|
2014-11-27 11:34:08 -05:00
|
|
|
|
|
|
|
alias_method :killtime, :runtime
|
2014-07-03 17:16:12 -04:00
|
|
|
|
2014-08-07 12:00:31 -04:00
|
|
|
# Test if mutation was handled successfully
|
2014-07-03 17:16:12 -04:00
|
|
|
#
|
|
|
|
# @return [Boolean]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
def success?
|
2014-11-27 11:34:08 -05:00
|
|
|
mutation.class.success?(test_result)
|
2014-07-03 17:16:12 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end # Mutation
|
|
|
|
end # Result
|
|
|
|
end # Mutant
|