Object
Registers MiniTest::Unit to run tests at process exit
# File minitest/unit.rb, line 497
def self.autorun
at_exit {
next if $! # don't run if there was an exception
# the order here is important. The at_exit handler must be
# installed before anyone else gets a chance to install their
# own, that way we can be assured that our exit will be last
# to run (at_exit stacks).
exit_code = nil
at_exit { exit false if exit_code && exit_code != 0 }
exit_code = MiniTest::Unit.new.run(ARGV)
} unless @@installed_at_exit
@@installed_at_exit = true
end
Sets MiniTest::Unit to write output to
stream. $stdout is the default output
# File minitest/unit.rb, line 517
def self.output= stream
@@out = stream
end
# File minitest/unit.rb, line 557
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 minitest/unit.rb, line 534
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 minitest/unit.rb, line 590
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 minitest/unit.rb, line 646
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
Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.
If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.
If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.
If you want to help improve the Ruby documentation, please see Improve the docs, or visit Documenting-ruby.org.