2003-02-11 22:12:14 -05:00
|
|
|
# :nodoc:
|
|
|
|
#
|
|
|
|
# Author:: Nathaniel Talbott.
|
|
|
|
# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
|
|
|
|
# License:: Ruby license.
|
|
|
|
|
2003-10-02 19:03:13 -04:00
|
|
|
require 'test/unit/util/backtracefilter'
|
|
|
|
|
2003-02-11 22:12:14 -05:00
|
|
|
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
|
2003-10-02 19:03:13 -04:00
|
|
|
include Util::BacktraceFilter
|
|
|
|
|
|
|
|
attr_reader(:test_name, :exception)
|
2003-02-11 22:12:14 -05:00
|
|
|
|
|
|
|
SINGLE_CHARACTER = 'E'
|
|
|
|
|
2003-10-02 19:03:13 -04:00
|
|
|
# Creates a new Error with the given test_name and
|
2003-02-11 22:12:14 -05:00
|
|
|
# exception.
|
2003-10-02 19:03:13 -04:00
|
|
|
def initialize(test_name, exception)
|
|
|
|
@test_name = test_name
|
2003-02-11 22:12:14 -05:00
|
|
|
@exception = exception
|
|
|
|
end
|
|
|
|
|
|
|
|
# Returns a single character representation of an error.
|
|
|
|
def single_character_display
|
|
|
|
SINGLE_CHARACTER
|
|
|
|
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
|
2003-10-02 19:03:13 -04:00
|
|
|
"#@test_name: #{message.split("\n")[0]}"
|
2003-02-11 22:12:14 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
# Returns a verbose version of the error description.
|
|
|
|
def long_display
|
2003-10-02 19:03:13 -04:00
|
|
|
backtrace = filter_backtrace(@exception.backtrace).join("\n ")
|
|
|
|
"Error:\n#@test_name:\n#{message}\n #{backtrace}"
|
2003-02-11 22:12:14 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
# Overridden to return long_display.
|
|
|
|
def to_s
|
|
|
|
long_display
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|