module Test::Unit::Options

Public Class Methods

new(*, &block) click to toggle source
Calls superclass method
# File lib/test/unit.rb, line 33
def initialize(*, &block)
  @init_hook = block
  @options = nil
  super(&nil)
end

Public Instance Methods

option_parser() click to toggle source
# File lib/test/unit.rb, line 39
def option_parser
  @option_parser ||= OptionParser.new
end
process_args(args = []) click to toggle source
# File lib/test/unit.rb, line 43
def process_args(args = [])
  return @options if @options
  orig_args = args.dup
  options = {}
  opts = option_parser
  setup_options(opts, options)
  opts.parse!(args)
  orig_args -= args
  args = @init_hook.call(args, options) if @init_hook
  non_options(args, options)
  @help = orig_args.map { |s| s =~ /[\s|&<>$()]/ ? s.inspect : s }.join " "
  @options = options
  if @options[:parallel]
    @files = args
    @args = orig_args
  end
  options
end

Private Instance Methods

non_options(files, options) click to toggle source
# File lib/test/unit.rb, line 140
def non_options(files, options)
  begin
    require "rbconfig"
  rescue LoadError
    warn "#{caller(1)[0]}: warning: Parallel running disabled because can't get path to ruby; run specify with --ruby argument"
    options[:parallel] = nil
  else
    options[:ruby] ||= [RbConfig.ruby]
  end

  true
end
setup_options(opts, options) click to toggle source
# File lib/test/unit.rb, line 63
def setup_options(opts, options)
  opts.separator 'minitest options:'
  opts.version = MiniTest::Unit::VERSION

  options[:retry] = true
  options[:job_status] = nil

  opts.on '-h', '--help', 'Display this help.' do
    puts opts
    exit
  end

  opts.on '-s', '--seed SEED', Integer, "Sets random seed" do |m|
    options[:seed] = m
  end

  opts.on '-v', '--verbose', "Verbose. Show progress processing files." do
    options[:verbose] = true
    self.verbose = options[:verbose]
  end

  opts.on '-n', '--name PATTERN', "Filter test names on pattern." do |a|
    options[:filter] = a
  end

  opts.on '--jobs-status [TYPE]', [:normal, :replace],
          "Show status of jobs every file; Disabled when --jobs isn't specified." do |type|
    options[:job_status] = type || :normal
  end

  opts.on '-j N', '--jobs N', "Allow run tests with N jobs at once" do |a|
    if /^t/ =~ a
      options[:testing] = true # For testing
      options[:parallel] = a[1..-1].to_i
    else
      options[:parallel] = a.to_i
    end
  end

  opts.on '--separate', "Restart job process after one testcase has done" do
    options[:parallel] ||= 1
    options[:separate] = true
  end

  opts.on '--retry', "Retry running testcase when --jobs specified" do
    options[:retry] = true
  end

  opts.on '--no-retry', "Disable --retry" do
    options[:retry] = false
  end

  opts.on '--ruby VAL', "Path to ruby; It'll have used at -j option" do |a|
    options[:ruby] = a.split(/ /).reject(&:empty?)
  end

  opts.on '-q', '--hide-skip', 'Hide skipped tests' do
    options[:hide_skip] = true
  end

  opts.on '--show-skip', 'Show skipped tests' do
    options[:hide_skip] = false
  end

  opts.on '--color[=WHEN]',
          [:always, :never, :auto],
          "colorize the output.  WHEN defaults to 'always'", "or can be 'never' or 'auto'." do |c|
    options[:color] = c || :always
  end

  opts.on '--tty[=WHEN]',
          [:yes, :no],
          "force to output tty control.  WHEN defaults to 'yes'", "or can be 'no'." do |c|
    @tty = c != :no
  end
end