Class: Test::CLI
- Inherits:
-
Object
- Object
- Test::CLI
- Defined in:
- lib/rubytest/cli.rb
Overview
Command line interface to test runner.
Constant Summary collapse
- GLOB_CONFIG =
Test configuration file can be in
etc/test.rborconfig/test.rb, orTestfileor ‘.test` with optional.rbextension, in that order of precedence. To use a different file there is the -c/–config option. '{etc/test.rb,config/test.rb,testfile.rb,testfile,.test.rb,.test}'
Class Method Summary collapse
-
.run(*argv) ⇒ Object
Convenience method for invoking the CLI.
Instance Method Summary collapse
- #autopath=(bool) ⇒ Object
- #autopath? ⇒ Boolean
- #chdir ⇒ Object
- #chdir=(dir) ⇒ Object
-
#config ⇒ Hash
Test run configuration.
-
#config_file ⇒ String
Find traditional configuration file.
- #format ⇒ Object
- #format=(format) ⇒ Object
-
#initialize ⇒ Object
constructor
Initialize CLI instance.
-
#load_config ⇒ Object
Load configuration file.
- #loadpath ⇒ Object
- #match ⇒ Object
-
#options ⇒ OptionParser
Setup OptionsParser instance.
- #profile ⇒ Object
- #profile=(name) ⇒ Object
- #requires ⇒ Object
-
#run(argv = nil) ⇒ Object
Run tests.
- #tags ⇒ Object
- #units ⇒ Object
- #verbose=(bool) ⇒ Object
- #verbose? ⇒ Boolean
Constructor Details
#initialize ⇒ Object
Initialize CLI instance.
24 25 26 27 28 29 |
# File 'lib/rubytest/cli.rb', line 24 def initialize require 'optparse' @config = {} @config_file = nil end |
Class Method Details
.run(*argv) ⇒ Object
Convenience method for invoking the CLI.
17 18 19 |
# File 'lib/rubytest/cli.rb', line 17 def self.run(*argv) new.run(*argv) end |
Instance Method Details
#autopath=(bool) ⇒ Object
176 177 178 |
# File 'lib/rubytest/cli.rb', line 176 def autopath=(bool) @config[:autopath] = !! bool end |
#autopath? ⇒ Boolean
172 173 174 |
# File 'lib/rubytest/cli.rb', line 172 def autopath? @config[:autopath] end |
#chdir ⇒ Object
180 181 182 |
# File 'lib/rubytest/cli.rb', line 180 def chdir @config[:chdir] end |
#chdir=(dir) ⇒ Object
184 185 186 |
# File 'lib/rubytest/cli.rb', line 184 def chdir=(dir) @config[:chdir] = dir.to_str end |
#config ⇒ Hash
Test run configuration.
120 121 122 |
# File 'lib/rubytest/cli.rb', line 120 def config @config end |
#config_file ⇒ String
Find traditional configuration file.
140 141 142 |
# File 'lib/rubytest/cli.rb', line 140 def config_file @config_file end |
#format ⇒ Object
152 153 154 |
# File 'lib/rubytest/cli.rb', line 152 def format @config[:format] end |
#format=(format) ⇒ Object
156 157 158 |
# File 'lib/rubytest/cli.rb', line 156 def format=(format) @config[:format] = format.to_s end |
#load_config ⇒ Object
Load configuration file.
125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/rubytest/cli.rb', line 125 def load_config file = config_file unless file if chdir file = Dir.glob(File.join(chdir, GLOB_CONFIG)).first else file = Dir.glob(GLOB_CONFIG).first end end load file if file end |
#loadpath ⇒ Object
188 189 190 |
# File 'lib/rubytest/cli.rb', line 188 def loadpath @config[:loadpath] ||= [] end |
#match ⇒ Object
168 169 170 |
# File 'lib/rubytest/cli.rb', line 168 def match @config[:match] ||= [] end |
#options ⇒ OptionParser
Setup OptionsParser instance.
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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/rubytest/cli.rb', line 52 def conf = self OptionParser.new do |opt| opt. = "Usage: #{File.basename($0)} [options] [files ...]" opt.on '-p', '--profile NAME', 'use configuration profile' do |name| conf.profile = name end opt.on '-f', '--format NAME', 'report format' do |name| conf.format = name end opt.on '-y', '--tapy', 'shortcut for -f tapy' do conf.format = 'tapy' end opt.on '-j', '--tapj', 'shortcut for -f tapj' do conf.format = 'tapj' end opt.on '-t', '--tag TAG', 'select tests by tag' do |tag| conf..concat makelist(tag) end opt.on '-u', '--unit TAG', 'select tests by software unit' do |unit| conf.units.concat makelist(unit) end opt.on '-m', '--match TEXT', 'select tests by description' do |text| conf.match.concat makelist(text) end opt.on '-A', '--autopath', 'automatically add paths to $LOAD_PATH' do |paths| conf.autopath = true end opt.on '-I', '--loadpath PATH', 'add given path to $LOAD_PATH' do |paths| conf.loadpath.concat makelist(paths) end opt.on '-C', '--chdir DIR', 'change directory before running tests' do |dir| conf.chdir = dir end opt.on '-R', '--chroot', 'change to project root directory before running tests' do conf.chdir = Config.root end opt.on '-r', '--require FILE', 'require file' do |file| conf.requires.concat makelist(file) end opt.on '-c', '--config FILE', "use alternate config file" do |file| conf.config_files << file end opt.on '-V' , '--verbose', 'provide extra detail in reports' do conf.verbose = true end opt.on("--[no-]ansi" , 'turn on/off ANSI colors'){ |v| $ansi = v } opt.on("--debug" , 'turn on debugging mode'){ $DEBUG = true } opt.on('--version' , 'display rubytest version') do puts "rubytest v#{Test::VERSION}" exit end opt.on('-h', '--help', 'display this help message'){ puts opt exit } end end |
#profile ⇒ Object
144 145 146 |
# File 'lib/rubytest/cli.rb', line 144 def profile @profile end |
#profile=(name) ⇒ Object
148 149 150 |
# File 'lib/rubytest/cli.rb', line 148 def profile=(name) @profile = name.to_s end |
#requires ⇒ Object
192 193 194 |
# File 'lib/rubytest/cli.rb', line 192 def requires @config[:requires] ||= [] end |
#run(argv = nil) ⇒ Object
Run tests.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/rubytest/cli.rb', line 34 def run(argv=nil) argv = (argv || ARGV.dup) .parse!(argv) @config[:files] = argv unless argv.empty? load_config test_config = Test.configuration(profile) test_config.apply_environment_defaults test_config.apply(@config) Test.run!(test_config) end |
#tags ⇒ Object
160 161 162 |
# File 'lib/rubytest/cli.rb', line 160 def @config[:tags] ||= [] end |
#units ⇒ Object
164 165 166 |
# File 'lib/rubytest/cli.rb', line 164 def units @config[:units] ||= [] end |
#verbose=(bool) ⇒ Object
200 201 202 |
# File 'lib/rubytest/cli.rb', line 200 def verbose=(bool) @config[:verbose] = !! bool end |
#verbose? ⇒ Boolean
196 197 198 |
# File 'lib/rubytest/cli.rb', line 196 def verbose? @config[:verbose] end |