Skip to content

Commit

Permalink
Change test runner on --fail-fast to report first error deterministic…
Browse files Browse the repository at this point in the history
…ally
  • Loading branch information
mbj committed May 11, 2024
1 parent 363ccf2 commit 48ffff9
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 17 deletions.
8 changes: 8 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# v0.12.1 2024-05-11

* [#1443](https://github.com/mbj/mutant/pull/1443)

In regular single threaded test execution (Rspec native) `--fail-fast` stops at the first error. Mutants
rspec/minitest execution option can reach multiple errors on parallel execution before the parallel engine can
react to the first known error. This change makes sure only the first error gets reported when using `--fail-fast`.

# v0.12.0 2024-04-22

Drop the license gem, entirely. This reduces DRM in mutants code base to the absolute minimum.
Expand Down
23 changes: 22 additions & 1 deletion lib/mutant/reporter/cli/printer/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class EnvResult < self
#
# @return [undefined]
def run
visit_collection(Result, object.failed_test_results)
visit_failed
visit(Env, object.env)
FORMATS.each do |report, format, value|
__send__(report, format, __send__(value))
Expand All @@ -77,6 +77,27 @@ def run

private

def visit_failed
failed = object.failed_test_results

if object.env.config.fail_fast
visit_failed_tests(failed.take(1))
visit_other_failed(failed.drop(1))
else
visit_failed_tests(failed)
end
end

def visit_other_failed(other)
return if other.empty?

puts('Other failed tests (report suppressed from fail fast): %d' % other.length)
end

def visit_failed_tests(failed)
visit_collection(Result, failed)
end

def efficiency_percent
(testtime / runtime) * 100
end
Expand Down
97 changes: 81 additions & 16 deletions spec/unit/mutant/reporter/cli/printer/test/env_result_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,99 @@

let(:test_result_a) do
Mutant::Result::Test.new(
output: '<test-output>',
output: '<test-output-a>',
passed: false,
runtime: 0.1
)
end

let(:test_result_b) do
Mutant::Result::Test.new(
output: '<test-output>',
output: '<test-output-b>',
passed: true,
runtime: 0.2
)
end

describe '.call' do
it_reports <<~'STR'
<test-output>
Test environment:
Fail-Fast: false
Integration: null
Jobs: auto
Tests: 2
Test-Results: 2
Test-Failed: 1
Test-Success: 1
Runtime: 0.80s
Testtime: 0.30s
Efficiency: 37.50%
STR
context 'single test failure' do
context 'without fail fast' do
it_reports <<~'STR'
<test-output-a>
Test environment:
Fail-Fast: false
Integration: null
Jobs: auto
Tests: 2
Test-Results: 2
Test-Failed: 1
Test-Success: 1
Runtime: 0.80s
Testtime: 0.30s
Efficiency: 37.50%
STR
end

context 'with fail fast' do
let(:config) { super().with(fail_fast: true) }

it_reports <<~'STR'
<test-output-a>
Test environment:
Fail-Fast: true
Integration: null
Jobs: auto
Tests: 2
Test-Results: 2
Test-Failed: 1
Test-Success: 1
Runtime: 0.80s
Testtime: 0.30s
Efficiency: 37.50%
STR
end
end

context 'with multiple test failures' do
let(:test_result_b) { super().with(passed: false) }

context 'without fail fast' do
it_reports <<~'STR'
<test-output-a>
<test-output-b>
Test environment:
Fail-Fast: false
Integration: null
Jobs: auto
Tests: 2
Test-Results: 2
Test-Failed: 2
Test-Success: 0
Runtime: 0.80s
Testtime: 0.30s
Efficiency: 37.50%
STR
end

context 'with fail fast' do
let(:config) { super().with(fail_fast: true) }

it_reports <<~'STR'
<test-output-a>
Other failed tests (report suppressed from fail fast): 1
Test environment:
Fail-Fast: true
Integration: null
Jobs: auto
Tests: 2
Test-Results: 2
Test-Failed: 2
Test-Success: 0
Runtime: 0.80s
Testtime: 0.30s
Efficiency: 37.50%
STR
end
end
end
end

0 comments on commit 48ffff9

Please sign in to comment.