test-unit/lib/test/unit/ui/console/testrunner.rb in activesambaldap-0.0.6 vs test-unit/lib/test/unit/ui/console/testrunner.rb in activesambaldap-0.0.7

- old
+ new

@@ -2,11 +2,11 @@ # # Author:: Nathaniel Talbott. # Copyright:: Copyright (c) 2000-2003 Nathaniel Talbott. All rights reserved. # License:: Ruby license. -require 'test/unit/color' +require 'test/unit/color-scheme' require 'test/unit/ui/testrunner' require 'test/unit/ui/testrunnermediator' require 'test/unit/ui/console/outputlevel' module Test @@ -16,21 +16,10 @@ # Runs a Test::Unit::TestSuite on the console. class TestRunner < UI::TestRunner include OutputLevel - COLOR_SCHEMES = { - :default => { - "success" => Color.new("green", :bold => true), - "failure" => Color.new("red", :bold => true), - "pending" => Color.new("magenta", :bold => true), - "omission" => Color.new("blue", :bold => true), - "notification" => Color.new("cyan", :bold => true), - "error" => Color.new("yellow", :bold => true), - }, - } - # Creates a new TestRunner for running the passed # suite. If quiet_mode is true, the output while # running is limited to progress dots, errors and # failures, and the final result. io specifies # where runner output should go to; defaults to @@ -39,12 +28,15 @@ super @output_level = @options[:output_level] || NORMAL @output = @options[:output] || STDOUT @use_color = @options[:use_color] @use_color = guess_color_availability if @use_color.nil? - @color_scheme = COLOR_SCHEMES[:default] + @color_scheme = @options[:color_scheme] || ColorScheme.default @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 @faults = [] end # Begins the test run. @@ -82,13 +74,11 @@ return @mediator.run_suite end def add_fault(fault) @faults << fault - output_single(fault.single_character_display, - fault_color(fault), - PROGRESS_ONLY) + output_progress(fault.single_character_display, fault_color(fault)) @already_outputted = true end def started(result) @result = result @@ -122,11 +112,11 @@ output_single(name + ": ", nil, VERBOSE) end def test_finished(name) unless @already_outputted - output_single(".", @color_scheme["success"], PROGRESS_ONLY) + output_progress(".", color("success")) end nl(VERBOSE) @already_outputted = false end @@ -139,51 +129,89 @@ output_single(something, color, level) @output.puts end def output_single(something, color=nil, level=NORMAL) - return unless output?(level) + return false unless output?(level) if @use_color and color something = "%s%s%s" % [color.escape_sequence, something, @reset_color.escape_sequence] end @output.write(something) @output.flush + true end - + + def output_progress(mark, color=nil) + if output_single(mark, color, PROGRESS_ONLY) + return unless @progress_row_max > 0 + @progress_row += mark.size + if @progress_row >= @progress_row_max + nl unless @output_level == VERBOSE + @progress_row = 0 + end + end + end + def output?(level) level <= @output_level end + def color(name) + @color_scheme[name] || ColorScheme.default[name] + end + def fault_color(fault) - @color_scheme[fault.class.name.split(/::/).last.downcase] + color(fault.class.name.split(/::/).last.downcase) end def result_color if @result.passed? if @result.pending_count > 0 - @color_scheme["pending"] + color("pending") elsif @result.omission_count > 0 - @color_scheme["omission"] + color("omission") elsif @result.notification_count > 0 - @color_scheme["notification"] + color("notification") else - @color_scheme["success"] + color("success") end elsif @result.error_count > 0 - @color_scheme["error"] + color("error") elsif @result.failure_count > 0 - @color_scheme["failure"] + color("failure") end end def guess_color_availability return false unless @output.tty? - term = ENV["TERM"] - return true if term and (/term\z/ =~ term or term == "screen") - return true if ENV["EMACS"] == "t" - false + case ENV["TERM"] + when /term(?:-color)?\z/, "screen" + true + else + return true if ENV["EMACS"] == "t" + false + end + end + + def guess_progress_row_max + term_width = guess_term_width + if term_width.zero? + if ENV["EMACS"] == "t" + -1 + else + 79 + end + else + term_width + end + end + + def guess_term_width + Integer(ENV["TERM_WIDTH"] || 0) + rescue ArgumentError + 0 end end end end end