Module: ForkingTestRunner
- Defined in:
- lib/forking_test_runner.rb,
lib/forking_test_runner/cli.rb,
lib/forking_test_runner/version.rb,
lib/forking_test_runner/coverage_capture.rb
Defined Under Namespace
Modules: CLI, CoverageCapture
Constant Summary collapse
- CLEAR =
"------"- COVERAGE_REPORT_PREFIX =
"coverage/fork-"- VERSION =
"1.16.0"
Class Attribute Summary collapse
-
.after_fork_callbacks ⇒ Object
Returns the value of attribute after_fork_callbacks.
-
.before_fork_callbacks ⇒ Object
Returns the value of attribute before_fork_callbacks.
Class Method Summary collapse
Class Attribute Details
.after_fork_callbacks ⇒ Object
Returns the value of attribute after_fork_callbacks.
15 16 17 |
# File 'lib/forking_test_runner.rb', line 15 def after_fork_callbacks @after_fork_callbacks end |
.before_fork_callbacks ⇒ Object
Returns the value of attribute before_fork_callbacks.
15 16 17 |
# File 'lib/forking_test_runner.rb', line 15 def before_fork_callbacks @before_fork_callbacks end |
Class Method Details
.cli(argv) ⇒ Object
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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/forking_test_runner.rb', line 17 def cli(argv) @options, tests = CLI.(argv) # figure out what we need to run runtime_log = @options.fetch(:runtime_log) groups, group_count = find_group_args parallel = @options.fetch(:parallel) test_groups = if parallel && !@options.fetch(:group) Array.new(parallel) { |i| find_tests_for_group(i + 1, parallel, tests, runtime_log) } else raise ArgumentError, "Use the same amount of processors as groups" if parallel && parallel != groups.count groups.map { |group| find_tests_for_group(group, group_count, tests, runtime_log) } end # say what we are running all_tests = test_groups.flatten(1) if @options.fetch(:quiet) puts "Running #{all_tests.size} test files" else puts "Running tests #{all_tests.map(&:first).join(" ")}" end @before_fork_callbacks = [] @after_fork_callbacks = [] # run all the tests results = with_lock do |lock| Parallel.map_with_index(test_groups, in_processes: parallel || 0) do |tests_group, env_index| if parallel ENV["TEST_ENV_NUMBER"] = (env_index == 0 ? '' : (env_index + 1).to_s) # NOTE: does not support first_is_1 option end reraise_clean_ar_error { load_test_env } tests_group.map do |file, expected| print_started file unless parallel result = [file, expected, *benchmark { run_test(file) }] sync_stdout lock do print_started file if parallel print_finished(*result) end result end end.flatten(1) end unless @options.fetch(:quiet) # pretty print the results puts "\nResults:" puts( results .sort_by { |_, _, _, r, _| r ? 0 : 1 } # failures should be last so they are easy to find .map { |f, _, _, r, _| "#{f}: #{r ? "OK" : "Fail"}" } ) puts end success = results.map { |r| r[3] }.all? puts colorize(success, summarize_results(results.map { |r| r[4] })) if runtime_log # show how long they ran vs expected diff = results.map { |_, expected, time| time - expected }.inject(:+).to_f puts "Time: #{diff.round(2)} diff to expected" end if mode = @options.fetch(:record_runtime) # store runtime log log = runtime_log || 'runtime.log' record_test_runtime(mode, results, log) end summarize_partial_reports if partial_reports_for_single_cov? # exit with success or failure success ? 0 : 1 end |