-
-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
130 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# frozen_string_literal: true | ||
|
||
module Mutant | ||
class Test | ||
module Runner | ||
# Run against env | ||
# | ||
# @return [Either<String, Result>] | ||
def self.call(env) | ||
reporter(env).start(env) | ||
|
||
Either::Right.new(run_tests(env)) | ||
end | ||
|
||
def self.run_tests(env) | ||
reporter = reporter(env) | ||
|
||
env | ||
.record(:tests) { run_driver(reporter, async_driver(env)) } | ||
.tap { |result| env.record(:report) { reporter.report(result) } } | ||
end | ||
private_class_method :run_tests | ||
|
||
def self.async_driver(env) | ||
Parallel.async(env.world, test_config(env)) | ||
end | ||
private_class_method :async_driver | ||
|
||
def self.run_driver(reporter, driver) | ||
Signal.trap('INT') do | ||
driver.stop | ||
end | ||
|
||
loop do | ||
status = driver.wait_timeout(reporter.delay) | ||
break status.payload if status.done? | ||
reporter.progress(status) | ||
end | ||
end | ||
private_class_method :run_driver | ||
|
||
def self.test_config(env) | ||
Parallel::Config.new( | ||
block: ->(index) { run_test_index(env, index) }, | ||
jobs: env.config.jobs, | ||
process_name: 'mutant-worker-process', | ||
sink: Sink.new(env), | ||
source: Parallel::Source::Array.new(jobs: env.integration.all_tests.each_index.to_a), | ||
thread_name: 'mutant-worker-thread' | ||
) | ||
end | ||
private_class_method :test_config | ||
|
||
def self.run_test_index(env, test_index) | ||
env.integration.call([env.integration.all_tests.fetch(test_index)]) | ||
end | ||
private_class_method :run_test_index | ||
|
||
def self.reporter(env) | ||
env.config.reporter | ||
end | ||
private_class_method :reporter | ||
|
||
end # Runner | ||
end # Test | ||
end # Mutant |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# frozen_string_literal: true | ||
|
||
module Mutant | ||
class Test | ||
module Runner | ||
class Sink | ||
include Concord.new(:env) | ||
|
||
# Initialize object | ||
# | ||
# @return [undefined] | ||
def initialize(*) | ||
super | ||
@start = env.world.timer.now | ||
@test_results = [] | ||
end | ||
|
||
# Runner status | ||
# | ||
# @return [Result::Env] | ||
def status | ||
Result::Env.new( | ||
env: env, | ||
runtime: env.world.timer.now - @start, | ||
subject_results: [] | ||
) | ||
end | ||
|
||
# Test if scheduling stopped | ||
# | ||
# @return [Boolean] | ||
def stop? | ||
@test_results.length.eql?(env.integration.all_tests.length) | ||
end | ||
|
||
# Handle mutation finish | ||
# | ||
# @return [self] | ||
def result(result) | ||
@test_results << result | ||
self | ||
end | ||
end # Sink | ||
end # Runner | ||
end # Test | ||
end # Mutant |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
while inotifywait ../unparser/**/*.rb **/*.rb Gemfile Gemfile.shared mutant.gemspec; do | ||
bundle exec rspec spec/unit -fd --fail-fast --order default \ | ||
&& bundle exec mutant run --since main --fail-fast --zombie -- 'Mutant*' \ | ||
&& bundle exec rubocop | ||
bundle exec mutant environment test run # \ | ||
## && bundle exec mutant run --since main --fail-fast --zombie -- 'Mutant*' \ | ||
## && bundle exec rubocop | ||
done |