free_mutant/lib/mutant/runner.rb

85 lines
1.6 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2018-09-12 13:15:43 +00:00
2012-08-14 22:45:34 +02:00
module Mutant
2013-04-20 20:50:36 +02:00
# Runner baseclass
2012-08-14 22:45:34 +02:00
class Runner
2014-07-17 13:59:25 +00:00
include Adamantium::Flat, Concord.new(:env), Procto.call(:result)
# Initialize object
#
# @return [undefined]
2014-10-23 11:37:53 +00:00
def initialize(*)
super
reporter.start(env)
2014-12-09 00:10:31 +00:00
run_mutation_analysis
end
# Final result
2014-12-09 00:10:31 +00:00
#
# @return [Result::Env]
attr_reader :result
private
# Run mutation analysis
#
2015-07-03 15:24:31 +00:00
# @return [undefined]
2014-12-09 00:10:31 +00:00
def run_mutation_analysis
@result = run_driver(Parallel.async(mutation_test_config))
reporter.report(result)
2014-12-09 00:10:31 +00:00
end
2014-12-09 00:10:31 +00:00
# Run driver
#
# @param [Driver] driver
#
# @return [Object]
# the last returned status payload
def run_driver(driver)
2014-10-23 11:37:53 +00:00
status = nil
2015-11-21 22:02:51 +00:00
sleep = env.config.kernel.method(:sleep)
2014-07-17 13:59:25 +00:00
2014-10-23 11:37:53 +00:00
loop do
2014-12-09 00:10:31 +00:00
status = driver.status
2014-10-23 11:37:53 +00:00
reporter.progress(status)
2014-12-09 00:10:31 +00:00
break if status.done
2015-11-21 22:02:51 +00:00
sleep.call(reporter.delay)
end
2014-12-09 00:10:31 +00:00
driver.stop
2014-07-17 13:59:25 +00:00
2014-12-09 00:10:31 +00:00
status.payload
2014-07-17 13:59:25 +00:00
end
2015-11-18 15:06:22 -08:00
# Configuration for parallel execution engine
2014-07-17 13:59:25 +00:00
#
2015-07-06 21:36:39 +03:00
# @return [Parallel::Config]
2014-12-09 00:10:31 +00:00
def mutation_test_config
Parallel::Config.new(
2014-12-22 18:04:41 +00:00
env: env.actor_env,
2014-12-09 00:10:31 +00:00
jobs: config.jobs,
processor: env.method(:kill),
sink: Sink.new(env),
source: Parallel::Source::Array.new(env.mutations)
2014-12-09 00:10:31 +00:00
)
end
# Reporter to use
#
2014-10-23 11:37:53 +00:00
# @return [Reporter]
def reporter
env.config.reporter
end
# Config for this mutant execution
#
# @return [Config]
def config
env.config
end
2013-06-14 20:54:02 +02:00
end # Runner
end # Mutant