2012-08-14 16:45:34 -04:00
|
|
|
module Mutant
|
2013-04-20 14:50:36 -04:00
|
|
|
# Runner baseclass
|
2012-08-14 16:45:34 -04:00
|
|
|
class Runner
|
2014-07-17 09:59:25 -04:00
|
|
|
include Adamantium::Flat, Concord.new(:env), Procto.call(:result)
|
2013-07-14 19:17:15 -04:00
|
|
|
|
2014-07-03 17:16:12 -04:00
|
|
|
# Initialize object
|
2013-07-14 19:17:15 -04:00
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2014-07-03 17:16:12 -04:00
|
|
|
def initialize(env)
|
|
|
|
super
|
2013-07-14 19:17:15 -04:00
|
|
|
|
2014-07-17 09:59:25 -04:00
|
|
|
@collector = Collector.new(env)
|
|
|
|
@mutex = Mutex.new
|
|
|
|
@mutations = env.mutations.dup
|
2013-07-14 19:17:15 -04:00
|
|
|
|
2014-07-03 17:16:12 -04:00
|
|
|
config.integration.setup
|
2014-08-10 18:09:29 -04:00
|
|
|
|
|
|
|
config.reporter.start(env)
|
|
|
|
|
2014-07-17 09:59:25 -04:00
|
|
|
run
|
2013-07-14 19:17:15 -04:00
|
|
|
|
2014-07-17 09:59:25 -04:00
|
|
|
@result = @collector.result.update(done: true)
|
2014-07-16 11:26:47 -04:00
|
|
|
|
|
|
|
config.reporter.report(result)
|
2014-05-27 10:42:15 -04:00
|
|
|
end
|
|
|
|
|
2014-07-03 17:16:12 -04:00
|
|
|
# Return result
|
2012-11-21 16:28:08 -05:00
|
|
|
#
|
2014-07-03 17:16:12 -04:00
|
|
|
# @return [Result::Env]
|
2012-11-21 16:28:08 -05:00
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2014-07-03 17:16:12 -04:00
|
|
|
attr_reader :result
|
2012-11-21 16:28:08 -05:00
|
|
|
|
2014-07-03 17:16:12 -04:00
|
|
|
private
|
|
|
|
|
2014-07-17 09:59:25 -04:00
|
|
|
# Run mutation analysis
|
2012-08-16 13:26:15 -04:00
|
|
|
#
|
2014-07-03 17:16:12 -04:00
|
|
|
# @return [Report::Subject]
|
2012-08-16 13:26:15 -04:00
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2014-07-17 09:59:25 -04:00
|
|
|
def run
|
|
|
|
Parallel.map(
|
|
|
|
@mutations,
|
2014-09-24 15:16:39 -04:00
|
|
|
in_threads: config.jobs,
|
|
|
|
finish: method(:finish),
|
|
|
|
start: method(:start),
|
2014-07-17 09:59:25 -04:00
|
|
|
&method(:run_mutation)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Handle started mutation
|
|
|
|
#
|
|
|
|
# @param [Mutation] mutation
|
|
|
|
# @param [Fixnum] _index
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def start(mutation, _index)
|
|
|
|
@mutex.synchronize do
|
|
|
|
@collector.start(mutation)
|
2014-07-14 10:04:08 -04:00
|
|
|
end
|
2013-01-15 17:46:05 -05:00
|
|
|
end
|
|
|
|
|
2014-07-17 09:59:25 -04:00
|
|
|
# Handle finished mutation
|
|
|
|
#
|
|
|
|
# @param [Mutation] mutation
|
|
|
|
# @param [Fixnum] index
|
|
|
|
# @param [Object] result
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def finish(mutation, index, result)
|
|
|
|
return unless result.kind_of?(Mutant::Result::Mutation)
|
|
|
|
|
|
|
|
test_results = result.test_results.zip(mutation.subject.tests).map do |test_result, test|
|
|
|
|
test_result.update(test: test, mutation: mutation) if test_result
|
|
|
|
end.compact
|
|
|
|
|
|
|
|
@mutex.synchronize do
|
|
|
|
process_result(result.update(index: index, mutation: mutation, test_results: test_results))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Process result
|
|
|
|
#
|
|
|
|
# @param [Result::Mutation] result
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def process_result(result)
|
|
|
|
@collector.finish(result)
|
|
|
|
config.reporter.progress(@collector)
|
|
|
|
handle_exit(result)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Handle exit if needed
|
|
|
|
#
|
2014-08-12 19:20:34 -04:00
|
|
|
# @param [Result::Mutation] result
|
2014-07-17 09:59:25 -04:00
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def handle_exit(result)
|
|
|
|
return if !config.fail_fast || result.success?
|
|
|
|
|
|
|
|
@mutations.clear
|
|
|
|
end
|
|
|
|
|
2014-07-03 17:16:12 -04:00
|
|
|
# Run mutation
|
2013-07-14 19:17:15 -04:00
|
|
|
#
|
2014-07-17 09:59:25 -04:00
|
|
|
# @param [Mutation] mutation
|
2014-07-14 09:55:18 -04:00
|
|
|
#
|
2014-07-03 17:16:12 -04:00
|
|
|
# @return [Report::Mutation]
|
2013-07-14 19:17:15 -04:00
|
|
|
#
|
2013-07-15 04:47:44 -04:00
|
|
|
# @api private
|
|
|
|
#
|
2014-07-03 17:16:12 -04:00
|
|
|
def run_mutation(mutation)
|
2014-07-14 10:04:08 -04:00
|
|
|
Result::Mutation.compute do
|
|
|
|
{
|
2014-07-17 09:59:25 -04:00
|
|
|
index: nil,
|
|
|
|
mutation: nil,
|
2014-07-14 10:04:08 -04:00
|
|
|
test_results: kill_mutation(mutation)
|
|
|
|
}
|
|
|
|
end
|
2013-07-14 19:17:15 -04:00
|
|
|
end
|
|
|
|
|
2014-07-14 09:55:18 -04:00
|
|
|
# Kill mutation
|
|
|
|
#
|
|
|
|
# @param [Mutation] mutation
|
|
|
|
#
|
|
|
|
# @return [Array<Result::Test>]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def kill_mutation(mutation)
|
|
|
|
mutation.subject.tests.each_with_object([]) do |test, results|
|
2014-07-17 09:59:25 -04:00
|
|
|
results << result = run_mutation_test(mutation, test)
|
2014-07-14 09:55:18 -04:00
|
|
|
return results if mutation.killed_by?(result)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-07-03 17:16:12 -04:00
|
|
|
# Return config
|
2013-04-20 20:20:18 -04:00
|
|
|
#
|
2014-07-03 17:16:12 -04:00
|
|
|
# @return [Config]
|
2013-04-20 20:20:18 -04:00
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2014-07-03 17:16:12 -04:00
|
|
|
def config
|
|
|
|
env.config
|
2013-04-20 20:20:18 -04:00
|
|
|
end
|
|
|
|
|
2014-07-03 17:16:12 -04:00
|
|
|
# Return test result
|
2013-07-14 19:17:15 -04:00
|
|
|
#
|
2014-07-03 17:16:12 -04:00
|
|
|
# @return [Report::Test]
|
2013-07-14 19:17:15 -04:00
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2014-07-03 17:16:12 -04:00
|
|
|
def run_mutation_test(mutation, test)
|
2014-07-07 10:07:47 -04:00
|
|
|
time = Time.now
|
2014-07-05 22:11:31 -04:00
|
|
|
config.isolation.call do
|
2014-07-03 17:16:12 -04:00
|
|
|
mutation.insert
|
|
|
|
test.run
|
2014-07-17 09:59:25 -04:00
|
|
|
end
|
2014-07-07 10:07:47 -04:00
|
|
|
rescue Isolation::Error => exception
|
2014-07-03 17:16:12 -04:00
|
|
|
Result::Test.new(
|
2014-07-17 09:59:25 -04:00
|
|
|
test: nil,
|
|
|
|
mutation: nil,
|
2014-07-07 10:07:47 -04:00
|
|
|
runtime: Time.now - time,
|
|
|
|
output: exception.message,
|
|
|
|
passed: false
|
2014-07-03 17:16:12 -04:00
|
|
|
)
|
2013-07-14 19:17:15 -04:00
|
|
|
end
|
|
|
|
|
2013-06-14 14:54:02 -04:00
|
|
|
end # Runner
|
|
|
|
end # Mutant
|