|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require_relative '../runner' |
| 4 | + |
| 5 | +module Minitest |
| 6 | + def self.run_all_suites(reporter, options) |
| 7 | + suites = Runnable.runnables |
| 8 | + suites.map { |suite| suite.run_suite reporter, options } |
| 9 | + end |
| 10 | + |
| 11 | + class Runnable |
| 12 | + def failure_count |
| 13 | + failures.length |
| 14 | + end |
| 15 | + end |
| 16 | + |
| 17 | + class Test |
| 18 | + def self.runnables=(runnables) |
| 19 | + @@runnables = runnables |
| 20 | + end |
| 21 | + |
| 22 | + # Synchronize all tests, even serial ones. |
| 23 | + # |
| 24 | + # Minitest runs serial tests before parallel ones to ensure the |
| 25 | + # unsynchronized serial tests don't overlap the parallel tests. But since |
| 26 | + # the test-queue master hands out tests without actually loading their |
| 27 | + # code, there's no way to know which are parallel and which are serial. |
| 28 | + # Synchronizing serial tests does add some overhead, but hopefully this is |
| 29 | + # outweighed by the speed benefits of using test-queue. |
| 30 | + def _synchronize |
| 31 | + Test.io_lock.synchronize { yield } |
| 32 | + end |
| 33 | + end |
| 34 | + |
| 35 | + class ProgressReporter |
| 36 | + # Override original method to make test-queue specific output |
| 37 | + def record(result) |
| 38 | + io.print ' ' |
| 39 | + io.print result.klass |
| 40 | + io.print ': ' |
| 41 | + io.print result.result_code |
| 42 | + io.puts(' <%.3f>' % result.time) |
| 43 | + end |
| 44 | + end |
| 45 | + |
| 46 | + begin |
| 47 | + require 'minitest/minitest_reporter_plugin' |
| 48 | + |
| 49 | + class << self |
| 50 | + private |
| 51 | + |
| 52 | + def total_count(_options) |
| 53 | + 0 |
| 54 | + end |
| 55 | + end |
| 56 | + rescue LoadError |
| 57 | + # noop |
| 58 | + end |
| 59 | +end |
| 60 | + |
| 61 | +module TestQueue |
| 62 | + class Runner |
| 63 | + class Minitest < Runner |
| 64 | + def initialize |
| 65 | + @options = ::Minitest.process_args ARGV |
| 66 | + |
| 67 | + if ::Minitest.respond_to?(:seed) |
| 68 | + ::Minitest.seed = @options[:seed] |
| 69 | + srand ::Minitest.seed |
| 70 | + end |
| 71 | + |
| 72 | + if ::Minitest::Test.runnables.any? { |r| r.runnable_methods.any? } |
| 73 | + raise 'Do not `require` test files. Pass them via ARGV instead and they will be required as needed.' |
| 74 | + end |
| 75 | + |
| 76 | + super(TestFramework::Minitest.new) |
| 77 | + end |
| 78 | + |
| 79 | + def start_master |
| 80 | + puts "Run options: #{@options[:args]}\n\n" |
| 81 | + |
| 82 | + super |
| 83 | + end |
| 84 | + |
| 85 | + def run_worker(iterator) |
| 86 | + ::Minitest::Test.runnables = iterator |
| 87 | + ::Minitest.run ? 0 : 1 |
| 88 | + end |
| 89 | + end |
| 90 | + end |
| 91 | + |
| 92 | + class TestFramework |
| 93 | + class Minitest < TestFramework |
| 94 | + def all_suite_files |
| 95 | + ARGV |
| 96 | + end |
| 97 | + |
| 98 | + def suites_from_file(path) |
| 99 | + ::Minitest::Test.reset |
| 100 | + require File.absolute_path(path) |
| 101 | + ::Minitest::Test.runnables |
| 102 | + .reject { |s| s.runnable_methods.empty? } |
| 103 | + .map { |s| [s.name, s] } |
| 104 | + end |
| 105 | + end |
| 106 | + end |
| 107 | +end |
0 commit comments