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 do |o|
    o.pretty_inspect
  end
end

def self.parallelize_me!

def self.parallelize_me!
  require "minitest/parallel_each"
  class << self
    undef_method :test_order if method_defined? :test_order
    define_method :test_order do :parallel end
  end
end

def self.runnable_methods

def self.runnable_methods
  methods = methods_matching(/^test_/)
  case self.test_order
  when :parallel
    max = methods.size
    ParallelEach.new methods.sort.sort_by { rand max }
  when :random then
    max = methods.size
    methods.sort.sort_by { rand max }
  when :alpha, :sorted then
    methods.sort
  else
    raise "Unknown test_order: #{self.test_order.inspect}"
  end
end

def self.synchronize # :nodoc:

:nodoc:
def self.synchronize # :nodoc:
  if @mutex then # see parallel_each.rb
    @mutex.synchronize { yield }
  else
    yield
  end
end

def self.test_order

def self.test_order
  :random
end

def capture_exceptions # :nodoc:

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

def capture_io(&b)

def capture_io(&b)
  Test.synchronize do
    simple_capture_io(&b)
  end
end

def capture_subprocess_io(&b)

def capture_subprocess_io(&b)
  Test.synchronize do
    simple_capture_subprocess_io(&b)
  end
end

def dup # :nodoc:

:nodoc:
def dup # :nodoc:
  obj = super
  obj.time = self.time
  obj
end

def error?

def error?
  self.failures.any? { |f| UnexpectedError === f }
end

def location

def location
  loc = " [#{self.failure.location}]" unless passed? or error?
  "#{self.class}##{self.name}#{loc}"
end

def passed?

def passed?
  not self.failure
end

def result_code

def result_code
  self.failure and self.failure.result_code or "."
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
      %w{ before_teardown teardown after_teardown }.each do |hook|
        capture_exceptions do
          self.send hook
        end
      end
    end
  end
  self # per contract
end

def skipped?

def skipped?
  self.failure and Skip === self.failure
end

def test_order # :nodoc:

:nodoc:
def test_order # :nodoc:
  :parallel
end

def time_it # :nodoc:

:nodoc:
def time_it # :nodoc:
  t0 = Time.now
  yield
ensure
  self.time = Time.now - t0
end

def to_s # :nodoc:

:nodoc:
def to_s # :nodoc:
  return location if passed? and not skipped?
  failures.map { |failure|
    "#{failure.result_label}:\n#{self.location}:\n#{failure.message}\n"
  }.join "\n"
end

def with_info_handler # :nodoc:

:nodoc:
def with_info_handler # :nodoc:
  supports_info_signal = Signal.list["INFO"]
  t0 = Time.now
  trap "INFO" do
    warn ""
    warn "Current: %s#%s %.2fs" % [self.class, self.name, Time.now - t0]
  end if supports_info_signal
  yield
ensure
  trap "INFO", "DEFAULT" if supports_info_signal
end