Cleanup CLI reporter format specs

This commit is contained in:
Markus Schirp 2014-08-11 14:29:32 +00:00
parent 7f86a53cc4
commit fe4f62e109
3 changed files with 122 additions and 99 deletions

View file

@ -96,7 +96,9 @@ module Mutant
# @api private # @api private
# #
def progress(collector) def progress(collector)
format(Printer::MutationProgressResult, collector.last_mutation_result) last_mutation_result = collector.last_mutation_result
return EMPTY_STRING unless last_mutation_result
format(Printer::MutationProgressResult, last_mutation_result)
end end
private private

View file

@ -2,6 +2,7 @@ module CompressHelper
def strip_indent(string) def strip_indent(string)
lines = string.lines lines = string.lines
match = /\A( *)/.match(lines.first) match = /\A( *)/.match(lines.first)
return string unless match
whitespaces = match[1].to_s.length whitespaces = match[1].to_s.length
lines.map { |line| line[whitespaces..-1] }.join lines.map { |line| line[whitespaces..-1] }.join
end end

View file

@ -2,30 +2,33 @@ RSpec.describe Mutant::Reporter::CLI do
let(:object) { described_class.new(output, format) } let(:object) { described_class.new(output, format) }
let(:output) { StringIO.new } let(:output) { StringIO.new }
let(:format) do let(:framed_format) do
described_class::Format::Framed.new( described_class::Format::Framed.new(
tty: false, tty: false,
tput: described_class::Tput::UNAVAILABLE tput: described_class::Tput::UNAVAILABLE
) )
end end
let(:progressive_format) do
described_class::Format::Progressive.new(tty: false)
end
let(:format) { framed_format }
def contents def contents
output.rewind output.rewind
output.read output.read
end end
before do def self.it_reports(expected_content)
allow(Time).to receive(:now).and_return(Time.now) it 'writes expected report to output' do
subject
expect(contents).to eql(strip_indent(expected_content))
end
end end
describe '#warn' do before do
subject { object.warn(message) } allow(Time).to receive(:now).and_return(Time.now)
let(:message) { 'message' }
it 'writes message to output' do
expect { subject }.to change { contents }.from('').to("message\n")
end
end end
let(:result) do let(:result) do
@ -133,6 +136,36 @@ RSpec.describe Mutant::Reporter::CLI do
let(:subjects) { [_subject] } let(:subjects) { [_subject] }
describe '#warn' do
subject { object.warn(message) }
let(:message) { 'message' }
it_reports("message\n")
end
describe '#start' do
subject { object.start(env) }
context 'on progressive format' do
let(:format) { progressive_format }
it_reports(<<-REPORT)
Mutant configuration:
Matcher: #<Mutant::Matcher::Config match_expressions=[] subject_ignores=[] subject_selects=[]>
Integration: null
Expect Coverage: 100.00%
Processes: 1
Includes: []
Requires: []
REPORT
end
context 'on framed format' do
it_reports ''
end
end
describe '#progress' do describe '#progress' do
subject { object.progress(collector) } subject { object.progress(collector) }
@ -142,14 +175,40 @@ RSpec.describe Mutant::Reporter::CLI do
let(:mutation_result_success) { true } let(:mutation_result_success) { true }
context 'with empty collector' do context 'on progressive format' do
it 'writes expected output' do
subject let(:format) { progressive_format }
expect(contents).to eql(expected_output)
context 'with empty collector' do
it_reports ''
end end
let(:expected_output) do context 'with last mutation present' do
strip_indent(<<-REPORT)
before do
collector.start(mutation_a)
collector.finish(mutation_a_result)
end
context 'when mutation is successful' do
it_reports '.'
end
context 'when mutation is NOT successful' do
let(:mutation_result_success) { false }
it_reports 'F'
end
end
end
context 'on framed format' do
let(:mutation_result_success) { true }
context 'with empty collector' do
it_reports <<-REPORT
Mutant configuration: Mutant configuration:
Matcher: #<Mutant::Matcher::Config match_expressions=[] subject_ignores=[] subject_selects=[]> Matcher: #<Mutant::Matcher::Config match_expressions=[] subject_ignores=[] subject_selects=[]>
Integration: null Integration: null
@ -170,22 +229,15 @@ RSpec.describe Mutant::Reporter::CLI do
Active subjects: 0 Active subjects: 0
REPORT REPORT
end end
end
context 'with collector active on one subject' do context 'with collector active on one subject' do
before do before do
collector.start(mutation_a) collector.start(mutation_a)
end
context 'without progress' do
it 'writes expected output' do
subject
expect(contents).to eql(expected_output)
end end
let(:expected_output) do context 'without progress' do
strip_indent(<<-REPORT)
it_reports(<<-REPORT)
Mutant configuration: Mutant configuration:
Matcher: #<Mutant::Matcher::Config match_expressions=[] subject_ignores=[] subject_selects=[]> Matcher: #<Mutant::Matcher::Config match_expressions=[] subject_ignores=[] subject_selects=[]>
Integration: null Integration: null
@ -209,27 +261,20 @@ RSpec.describe Mutant::Reporter::CLI do
(00/01) 0% - killtime: 0.00s runtime: 0.00s overhead: 0.00s (00/01) 0% - killtime: 0.00s runtime: 0.00s overhead: 0.00s
REPORT REPORT
end end
end
context 'with progress' do context 'with progress' do
let(:subject_mutations) { [mutation_a, mutation_b] } let(:subject_mutations) { [mutation_a, mutation_b] }
before do before do
collector.start(mutation_b) collector.start(mutation_b)
collector.finish(mutation_a_result) collector.finish(mutation_a_result)
end
context 'on failure' do
let(:mutation_result_success) { false }
it 'writes expected output' do
subject
expect(contents).to eql(expected_output)
end end
let(:expected_output) do context 'on failure' do
strip_indent(<<-REPORT) let(:mutation_result_success) { false }
it_reports(<<-REPORT)
Mutant configuration: Mutant configuration:
Matcher: #<Mutant::Matcher::Config match_expressions=[] subject_ignores=[] subject_selects=[]> Matcher: #<Mutant::Matcher::Config match_expressions=[] subject_ignores=[] subject_selects=[]>
Integration: null Integration: null
@ -254,16 +299,9 @@ RSpec.describe Mutant::Reporter::CLI do
(00/02) 0% - killtime: 0.50s runtime: 1.00s overhead: 0.50s (00/02) 0% - killtime: 0.50s runtime: 1.00s overhead: 0.50s
REPORT REPORT
end end
end
context 'on success' do context 'on success' do
it 'writes expected output' do it_reports(<<-REPORT)
subject
expect(contents).to eql(expected_output)
end
let(:expected_output) do
strip_indent(<<-REPORT)
Mutant configuration: Mutant configuration:
Matcher: #<Mutant::Matcher::Config match_expressions=[] subject_ignores=[] subject_selects=[]> Matcher: #<Mutant::Matcher::Config match_expressions=[] subject_ignores=[] subject_selects=[]>
Integration: null Integration: null
@ -291,17 +329,14 @@ RSpec.describe Mutant::Reporter::CLI do
end end
end end
end end
end
describe '#report' do describe '#report' do
subject { object.report(result) } subject { object.report(result) }
context 'with full coverage' do context 'with full coverage' do
let(:mutation_result_success) { true } let(:mutation_result_success) { true }
it 'writes report to output' do it_reports(<<-REPORT)
subject
expect(contents).to eql(strip_indent(<<-REPORT))
Mutant configuration: Mutant configuration:
Matcher: #<Mutant::Matcher::Config match_expressions=[] subject_ignores=[] subject_selects=[]> Matcher: #<Mutant::Matcher::Config match_expressions=[] subject_ignores=[] subject_selects=[]>
Integration: null Integration: null
@ -321,16 +356,13 @@ RSpec.describe Mutant::Reporter::CLI do
Expected: 100.00% Expected: 100.00%
REPORT REPORT
end end
end
context 'and partial coverage' do context 'and partial coverage' do
let(:mutation_result_success) { false } let(:mutation_result_success) { false }
context 'on evil mutation' do context 'on evil mutation' do
context 'with a diff' do context 'with a diff' do
it 'writes report to output' do it_reports(<<-REPORT)
subject
expect(contents).to eql(strip_indent(<<-REPORT))
subject_id subject_id
- test_id - test_id
mutation_id-a mutation_id-a
@ -357,14 +389,11 @@ RSpec.describe Mutant::Reporter::CLI do
Expected: 100.00% Expected: 100.00%
REPORT REPORT
end end
end
context 'without a diff' do context 'without a diff' do
let(:mutation_source) { 'true' } let(:mutation_source) { 'true' }
it 'writes report to output' do it_reports(<<-REPORT)
subject
expect(contents).to eql(strip_indent(<<-REPORT))
subject_id subject_id
- test_id - test_id
mutation_id-a mutation_id-a
@ -394,15 +423,12 @@ RSpec.describe Mutant::Reporter::CLI do
REPORT REPORT
end end
end end
end
context 'on neutral mutation' do context 'on neutral mutation' do
let(:mutation_class) { Mutant::Mutation::Neutral } let(:mutation_class) { Mutant::Mutation::Neutral }
let(:mutation_source) { 'true' } let(:mutation_source) { 'true' }
it 'writes report to output' do it_reports(<<-REPORT)
subject
expect(contents).to eql(strip_indent(<<-REPORT))
subject_id subject_id
- test_id - test_id
mutation_id-a mutation_id-a
@ -437,14 +463,11 @@ RSpec.describe Mutant::Reporter::CLI do
Expected: 100.00% Expected: 100.00%
REPORT REPORT
end end
end
context 'on noop mutation' do context 'on noop mutation' do
let(:mutation_class) { Mutant::Mutation::Noop } let(:mutation_class) { Mutant::Mutation::Noop }
it 'writes report to output' do it_reports(<<-REPORT)
subject
expect(contents).to eql(strip_indent(<<-REPORT))
subject_id subject_id
- test_id - test_id
mutation_id-a mutation_id-a
@ -476,17 +499,14 @@ RSpec.describe Mutant::Reporter::CLI do
REPORT REPORT
end end
end end
end
context 'without subjects' do context 'without subjects' do
let(:subjects) { [] } let(:subjects) { [] }
let(:subject_results) { [] } let(:subject_results) { [] }
let(:config) { Mutant::Config::DEFAULT.update(processes: 1, includes: %w[include-dir], requires: %w[require-name]) } let(:config) { Mutant::Config::DEFAULT.update(processes: 1, includes: %w[include-dir], requires: %w[require-name]) }
it 'writes report to output' do it_reports(<<-REPORT)
subject
expect(contents).to eql(strip_indent(<<-REPORT))
Mutant configuration: Mutant configuration:
Matcher: #<Mutant::Matcher::Config match_expressions=[] subject_ignores=[] subject_selects=[]> Matcher: #<Mutant::Matcher::Config match_expressions=[] subject_ignores=[] subject_selects=[]>
Integration: null Integration: null