Class: TestBench::CLI
- Inherits:
-
Object
- Object
- TestBench::CLI
- Defined in:
- lib/test_bench/cli/cli.rb
Instance Attribute Summary collapse
-
#argv ⇒ Object
readonly
Returns the value of attribute argv.
- #root_directory ⇒ Object
- #settings ⇒ Object
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
- #help ⇒ Object
-
#initialize(argv) ⇒ CLI
constructor
A new instance of CLI.
- #option_parser ⇒ Object
- #program_name ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(argv) ⇒ CLI
7 8 9 |
# File 'lib/test_bench/cli/cli.rb', line 7 def initialize argv @argv = argv end |
Instance Attribute Details
#argv ⇒ Object (readonly)
Returns the value of attribute argv.
3 4 5 |
# File 'lib/test_bench/cli/cli.rb', line 3 def argv @argv end |
#root_directory ⇒ Object
90 91 92 |
# File 'lib/test_bench/cli/cli.rb', line 90 def root_directory @root_directory ||= File. Dir.pwd end |
#settings ⇒ Object
94 95 96 |
# File 'lib/test_bench/cli/cli.rb', line 94 def settings @settings ||= Settings.new end |
Class Method Details
.call(argv = nil, exclude_pattern: nil, tests_directory: nil) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/test_bench/cli/cli.rb', line 11 def self.call argv=nil, exclude_pattern: nil, tests_directory: nil argv ||= ARGV settings = Settings.toplevel settings.exclude_pattern = exclude_pattern unless exclude_pattern.nil? settings.tests_dir = tests_directory unless tests_directory.nil? instance = new argv instance.settings = settings instance.() end |
Instance Method Details
#call ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/test_bench/cli/cli.rb', line 25 def call option_parser.parse! argv paths = argv paths << settings.tests_dir if paths.empty? TestBench::Runner.(paths, root_directory) or exit 1 end |
#help ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/test_bench/cli/cli.rb', line 34 def help puts option_parser.help puts puts "If no paths are specified, \#{program_name} runs all files in ./tests. The following environment variables can also control execution:\n\n TEST_BENCH_ABORT_ON_ERROR Same as -a or --abort-on-error\n TEST_BENCH_COLOR Set color on or off\n TEST_BENCH_EXCLUDE_PATTERN Regular expression that matches paths to be excluded from execution\n TEST_BENCH_RECORD_TELEMETRY Causes Test Bench to preserve telemetry events (needed for testing Test Bench itself)\n TEST_BENCH_REVERSE_BACKTRACES Prints exceptions in reverse order\n TEST_BENCH_QUIET Same as -q or --quiet\n TEST_BENCH_TESTS_DIR Specifies the default directory where Test Bench searches for tests\n TEST_BENCH_VERBOSE Same as -v or --verbose\n\n TEXT\nend\n" |
#option_parser ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/test_bench/cli/cli.rb', line 52 def option_parser @option_parser ||= OptionParser.new do |parser| parser.on '-a', '--abort-on-error', "Exit immediately after any test script fails" do settings.abort_on_error = true end parser.on '-h', '--help', "Print this help message and exit successfully" do help exit 0 end parser.on '-q', '--quiet', "Lower verbosity level" do settings.lower_verbosity end parser.on '-r', '--reverse-backtraces', "Reverse error backtraces" do settings.reverse_backtraces = true end parser.on '-v', '--verbose', "Raise verbosity level" do settings.raise_verbosity end parser.on '-V', '--version', "Print version and exit successfully" do puts "test-bench (#{parser.program_name}) version #{version}" exit 0 end parser.on '-x', '--exclude PATTERN', %{Filter out files matching PATTERN (Default is "_init$")} do |pattern| settings.exclude_pattern = pattern end end end |
#program_name ⇒ Object
86 87 88 |
# File 'lib/test_bench/cli/cli.rb', line 86 def program_name File.basename $PROGRAM_NAME end |
#version ⇒ Object
98 99 100 101 102 103 104 105 106 |
# File 'lib/test_bench/cli/cli.rb', line 98 def version spec = Gem.loaded_specs['test_bench'] if spec spec.version else '(local)'.freeze end end |