diff options
| author | ntalbott <ntalbott@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-02-12 03:12:14 +0000 |
|---|---|---|
| committer | ntalbott <ntalbott@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-02-12 03:12:14 +0000 |
| commit | f4fade43ce5d51ab9e35463a0ee093a695286741 (patch) | |
| tree | 4354dc87a540b777a7eb6a2276f44be51ec8bebb /lib/test/unit/error.rb | |
| parent | 045623d3287ee000a1c7e8275a643e88081132d2 (diff) | |
| download | ruby-f4fade43ce5d51ab9e35463a0ee093a695286741.tar.gz ruby-f4fade43ce5d51ab9e35463a0ee093a695286741.tar.xz ruby-f4fade43ce5d51ab9e35463a0ee093a695286741.zip | |
Initial revision
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@3477 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/test/unit/error.rb')
| -rw-r--r-- | lib/test/unit/error.rb | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/lib/test/unit/error.rb b/lib/test/unit/error.rb new file mode 100644 index 000000000..46c6663d8 --- /dev/null +++ b/lib/test/unit/error.rb @@ -0,0 +1,68 @@ +# :nodoc: +# +# Author:: Nathaniel Talbott. +# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. +# License:: Ruby license. + +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 + attr_reader(:location, :exception) + + SINGLE_CHARACTER = 'E' + + # Creates a new Error with the given location and + # exception. + def initialize(location, exception) + @location = location + @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 + "#{@location}:\n#{message}" + end + + # Returns a verbose version of the error description. + def long_display + backtrace = self.class.filter(@exception.backtrace).join("\n ") + "Error!!!\n#{short_display}\n #{backtrace}" + end + + # Overridden to return long_display. + def to_s + long_display + end + + SEPARATOR_PATTERN = '[\\\/:]' + def self.filter(backtrace) # :nodoc: + @test_unit_patterns ||= $:.collect { + | path | + /^#{Regexp.escape(path)}#{SEPARATOR_PATTERN}test#{SEPARATOR_PATTERN}unit#{SEPARATOR_PATTERN}/ + }.push(/#{SEPARATOR_PATTERN}test#{SEPARATOR_PATTERN}unit\.rb/) + + return backtrace.delete_if { + | line | + @test_unit_patterns.detect { + | pattern | + line =~ pattern + } + } + end + end + end +end |
