test-unit/lib/test/unit/ui/console/testrunner.rb in groonga-0.0.6 vs test-unit/lib/test/unit/ui/console/testrunner.rb in groonga-0.0.7
- old
+ new
@@ -1,9 +1,11 @@
#--
#
# Author:: Nathaniel Talbott.
-# Copyright:: Copyright (c) 2000-2003 Nathaniel Talbott. All rights reserved.
+# Copyright::
+# * Copyright (c) 2000-2003 Nathaniel Talbott. All rights reserved.
+# * Copyright (c) 2008-2009 Kouhei Sutou <kou@clear-code.com>
# License:: Ruby license.
require 'test/unit/color-scheme'
require 'test/unit/ui/testrunner'
require 'test/unit/ui/testrunnermediator'
@@ -34,10 +36,13 @@
@reset_color = Color.new("reset")
@progress_row = 0
@progress_row_max = @options[:progress_row_max]
@progress_row_max ||= guess_progress_row_max
@already_outputted = false
+ @n_successes = 0
+ @indent = 0
+ @top_level = true
@faults = []
end
# Begins the test run.
def start
@@ -66,10 +71,12 @@
@mediator.add_listener(TestResult::FAULT, &method(:add_fault))
@mediator.add_listener(TestRunnerMediator::STARTED, &method(:started))
@mediator.add_listener(TestRunnerMediator::FINISHED, &method(:finished))
@mediator.add_listener(TestCase::STARTED, &method(:test_started))
@mediator.add_listener(TestCase::FINISHED, &method(:test_finished))
+ @mediator.add_listener(TestSuite::STARTED, &method(:test_suite_started))
+ @mediator.add_listener(TestSuite::FINISHED, &method(:test_suite_finished))
end
def start_mediator
return @mediator.run_suite
end
@@ -89,38 +96,86 @@
output("Started")
end
def finished(elapsed_time)
nl if output?(NORMAL) and !output?(VERBOSE)
- nl
- output("Finished in #{elapsed_time} seconds.")
@faults.each_with_index do |fault, index|
nl
output_single("%3d) " % (index + 1))
label, detail = format_fault(fault).split(/\r?\n/, 2)
output(label, fault_color(fault))
output(detail)
end
nl
+ output("Finished in #{elapsed_time} seconds.")
+ nl
output(@result, result_color)
+ n_tests = @result.run_count
+ if n_tests.zero?
+ pass_percentage = 0
+ else
+ pass_percentage = 100.0 * (@n_successes / n_tests.to_f)
+ end
+ output("%g%% passed" % pass_percentage, result_color)
end
def format_fault(fault)
fault.long_display
end
-
+
def test_started(name)
- output_single(name + ": ", nil, VERBOSE)
+ return unless output?(VERBOSE)
+
+ name = name.sub(/\(.+?\)\z/, '')
+ right_space = 8 * 2
+ left_space = @progress_row_max - right_space
+ left_space = left_space - indent.size - name.size
+ tab_stop = "\t" * ((left_space - 1) / 8)
+ output_single("#{indent}#{name}:#{tab_stop}", nil, VERBOSE)
+ @test_start = Time.now
end
-
+
def test_finished(name)
unless @already_outputted
+ @n_successes += 1
output_progress(".", color("success"))
end
- nl(VERBOSE)
@already_outputted = false
+
+ return unless output?(VERBOSE)
+
+ output(": (%f)" % (Time.now - @test_start), nil, VERBOSE)
end
-
+
+ def test_suite_started(name)
+ if @top_level
+ @top_level = false
+ return
+ end
+
+ output_single(indent, nil, VERBOSE)
+ if /\A[A-Z]/ =~ name
+ _color = color("case")
+ else
+ _color = color("suite")
+ end
+ output_single(name, _color, VERBOSE)
+ output(": ", nil, VERBOSE)
+ @indent += 2
+ end
+
+ def test_suite_finished(name)
+ @indent -= 2
+ end
+
+ def indent
+ if output?(VERBOSE)
+ " " * @indent
+ else
+ ""
+ end
+ end
+
def nl(level=NORMAL)
output("", nil, level)
end
def output(something, color=nil, level=NORMAL)