Skip to content

Commit ae1515e

Browse files
authored
Merge pull request #937 from mbj/improve/reporting
Add env details to start report
2 parents 69a7f96 + 7f63ac5 commit ae1515e

File tree

16 files changed

+190
-114
lines changed

16 files changed

+190
-114
lines changed

docs/mutant-minitest.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ bundle exec mutant --include lib --require auom --use minitest -- 'AUOM*'
6363
This prints a report like:
6464

6565
```sh
66-
Mutant configuration:
66+
Mutant environment:
6767
Matcher: #<Mutant::Matcher::Config match_expressions: [AUOM*]>
6868
Integration: Mutant::Integration::Minitest
6969
Jobs: 8

docs/mutant-rspec.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ bundle exec mutant --include lib --require auom --use rspec -- 'AUOM*'
3737
This prints a report like:
3838

3939
```sh
40-
Mutant configuration:
40+
Mutant environment:
4141
Matcher: #<Mutant::Matcher::Config match_expressions: [AUOM*]>
4242
Integration: Mutant::Integration::Rspec
4343
Jobs: 8

lib/mutant.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ module Mutant
169169
require 'mutant/reporter/cli'
170170
require 'mutant/reporter/cli/printer'
171171
require 'mutant/reporter/cli/printer/config'
172+
require 'mutant/reporter/cli/printer/env'
172173
require 'mutant/reporter/cli/printer/env_progress'
173174
require 'mutant/reporter/cli/printer/env_result'
174175
require 'mutant/reporter/cli/printer/isolation_result'

lib/mutant/env.rb

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,54 @@ def warn(message)
7474
self
7575
end
7676

77+
# Selected tests
78+
#
79+
# @return [Set<Test>]
80+
def selected_tests
81+
selections.values.flatten.to_set
82+
end
83+
memoize :selected_tests
84+
85+
# Amount of mutations
86+
#
87+
# @return [Integer]
88+
def amount_mutations
89+
mutations.length
90+
end
91+
memoize :amount_mutations
92+
93+
# Amount of tests reachable by integration
94+
#
95+
# @return [Integer]
96+
def amount_total_tests
97+
integration.all_tests.length
98+
end
99+
memoize :amount_total_tests
100+
101+
# Amount of selected subjects
102+
#
103+
# @return [Integer]
104+
def amount_subjects
105+
subjects.length
106+
end
107+
memoize :amount_subjects
108+
109+
# Amount of selected tests
110+
#
111+
# @return [Integer]
112+
def amount_selected_tests
113+
selected_tests.length
114+
end
115+
memoize :amount_selected_tests
116+
117+
# Ratio between selected tests and subjects
118+
#
119+
# @return [Rational]
120+
def test_subject_ratio
121+
Rational(amount_selected_tests, amount_subjects)
122+
end
123+
memoize :test_subject_ratio
124+
77125
private
78126

79127
# Kill mutation under isolation with integration

lib/mutant/reporter/cli/format.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class Progressive < self
7272
#
7373
# @return [String]
7474
def start(env)
75-
format(Printer::Config, env.config)
75+
format(Printer::Env, env)
7676
end
7777

7878
# Progress representation

lib/mutant/reporter/cli/printer/config.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ class Config < self
1313
#
1414
# @return [undefined]
1515
def run
16-
info 'Mutant configuration:'
1716
info 'Matcher: %s', object.matcher.inspect
1817
info 'Integration: %s', object.integration
1918
info 'Jobs: %d', object.jobs
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# frozen_string_literal: true
2+
3+
module Mutant
4+
class Reporter
5+
class CLI
6+
class Printer
7+
# Env printer
8+
class Env < self
9+
delegate(
10+
:amount_mutations,
11+
:amount_selected_tests,
12+
:amount_subjects,
13+
:amount_total_tests,
14+
:config,
15+
:test_subject_ratio
16+
)
17+
18+
FORMATS = IceNine.deep_freeze([
19+
[:info, 'Subjects: %s', :amount_subjects ],
20+
[:info, 'Total-Tests: %s', :amount_total_tests ],
21+
[:info, 'Selected-Tests: %s', :amount_selected_tests],
22+
[:info, 'Tests/Subject: %0.2f avg', :test_subject_ratio ],
23+
[:info, 'Mutations: %s', :amount_mutations ]
24+
])
25+
26+
# Run printer
27+
#
28+
# @return [undefined]
29+
def run
30+
info('Mutant environment:')
31+
visit(Config, config)
32+
FORMATS.each do |report, format, value|
33+
__send__(report, format, __send__(value))
34+
end
35+
end
36+
end # EnvProgress
37+
end # Printer
38+
end # CLI
39+
end # Reporter
40+
end # Mutant

