class Minitest::Test

def self.i_suck_and_my_tests_are_order_dependent!

def self.i_suck_and_my_tests_are_order_dependent!
  class << self
    undef_method :test_order if method_defined? :test_order
    define_method :test_order do :alpha end
  end
end

def self.make_my_diffs_pretty!

def self.make_my_diffs_pretty!
  require "pp"
  define_method :mu_pp, &:pretty_inspect
end

def self.parallelize_me!

def self.parallelize_me!
  include Minitest::Parallel::Test
  extend Minitest::Parallel::Test::ClassMethods
end

def self.runnable_methods

def self.runnable_methods
  methods = methods_matching(/^test_/)
  case self.test_order
  when :random, :parallel then
    srand Minitest.seed
    methods.sort.shuffle
  when :alpha, :sorted then
    methods.sort
  else
    raise "Unknown test_order: #{self.test_order.inspect}"
  end
end

def self.test_order

def self.test_order
  :random
end

def capture_exceptions # :nodoc:

:nodoc:
def capture_exceptions # :nodoc:
  yield
rescue *PASSTHROUGH_EXCEPTIONS
  raise
rescue Assertion => e
  self.failures << e
rescue Exception => e
  self.failures << UnexpectedError.new(sanitize_exception e)
end

def class_name # :nodoc:

:nodoc:
def class_name # :nodoc:
  self.class.name # for Minitest::Reportable
end

def neuter_exception e

def neuter_exception e
  bt = e.backtrace
  msg = e.message.dup
  new_exception e.class, msg, bt            # e.class can be a problem...
rescue TypeError
  msg.prepend "Neutered Exception #{e.class}: "
  new_exception RuntimeError, msg, bt, true # but if this raises, we die
end

def new_exception klass, msg, bt, kill = false

def new_exception klass, msg, bt, kill = false
  ne = klass.new msg
  ne.set_backtrace bt
  if kill then
    ne.instance_variables.each do |v|
      ne.remove_instance_variable v
    end
  end
  Marshal.dump ne                           # can raise TypeError
  ne
end

def run

def run
  with_info_handler do
    time_it do
      capture_exceptions do
        before_setup; setup; after_setup
        self.send self.name
      end
      TEARDOWN_METHODS.each do |hook|
        capture_exceptions do
          self.send hook
        end
      end
    end
  end
  Result.from self # per contract
end

def sanitize_exception e # :nodoc:

:nodoc:
def sanitize_exception e # :nodoc:
  Marshal.dump e
  e                                         # good: use as-is
rescue TypeError
  neuter_exception e
end

def with_info_handler &block # :nodoc:

:nodoc:
def with_info_handler &block # :nodoc:
  t0 = Minitest.clock_time
  handler = lambda do
    warn "\nCurrent: %s#%s %.2fs" % [self.class, self.name, Minitest.clock_time - t0]
  end
  self.class.on_signal ::Minitest.info_signal, handler, &block
end