Class: Test::CLI
- Inherits:
-
Object
- Object
- Test::CLI
- Defined in:
- lib/rubytest/cli.rb
Overview
Command line interface to test runner.
TODO: Use cli based library instead of option parser?
Class Method Summary collapse
-
.run(*argv) ⇒ Object
Convenience method for invoking the CLI.
Instance Method Summary collapse
-
#config ⇒ Config
Test run configuration.
-
#initialize ⇒ Object
constructor
Initialize CLI instance.
-
#makelist(list) ⇒ Array<String>
If given a String then split up at
:and ‘;` markers. -
#options ⇒ OptionParser
Setup OptionsParser instance.
-
#run(argv = nil) ⇒ Object
Run tests.
Constructor Details
#initialize ⇒ Object
Initialize CLI instance.
19 20 21 22 23 |
# File 'lib/rubytest/cli.rb', line 19 def initialize require 'optparse' @config = Test.configuration(true) end |
Class Method Details
.run(*argv) ⇒ Object
Convenience method for invoking the CLI.
12 13 14 |
# File 'lib/rubytest/cli.rb', line 12 def self.run(*argv) new.run(*argv) end |
Instance Method Details
#config ⇒ Config
Test run configuration.
28 29 30 |
# File 'lib/rubytest/cli.rb', line 28 def config @config end |
#makelist(list) ⇒ Array<String>
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.
153 154 155 156 157 158 159 160 161 |
# File 'lib/rubytest/cli.rb', line 153 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 |
#options ⇒ OptionParser
Setup OptionsParser instance.
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 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 |
# File 'lib/rubytest/cli.rb', line 59 def this = self OptionParser.new do |opt| opt. = "Usage: #{File.basename($0)} [options] [files ...]" #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| config.format = name end opt.on '-y', '--tapy', 'shortcut for -f tapy' do config.format = 'tapy' end opt.on '-j', '--tapj', 'shortcut for -f tapj' do config.format = 'tapj' end # tempted to change -T opt.on '-t', '--tag TAG', 'select tests by tag' do |tag| config..concat makelist(tag) end opt.on '-u', '--unit TAG', 'select tests by software unit' do |unit| config.units.concat makelist(unit) end opt.on '-m', '--match TEXT', 'select tests by description' do |text| config.match.concat makelist(text) end opt.on '-A', '--autopath', 'automatically add paths to $LOAD_PATH' do |paths| config.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 config.loadpath.concat makelist(paths) end opt.on '-C', '--chdir DIR', 'change directory before running tests' do |dir| config.chdir = dir end opt.on '-R', '--chroot', 'change to project root directory before running tests' do config.chdir = Config.root end opt.on '-r', '--require FILE', 'require file' do |file| #require file config.requires.concat makelist(file) end opt.on '-c', '--config FILE', "require local config file (immediately)" do |file| config.load_config(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 config.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 |
#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 |
# File 'lib/rubytest/cli.rb', line 35 def run(argv=nil) argv = (argv || ARGV.dup) .parse!(argv) config.files.replace(argv) unless argv.empty? config.apply_environment_overrides #Test.run(config) runner = Runner.new(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 |