module Minitest::Hooks::ClassMethods

def _record_minitest_hooks_error(reporter, instance)

def _record_minitest_hooks_error(reporter, instance)
  # In Minitest 5.11+, use Minitest::Result for wrapping the object to send
  # to the reporter.
  if(defined?(Minitest::Result))
    result = Minitest::Result.from(instance)
  # :nocov:
  else
    result = instance
  # :nocov:
  end
  reporter.record result
end

def after(type=nil, &block)

If type is :all, set the after_all hook instead of the after hook.
def after(type=nil, &block)
  if type == :all
   define_method(:after_all) do
      instance_exec(&block)
      super()
    end
    nil
  else
    super
  end
end

def around(type=nil, &block)

If type is :all, set the around_all hook, otherwise set the around hook.
def around(type=nil, &block)
  meth = type == :all ? :around_all : :around
  define_method(meth, &block)
end

def before(type=nil, &block)

If type is :all, set the before_all hook instead of the before hook.
def before(type=nil, &block)
  if type == :all
   define_method(:before_all) do
      super()
      instance_exec(&block)
    end
    nil
  else
    super
  end
end

def new(name)

Unless name is NEW, return a dup singleton instance.
def new(name)
  if name.equal?(NEW)
    return super('around_all')
  end
  instance = @instance.dup
  instance.name = name
  instance.failures = []
  instance
end

def with_info_handler(reporter, &block)

dup of the singleton instance.
used to implement around_all/before_all/after_all hooks, and each spec will run as a
When running the specs in the class, first create a singleton instance, the singleton is
def with_info_handler(reporter, &block)
  @instance = new(NEW)
  @instance.time = 0
  @instance.name = "around_all"
 
  begin
    @instance.around_all do
      begin
        @instance.capture_exceptions do
          @instance.name = "before_all"
          @instance.before_all
        end
        if @instance.failure
          failed = true
          _record_minitest_hooks_error(reporter, @instance)
        else
          super(reporter, &block)
        end
      ensure
        @instance.capture_exceptions do
          @instance.name = "after_all" unless failed
          @instance.after_all
        end
        if @instance.failure && !failed
          failed = true
          _record_minitest_hooks_error(reporter, @instance)
        end
        @instance.name = "around_all" unless failed
      end
    end
  rescue => e
    @instance.capture_exceptions do
      raise e
    end
    _record_minitest_hooks_error(reporter, @instance)
  end
end