module ForkingTestRunner::CLI

read and delete options we support and pass the rest through to the underlying test runner (-v / –seed etc)

Constants

OPTIONS

Public Class Methods

parse_options(argv) click to toggle source
# File lib/forking_test_runner/cli.rb, line 29
def parse_options(argv)
  options = OPTIONS.each_with_object({}) do |(setting, flag, _, type), all|
    all[setting] = delete_argv(flag.split('=', 2)[0], argv, type:)
  end

  # show version
  if options.fetch(:version)
    puts VERSION
    exit 0
  end

  # show help
  if options[:help]
    puts help
    exit 0
  end

  # check if we can use merge_coverage
  if options.fetch(:merge_coverage) && "2.3.0" > RUBY_VERSION
    abort "merge_coverage does not work on ruby prior to 2.3"
  end

  if !!options.fetch(:group) ^ !!options.fetch(:groups)
    abort "use --group and --groups together"
  end

  # all remaining non-flag options until the next flag must be tests
  next_flag = argv.index { |arg| arg.start_with?("-") } || argv.size
  tests = argv.slice!(0, next_flag)
  abort "No tests or folders found in arguments" if tests.empty?
  tests.each { |t| abort "Unable to find #{t}" unless File.exist?(t) }

  [options, tests]
end

Private Class Methods

delete_argv(name, argv, type: nil) click to toggle source

we remove the args we understand and leave the rest alone so minitest / rspec can read their own options (–seed / -v …)

- keep our options clear / unambiguous to avoid overriding
- read all serial non-flag arguments as tests and leave only unknown options behind
- use .fetch everywhere to make sure nothing is misspelled

GOOD: test –ours –theirs OK: –ours test –theirs BAD: –theirs test –ours

# File lib/forking_test_runner/cli.rb, line 83
def delete_argv(name, argv, type: nil)
  return unless index = argv.index(name)
  argv.delete_at(index)
  if type
    found = argv.delete_at(index) || raise("Missing argument for #{name}")
    send(type.name, found) # case found
  else
    true
  end
end
help() click to toggle source

fake parser that will print nicely

# File lib/forking_test_runner/cli.rb, line 67
def help
  OptionParser.new("forking-test-runner folder [options]", 32, '') do |opts|
    OPTIONS.each do |_, flag, desc, type|
      opts.on(flag, desc, type)
    end
  end
end