lib/mutant/reporter/cli/printer/env_progress.rb

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,41 +8,31 @@ class Printer
88
class EnvProgress < self
99
delegate(
1010
:amount_mutation_results,
11-
:amount_mutations,
1211
:amount_mutations_alive,
1312
:amount_mutations_killed,
14-
:amount_selected_tests,
15-
:amount_subjects,
16-
:amount_total_tests,
1713
:coverage,
1814
:env,
1915
:killtime,
2016
:overhead,
21-
:runtime,
22-
:test_subject_ratio
17+
:runtime
2318
)
2419

2520
FORMATS = IceNine.deep_freeze([
26-
[:info, 'Subjects: %s', :amount_subjects ],
27-
[:info, 'Total-Tests: %s', :amount_total_tests ],
28-
[:info, 'Selected-Tests: %s', :amount_selected_tests ],
29-
[:info, 'Tests/Subject: %0.2f avg', :test_subject_ratio ],
30-
[:info, 'Mutations: %s', :amount_mutations ],
31-
[:info, 'Results: %s', :amount_mutation_results ],
32-
[:info, 'Kills: %s', :amount_mutations_killed ],
33-
[:info, 'Alive: %s', :amount_mutations_alive ],
34-
[:info, 'Runtime: %0.2fs', :runtime ],
35-
[:info, 'Killtime: %0.2fs', :killtime ],
36-
[:info, 'Overhead: %0.2f%%', :overhead_percent ],
37-
[:info, 'Mutations/s: %0.2f', :mutations_per_second ],
38-
[:status, 'Coverage: %0.2f%%', :coverage_percent ]
21+
[:info, 'Results: %s', :amount_mutation_results],
22+
[:info, 'Kills: %s', :amount_mutations_killed],
23+
[:info, 'Alive: %s', :amount_mutations_alive ],
24+
[:info, 'Runtime: %0.2fs', :runtime ],
25+
[:info, 'Killtime: %0.2fs', :killtime ],
26+
[:info, 'Overhead: %0.2f%%', :overhead_percent ],
27+
[:info, 'Mutations/s: %0.2f', :mutations_per_second ],
28+
[:status, 'Coverage: %0.2f%%', :coverage_percent ]
3929
])
4030

4131
# Run printer
4232
#
4333
# @return [undefined]
4434
def run
45-
visit(Config, env.config)
35+
visit(Env, env)
4636
FORMATS.each do |report, format, value|
4737
__send__(report, format, __send__(value))
4838
end

lib/mutant/result.rb

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -101,35 +101,6 @@ def amount_mutations
101101
env.mutations.length
102102
end
103103

104-
# Amount of subjects
105-
#
106-
# @return [Integer]
107-
def amount_subjects
108-
env.subjects.length
109-
end
110-
111-
# Amount of tests reachable by integration
112-
#
113-
# @return [Integer]
114-
def amount_total_tests
115-
env.integration.all_tests.length
116-
end
117-
118-
# Amount of selected tests
119-
#
120-
# @return [Integer]
121-
def amount_selected_tests
122-
env.selections.values.flatten.to_set.length
123-
end
124-
memoize :amount_selected_tests
125-
126-
# Ratio between selected tests and subjects
127-
#
128-
# @return [Rational]
129-
def test_subject_ratio
130-
Rational(amount_selected_tests, amount_subjects)
131-
end
132-
133104
# Test if processing needs to stop
134105
#
135106
# @return [Boolean]

spec/support/shared_context.rb

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def setup_shared_context
3636
let(:output) { StringIO.new }
3737
let(:subject_a_node) { s(:true) }
3838
let(:test_a) { instance_double(Mutant::Test, identification: 'test-a') }
39+
let(:subjects) { [subject_a] }
3940

