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 23, 2023
1 parent 1d3fda7 commit 9bb122d
Show file tree
Hide file tree
Showing 20 changed files with 502 additions and 42 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ source 'https://rubygems.org'

gemspec name: 'mutant'

gem 'rspec-core', path: '../rspec-core'

eval_gemfile 'Gemfile.shared'
10 changes: 7 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
PATH
remote: ../rspec-core
specs:
rspec-core (3.12.1)
rspec-support (~> 3.12.0)

PATH
remote: .
specs:
Expand Down Expand Up @@ -33,8 +39,6 @@ GEM
rspec-core (~> 3.12.0)
rspec-expectations (~> 3.12.0)
rspec-mocks (~> 3.12.0)
rspec-core (3.12.2)
rspec-support (~> 3.12.0)
rspec-expectations (3.12.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
Expand Down Expand Up @@ -74,7 +78,7 @@ DEPENDENCIES
mutant-license!
parallel (~> 1.3)
rspec (~> 3.10)
rspec-core (~> 3.10)
rspec-core!
rspec-its (~> 1.3.0)
rubocop (~> 1.7)

Expand Down
1 change: 1 addition & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ integration:
# Below shows an example configuring rspec to use a static seed from the config file.
arguments:
- --fail-fast # rspec integration default, keep this when specifying manual options!
- --force-color # rspec integration default, keep this if colored output is not an issue for you
- --seed # option
- '0' # option value, needs to be a string.
- spec # rspec integration default, tell rspec integration where to find specs
Expand Down
3 changes: 3 additions & 0 deletions lib/mutant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,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 Expand Up @@ -243,6 +245,7 @@ module Mutant
require 'mutant/reporter/cli/printer/mutation_result'
require 'mutant/reporter/cli/printer/status_progressive'
require 'mutant/reporter/cli/printer/subject_result'
require 'mutant/reporter/cli/printer/test'
require 'mutant/reporter/cli/format'
require 'mutant/repository'
require 'mutant/repository/diff'
Expand Down
28 changes: 25 additions & 3 deletions lib/mutant/bootstrap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ module Bootstrap
# @param [Env] env
#
# @return [Either<String, Env>]
#
# rubocop:disable Metrics/MethodLength
def self.call(env)
env.record(:bootstrap) do
env = load_hooks(env)
Expand All @@ -47,6 +45,31 @@ def self.call(env)
selected_subjects.flat_map(&:mutations)
end

setup_integration(
env: env,
mutations: mutations,
selected_subjects: selected_subjects
)
end
end

# Run test only bootstrap
#
# @param [Env] env
#
# @return [Either<String, Env>]
def self.call_test(env)
env.record(:bootstrap) do
setup_integration(
env: load_hooks(env),
mutations: [],
selected_subjects: []
)
end
end

def self.setup_integration(env:, mutations:, selected_subjects:)
env.record(__method__) do
Integration.setup(env).fmap do |integration|
env.with(
integration: integration,
Expand All @@ -57,7 +80,6 @@ def self.call(env)
end
end
end
# rubocop:enable Metrics/MethodLength

def self.load_hooks(env)
env.record(__method__) do
Expand Down
24 changes: 23 additions & 1 deletion lib/mutant/cli/command/environment/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ class Test < self
NAME = 'test'
SHORT_DESCRIPTION = 'test subcommands'

private

def bootstrap
env = Env.empty(world, @config)

env
.record(:config) { Config.load(cli_config: @config, world: world) }
.bind { |config| Bootstrap.call_test(env.with(config: config)) }
end

class List < self
NAME = 'list'
SHORT_DESCRIPTION = 'List tests detected in the environment'
Expand All @@ -28,7 +38,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
6 changes: 5 additions & 1 deletion lib/mutant/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ module Mutant

# Abstract base class mutant test framework integrations
class Integration
include AbstractType, Adamantium, Anima.new(:arguments, :expression_parser, :world)
include AbstractType, Adamantium, Anima.new(
:arguments,
:expression_parser,
:world
)

LOAD_MESSAGE = <<~'MESSAGE'
Unable to load integration mutant-%<integration_name>s:
Expand Down
5 changes: 3 additions & 2 deletions lib/mutant/integration/rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Rspec < self
ALL_EXPRESSION = Expression::Namespace::Recursive.new(scope_name: nil)
EXPRESSION_CANDIDATE = /\A([^ ]+)(?: )?/.freeze
EXIT_SUCCESS = 0
DEFAULT_CLI_OPTIONS = %w[--fail-fast spec].freeze
DEFAULT_CLI_OPTIONS = %w[--fail-fast --force-color spec].freeze
TEST_ID_FORMAT = 'rspec:%<index>d:%<location>s/%<description>s'

private_constant(*constants(false))
Expand All @@ -42,7 +42,7 @@ def initialize(*)
#
# @return [self]
def setup
@runner.setup($stderr, $stdout)
@runner.setup(world.stderr, world.stdout)
example_group_map
reset_examples
self
Expand All @@ -55,6 +55,7 @@ def setup
#
# @return [Result::Test]
def call(tests)
reset_examples
setup_examples(tests.map(&all_tests_index))
start = timer.now
passed = @runner.run_specs(@rspec_world.ordered_example_groups).equal?(EXIT_SUCCESS)
Expand Down
28 changes: 28 additions & 0 deletions lib/mutant/reporter/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ def start(env)
self
end

# Report test start
#
# @param [Env] env
#
# @return [self]
def test_start(env)
write(format.test_start(env))
self
end

# Report progress object
#
# @param [Parallel::Status] status
Expand All @@ -38,6 +48,14 @@ def progress(status)
self
end

# Report progress object
#
# @return [self]
def test_progress(status)
write(format.test_progress(status))
self
end

# Report delay in seconds
#
# @return [Float]
Expand Down Expand Up @@ -65,6 +83,16 @@ def report(env)
self
end

# Report env
#
# @param [Result::Env] env
#
# @return [self]
def test_report(env)
Printer::Test::EnvResult.call(output: output, object: env)
self
end

private

def write(frame)
Expand Down
21 changes: 19 additions & 2 deletions lib/mutant/reporter/cli/format.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ class Format

# Progress representation
#
# @param [Runner::Status] status
#
# @return [String]
abstract_method :progress

# Progress representation
#
# @return [String]
abstract_method :test_progress

# Report delay in seconds
#
# @return [Float]
Expand Down Expand Up @@ -69,13 +72,27 @@ def start(env)
format(Printer::Env, env)
end

# Test start representation
#
# @return [String]
def test_start(env)
format(Printer::Test::Env, env)
end

# Progress representation
#
# @return [String]
def progress(status)
format(Printer::StatusProgressive, status)
end

# Progress representation
#
# @return [String]
def test_progress(status)
format(Printer::Test::StatusProgressive, status)
end

private

def new_buffer
Expand Down
Loading

0 comments on commit 9bb122d

Please sign in to comment.