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.rb` or `config/test.rb`, or `Testfile` or ’.test` with optional ‘.rb` extension, 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
deprecated
Deprecated.
Planned for deprecation in April 2013.
- #loadpath ⇒ Object
-
#makelist(list) ⇒ Array<String>
private
If given a String then split up at ‘:` and `;` markers.
- #match ⇒ Object
-
#options ⇒ OptionParser
Setup OptionsParser instance.
- #profile ⇒ Object
- #profile=(name) ⇒ Object
-
#require_dotopts ⇒ Object
TODO: Not sure if this should be used or not.
- #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 30 |
# File 'lib/rubytest-cli.rb', line 24 def initialize require 'optparse' @config = {} @config_file = nil #@config = Test.configuration(true) 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
233 234 235 |
# File 'lib/rubytest-cli.rb', line 233 def autopath=(bool) @config[:autopath] = !! bool end |
#autopath? ⇒ Boolean
229 230 231 |
# File 'lib/rubytest-cli.rb', line 229 def autopath? @config[:autopath] end |
#chdir ⇒ Object
237 238 239 |
# File 'lib/rubytest-cli.rb', line 237 def chdir @config[:chdir] end |
#chdir=(dir) ⇒ Object
241 242 243 |
# File 'lib/rubytest-cli.rb', line 241 def chdir=(dir) @config[:chdir] = dir.to_str end |
#config ⇒ Hash
Test run configuration.
167 168 169 |
# File 'lib/rubytest-cli.rb', line 167 def config @config end |
#config_file ⇒ String
Find traditional configuration file.
193 194 195 |
# File 'lib/rubytest-cli.rb', line 193 def config_file @config_file end |
#format ⇒ Object
208 209 210 |
# File 'lib/rubytest-cli.rb', line 208 def format @config[:format] end |
#format=(format) ⇒ Object
213 214 215 |
# File 'lib/rubytest-cli.rb', line 213 def format=(format) @config[:format] = format.to_s end |
#load_config ⇒ Object
Planned for deprecation in April 2013.
Load configuration file. An example file might look like:
Test.configure do |run|
run.files << 'test/case_*.rb'
end
178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/rubytest-cli.rb', line 178 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
245 246 247 |
# File 'lib/rubytest-cli.rb', line 245 def loadpath @config[:loadpath] ||= [] end |
#makelist(list) ⇒ Array<String> (private)
If given a String then split up at ‘:` and `;` markers. Otherwise ensure the list is an Array and the entries are all strings and not empty.
268 269 270 271 272 273 274 275 276 |
# File 'lib/rubytest-cli.rb', line 268 def makelist(list) case list when String list = list.split(/[:;]/) else list = Array(list).map{ |path| path.to_s } end list.reject{ |path| path.strip.empty? } end |
#match ⇒ Object
225 226 227 |
# File 'lib/rubytest-cli.rb', line 225 def match @config[:match] ||= [] end |
#options ⇒ OptionParser
Setup OptionsParser instance.
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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/rubytest-cli.rb', line 72 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.separator "PRESET OPTIONS:" #pnames = profile_names #unless pnames.empty? # pnames.each do |pname| # opt.separator((" " * 40) + "* #{pname}") # end #end #opt.separator "CONFIG OPTIONS:" 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 # tempted to change -T 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| #makelist(paths).reverse_each do |path| # $LOAD_PATH.unshift path #end 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 '-T', '--tests GLOB', "tests to run (if none given as arguments)" do |glob| # config.files << glob #end opt.on '-V' , '--verbose', 'provide extra detail in reports' do conf.verbose = true end #opt.on('--log PATH', 'log test output to path'){ |path| # config.log = path #} opt.on("--[no-]ansi" , 'turn on/off ANSI colors'){ |v| $ansi = v } opt.on("--debug" , 'turn on debugging mode'){ $DEBUG = true } #opt.separator "COMMAND OPTIONS:" opt.on('--about' , 'display information about rubytest') do puts "Ruby Test v%s" % [Test.index['version']] Test.index['copyrights'].each do |c| puts "(c) %s %s (%s)" % c.values_at('year', 'holder', 'license') end exit end opt.on('--version' , 'display rubytest version') do puts Test::VERSION exit end opt.on('-h', '--help', 'display this help message'){ puts opt exit } end end |
#profile ⇒ Object
198 199 200 |
# File 'lib/rubytest-cli.rb', line 198 def profile @profile end |
#profile=(name) ⇒ Object
203 204 205 |
# File 'lib/rubytest-cli.rb', line 203 def profile=(name) @profile = name.to_s end |
#require_dotopts ⇒ Object
TODO: Not sure if this should be used or not.
62 63 64 65 66 67 |
# File 'lib/rubytest-cli.rb', line 62 def require_dotopts begin require 'dotopts' rescue LoadError end end |
#requires ⇒ Object
249 250 251 |
# File 'lib/rubytest-cli.rb', line 249 def requires @config[:requires] ||= [] end |
#run(argv = nil) ⇒ Object
Run tests.
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 |
# File 'lib/rubytest-cli.rb', line 35 def run(argv=nil) #require_dotopts 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) #runner = Runner.new(test_config) #begin # success = runner.run # exit -1 unless success #rescue => error # raise error if $DEBUG # $stderr.puts('ERROR: ' + error.to_s) # exit -1 #end end |
#tags ⇒ Object
217 218 219 |
# File 'lib/rubytest-cli.rb', line 217 def @config[:tags] ||= [] end |
#units ⇒ Object
221 222 223 |
# File 'lib/rubytest-cli.rb', line 221 def units @config[:units] ||= [] end |
#verbose=(bool) ⇒ Object
257 258 259 |
# File 'lib/rubytest-cli.rb', line 257 def verbose=(bool) @config[:verbose] = !! bool end |
#verbose? ⇒ Boolean
253 254 255 |
# File 'lib/rubytest-cli.rb', line 253 def verbose? @config[:verbose] end |