free_mutant/lib/mutant/env.rb
Markus Schirp 3cea008fcd Fix Matcher env arguments
* Due historical reasons Env#warn also existed and in specs we actually
  passed an Env object where runtime passes Env::Boostrap objects.
* Fix documentation for runtime type
* Fix specs to pass in the runtime type
* Remove now unused Env#warn
2015-11-16 01:07:31 +00:00

64 lines
1.4 KiB
Ruby

module Mutant
# Abstract base class for mutant environments
class Env
include Adamantium::Flat, Anima.new(
:config,
:actor_env,
:parser,
:subjects,
:matchable_scopes,
:integration,
:selector,
:mutations
)
SEMANTICS_MESSAGE =
"Fix your lib to follow normal ruby semantics!\n" \
'{Module,Class}#name should return resolvable constant name as String or nil'.freeze
# Kill mutation
#
# @param [Mutation] mutation
#
# @return [Result::Mutation]
#
# @api private
def kill(mutation)
test_result = run_mutation_tests(mutation)
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
#
# @api private
def run_mutation_tests(mutation)
start = Time.now
tests = selector.call(mutation.subject)
config.isolation.call do
mutation.insert
integration.call(tests)
end
rescue Isolation::Error => error
Result::Test.new(
tests: tests,
output: error.message,
runtime: Time.now - start,
passed: false
)
end
end # Env
end # Mutant