4041
let(:job_a) do
4142
Mutant::Parallel::Source::Job.new(
@@ -54,14 +55,24 @@ def setup_shared_context
5455
let(:env) do
5556
instance_double(
5657
Mutant::Env,
57-
config: config,
58-
integration: integration,
59-
mutations: mutations,
60-
selections: { subject_a => [test_a] },
61-
subjects: [subject_a]
58+
amount_mutations: mutations.length,
59+
amount_selected_tests: selections.values.flatten.to_set.length,
60+
amount_subjects: subjects.length,
61+
amount_total_tests: integration.all_tests.length,
62+
config: config,
63+
integration: integration,
64+
mutations: mutations,
65+
selected_tests: [test_a].to_set,
66+
selections: selections,
67+
subjects: subjects,
68+
test_subject_ratio: Rational(1)
6269
)
6370
end
6471

72+
let(:selections) do
73+
{ subject_a => [test_a] }
74+
end
75+
6576
let(:integration) do
6677
instance_double(
6778
Mutant::Integration,

spec/unit/mutant/env_spec.rb

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,31 @@
88
matchable_scopes: [],
99
mutations: [],
1010
selector: selector,
11-
subjects: [mutation_subject],
11+
subjects: [subject_a, subject_b],
1212
parser: Mutant::Parser.new,
1313
world: world
1414
)
1515
end
1616

17-
let(:integration) { instance_double(Mutant::Integration) }
1817
let(:integration_class) { Mutant::Integration::Null }
1918
let(:isolation) { Mutant::Isolation::None.new }
2019
let(:kernel) { instance_double(Object, 'kernel') }
21-
let(:mutation_subject) { instance_double(Mutant::Subject) }
20+
let(:subject_a) { instance_double(Mutant::Subject, :a) }
21+
let(:subject_b) { instance_double(Mutant::Subject, :b) }
2222
let(:reporter) { instance_double(Mutant::Reporter) }
2323
let(:selector) { instance_double(Mutant::Selector) }
24-
let(:test_a) { instance_double(Mutant::Test) }
25-
let(:test_b) { instance_double(Mutant::Test) }
26-
let(:tests) { [test_a, test_b] }
24+
let(:test_a) { instance_double(Mutant::Test, :a) }
25+
let(:test_b) { instance_double(Mutant::Test, :b) }
26+
let(:test_c) { instance_double(Mutant::Test, :c) }
27+
28+
let(:integration) do
29+
instance_double(Mutant::Integration, all_tests: [test_a, test_b, test_c])
30+
end
2731

2832
let(:mutation) do
2933
instance_double(
3034
Mutant::Mutation,
31-
subject: mutation_subject
35+
subject: subject_a
3236
)
3337
end
3438

@@ -50,8 +54,12 @@
5054

5155
before do
5256
allow(selector).to receive(:call)
53-
.with(mutation_subject)
54-
.and_return(tests)
57+
.with(subject_a)
58+
.and_return([test_a, test_b])
59+
60+
allow(selector).to receive(:call)
61+
.with(subject_b)
62+
.and_return([test_b, test_c])
5563

5664
allow(Mutant::Timer).to receive(:now).and_return(2.0, 3.0)
5765
end
@@ -98,7 +106,7 @@ def apply
98106

99107
expect(isolation).to have_received(:call).ordered
100108
expect(mutation).to have_received(:insert).ordered.with(kernel)
101-
expect(integration).to have_received(:call).ordered.with(tests)
109+
expect(integration).to have_received(:call).ordered.with([test_a, test_b])
102110
end
103111

104112
include_examples 'mutation kill'
@@ -128,7 +136,10 @@ def apply
128136
end
129137

130138
it 'returns expected selections' do
131-
expect(apply).to eql(mutation_subject => tests)
139+
expect(apply).to eql(
140+
subject_a => [test_a, test_b],
141+
subject_b => [test_b, test_c]
142+
)
132143
end
133144
end
134145

@@ -154,6 +165,38 @@ def apply
154165
end
155166
end
156167

168+
describe '#amount_mutations' do
169+
def apply
170+
subject.amount_mutations
171+
end
172+
173+
it 'returns expected value' do
174+
expect(apply).to be(0)
175+
end
176+
end
177+
178+
describe '#amount_total_tests' do
179+
def apply
180+
subject.amount_total_tests
181+
end
182+
183+
it 'returns expected value' do
184+
expect(apply).to be(3)
185+
end
186+
end
187+
188+
describe '#test_subject_ratio' do
189+
def apply
190+
subject.test_subject_ratio
191+
end
192+
193+
let(:subjects) { [subject_a, instance_double(Mutant::Subject)] }
194+
195+
it 'returns expected value' do
196+
expect(apply).to eql(Rational(3, 2))
197+
end
198+
end
199+
157200
describe '.empty' do
158201
def apply
159202
described_class.empty(world, config)

0 commit comments

Comments
 (0)