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 Feb 1, 2024
1 parent 34a635e commit 2f44c81
Show file tree
Hide file tree
Showing 19 changed files with 511 additions and 26 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@ jobs:
ruby: ruby-3.1
- os: macos-latest
ruby: ruby-3.0
execution:
- bundle exec rspec spec/unit
- bundle exec mutant test run spec/unit
steps:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- run: bundle exec rspec spec/unit
- run: ${{ matrix.execution }}
ruby-mutant:
name: Mutation coverage
runs-on: ${{ matrix.os }}
Expand Down
14 changes: 7 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ GEM
remote: https://rubygems.org/
specs:
ast (2.4.2)
diff-lcs (1.5.0)
diff-lcs (1.5.1)
json (2.7.1)
language_server-protocol (3.17.0.3)
parallel (1.24.0)
parser (3.3.0.2)
parser (3.3.0.5)
ast (~> 2.4.1)
racc
racc (1.7.3)
Expand All @@ -44,11 +44,11 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-support (3.12.1)
rubocop (1.59.0)
rubocop (1.60.2)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.2.2.4)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
Expand All @@ -58,11 +58,11 @@ GEM
rubocop-ast (1.30.0)
parser (>= 3.2.1.0)
ruby-progressbar (1.13.0)
sorbet-runtime (0.5.11180)
sorbet-runtime (0.5.11222)
unicode-display_width (2.5.0)
unparser (0.6.12)
unparser (0.6.13)
diff-lcs (~> 1.3)
parser (>= 3.2.2.4)
parser (>= 3.3.0)

PLATFORMS
ruby
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
27 changes: 26 additions & 1 deletion lib/mutant/bootstrap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,32 @@ def self.call(env)
selected_subjects.flat_map(&:mutations)
end

setup_integration(
env: env,
mutations: mutations,
selected_subjects: selected_subjects
)
end
end
# rubocop:enable Metrics/MethodLength

# 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 +83,6 @@ def self.call(env)
end
end
end
# rubocop:enable Metrics/MethodLength

def self.load_hooks(env)
env.record(__method__) do
Expand Down
29 changes: 28 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,24 @@ def list_tests(env)
end
end

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

private

def parse_remaining_arguments(arguments)
arguments.each(&method(:add_integration_argument))
Either::Right.new(self)
end

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([^ ]+)(?: )?/
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 2f44c81

Please sign in to comment.