Skip to content

Commit

Permalink
Change to optional warning display
Browse files Browse the repository at this point in the history
  • Loading branch information
mbj committed Mar 2, 2024
1 parent 1ccc566 commit f763dc5
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 11 deletions.
9 changes: 9 additions & 0 deletions lib/mutant/cli/command/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Environment < self
add_runner_options
add_integration_options
add_matcher_options
add_reporter_options
].freeze

private
Expand Down Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions lib/mutant/reporter/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand All @@ -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

Expand Down Expand Up @@ -51,7 +52,7 @@ def delay
#
# @return [self]
def warn(message)
output.puts(message)
output.puts(message) if print_warnings
self
end

Expand Down
54 changes: 54 additions & 0 deletions spec/unit/mutant/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

{
Expand Down Expand Up @@ -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

{
Expand Down Expand Up @@ -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

{
Expand Down Expand Up @@ -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'

Expand Down
22 changes: 15 additions & 7 deletions spec/unit/mutant/reporter/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit f763dc5

Please sign in to comment.