free_mutant/spec/unit/mutant/reporter/cli_spec.rb

457 lines
14 KiB
Ruby
Raw Normal View History

RSpec.describe Mutant::Reporter::CLI do
2014-10-23 11:37:53 +00:00
setup_shared_context
let(:object) { described_class.new(output, format) }
let(:output) { StringIO.new }
2014-08-11 14:29:32 +00:00
let(:framed_format) do
described_class::Format::Framed.new(
tty: false,
tput: described_class::Tput::UNAVAILABLE
)
end
2014-08-11 14:29:32 +00:00
let(:progressive_format) do
described_class::Format::Progressive.new(tty: false)
end
let(:format) { framed_format }
def contents
output.rewind
output.read
end
2014-08-11 14:29:32 +00:00
def self.it_reports(expected_content)
it 'writes expected report to output' do
subject
expect(contents).to eql(strip_indent(expected_content))
end
2014-07-17 13:59:25 +00:00
end
2014-08-11 14:29:32 +00:00
before do
allow(Time).to receive(:now).and_return(Time.now)
end
2014-08-11 14:52:31 +00:00
describe '.build' do
subject { described_class.build(output) }
let(:progressive_format) do
described_class::Format::Progressive.new(tty: tty?)
2014-08-11 14:52:31 +00:00
end
let(:framed_format) do
described_class::Format::Framed.new(
tty: true,
tput: described_class::Tput::INSTANCE
)
end
before do
expect(ENV).to receive(:key?).with('CI').and_return(ci?)
end
let(:output) { double('Output', tty?: tty?) }
let(:tty?) { true }
let(:ci?) { false }
context 'when not on CI and on a tty' do
it { should eql(described_class.new(output, framed_format)) }
end
context 'when on CI' do
let(:ci?) { true }
it { should eql(described_class.new(output, progressive_format)) }
end
context 'when output is not a tty?' do
let(:tty?) { false }
it { should eql(described_class.new(output, progressive_format)) }
end
context 'when output does not respond to #tty?' do
let(:output) { double('Output') }
let(:tty?) { false }
it { should eql(described_class.new(output, progressive_format)) }
end
end
2014-08-11 14:29:32 +00:00
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%
Jobs: 1
2014-08-11 14:29:32 +00:00
Includes: []
Requires: []
REPORT
end
context 'on framed format' do
it_reports ''
end
end
2014-07-06 21:51:22 +00:00
describe '#progress' do
2014-10-23 11:37:53 +00:00
subject { object.progress(status) }
2014-07-06 21:51:22 +00:00
2014-08-11 14:29:32 +00:00
context 'on progressive format' do
let(:format) { progressive_format }
2014-10-23 11:37:53 +00:00
context 'with empty scheduler' do
update(:env_result) { { subject_results: [] } }
2014-08-11 14:29:32 +00:00
it_reports ''
2014-07-17 13:59:25 +00:00
end
2014-08-11 14:29:32 +00:00
context 'with last mutation present' do
2014-10-23 11:37:53 +00:00
update(:env_result) { { subject_results: [subject_a_result] } }
2014-08-11 14:29:32 +00:00
context 'when mutation is successful' do
2014-10-23 11:37:53 +00:00
it_reports '..'
2014-08-11 14:29:32 +00:00
end
context 'when mutation is NOT successful' do
update(:mutation_a_test_result) { { passed: true } }
2014-10-23 11:37:53 +00:00
it_reports 'F.'
2014-08-11 14:29:32 +00:00
end
end
end
context 'on framed format' do
2014-10-23 11:37:53 +00:00
context 'with empty scheduler' do
update(:env_result) { { subject_results: [] } }
2014-08-11 14:29:32 +00:00
it_reports <<-REPORT
2014-07-06 21:51:22 +00:00
Mutant configuration:
Matcher: #<Mutant::Matcher::Config match_expressions=[] subject_ignores=[] subject_selects=[]>
Integration: null
Expect Coverage: 100.00%
Jobs: 1
2014-07-17 13:59:25 +00:00
Includes: []
Requires: []
Available Subjects: 1
2014-07-06 21:51:22 +00:00
Subjects: 1
2014-10-23 11:37:53 +00:00
Mutations: 2
2014-07-17 13:59:25 +00:00
Kills: 0
Alive: 0
2014-10-23 11:37:53 +00:00
Runtime: 4.00s
2014-07-17 13:59:25 +00:00
Killtime: 0.00s
2014-10-23 11:37:53 +00:00
Overhead: Inf%
2014-07-17 13:59:25 +00:00
Coverage: 0.00%
Expected: 100.00%
Active subjects: 0
2014-07-06 21:51:22 +00:00
REPORT
end
2014-10-23 11:37:53 +00:00
context 'with scheduler active on one subject' do
2014-08-11 14:29:32 +00:00
context 'without progress' do
2014-10-23 11:37:53 +00:00
update(:status) { { active_jobs: [].to_set } }
2014-08-11 14:29:32 +00:00
it_reports(<<-REPORT)
2014-07-17 13:59:25 +00:00
Mutant configuration:
Matcher: #<Mutant::Matcher::Config match_expressions=[] subject_ignores=[] subject_selects=[]>
Integration: null
Expect Coverage: 100.00%
Jobs: 1
2014-07-17 13:59:25 +00:00
Includes: []
Requires: []
Available Subjects: 1
Subjects: 1
2014-10-23 11:37:53 +00:00
Mutations: 2
Kills: 2
2014-07-17 13:59:25 +00:00
Alive: 0
2014-10-23 11:37:53 +00:00
Runtime: 4.00s
Killtime: 2.00s
Overhead: 100.00%
2014-10-23 11:37:53 +00:00
Coverage: 100.00%
2014-07-17 13:59:25 +00:00
Expected: 100.00%
2014-10-23 11:37:53 +00:00
Active subjects: 0
2014-07-17 13:59:25 +00:00
REPORT
end
2014-08-11 14:29:32 +00:00
context 'with progress' do
2014-10-23 11:37:53 +00:00
update(:status) { { active_jobs: [job_a].to_set } }
2014-07-17 13:59:25 +00:00
2014-08-11 14:29:32 +00:00
context 'on failure' do
update(:mutation_a_test_result) { { passed: true } }
2014-08-11 14:29:32 +00:00
it_reports(<<-REPORT)
2014-07-17 13:59:25 +00:00
Mutant configuration:
Matcher: #<Mutant::Matcher::Config match_expressions=[] subject_ignores=[] subject_selects=[]>
Integration: null
Expect Coverage: 100.00%
Jobs: 1
2014-07-17 13:59:25 +00:00
Includes: []
Requires: []
Available Subjects: 1
Subjects: 1
Mutations: 2
2014-10-23 11:37:53 +00:00
Kills: 1
2014-07-17 13:59:25 +00:00
Alive: 1
2014-10-23 11:37:53 +00:00
Runtime: 4.00s
Killtime: 2.00s
Overhead: 100.00%
2014-10-23 11:37:53 +00:00
Coverage: 50.00%
2014-07-17 13:59:25 +00:00
Expected: 100.00%
Active subjects: 1
2014-10-23 11:37:53 +00:00
subject-a mutations: 2
- test-a
F.
(01/02) 50% - killtime: 2.00s runtime: 2.00s overhead: 0.00s
2014-10-23 11:37:53 +00:00
Active Jobs:
0: evil:subject-a:d27d2
2014-07-17 13:59:25 +00:00
REPORT
end
2014-08-11 14:29:32 +00:00
context 'on success' do
it_reports(<<-REPORT)
2014-07-17 13:59:25 +00:00
Mutant configuration:
Matcher: #<Mutant::Matcher::Config match_expressions=[] subject_ignores=[] subject_selects=[]>
Integration: null
Expect Coverage: 100.00%
Jobs: 1
2014-07-17 13:59:25 +00:00
Includes: []
Requires: []
Available Subjects: 1
Subjects: 1
Mutations: 2
2014-10-23 11:37:53 +00:00
Kills: 2
2014-07-17 13:59:25 +00:00
Alive: 0
2014-10-23 11:37:53 +00:00
Runtime: 4.00s
Killtime: 2.00s
Overhead: 100.00%
2014-07-17 13:59:25 +00:00
Coverage: 100.00%
Expected: 100.00%
Active subjects: 1
2014-10-23 11:37:53 +00:00
subject-a mutations: 2
- test-a
..
(02/02) 100% - killtime: 2.00s runtime: 2.00s overhead: 0.00s
2014-10-23 11:37:53 +00:00
Active Jobs:
0: evil:subject-a:d27d2
2014-07-17 13:59:25 +00:00
REPORT
end
2014-07-06 21:51:22 +00:00
end
end
end
2014-08-11 14:29:32 +00:00
describe '#report' do
2014-10-23 11:37:53 +00:00
subject { object.report(status.env_result) }
2014-08-11 14:29:32 +00:00
context 'with full coverage' do
it_reports(<<-REPORT)
2014-07-17 13:59:25 +00:00
Mutant configuration:
Matcher: #<Mutant::Matcher::Config match_expressions=[] subject_ignores=[] subject_selects=[]>
Integration: null
Expect Coverage: 100.00%
Jobs: 1
2014-07-17 13:59:25 +00:00
Includes: []
Requires: []
Available Subjects: 1
Subjects: 1
2014-10-23 11:37:53 +00:00
Mutations: 2
Kills: 2
2014-07-17 13:59:25 +00:00
Alive: 0
2014-10-23 11:37:53 +00:00
Runtime: 4.00s
Killtime: 2.00s
Overhead: 100.00%
2014-07-17 13:59:25 +00:00
Coverage: 100.00%
Expected: 100.00%
REPORT
end
2014-08-11 14:29:32 +00:00
context 'and partial coverage' do
update(:mutation_a_test_result) { { passed: true } }
2014-08-11 14:29:32 +00:00
context 'on evil mutation' do
context 'with a diff' do
it_reports(<<-REPORT)
2014-10-23 11:37:53 +00:00
subject-a
- test-a
evil:subject-a:d27d2
2014-07-17 13:59:25 +00:00
@@ -1,2 +1,2 @@
-true
+false
-----------------------
2014-07-17 13:59:25 +00:00
Mutant configuration:
Matcher: #<Mutant::Matcher::Config match_expressions=[] subject_ignores=[] subject_selects=[]>
Integration: null
Expect Coverage: 100.00%
Jobs: 1
2014-07-17 13:59:25 +00:00
Includes: []
Requires: []
Available Subjects: 1
Subjects: 1
2014-10-23 11:37:53 +00:00
Mutations: 2
Kills: 1
2014-07-17 13:59:25 +00:00
Alive: 1
2014-10-23 11:37:53 +00:00
Runtime: 4.00s
Killtime: 2.00s
Overhead: 100.00%
2014-10-23 11:37:53 +00:00
Coverage: 50.00%
2014-07-17 13:59:25 +00:00
Expected: 100.00%
REPORT
end
2014-08-11 14:29:32 +00:00
context 'without a diff' do
2014-10-23 11:37:53 +00:00
let(:mutation_a_node) { s(:true) }
2014-08-11 14:29:32 +00:00
it_reports(<<-REPORT)
2014-10-23 11:37:53 +00:00
subject-a
- test-a
evil:subject-a:d5318
Original source:
true
Mutated Source:
true
2014-10-23 11:37:53 +00:00
BUG: Mutation NOT resulted in exactly one diff hunk. Please report a reproduction!
2014-07-07 15:03:31 +00:00
-----------------------
2014-07-17 13:59:25 +00:00
Mutant configuration:
Matcher: #<Mutant::Matcher::Config match_expressions=[] subject_ignores=[] subject_selects=[]>
Integration: null
Expect Coverage: 100.00%
Jobs: 1
2014-07-17 13:59:25 +00:00
Includes: []
Requires: []
Available Subjects: 1
Subjects: 1
2014-10-23 11:37:53 +00:00
Mutations: 2
Kills: 1
2014-07-17 13:59:25 +00:00
Alive: 1
2014-10-23 11:37:53 +00:00
Runtime: 4.00s
Killtime: 2.00s
Overhead: 100.00%
2014-10-23 11:37:53 +00:00
Coverage: 50.00%
2014-07-17 13:59:25 +00:00
Expected: 100.00%
REPORT
end
end
2014-07-17 13:59:25 +00:00
2014-08-11 14:29:32 +00:00
context 'on neutral mutation' do
update(:mutation_a_test_result) { { passed: false } }
2014-10-23 11:37:53 +00:00
let(:mutation_a) do
Mutant::Mutation::Neutral.new(subject_a, s(:true))
end
2014-07-17 13:59:25 +00:00
2014-08-11 14:29:32 +00:00
it_reports(<<-REPORT)
2014-10-23 11:37:53 +00:00
subject-a
- test-a
neutral:subject-a:d5318
2014-07-17 13:59:25 +00:00
--- Neutral failure ---
Original code was inserted unmutated. And the test did NOT PASS.
Your tests do not pass initially or you found a bug in mutant / unparser.
Subject AST:
(true)
Unparsed Source:
true
Test Result:
- 1 @ runtime: 1.0
- test-a
2014-10-23 11:37:53 +00:00
Test Output:
mutation a test result output
2014-10-23 11:37:53 +00:00
-----------------------
neutral:subject-a:d5318
--- Neutral failure ---
Original code was inserted unmutated. And the test did NOT PASS.
Your tests do not pass initially or you found a bug in mutant / unparser.
Subject AST:
(true)
Unparsed Source:
true
Test Result:
- 1 @ runtime: 1.0
- test-a
2014-10-23 11:37:53 +00:00
Test Output:
mutation b test result output
2014-07-17 13:59:25 +00:00
-----------------------
Mutant configuration:
Matcher: #<Mutant::Matcher::Config match_expressions=[] subject_ignores=[] subject_selects=[]>
Integration: null
Expect Coverage: 100.00%
Jobs: 1
2014-07-17 13:59:25 +00:00
Includes: []
Requires: []
Available Subjects: 1
Subjects: 1
2014-10-23 11:37:53 +00:00
Mutations: 2
2014-07-17 13:59:25 +00:00
Kills: 0
2014-10-23 11:37:53 +00:00
Alive: 2
Runtime: 4.00s
Killtime: 2.00s
Overhead: 100.00%
2014-07-17 13:59:25 +00:00
Coverage: 0.00%
Expected: 100.00%
REPORT
end
2014-08-11 14:29:32 +00:00
context 'on noop mutation' do
update(:mutation_a_test_result) { { passed: false } }
2014-10-23 11:37:53 +00:00
let(:mutation_a) do
Mutant::Mutation::Noop.new(subject_a, s(:true))
end
2014-07-17 13:59:25 +00:00
2014-08-11 14:29:32 +00:00
it_reports(<<-REPORT)
2014-10-23 11:37:53 +00:00
subject-a
- test-a
noop:subject-a:d5318
---- Noop failure -----
No code was inserted. And the test did NOT PASS.
This is typically a problem of your specs not passing unmutated.
Test Result:
- 1 @ runtime: 1.0
- test-a
2014-10-23 11:37:53 +00:00
Test Output:
mutation a test result output
2014-10-23 11:37:53 +00:00
-----------------------
noop:subject-a:d5318
2014-07-17 13:59:25 +00:00
---- Noop failure -----
No code was inserted. And the test did NOT PASS.
This is typically a problem of your specs not passing unmutated.
Test Result:
- 1 @ runtime: 1.0
- test-a
2014-07-17 13:59:25 +00:00
Test Output:
mutation b test result output
2014-07-17 13:59:25 +00:00
-----------------------
Mutant configuration:
Matcher: #<Mutant::Matcher::Config match_expressions=[] subject_ignores=[] subject_selects=[]>
Integration: null
Expect Coverage: 100.00%
Jobs: 1
2014-07-17 13:59:25 +00:00
Includes: []
Requires: []
Available Subjects: 1
Subjects: 1
2014-10-23 11:37:53 +00:00
Mutations: 2
2014-07-17 13:59:25 +00:00
Kills: 0
2014-10-23 11:37:53 +00:00
Alive: 2
Runtime: 4.00s
Killtime: 2.00s
Overhead: 100.00%
2014-07-17 13:59:25 +00:00
Coverage: 0.00%
Expected: 100.00%
REPORT
end
end
end
end
end