module Minitest

def self.process_args args = [] # :nodoc:

:nodoc:
def self.process_args args = [] # :nodoc:
  options = {
             :io => $stdout,
            }
  orig_args = args.dup
  OptionParser.new do |opts|
    opts.banner  = "minitest options:"
    opts.version = Minitest::VERSION
    opts.on "-h", "--help", "Display this help." do
      puts opts
      exit
    end
    opts.on "--no-plugins", "Bypass minitest plugin auto-loading (or set $MT_NO_PLUGINS)."
    desc = "Sets random seed. Also via env. Eg: SEED=n rake"
    opts.on "-s", "--seed SEED", Integer, desc do |m|
      options[:seed] = m.to_i
    end
    opts.on "-v", "--verbose", "Verbose. Show progress processing files." do
      options[:verbose] = true
    end
    opts.on "-q", "--quiet", "Quiet. Show no progress processing files." do
      options[:quiet] = true
    end
    opts.on "--show-skips", "Show skipped at the end of run." do
      options[:show_skips] = true
    end
    opts.on "-n", "--name PATTERN", "Filter run on /regexp/ or string." do |a|
      options[:filter] = a
    end
    opts.on "-e", "--exclude PATTERN", "Exclude /regexp/ or string from run." do |a|
      options[:exclude] = a
    end
    opts.on "-S", "--skip CODES", String, "Skip reporting of certain types of results (eg E)." do |s|
      options[:skip] = s.chars.to_a
    end
    ruby27plus = ::Warning.respond_to?(:[]=)
    opts.on "-W[error]", String, "Turn Ruby warnings into errors" do |s|
      options[:Werror] = true
      case s
      when "error", "all", nil then
        require "minitest/error_on_warning"
        $VERBOSE = true
        ::Warning[:deprecated] = true if ruby27plus
      else
        ::Warning[s.to_sym] = true if ruby27plus # check validity of category
      end
    end
    unless extensions.empty?
      opts.separator ""
      opts.separator "Known extensions: #{extensions.join(", ")}"
      extensions.each do |mod_or_meth|
        case mod_or_meth
        when Symbol, String then
          meth = mod_or_meth
          msg = "plugin_#{meth}_options"
          send msg, opts, options if respond_to?(msg)
        when Module
          recv = mod_or_meth
          next unless recv.respond_to? :minitest_plugin_options
          recv.minitest_plugin_options opts, options
        else
          raise ArgumentError, "blahblah %p" % [mod_or_meth]
        end
      end
    end
    begin
      opts.parse! args
    rescue OptionParser::InvalidOption => e
      puts
      puts e
      puts
      puts opts
      exit 1
    end
    orig_args -= args
  end
  unless options[:seed] then
    srand
    options[:seed] = (ENV["SEED"] || srand).to_i % 0xFFFF
    orig_args << "--seed" << options[:seed].to_s
  end
  options[:args] = orig_args.map { |s|
    s =~ /[\s|&<>$()]/ ? s.inspect : s
  }.join " "
  options
end