Module: ForkingTestRunner::CLI

Defined in:
lib/forking_test_runner/cli.rb

Overview

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

Constant Summary collapse

OPTIONS =
[
  [:rspec, "--rspec", "RSpec mode"],
  [:helper, "--helper", "Helper file to load before tests start", String],
  [:quiet, "--quiet", "Quiet"],
  [:no_fixtures, "--no-fixtures", "Do not load fixtures"],
  [:no_ar, "--no-ar", "Disable ActiveRecord logic"],
  [:merge_coverage, "--merge-coverage", "Merge base code coverage into individual files coverage and summarize coverage report"],
  [:report_line_coverage, "--report-line-coverage", "Convert coverage report to line coverage (for compatibility)"],
  [
    :record_runtime,
    "--record-runtime=MODE",
    "\n      Record test runtime:\n" <<
      "        simple = write to disk at --runtime-log)\n" <<
      "        amend  = write from multiple remote workers via http://github.com/grosser/amend, needs TRAVIS_REPO_SLUG & TRAVIS_BUILD_NUMBER",
    String
  ],
  [:runtime_log, "--runtime-log=FILE", "File to store runtime log in or runtime.log", String],
  [:parallel, "--parallel=NUM", "Number of parallel groups to run at once", Integer],
  [:group, "--group=NUM[,NUM]", "What group this is (use with --groups / starts at 1)", String],
  [:groups, "--groups=NUM", "How many groups there are in total (use with --group)", Integer],
  [:version, "--version", "Show version"],
  [:help, "--help", "Show help"]
]

Class Method Summary collapse

Class Method Details

.parse_options(argv) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# 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: 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)
    abort "merge_coverage does not work on ruby prior to 2.3" if RUBY_VERSION < "2.3.0"
  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