Class: Test::Unit::AutoRunner
- Inherits:
-
Object
- Object
- Test::Unit::AutoRunner
- Defined in:
- lib/test/unit/autorunner.rb
Constant Summary collapse
- RUNNERS =
{ :console => proc do |r| require 'test/unit/ui/console/testrunner' Test::Unit::UI::Console::TestRunner end, :gtk => proc do |r| require 'test/unit/ui/gtk/testrunner' Test::Unit::UI::GTK::TestRunner end, :gtk2 => proc do |r| require 'test/unit/ui/gtk2/testrunner' Test::Unit::UI::GTK2::TestRunner end, :fox => proc do |r| require 'test/unit/ui/fox/testrunner' Test::Unit::UI::Fox::TestRunner end, :tk => proc do |r| require 'test/unit/ui/tk/testrunner' Test::Unit::UI::Tk::TestRunner end, }
- OUTPUT_LEVELS =
[ [:silent, UI::SILENT], [:progress, UI::PROGRESS_ONLY], [:normal, UI::NORMAL], [:verbose, UI::VERBOSE], ]
- COLLECTORS =
{ :objectspace => proc do |r| require 'test/unit/collector/objectspace' c = Collector::ObjectSpace.new c.filter = r.filters c.collect($0.sub(/\.rb\Z/, '')) end, :dir => proc do |r| require 'test/unit/collector/dir' c = Collector::Dir.new c.filter = r.filters c.pattern.concat(r.pattern) if(r.pattern) c.exclude.concat(r.exclude) if(r.exclude) c.base = r.base $:.push(r.base) if r.base c.collect(*(r.to_run.empty? ? ['.'] : r.to_run)) end, }
Instance Attribute Summary collapse
-
#base ⇒ Object
Returns the value of attribute base.
-
#collector ⇒ Object
writeonly
Sets the attribute collector.
-
#exclude ⇒ Object
Returns the value of attribute exclude.
-
#filters ⇒ Object
Returns the value of attribute filters.
-
#output_level ⇒ Object
Returns the value of attribute output_level.
-
#pattern ⇒ Object
Returns the value of attribute pattern.
-
#runner ⇒ Object
writeonly
Sets the attribute runner.
-
#suite ⇒ Object
readonly
Returns the value of attribute suite.
-
#to_run ⇒ Object
Returns the value of attribute to_run.
-
#workdir ⇒ Object
Returns the value of attribute workdir.
Class Method Summary collapse
- .run(force_standalone = false, default_dir = nil, argv = ARGV, &block) ⇒ Object
- .standalone? ⇒ Boolean
Instance Method Summary collapse
-
#initialize(standalone) {|_self| ... } ⇒ AutoRunner
constructor
A new instance of AutoRunner.
- #keyword_display(array) ⇒ Object
- #options ⇒ Object
- #process_args(args = ARGV) ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(standalone) {|_self| ... } ⇒ AutoRunner
Returns a new instance of AutoRunner.
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/test/unit/autorunner.rb', line 76 def initialize(standalone) Unit.run = true @standalone = standalone @runner = RUNNERS[:console] @collector = COLLECTORS[(standalone ? :dir : :objectspace)] @filters = [] @to_run = [] @output_level = UI::NORMAL @workdir = nil yield(self) if(block_given?) end |
Instance Attribute Details
#base ⇒ Object
Returns the value of attribute base.
73 74 75 |
# File 'lib/test/unit/autorunner.rb', line 73 def base @base end |
#collector=(value) ⇒ Object (writeonly)
Sets the attribute collector
74 75 76 |
# File 'lib/test/unit/autorunner.rb', line 74 def collector=(value) @collector = value end |
#exclude ⇒ Object
Returns the value of attribute exclude.
73 74 75 |
# File 'lib/test/unit/autorunner.rb', line 73 def exclude @exclude end |
#filters ⇒ Object
Returns the value of attribute filters.
73 74 75 |
# File 'lib/test/unit/autorunner.rb', line 73 def filters @filters end |
#output_level ⇒ Object
Returns the value of attribute output_level.
73 74 75 |
# File 'lib/test/unit/autorunner.rb', line 73 def output_level @output_level end |
#pattern ⇒ Object
Returns the value of attribute pattern.
73 74 75 |
# File 'lib/test/unit/autorunner.rb', line 73 def pattern @pattern end |
#runner=(value) ⇒ Object (writeonly)
Sets the attribute runner
74 75 76 |
# File 'lib/test/unit/autorunner.rb', line 74 def runner=(value) @runner = value end |
#suite ⇒ Object (readonly)
Returns the value of attribute suite.
72 73 74 |
# File 'lib/test/unit/autorunner.rb', line 72 def suite @suite end |
#to_run ⇒ Object
Returns the value of attribute to_run.
73 74 75 |
# File 'lib/test/unit/autorunner.rb', line 73 def to_run @to_run end |
#workdir ⇒ Object
Returns the value of attribute workdir.
73 74 75 |
# File 'lib/test/unit/autorunner.rb', line 73 def workdir @workdir end |
Class Method Details
.run(force_standalone = false, default_dir = nil, argv = ARGV, &block) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/test/unit/autorunner.rb', line 8 def self.run(force_standalone=false, default_dir=nil, argv=ARGV, &block) r = new(force_standalone || standalone?, &block) r.base = default_dir r.process_args(argv) r.run end |
.standalone? ⇒ Boolean
15 16 17 18 19 20 21 |
# File 'lib/test/unit/autorunner.rb', line 15 def self.standalone? return false unless("-e" == $0) ObjectSpace.each_object(Class) do |klass| return false if(klass < TestCase) end true end |
Instance Method Details
#keyword_display(array) ⇒ Object
206 207 208 209 210 |
# File 'lib/test/unit/autorunner.rb', line 206 def keyword_display(array) list = array.collect {|e, *| e.to_s} Array === array or list.sort! list.collect {|e| e.sub(/^(.)([A-Za-z]+)(?=\w*$)/, '\\1[\\2]')}.join(", ") end |
#options ⇒ Object
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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/test/unit/autorunner.rb', line 102 def @options ||= OptionParser.new do |o| o. = "Test::Unit automatic runner." o. << "\nUsage: #{$0} [options] [-- untouched arguments]" o.on o.on('-r', '--runner=RUNNER', RUNNERS, "Use the given RUNNER.", "(" + keyword_display(RUNNERS) + ")") do |r| @runner = r end if(@standalone) o.on('-b', '--basedir=DIR', "Base directory of test suites.") do |b| @base = b end o.on('-w', '--workdir=DIR', "Working directory to run tests.") do |w| @workdir = w end o.on('-a', '--add=TORUN', Array, "Add TORUN to the list of things to run;", "can be a file or a directory.") do |a| @to_run.concat(a) end @pattern = [] o.on('-p', '--pattern=PATTERN', Regexp, "Match files to collect against PATTERN.") do |e| @pattern << e end @exclude = [] o.on('-x', '--exclude=PATTERN', Regexp, "Ignore files to collect against PATTERN.") do |e| @exclude << e end end o.on('-n', '--name=NAME', String, "Runs tests matching NAME.", "(patterns may be used).") do |n| n = (%r{\A/(.*)/\Z} =~ n ? Regexp.new($1) : n) case n when Regexp @filters << proc{|t| n =~ t.method_name ? true : nil} else @filters << proc{|t| n == t.method_name ? true : nil} end end o.on('-t', '--testcase=TESTCASE', String, "Runs tests in TestCases matching TESTCASE.", "(patterns may be used).") do |n| n = (%r{\A/(.*)/\Z} =~ n ? Regexp.new($1) : n) case n when Regexp @filters << proc{|t| n =~ t.class.name ? true : nil} else @filters << proc{|t| n == t.class.name ? true : nil} end end o.on('-I', "--load-path=DIR[#{File::PATH_SEPARATOR}DIR...]", "Appends directory list to $LOAD_PATH.") do |dirs| $LOAD_PATH.concat(dirs.split(File::PATH_SEPARATOR)) end o.on('-v', '--verbose=[LEVEL]', OUTPUT_LEVELS, "Set the output level (default is verbose).", "(" + keyword_display(OUTPUT_LEVELS) + ")") do |l| @output_level = l || UI::VERBOSE end o.on('--', "Stop processing options so that the", "remaining options will be passed to the", "test."){o.terminate} o.on('-h', '--help', 'Display this help.'){puts o; exit} o.on_tail o.on_tail('Deprecated options:') o.on_tail('--console', 'Console runner (use --runner).') do warn("Deprecated option (--console).") @runner = RUNNERS[:console] end o.on_tail('--gtk', 'GTK runner (use --runner).') do warn("Deprecated option (--gtk).") @runner = RUNNERS[:gtk] end o.on_tail('--fox', 'Fox runner (use --runner).') do warn("Deprecated option (--fox).") @runner = RUNNERS[:fox] end o.on_tail end end |
#process_args(args = ARGV) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/test/unit/autorunner.rb', line 88 def process_args(args = ARGV) begin .order!(args) {|arg| @to_run << arg} rescue OptionParser::ParseError => e puts e puts $! = nil abort else @filters << proc{false} unless(@filters.empty?) end not @to_run.empty? end |
#run ⇒ Object
212 213 214 215 216 217 |
# File 'lib/test/unit/autorunner.rb', line 212 def run @suite = @collector[self] result = @runner[self] or return false Dir.chdir(@workdir) if @workdir result.run(@suite, @output_level).passed? end |