8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/parallel_tests/extensions.rb', line 8
def retry_failed_tests(ignore: nil)
if defined?(Minitest)
if first_process?
report = Minitest::Reporters::ParallelTestsReporter.compile_reports!
failed = report.select {|r| r[:failures].any?}
if failed.any?
puts "\nThe following tests failed:"
puts failed.map {|f| f[:location]}.join("\n")
puts "\nRe-running failed tests"
found_all_test_files_for_failures = true
test_failures = failed.flat_map do |test|
guessed_test_name = test[:test_class_name].split('::').last
test_files = Dir["**/#{guessed_test_name.underscore}.rb"].entries
found_all_test_files_for_failures = false if test_files.empty?
test_files
end
test_files.reject! {|f| f[ignore]} if ignore
ENV.delete 'TEST_ENV_NUMBER'
cmd = %Q{ruby -Ilib:test -e "#{test_failures.uniq.map {|f| "load '#{f}';"}.join("\n")}"}
puts cmd
did_pass = system cmd
if did_pass && found_all_test_files_for_failures
puts 'All tests passed on retry, marking build as success'
exit(0)
else
end
end
end
end
end
|