Registers MiniTest::Unit to run tests at process exit
# File lib/minitest/unit.rb, line 483 def self.autorun at_exit { next if $! # don't run if there was an exception exit_code = MiniTest::Unit.new.run(ARGV) exit false if exit_code && exit_code != 0 } unless @@installed_at_exit @@installed_at_exit = true end
Sets MiniTest::Unit to write output to stream. $stdout is the default output
# File lib/minitest/unit.rb, line 496 def self.output= stream @@out = stream end
# File lib/minitest/unit.rb, line 536 def process_args args = [] options = {} OptionParser.new do |opts| opts.banner = 'minitest options:' opts.version = MiniTest::Unit::VERSION opts.on '-h', '--help', 'Display this help.' do puts opts exit end opts.on '-s', '--seed SEED', Integer, "Sets random seed" do |m| options[:seed] = m.to_i end opts.on '-v', '--verbose', "Verbose. Show progress processing files." do options[:verbose] = true end opts.on '-n', '--name PATTERN', "Filter test names on pattern." do |a| options[:filter] = a end opts.parse args end options end
Writes status for failed test meth in klass which finished with exception e
# File lib/minitest/unit.rb, line 513 def puke klass, meth, e e = case e when MiniTest::Skip then @skips += 1 "Skipped:\n#{meth}(#{klass}) [#{location e}]:\n#{e.message}\n" when MiniTest::Assertion then @failures += 1 "Failure:\n#{meth}(#{klass}) [#{location e}]:\n#{e.message}\n" else @errors += 1 bt = MiniTest::filter_backtrace(e.backtrace).join("\n ") "Error:\n#{meth}(#{klass}):\n#{e.class}: #{e.message}\n #{bt}\n" end @report << e e[0, 1] end
Top level driver, controls all output and filtering.
# File lib/minitest/unit.rb, line 569 def run args = [] options = process_args args @verbose = options[:verbose] filter = options[:filter] || '/./' filter = Regexp.new $1 if filter and filter =~ /\/(.*)\// seed = options[:seed] unless seed then srand seed = srand % 0xFFFF end srand seed @@out.puts "Loaded suite #{$0.sub(/\.rb$/, '')}\nStarted" start = Time.now run_test_suites filter @@out.puts @@out.puts "Finished in #{'%.6f' % (Time.now - start)} seconds." @report.each_with_index do |msg, i| @@out.puts "\n%3d) %s" % [i + 1, msg] end @@out.puts status @@out.puts help = ["--seed", seed] help.push "--verbose" if @verbose help.push("--name", options[:filter].inspect) if options[:filter] @@out.puts "Test run options: #{help.join(" ")}" return failures + errors if @test_count > 0 # or return nil... rescue Interrupt abort 'Interrupted' end
Runs test suites matching filter
# File lib/minitest/unit.rb, line 625 def run_test_suites filter = /./ @test_count, @assertion_count = 0, 0 old_sync, @@out.sync = @@out.sync, true if @@out.respond_to? :sync= TestCase.test_suites.each do |suite| suite.test_methods.grep(filter).each do |test| inst = suite.new test inst._assertions = 0 @@out.print "#{suite}##{test}: " if @verbose @start_time = Time.now result = inst.run(self) @@out.print "%.2f s: " % (Time.now - @start_time) if @verbose @@out.print result @@out.puts if @verbose @test_count += 1 @assertion_count += inst._assertions end end @@out.sync = old_sync if @@out.respond_to? :sync= [@test_count, @assertion_count] end
Generated with the Darkfish Rdoc Generator 2.