Skip to content

Commit

Permalink
Add test only runner
Browse files Browse the repository at this point in the history
  • Loading branch information
mbj committed Apr 24, 2023
1 parent e153741 commit 718a130
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 4 deletions.
2 changes: 2 additions & 0 deletions lib/mutant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ module Mutant
require 'mutant/expression/namespace'
require 'mutant/expression/parser'
require 'mutant/test'
require 'mutant/test/runner'
require 'mutant/test/runner/sink'
require 'mutant/timer'
require 'mutant/integration'
require 'mutant/integration/null'
Expand Down
14 changes: 13 additions & 1 deletion lib/mutant/cli/command/environment/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,19 @@ def list_tests(env)
end
end

SUBCOMMANDS = [List].freeze
class Run < self
NAME = 'run'
SHORT_DESCRIPTION = 'Run tests'
SUBCOMMANDS = EMPTY_ARRAY

private

def action
bootstrap.bind(&Mutant::Test::Runner.method(:call))
end
end

SUBCOMMANDS = [List, Run].freeze
end # Test
end # Environment
end # Command
Expand Down
66 changes: 66 additions & 0 deletions lib/mutant/test/runner.rb
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
46 changes: 46 additions & 0 deletions lib/mutant/test/runner/sink.rb
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
6 changes: 3 additions & 3 deletions scripts/devloop.sh
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

0 comments on commit 718a130

Please sign in to comment.