Registers MiniTest::Unit to run tests at process exit
# File lib/minitest/unit.rb, line 512
512: def self.autorun
513: at_exit {
514: next if $! # don't run if there was an exception
515: exit_code = MiniTest::Unit.new.run(ARGV)
516: exit false if exit_code && exit_code != 0
517: } unless @@installed_at_exit
518: @@installed_at_exit = true
519: end
Sets MiniTest::Unit to write output to stream. $stdout is the default output
# File lib/minitest/unit.rb, line 525
525: def self.output= stream
526: @@out = stream
527: end
# File lib/minitest/unit.rb, line 565
565: def process_args args = []
566: options = {}
567:
568: OptionParser.new do |opts|
569: opts.banner = 'minitest options:'
570: opts.version = MiniTest::Unit::VERSION
571:
572: opts.on '-h', '--help', 'Display this help.' do
573: puts opts
574: exit
575: end
576:
577: opts.on '-s', '--seed SEED', Integer, "Sets random seed" do |m|
578: options[:seed] = m.to_i
579: end
580:
581: opts.on '-v', '--verbose', "Verbose. Show progress processing files." do
582: options[:verbose] = true
583: end
584:
585: opts.on '-n', '--name PATTERN', "Filter test names on pattern." do |a|
586: options[:filter] = a
587: end
588:
589: opts.parse args
590: end
591:
592: options
593: end
Writes status for failed test meth in klass which finished with exception e
# File lib/minitest/unit.rb, line 542
542: def puke klass, meth, e
543: e = case e
544: when MiniTest::Skip then
545: @skips += 1
546: "Skipped:\n#{meth}(#{klass}) [#{location e}]:\n#{e.message}\n"
547: when MiniTest::Assertion then
548: @failures += 1
549: "Failure:\n#{meth}(#{klass}) [#{location e}]:\n#{e.message}\n"
550: else
551: @errors += 1
552: bt = MiniTest::filter_backtrace(e.backtrace).join("\n ")
553: "Error:\n#{meth}(#{klass}):\n#{e.class}: #{e.message}\n #{bt}\n"
554: end
555: @report << e
556: e[0, 1]
557: end
Top level driver, controls all output and filtering.
# File lib/minitest/unit.rb, line 598
598: def run args = []
599: options = process_args args
600:
601: @verbose = options[:verbose]
602:
603: filter = options[:filter] || '/./'
604: filter = Regexp.new $1 if filter and filter =~ /\/(.*)\//
605:
606: seed = options[:seed]
607: unless seed then
608: srand
609: seed = srand % 0xFFFF
610: end
611:
612: srand seed
613:
614: help = ["--seed", seed]
615: help.push "--verbose" if @verbose
616: help.push("--name", options[:filter].inspect) if options[:filter]
617:
618: @@out.puts "Test run options: #{help.join(" ")}"
619: @@out.puts
620: @@out.puts "Loaded suite #{$0.sub(/\.rb$/, '')}\nStarted"
621:
622: start = Time.now
623: run_test_suites filter
624:
625: @@out.puts
626: @@out.puts "Finished in #{'%.6f' % (Time.now - start)} seconds."
627:
628: @report.each_with_index do |msg, i|
629: @@out.puts "\n%3d) %s" % [i + 1, msg]
630: end
631:
632: @@out.puts
633:
634: status
635:
636: @@out.puts
637:
638: @@out.puts "Test run options: #{help.join(" ")}"
639:
640: return failures + errors if @test_count > 0 # or return nil...
641: rescue Interrupt
642: abort 'Interrupted'
643: end
Runs test suites matching filter
# File lib/minitest/unit.rb, line 656
656: def run_test_suites filter = /./
657: @test_count, @assertion_count = 0, 0
658: old_sync, @@out.sync = @@out.sync, true if @@out.respond_to? :sync=
659: TestCase.test_suites.each do |suite|
660: suite.test_methods.grep(filter).each do |test|
661: inst = suite.new test
662: inst._assertions = 0
663: @@out.print "#{suite}##{test}: " if @verbose
664:
665: @start_time = Time.now
666: result = inst.run(self)
667:
668: @@out.print "%.2f s: " % (Time.now - @start_time) if @verbose
669: @@out.print result
670: @@out.puts if @verbose
671: @test_count += 1
672: @assertion_count += inst._assertions
673: end
674: end
675: @@out.sync = old_sync if @@out.respond_to? :sync=
676: [@test_count, @assertion_count]
677: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.