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-03 17:16:12 -04:00
|
|
|
include Adamantium, 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-03 17:16:12 -04:00
|
|
|
@stop = false
|
2013-07-14 19:17:15 -04:00
|
|
|
|
2014-07-03 17:16:12 -04:00
|
|
|
config.integration.setup
|
2013-07-14 19:17:15 -04:00
|
|
|
|
2014-07-03 17:16:12 -04:00
|
|
|
progress(env)
|
2012-08-14 16:45:34 -04:00
|
|
|
|
2014-07-14 10:04:08 -04:00
|
|
|
@result = Result::Env.compute do
|
|
|
|
{
|
|
|
|
env: env,
|
|
|
|
subject_results: visit_collection(env.subjects, &method(:run_subject))
|
|
|
|
}
|
|
|
|
end
|
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
|
|
|
|
|
|
|
|
# Run subject
|
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-03 17:16:12 -04:00
|
|
|
def run_subject(subject)
|
2014-07-14 10:04:08 -04:00
|
|
|
Result::Subject.compute do
|
|
|
|
{
|
|
|
|
subject: subject,
|
|
|
|
mutation_results: visit_collection(subject.mutations, &method(:run_mutation))
|
|
|
|
}
|
|
|
|
end
|
2013-01-15 17:46:05 -05:00
|
|
|
end
|
|
|
|
|
2014-07-03 17:16:12 -04:00
|
|
|
# Run mutation
|
2013-07-14 19:17:15 -04:00
|
|
|
#
|
2014-07-14 09:55:18 -04:00
|
|
|
# @param [Mutation]
|
|
|
|
#
|
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
|
|
|
|
{
|
|
|
|
mutation: mutation,
|
|
|
|
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|
|
|
|
|
results << result = run_mutation_test(mutation, test).tap(&method(:progress))
|
|
|
|
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
|
|
|
# Visit collection
|
2013-03-27 10:52:02 -04:00
|
|
|
#
|
2014-07-03 17:16:12 -04:00
|
|
|
# @return [Array<Result>]
|
2013-03-27 10:52:02 -04:00
|
|
|
#
|
|
|
|
# @api private
|
2013-04-17 23:31:21 -04:00
|
|
|
#
|
2014-07-03 17:16:12 -04:00
|
|
|
def visit_collection(collection)
|
2014-07-14 09:55:18 -04:00
|
|
|
collection.each_with_object([]) do |item, results|
|
2014-07-03 17:16:12 -04:00
|
|
|
progress(item)
|
|
|
|
start = Time.now
|
|
|
|
results << result = yield(item).update(runtime: Time.now - start).tap(&method(:progress))
|
2014-07-14 09:55:18 -04:00
|
|
|
return results if @stop ||= config.fail_fast? && result.fail?
|
2014-07-03 17:16:12 -04:00
|
|
|
end
|
|
|
|
end
|
2012-08-14 16:45:34 -04:00
|
|
|
|
2014-07-03 17:16:12 -04:00
|
|
|
# Report progress
|
2013-04-20 14:50:36 -04:00
|
|
|
#
|
|
|
|
# @param [Object] object
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2014-05-12 09:48:15 -04:00
|
|
|
def progress(object)
|
2014-07-03 17:16:12 -04:00
|
|
|
config.reporter.progress(object)
|
2013-04-20 14:50:36 -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-06 09:50:54 -04:00
|
|
|
end.update(test: test, mutation: mutation)
|
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-07 10:07:47 -04:00
|
|
|
test: test,
|
|
|
|
mutation: mutation,
|
|
|
|
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
|