Class: Test::Runner
- Inherits:
-
Object
- Object
- Test::Runner
- Defined in:
- lib/test/cli.rb,
lib/test/runner.rb
Overview
The Test::Runner class handles the execution of tests.
Constant Summary collapse
- DEFAULT_FORMAT =
Default report is in the old “dot-progress” format.
'dotprogress'
- OPEN_ERRORS =
Exceptions that are not caught by test runner.
[NoMemoryError, SignalException, Interrupt, SystemExit]
Instance Attribute Summary collapse
-
#files ⇒ Object
readonly
Test files to load.
-
#format ⇒ Object
Reporter format name, or name fragment, used to look up reporter class.
-
#match ⇒ Object
readonly
Matching text used to filter which tests are run.
-
#observers ⇒ Object
readonly
Array of observers, typically this just contains the recorder and reporter instances.
-
#recorder ⇒ Object
readonly
Record pass, fail, error, pending and omitted tests.
-
#reporter ⇒ Object
readonly
The reporter to use for ouput.
-
#suite ⇒ Object
readonly
Test suite to run.
-
#tags ⇒ Object
readonly
Selected tags used to filter which tests are run.
-
#units ⇒ Object
readonly
List of units with which to filter tests.
Class Method Summary collapse
-
.cli(*argv) ⇒ Object
Test runner command line interface.
- .cli_options(runner, argv) ⇒ Object
-
.files ⇒ Object
Default list of test files to load.
- .format ⇒ Object
- .format=(format) ⇒ Object
- .hard ⇒ Object
- .hard=(boolean) ⇒ Object
-
.match ⇒ Object
Default description match for filtering tests.
-
.suite ⇒ Object
Default test suite ($TEST_SUITE).
-
.tags ⇒ Object
Default selection of tags for filtering tests.
-
.units ⇒ Object
Default selection of units for filtering tests.
- .verbose ⇒ Object
- .verbose=(boolean) ⇒ Object
Instance Method Summary collapse
- #hard=(boolean) ⇒ Object
-
#hard? ⇒ Boolean
Use “hard” test mode?.
-
#initialize(options = {}, &block) ⇒ Runner
constructor
New Runner.
-
#run ⇒ Boolean
Run test suite.
- #verbose=(boolean) ⇒ Object
-
#verbose? ⇒ Boolean
Show extra details in reports.
Constructor Details
#initialize(options = {}, &block) ⇒ Runner
New Runner.
132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/test/runner.rb', line 132 def initialize(={}, &block) @suite = [:suite] || self.class.suite @files = [:files] || self.class.files @format = [:format] || self.class.format @tags = [:tags] || self.class. @units = [:units] || self.class.units @match = [:match] || self.class.match @verbose = [:verbose] || self.class.verbose @hard = [:hard] || self.class.hard block.call(self) if block end |
Instance Attribute Details
#files ⇒ Object (readonly)
Test files to load.
87 88 89 |
# File 'lib/test/runner.rb', line 87 def files @files end |
#format ⇒ Object
Reporter format name, or name fragment, used to look up reporter class.
90 91 92 |
# File 'lib/test/runner.rb', line 90 def format @format end |
#match ⇒ Object (readonly)
Matching text used to filter which tests are run.
98 99 100 |
# File 'lib/test/runner.rb', line 98 def match @match end |
#observers ⇒ Object (readonly)
Array of observers, typically this just contains the recorder and reporter instances.
153 154 155 |
# File 'lib/test/runner.rb', line 153 def observers @observers end |
#recorder ⇒ Object (readonly)
Record pass, fail, error, pending and omitted tests.
149 150 151 |
# File 'lib/test/runner.rb', line 149 def recorder @recorder end |
#reporter ⇒ Object (readonly)
The reporter to use for ouput.
146 147 148 |
# File 'lib/test/runner.rb', line 146 def reporter @reporter end |
#suite ⇒ Object (readonly)
Test suite to run. This is a list of compliant test units and test cases.
84 85 86 |
# File 'lib/test/runner.rb', line 84 def suite @suite end |
#tags ⇒ Object (readonly)
Selected tags used to filter which tests are run.
101 102 103 |
# File 'lib/test/runner.rb', line 101 def @tags end |
#units ⇒ Object (readonly)
List of units with which to filter tests. It is an array of strings which are matched against module, class and method names.
105 106 107 |
# File 'lib/test/runner.rb', line 105 def units @units end |
Class Method Details
.cli(*argv) ⇒ Object
Test runner command line interface.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/test/cli.rb', line 11 def self.cli(*argv) runner = new Test::Config.load (runner, argv) begin # Add standard location if it exists. $LOAD_PATH.unshift(File.('lib')) if File.directory?('lib') success = runner.run exit -1 unless success rescue => error raise error if $DEBUG $stderr.puts('ERROR: ' + error.to_s) end end |
.cli_options(runner, argv) ⇒ Object
31 32 33 34 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 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 |
# File 'lib/test/cli.rb', line 31 def self.(runner, argv) require 'optparse' config = Test.config.dup config_loaded = false common = config.delete('common') default = config.delete('default') common.call(runner) if common OptionParser.new do |opt| opt. = "Usage: #{$0} [options] [files ...]" unless config.empty? opt.separator "PRESET OPTIONS:" config.each do |name, block| opt.on("--#{name}") do block.call(runner) end end end opt.separator "CONFIG OPTIONS:" opt.on '-f', '--format NAME', 'report format' do |name| runner.format = name end opt.on '-y', '--tapy', 'shortcut for -f tapy' do runner.format = 'tapy' end opt.on '-j', '--tapj', 'shortcut for -f tapj' do runner.format = 'tapj' end opt.on '-t', '--tag TAG', 'select tests by tag' do |tag| runner. << tag end opt.on '-u', '--unit TAG', 'select tests by software unit' do |unit| runner.units << unit end opt.on '-m', '--match TEXT', 'select tests by description' do |text| runner.match << text end opt.on '-I', '--loadpath PATH', 'add to $LOAD_PATH' do |paths| paths.split(/[:;]/).reverse_each do |path| $LOAD_PATH.unshift path end end opt.on '-r', '--require FILE', 'require file' do |file| require file end opt.on '-v' , '--verbose', 'provide extra detailed report' do runner.verbose = true end #opt.on('--log DIRECTORY', 'log directory'){ |dir| # options[:log] = dir #} opt.on_tail("--[no-]ansi" , 'turn on/off ANSI colors'){ |v| $ansi = v } opt.on_tail("--debug" , 'turn on debugging mode'){ $DEBUG = true } #opt.on_tail("--about" , 'display information about lemon'){ # puts "Ruby Test v#{VERSION}" # puts "#{COPYRIGHT}" # exit #} opt.on_tail('-h', '--help', 'display this help message'){ puts opt exit } end.parse!(argv) default.call(runner) if default && !config_loaded runner.files.replace(argv) unless argv.empty? end |
.files ⇒ Object
Default list of test files to load.
32 33 34 |
# File 'lib/test/runner.rb', line 32 def self.files @files ||= [] end |
.format ⇒ Object
37 38 39 |
# File 'lib/test/runner.rb', line 37 def self.format @format || DEFAULT_FORMAT end |
.format=(format) ⇒ Object
42 43 44 |
# File 'lib/test/runner.rb', line 42 def self.format=(format) @format = format end |
.hard ⇒ Object
72 73 74 |
# File 'lib/test/runner.rb', line 72 def self.hard @hard end |
.hard=(boolean) ⇒ Object
77 78 79 |
# File 'lib/test/runner.rb', line 77 def self.hard=(boolean) @hard = !!boolean end |
.match ⇒ Object
Default description match for filtering tests.
57 58 59 |
# File 'lib/test/runner.rb', line 57 def self.match @match ||= [] end |
.suite ⇒ Object
Default test suite ($TEST_SUITE).
27 28 29 |
# File 'lib/test/runner.rb', line 27 def self.suite $TEST_SUITE end |
.tags ⇒ Object
Default selection of tags for filtering tests.
62 63 64 |
# File 'lib/test/runner.rb', line 62 def self. @tags ||= [] end |
.units ⇒ Object
Default selection of units for filtering tests.
67 68 69 |
# File 'lib/test/runner.rb', line 67 def self.units @unit ||= [] end |
.verbose ⇒ Object
47 48 49 |
# File 'lib/test/runner.rb', line 47 def self.verbose @verbose end |
.verbose=(boolean) ⇒ Object
52 53 54 |
# File 'lib/test/runner.rb', line 52 def self.verbose=(boolean) @verbose = !!boolean end |
Instance Method Details
#hard=(boolean) ⇒ Object
123 124 125 |
# File 'lib/test/runner.rb', line 123 def hard=(boolean) @hard = !!boolean end |
#hard? ⇒ Boolean
Use “hard” test mode?
118 119 120 |
# File 'lib/test/runner.rb', line 118 def hard? @hard end |
#run ⇒ Boolean
Run test suite.
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/test/runner.rb', line 160 def run files_resolved.each do |file| require file end @reporter = reporter_load(format) @recorder = Recorder.new @observers = [@reporter, @recorder] #cd_tmp do observers.each{ |o| o.begin_suite(suite) } run_thru(suite) observers.each{ |o| o.end_suite(suite) } #end recorder.success? end |
#verbose=(boolean) ⇒ Object
113 114 115 |
# File 'lib/test/runner.rb', line 113 def verbose=(boolean) @verbose = !!boolean end |
#verbose? ⇒ Boolean
Show extra details in reports.
108 109 110 |
# File 'lib/test/runner.rb', line 108 def verbose? @verbose end |