class Test::CLI
Command line interface to test runner.
Constants
- 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.
Public Class Methods
Initialize CLI
instance.
@return nothing
# File lib/rubytest-cli.rb, line 24 def initialize require 'optparse' @config = {} @config_file = nil #@config = Test.configuration(true) end
Convenience method for invoking the CLI
.
@return nothing
# File lib/rubytest-cli.rb, line 17 def self.run(*argv) new.run(*argv) end
Public Instance Methods
# File lib/rubytest-cli.rb, line 233 def autopath=(bool) @config[:autopath] = !! bool end
# File lib/rubytest-cli.rb, line 229 def autopath? @config[:autopath] end
# File lib/rubytest-cli.rb, line 237 def chdir @config[:chdir] end
# File lib/rubytest-cli.rb, line 241 def chdir=(dir) @config[:chdir] = dir.to_str end
Find traditional configuration file.
@return [String] Config file path.
# File lib/rubytest-cli.rb, line 193 def config_file @config_file end
# File lib/rubytest-cli.rb, line 208 def format @config[:format] end
# File lib/rubytest-cli.rb, line 213 def format=(format) @config[:format] = format.to_s end
Load configuration file. An example file might look like:
Test.configure do |run| run.files << 'test/case_*.rb' end
@deprecated Planned for deprecation in April 2013.
# 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
# File lib/rubytest-cli.rb, line 245 def loadpath @config[:loadpath] ||= [] end
# File lib/rubytest-cli.rb, line 225 def match @config[:match] ||= [] end
Setup OptionsParser instance.
@return [OptionParser]
# File lib/rubytest-cli.rb, line 72 def options conf = self OptionParser.new do |opt| opt.banner = "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.tags.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
# File lib/rubytest-cli.rb, line 198 def profile @profile end
# File lib/rubytest-cli.rb, line 203 def profile=(name) @profile = name.to_s end
TODO: Not sure if this should be used or not.
# File lib/rubytest-cli.rb, line 62 def require_dotopts begin require 'dotopts' rescue LoadError end end
# File lib/rubytest-cli.rb, line 249 def requires @config[:requires] ||= [] end
Run tests.
@return nothing
# File lib/rubytest-cli.rb, line 35 def run(argv=nil) #require_dotopts argv = (argv || ARGV.dup) options.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
# File lib/rubytest-cli.rb, line 221 def units @config[:units] ||= [] end
# File lib/rubytest-cli.rb, line 257 def verbose=(bool) @config[:verbose] = !! bool end
# File lib/rubytest-cli.rb, line 253 def verbose? @config[:verbose] end
Private Instance Methods
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.
@return [Array<String>]
# 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