Skip to content

Commit

Permalink
Add process_status_abort coverage criteria
Browse files Browse the repository at this point in the history
  • Loading branch information
mbj committed Nov 22, 2020
1 parent 499d7a0 commit 7e1f349
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 16 deletions.
5 changes: 5 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ coverage_criteria:
# * `true` - mutant will consider timeouts as covering mutations.
# * `false` mutant will ignore timeouts when determining mutation coverage.
timeout: false
# Control te process status abort criteria, defaults to `false`:
# * `true` - mutant will consider unexpected process aborts (example segfaults)
# as covering the mutation that caused this behavior.
# * `false` - mutant will ignore unexpected process aborts when determining coverage.
process_abort: false
# Control the test result criteria, # defaults to `true`
# * `true` mutant will consider failing tests covering mutations.
# * `false` mutant will ignore test results when determining mutation coverage.
Expand Down
12 changes: 7 additions & 5 deletions lib/mutant/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,22 @@ class Config
private_constant(*constants(false))

class CoverageCriteria
include Anima.new(:timeout, :test_result)
include Anima.new(:process_abort, :test_result, :timeout)

DEFAULT = new(
timeout: false,
test_result: true
process_abort: false,
test_result: true,
timeout: false
)

TRANSFORM =
Transform::Sequence.new(
[
Transform::Hash.new(
optional: [
Transform::Hash::Key.new('timeout', Transform::BOOLEAN),
Transform::Hash::Key.new('test_result', Transform::BOOLEAN)
Transform::Hash::Key.new('process_abort', Transform::BOOLEAN),
Transform::Hash::Key.new('test_result', Transform::BOOLEAN),
Transform::Hash::Key.new('timeout', Transform::BOOLEAN)
],
required: []
),
Expand Down
16 changes: 13 additions & 3 deletions lib/mutant/result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ class CoverageCriteria
#
# @return [Boolean]
def success?
test_result || timeout
process_abort || test_result || timeout
end
end

Expand All @@ -250,8 +250,9 @@ class Mutation
# @praam [Result::CoverageCriteria]
def criteria_result(coverage_criteria)
CoverageCriteria.new(
test_result: coverage_criteria.test_result && test_result_success?,
timeout: coverage_criteria.timeout && timeout?
process_abort: coverage_criteria.process_abort && process_abort?,
test_result: coverage_criteria.test_result && test_result_success?,
timeout: coverage_criteria.timeout && timeout?
)
end

Expand All @@ -269,6 +270,15 @@ def timeout?
!isolation_result.timeout.nil?
end

# Test for unexpected process abort
#
# @return [Boolean]
def process_abort?
process_status = isolation_result.process_status or return false

!timeout? && !process_status.exited?
end

private

# Test if mutation was handled successfully
Expand Down
10 changes: 6 additions & 4 deletions spec/support/shared_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,17 @@ def setup_shared_context

let(:mutation_a_criteria_result) do
Mutant::Result::CoverageCriteria.new(
test_result: true,
timeout: false
process_abort: false,
test_result: true,
timeout: false
)
end

let(:mutation_b_criteria_result) do
Mutant::Result::CoverageCriteria.new(
test_result: true,
timeout: false
process_abort: false,
test_result: true,
timeout: false
)
end

Expand Down
18 changes: 14 additions & 4 deletions spec/unit/mutant/result/coverage_criteria_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
RSpec.describe Mutant::Result::CoverageCriteria do
let(:object) do
described_class.new(
test_result: test_result,
timeout: timeout
process_abort: process_abort,
test_result: test_result,
timeout: timeout
)
end

let(:timeout) { false }
let(:test_result) { false }
let(:timeout) { false }
let(:test_result) { false }
let(:process_abort) { false }

describe '#success?' do
def apply
Expand Down Expand Up @@ -37,5 +39,13 @@ def apply
expect(apply).to be(true)
end
end

context 'on process_abort criteria set' do
let(:process_abort) { true }

it 'returns true' do
expect(apply).to be(true)
end
end
end
end
4 changes: 4 additions & 0 deletions spec/unit/mutant/result/mutation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ def apply
allow(mutation.class).to receive_messages(success?: true)
end

context 'when process aborts cover mutations' do
let(:coverage_criteria) { super().with(process_abort: true) }
end

context 'when timeouts cover mutations' do
let(:coverage_criteria) { super().with(timeout: true) }

Expand Down

0 comments on commit 7e1f349

Please sign in to comment.