Skip to content

Commit

Permalink
Add mutant environment test list subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
mbj committed Jan 4, 2021
1 parent db75441 commit 502a3b3
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 24 deletions.
6 changes: 6 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Unreleased

* [#1205](https://github.com/mbj/mutant/pull/1205)

* Add `mutant environment test list` subcommand.
Useful to verify which tests mutant detects as candiates for test selection.

* [#1204](https://github.com/mbj/mutant/pull/1204)

* Allow constants to be passed to minitst integrations `cover` declaration.
`cover SomeClass` is equivalent to `cover 'SomeClass*'`.

Expand Down
1 change: 1 addition & 0 deletions lib/mutant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ module Mutant
require 'mutant/cli/command/environment/run'
require 'mutant/cli/command/environment/show'
require 'mutant/cli/command/environment/subject'
require 'mutant/cli/command/environment/test'
require 'mutant/cli/command/root'
require 'mutant/runner'
require 'mutant/runner/sink'
Expand Down
4 changes: 4 additions & 0 deletions lib/mutant/cli/command/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ def add_runner_options(parser)
set(mutation_timeout: Float(number))
end
end

def print(message)
world.stdout.puts(message)
end
end # Run
end # Command
end # CLI
Expand Down
4 changes: 0 additions & 4 deletions lib/mutant/cli/command/environment/subject.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ def list_subjects(env)
print(subject.expression.syntax)
end
end

def print(message)
world.stdout.puts(message)
end
end

SUBCOMMANDS = [List].freeze
Expand Down
36 changes: 36 additions & 0 deletions lib/mutant/cli/command/environment/test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true

module Mutant
module CLI
class Command
class Environment
class Test < self
NAME = 'test'
SHORT_DESCRIPTION = 'test subcommands'

class List < self
NAME = 'list'
SHORT_DESCRIPTION = 'List tests detected in the environment'
SUBCOMMANDS = EMPTY_ARRAY

private

def action
bootstrap.fmap(&method(:list_tests))
end

def list_tests(env)
tests = env.integration.all_tests
print('Tests in environment: %d' % tests.length)
tests.each do |test|
print(test.identification)
end
end
end

SUBCOMMANDS = [List].freeze
end # Test
end # Environment
end # Command
end # CLI
end # Mutant
2 changes: 1 addition & 1 deletion lib/mutant/cli/command/root.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Mutant
module CLI
class Command
class Environment < self
SUBCOMMANDS = [Environment::Subject, Environment::Show].freeze
SUBCOMMANDS = [Environment::Subject, Environment::Show, Environment::Test].freeze
end # Environment

class Root < self
Expand Down
82 changes: 63 additions & 19 deletions spec/unit/mutant/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -344,26 +344,34 @@ def self.main_body
end

shared_context 'environment' do
let(:arguments) { %w[run] }
let(:bootstrap_config) { env_config.merge(file_config).expand_defaults }
let(:bootstrap_result) { MPrelude::Either::Right.new(env) }
let(:env_result) { instance_double(Mutant::Result::Env, success?: true) }
let(:expected_events) { [license_validation_event] }
let(:expected_exit) { true }
let(:file_config_result) { MPrelude::Either::Right.new(file_config) }
let(:license_result) { MPrelude::Either::Right.new(subscription) }
let(:runner_result) { MPrelude::Either::Right.new(env_result) }
let(:arguments) { %w[run] }
let(:bootstrap_config) { env_config.merge(file_config).expand_defaults }
let(:bootstrap_result) { MPrelude::Either::Right.new(env) }
let(:env_result) { instance_double(Mutant::Result::Env, success?: true) }
let(:expected_events) { [license_validation_event] }
let(:expected_exit) { true }
let(:file_config_result) { MPrelude::Either::Right.new(file_config) }
let(:license_result) { MPrelude::Either::Right.new(subscription) }
let(:runner_result) { MPrelude::Either::Right.new(env_result) }
let(:subject_a_expression) { parse_expression('Object#send') }
let(:subjects) { [subject_a] }
let(:tests) { [test_a, test_b] }

let(:test_a) { instance_double(Mutant::Test, identification: 'test-a') }
let(:test_b) { instance_double(Mutant::Test, identification: 'test-b') }

let(:env) do
config = Mutant::Config::DEFAULT.with(
reporter: Mutant::Reporter::CLI.build(stdout)
)

Mutant::Env.empty(world, config).with(subjects: subjects)
Mutant::Env.empty(world, config)
.with(
integration: instance_double(Mutant::Integration, all_tests: tests),
subjects: subjects
)
end

let(:subject_a_expression) { parse_expression('Object#send') }

let(:subject_a) do
Mutant::Subject::Method::Instance.new(
context: Mutant::Context.new(
Expand All @@ -374,12 +382,6 @@ def self.main_body
)
end

let(:subjects) do
[
subject_a
]
end

let(:file_config) do
Mutant::Config::DEFAULT.with(
integration: 'file-integration',
Expand Down Expand Up @@ -432,6 +434,47 @@ def self.main_body
end
end

context 'environment test list' do
include_context 'environment'

let(:arguments) { %w[environment test list] }

context 'without additional arguments' do
let(:expected_exit) { true }

let(:expected_events) do
[
[
:load_config_file,
world
],
[
:bootstrap,
world,
bootstrap_config.inspect
],
[
:stdout,
:puts,
'Tests in environment: 2'
],
[
:stdout,
:puts,
'test-a'
],
[
:stdout,
:puts,
'test-b'
]
]
end

include_examples 'CLI run'
end
end

context 'environment subject list' do
include_context 'environment'

Expand Down Expand Up @@ -467,6 +510,7 @@ def self.main_body
include_examples 'CLI run'
end
end

context 'environment show' do
include_context 'environment'

Expand All @@ -481,7 +525,7 @@ def self.main_body
Includes: []
Requires: []
Subjects: 1
Total-Tests: 0
Total-Tests: 2
Selected-Tests: 0
Tests/Subject: 0.00 avg
Mutations: 0
Expand Down

0 comments on commit 502a3b3

Please sign in to comment.