Skip to content

Commit

Permalink
+ Added documentation for Reporter classes. (sshaw)
Browse files Browse the repository at this point in the history
[git-p4: depot-paths = "//src/minitest/dev/": change = 12319]
  • Loading branch information
zenspider committed Sep 27, 2019
1 parent 5d95229 commit 6d9b78d
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 6 deletions.
2 changes: 2 additions & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,8 @@ able to require minitest and run your tests.

== Developing Minitest:

Minitest requires {Hoe}[https://rubygems.org/gems/hoe].

=== Minitest's own tests require UTF-8 external encoding.

This is a common problem in Windows, where the default external Encoding is
Expand Down
63 changes: 57 additions & 6 deletions lib/minitest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,8 @@ def passed?

##
# Returns a single character string to print based on the result
# of the run. Eg ".", "F", or "E".
# of the run. One of <tt>"."</tt>, <tt>"F"</tt>,
# <tt>"E"</tt> or <tt>"S"</tt>.

def result_code
raise NotImplementedError, "subclass responsibility"
Expand Down Expand Up @@ -563,8 +564,10 @@ def prerecord klass, name
end

##
# Record a result and output the Runnable#result_code. Stores the
# result of the run if the run did not pass.
# Output and record the result of the test. Call
# {result#result_code}[rdoc-ref:Runnable#result_code] to get the
# result character string. Stores the result of the run if the run
# did not pass.

def record result
end
Expand Down Expand Up @@ -631,18 +634,63 @@ def record result # :nodoc:
#
# If you want to create an entirely different type of output (eg,
# CI, HTML, etc), this is the place to start.
#
# Example:
#
# class JenkinsCIReporter < StatisticsReporter
# def report
# super # Needed to calculate some statistics
#
# print "<testsuite "
# print "tests='#{count}' "
# print "failures='#{failures}' "
# # Remaining XML...
# end
# end

class StatisticsReporter < Reporter
# :stopdoc:
##
# Total number of assertions.

attr_accessor :assertions

##
# Total number of test cases.

attr_accessor :count

##
# An +Array+ of test cases that failed or were skipped.

attr_accessor :results

##
# Time the test run started. If available, the monotonic clock is
# used and this is a +Float+, otherwise it's an instance of
# +Time+.

attr_accessor :start_time

##
# Test run time. If available, the monotonic clock is used and
# this is a +Float+, otherwise it's an instance of +Time+.

attr_accessor :total_time

##
# Total number of tests that failed.

attr_accessor :failures

##
# Total number of tests that erred.

attr_accessor :errors

##
# Total number of tests that where skipped.

attr_accessor :skips
# :startdoc:

def initialize io = $stdout, options = {} # :nodoc:
super
Expand Down Expand Up @@ -672,7 +720,10 @@ def record result # :nodoc:
results << result if not result.passed? or result.skipped?
end

def report # :nodoc:
##
# Report on the tracked statistics.

def report
aggregate = results.group_by { |r| r.failure.class }
aggregate.default = [] # dumb. group_by should provide this

Expand Down

0 comments on commit 6d9b78d

Please sign in to comment.