free_mutant/lib/mutant/env.rb

61 lines
1.3 KiB
Ruby
Raw Normal View History

module Mutant
# Abstract base class for mutant environments
class Env
2015-09-04 20:20:56 +00:00
include Adamantium::Flat, Anima.new(
:actor_env,
:config,
:integration,
:matchable_scopes,
:mutations,
:parser,
:selector,
:subjects
)
2014-10-23 11:37:53 +00:00
SEMANTICS_MESSAGE =
"Fix your lib to follow normal ruby semantics!\n" \
'{Module,Class}#name should return resolvable constant name as String or nil'.freeze
2014-12-09 00:10:31 +00:00
# Kill mutation
#
# @param [Mutation] mutation
#
# @return [Result::Mutation]
def kill(mutation)
test_result = run_mutation_tests(mutation)
2014-12-09 00:10:31 +00:00
Result::Mutation.new(
mutation: mutation,
test_result: test_result
)
end
private
# Kill mutation under isolation with integration
#
# @param [Isolation] isolation
# @param [Integration] integration
#
# @return [Result::Test]
#
# rubocop:disable MethodLength
def run_mutation_tests(mutation)
start = Time.now
tests = selector.call(mutation.subject)
config.isolation.call do
2015-11-21 22:02:51 +00:00
mutation.insert(config.kernel)
integration.call(tests)
end
rescue Isolation::Error => error
Result::Test.new(
output: error.message,
passed: false,
runtime: Time.now - start,
tests: tests
)
end
end # Env
end # Mutant