1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
#--
#
# Author:: Nathaniel Talbott.
# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
# License:: Ruby license.
require 'test/unit/util/backtracefilter'
module Test
module Unit
# Encapsulates an error in a test. Created by
# Test::Unit::TestCase when it rescues an exception thrown
# during the processing of a test.
class Error
include Util::BacktraceFilter
attr_reader(:test_name, :exception)
SINGLE_CHARACTER = 'E'
LABEL = "Error"
# Creates a new Error with the given test_name and
# exception.
def initialize(test_name, exception)
@test_name = test_name
@exception = exception
end
# Returns a single character representation of an error.
def single_character_display
SINGLE_CHARACTER
end
def label
LABEL
end
# Returns the message associated with the error.
def message
"#{@exception.class.name}: #{@exception.message}"
end
# Returns a brief version of the error description.
def short_display
"#@test_name: #{message.split("\n")[0]}"
end
# Returns a verbose version of the error description.
def long_display
backtrace_display = backtrace.join("\n ")
"#{label}:\n#@test_name:\n#{message}\n #{backtrace_display}"
end
def backtrace
filter_backtrace(@exception.backtrace)
end
# Overridden to return long_display.
def to_s
long_display
end
end
module ErrorHandler
class << self
def included(base)
base.exception_handler(:handle_all_exception)
end
end
PASS_THROUGH_EXCEPTIONS = [NoMemoryError, SignalException, Interrupt,
SystemExit]
private
def handle_all_exception(exception)
case exception
when *PASS_THROUGH_EXCEPTIONS
false
else
problem_occurred
add_error(exception)
true
end
end
def add_error(exception)
current_result.add_error(Error.new(name, exception))
end
end
module TestResultErrorSupport
attr_reader :errors
# Records a Test::Unit::Error.
def add_error(error)
@errors << error
notify_fault(error)
notify_changed
end
# Returns the number of errors this TestResult has
# recorded.
def error_count
@errors.size
end
def error_occurred?
not @errors.empty?
end
private
def initialize_containers
super
@errors = []
@summary_generators << :error_summary
@problem_checkers << :error_occurred?
end
def error_summary
"#{error_count} errors"
end
end
end
end
|