From f763dc50456e042dfc438b37966194880dfdd526 Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Sat, 2 Mar 2024 16:14:22 +0000 Subject: [PATCH] Change to optional warning display --- lib/mutant/cli/command/environment.rb | 9 +++++ lib/mutant/reporter/cli.rb | 9 +++-- spec/unit/mutant/cli_spec.rb | 54 +++++++++++++++++++++++++++ spec/unit/mutant/reporter/cli_spec.rb | 22 +++++++---- 4 files changed, 83 insertions(+), 11 deletions(-) diff --git a/lib/mutant/cli/command/environment.rb b/lib/mutant/cli/command/environment.rb index 2da5bb25e..5c2807c85 100644 --- a/lib/mutant/cli/command/environment.rb +++ b/lib/mutant/cli/command/environment.rb @@ -13,6 +13,7 @@ class Environment < self add_runner_options add_integration_options add_matcher_options + add_reporter_options ].freeze private @@ -126,6 +127,14 @@ 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 end # Command end # CLI 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/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