diff --git a/Changelog.md b/Changelog.md index 39e8d5fb9..688f0e375 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,8 @@ +# v0.11.29 [unreleased] + +* [#1421](https://github.com/mbj/mutant/pull/1421) + Change to optional warning display via --print-warnings environment option. + # v0.11.28 2024-02-09 * [#1418](https://github.com/mbj/mutant/pull/1418) diff --git a/Gemfile.lock b/Gemfile.lock index d078e25ec..75ab00a30 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - mutant (0.11.28) + mutant (0.11.29) diff-lcs (~> 1.3) parser (~> 3.3.0) regexp_parser (~> 2.9.0) @@ -44,7 +44,7 @@ GEM diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.13.0) rspec-support (3.13.1) - rubocop (1.60.2) + rubocop (1.61.0) json (~> 2.3) language_server-protocol (>= 3.17.0) parallel (~> 1.10) @@ -55,10 +55,10 @@ GEM rubocop-ast (>= 1.30.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.30.0) - parser (>= 3.2.1.0) + rubocop-ast (1.31.1) + parser (>= 3.3.0.4) ruby-progressbar (1.13.0) - sorbet-runtime (0.5.11268) + sorbet-runtime (0.5.11284) unicode-display_width (2.5.0) unparser (0.6.13) diff-lcs (~> 1.3) diff --git a/lib/mutant/cli/command/environment.rb b/lib/mutant/cli/command/environment.rb index 2da5bb25e..cc1aa7a86 100644 --- a/lib/mutant/cli/command/environment.rb +++ b/lib/mutant/cli/command/environment.rb @@ -3,6 +3,7 @@ module Mutant module CLI class Command + # rubocop:disable Metrics/ClassLength class Environment < self NAME = 'environment' SHORT_DESCRIPTION = 'Environment subcommands' @@ -13,6 +14,7 @@ class Environment < self add_runner_options add_integration_options add_matcher_options + add_reporter_options ].freeze private @@ -126,7 +128,16 @@ def add_runner_options(parser) set(mutation: @config.mutation.with(timeout: Float(number))) end end + + def add_reporter_options(parser) + parser.separator('Reporting:') + + parser.on('--print-warnings', 'Print warnings') do + set(reporter: @config.reporter.with(print_warnings: true)) + end + end end # Run + # rubocop:enable Metrics/ClassLength end # Command end # CLI end # Mutant diff --git a/lib/mutant/reporter/cli.rb b/lib/mutant/reporter/cli.rb index d8e52bc7e..066079cc4 100644 --- a/lib/mutant/reporter/cli.rb +++ b/lib/mutant/reporter/cli.rb @@ -4,7 +4,7 @@ module Mutant class Reporter # Reporter that reports in human readable format class CLI < self - include Anima.new(:output, :format) + include Anima.new(:print_warnings, :output, :format) # Build reporter # @@ -13,8 +13,9 @@ class CLI < self # @return [Reporter::CLI] def self.build(output) new( - format: Format::Progressive.new(tty: output.respond_to?(:tty?) && output.tty?), - output: output + format: Format::Progressive.new(tty: output.respond_to?(:tty?) && output.tty?), + print_warnings: false, + output: output ) end @@ -51,7 +52,7 @@ def delay # # @return [self] def warn(message) - output.puts(message) + output.puts(message) if print_warnings self end diff --git a/lib/mutant/version.rb b/lib/mutant/version.rb index 1671962d5..11371a55d 100644 --- a/lib/mutant/version.rb +++ b/lib/mutant/version.rb @@ -2,5 +2,5 @@ module Mutant # Current mutant version - VERSION = '0.11.28' + VERSION = '0.11.29' end # Mutant diff --git a/spec/unit/mutant/cli_spec.rb b/spec/unit/mutant/cli_spec.rb index 90ce4cf31..9801472f9 100644 --- a/spec/unit/mutant/cli_spec.rb +++ b/spec/unit/mutant/cli_spec.rb @@ -320,6 +320,10 @@ def self.main_body --ignore-subject EXPRESSION Ignore subjects that match EXPRESSION as prefix --start-subject EXPRESSION Start mutation testing at a specific subject --since REVISION Only select subjects touched since REVISION + + + Reporting: + --print-warnings Print warnings MESSAGE { @@ -370,6 +374,10 @@ def self.main_body --ignore-subject EXPRESSION Ignore subjects that match EXPRESSION as prefix --start-subject EXPRESSION Start mutation testing at a specific subject --since REVISION Only select subjects touched since REVISION + + + Reporting: + --print-warnings Print warnings MESSAGE { @@ -420,6 +428,10 @@ def self.main_body --ignore-subject EXPRESSION Ignore subjects that match EXPRESSION as prefix --start-subject EXPRESSION Start mutation testing at a specific subject --since REVISION Only select subjects touched since REVISION + + + Reporting: + --print-warnings Print warnings MESSAGE { @@ -864,6 +876,48 @@ def self.main_body end end + context 'environment subject list --print-warnings' do + include_context 'environment' + + let(:arguments) { %w[environment subject list --print-warnings] } + + let(:expected_exit) { true } + + let(:expected_events) do + [ + %i[ + record + config + ], + [ + :load_config, + { + cli_config: expected_cli_config.with( + reporter: expected_cli_config.reporter.with(print_warnings: true) + ), + world: world + }.inspect + ], + [ + :bootstrap, + Mutant::Env.empty(world, bootstrap_config).inspect + ], + [ + :stdout, + :puts, + 'Subjects in environment: 1' + ], + [ + :stdout, + :puts, + 'Object#send' + ] + ] + end + + include_examples 'CLI run' + end + context 'environment subject list' do include_context 'environment' diff --git a/spec/unit/mutant/reporter/cli_spec.rb b/spec/unit/mutant/reporter/cli_spec.rb index e34a6d493..a0c47d177 100644 --- a/spec/unit/mutant/reporter/cli_spec.rb +++ b/spec/unit/mutant/reporter/cli_spec.rb @@ -3,9 +3,9 @@ RSpec.describe Mutant::Reporter::CLI do setup_shared_context - let(:format) { described_class::Format::Progressive.new(tty: tty?) } - let(:object) { described_class.new(format: format, output: output) } - let(:tty?) { false } + let(:format) { described_class::Format::Progressive.new(tty: tty?) } + let(:object) { described_class.new(format: format, output: output, print_warnings: false) } + let(:tty?) { false } def contents output.rewind @@ -26,18 +26,18 @@ def self.it_reports(expected_content) let(:tty?) { true } let(:output) { instance_double(IO, tty?: true) } - it { should eql(described_class.new(format: format, output: output)) } + it { should eql(described_class.new(format: format, output: output, print_warnings: false)) } end context 'when output is not a tty' do context 'and does not respond to #tty?' do let(:output) { nil } - it { should eql(described_class.new(format: format, output: output)) } + it { should eql(described_class.new(format: format, output: output, print_warnings: false)) } end context 'and does respond to #tty?' do - it { should eql(described_class.new(format: format, output: output)) } + it { should eql(described_class.new(format: format, output: output, print_warnings: false)) } end end end @@ -47,7 +47,15 @@ def self.it_reports(expected_content) let(:message) { 'message' } - it_reports("message\n") + context 'when print warnings is disabled' do + it_reports('') + end + + context 'when print warnings is enabled' do + let(:object) { super().with(print_warnings: true) } + + it_reports("message\n") + end end describe '#delay' do diff --git a/test_app/Gemfile.minitest.lock b/test_app/Gemfile.minitest.lock index 40027a1a7..5004d54ab 100644 --- a/test_app/Gemfile.minitest.lock +++ b/test_app/Gemfile.minitest.lock @@ -1,15 +1,15 @@ PATH remote: .. specs: - mutant (0.11.28) + mutant (0.11.29) diff-lcs (~> 1.3) parser (~> 3.3.0) regexp_parser (~> 2.9.0) sorbet-runtime (~> 0.5.0) unparser (~> 0.6.9) - mutant-minitest (0.11.28) + mutant-minitest (0.11.29) minitest (~> 5.11) - mutant (= 0.11.28) + mutant (= 0.11.29) GEM remote: https://oss:Px2ENN7S91OmWaD5G7MIQJi1dmtmYrEh@gem.mutant.dev/ diff --git a/test_app/Gemfile.rspec3.8.lock b/test_app/Gemfile.rspec3.8.lock index a097790d5..8cbc8bd74 100644 --- a/test_app/Gemfile.rspec3.8.lock +++ b/test_app/Gemfile.rspec3.8.lock @@ -1,14 +1,14 @@ PATH remote: .. specs: - mutant (0.11.28) + mutant (0.11.29) diff-lcs (~> 1.3) parser (~> 3.3.0) regexp_parser (~> 2.9.0) sorbet-runtime (~> 0.5.0) unparser (~> 0.6.9) - mutant-rspec (0.11.28) - mutant (= 0.11.28) + mutant-rspec (0.11.29) + mutant (= 0.11.29) rspec-core (>= 3.8.0, < 4.0.0) GEM