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 a9ca732
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 23 deletions.
5 changes: 5 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
10 changes: 5 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions lib/mutant/cli/command/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
module Mutant
module CLI
class Command
# rubocop:disable Metrics/ClassLength
class Environment < self
NAME = 'environment'
SHORT_DESCRIPTION = 'Environment subcommands'
Expand All @@ -13,6 +14,7 @@ class Environment < self
add_runner_options
add_integration_options
add_matcher_options
add_reporter_options
].freeze

private
Expand Down Expand Up @@ -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
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
2 changes: 1 addition & 1 deletion lib/mutant/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

module Mutant
# Current mutant version
VERSION = '0.11.28'
VERSION = '0.11.29'
end # Mutant
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
6 changes: 3 additions & 3 deletions test_app/Gemfile.minitest.lock
Original file line number Diff line number Diff line change
@@ -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:[email protected]/
Expand Down
6 changes: 3 additions & 3 deletions test_app/Gemfile.rspec3.8.lock
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit a9ca732

Please sign in to comment.