diff --git a/Changelog.md b/Changelog.md index df2bd4e73..bc9bdefd7 100644 --- a/Changelog.md +++ b/Changelog.md @@ -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*'`. diff --git a/lib/mutant.rb b/lib/mutant.rb index 6d7feed5b..25b8d303c 100644 --- a/lib/mutant.rb +++ b/lib/mutant.rb @@ -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' diff --git a/lib/mutant/cli/command/environment.rb b/lib/mutant/cli/command/environment.rb index d1e19cd3b..66c879001 100644 --- a/lib/mutant/cli/command/environment.rb +++ b/lib/mutant/cli/command/environment.rb @@ -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 diff --git a/lib/mutant/cli/command/environment/subject.rb b/lib/mutant/cli/command/environment/subject.rb index a5925579d..634f727b3 100644 --- a/lib/mutant/cli/command/environment/subject.rb +++ b/lib/mutant/cli/command/environment/subject.rb @@ -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 diff --git a/lib/mutant/cli/command/environment/test.rb b/lib/mutant/cli/command/environment/test.rb new file mode 100644 index 000000000..c6b0bb3da --- /dev/null +++ b/lib/mutant/cli/command/environment/test.rb @@ -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 diff --git a/lib/mutant/cli/command/root.rb b/lib/mutant/cli/command/root.rb index 741848858..949ebf2ff 100644 --- a/lib/mutant/cli/command/root.rb +++ b/lib/mutant/cli/command/root.rb @@ -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 diff --git a/spec/unit/mutant/cli_spec.rb b/spec/unit/mutant/cli_spec.rb index 04caa2ea1..428be9e24 100644 --- a/spec/unit/mutant/cli_spec.rb +++ b/spec/unit/mutant/cli_spec.rb @@ -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( @@ -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', @@ -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' @@ -467,6 +510,7 @@ def self.main_body include_examples 'CLI run' end end + context 'environment show' do include_context 'environment' @@ -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