2007-02-09 09:04:31 +01:00
|
|
|
require File.dirname(__FILE__) + '/../abstract_unit'
|
2007-01-22 14:43:50 +01:00
|
|
|
|
|
|
|
class ExceptionExtTests < Test::Unit::TestCase
|
2007-02-09 09:04:31 +01:00
|
|
|
|
2007-01-22 14:43:50 +01:00
|
|
|
def get_exception(cls = RuntimeError, msg = nil, trace = nil)
|
|
|
|
begin raise cls, msg, (trace || caller)
|
2007-02-09 09:04:31 +01:00
|
|
|
rescue Exception => e # passed Exception
|
2007-01-22 14:43:50 +01:00
|
|
|
return e
|
|
|
|
end
|
|
|
|
end
|
2007-02-09 09:04:31 +01:00
|
|
|
|
2007-01-22 14:43:50 +01:00
|
|
|
def setup
|
|
|
|
Exception::TraceSubstitutions.clear
|
|
|
|
end
|
2007-02-09 09:04:31 +01:00
|
|
|
|
2007-01-22 14:43:50 +01:00
|
|
|
def test_clean_backtrace
|
|
|
|
Exception::TraceSubstitutions << [/\s*hidden.*/, '']
|
|
|
|
e = get_exception RuntimeError, 'RAWR', ['bhal.rb', 'rawh hid den stuff is not here', 'almost all']
|
|
|
|
assert_kind_of Exception, e
|
|
|
|
assert_equal ['bhal.rb', 'rawh hid den stuff is not here', 'almost all'], e.clean_backtrace
|
|
|
|
end
|
2007-02-09 09:04:31 +01:00
|
|
|
|
2007-01-22 14:43:50 +01:00
|
|
|
def test_app_backtrace
|
|
|
|
Exception::TraceSubstitutions << [/\s*hidden.*/, '']
|
|
|
|
e = get_exception RuntimeError, 'RAWR', ['bhal.rb', ' vendor/file.rb some stuff', 'almost all']
|
|
|
|
assert_kind_of Exception, e
|
|
|
|
assert_equal ['bhal.rb', 'almost all'], e.application_backtrace
|
|
|
|
end
|
2007-02-09 09:04:31 +01:00
|
|
|
|
2007-01-22 14:43:50 +01:00
|
|
|
def test_app_backtrace_with_before
|
|
|
|
Exception::TraceSubstitutions << [/\s*hidden.*/, '']
|
|
|
|
e = get_exception RuntimeError, 'RAWR', ['vendor/file.rb some stuff', 'bhal.rb', ' vendor/file.rb some stuff', 'almost all']
|
|
|
|
assert_kind_of Exception, e
|
|
|
|
assert_equal ['vendor/file.rb some stuff', 'bhal.rb', 'almost all'], e.application_backtrace
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_framework_backtrace_with_before
|
|
|
|
Exception::TraceSubstitutions << [/\s*hidden.*/, '']
|
|
|
|
e = get_exception RuntimeError, 'RAWR', ['vendor/file.rb some stuff', 'bhal.rb', ' vendor/file.rb some stuff', 'almost all']
|
|
|
|
assert_kind_of Exception, e
|
|
|
|
assert_equal ['vendor/file.rb some stuff', ' vendor/file.rb some stuff'], e.framework_backtrace
|
|
|
|
end
|
2007-02-09 09:04:31 +01:00
|
|
|
|
2007-01-22 14:43:50 +01:00
|
|
|
def test_backtrace_should_clean_paths
|
|
|
|
Exception::TraceSubstitutions << [/\s*hidden.*/, '']
|
|
|
|
e = get_exception RuntimeError, 'RAWR', ['a/b/c/../d/../../../bhal.rb', 'rawh hid den stuff is not here', 'almost all']
|
|
|
|
assert_kind_of Exception, e
|
|
|
|
assert_equal ['bhal.rb', 'rawh hid den stuff is not here', 'almost all'], e.clean_backtrace
|
|
|
|
end
|
2007-02-09 09:04:31 +01:00
|
|
|
|
2007-01-22 14:43:50 +01:00
|
|
|
def test_clean_message_should_clean_paths
|
|
|
|
Exception::TraceSubstitutions << [/\s*hidden.*/, '']
|
|
|
|
e = get_exception RuntimeError, "I dislike a/z/x/../../b/y/../c", ['a/b/c/../d/../../../bhal.rb', 'rawh hid den stuff is not here', 'almost all']
|
|
|
|
assert_kind_of Exception, e
|
|
|
|
assert_equal "I dislike a/b/c", e.clean_message
|
|
|
|
end
|
2007-02-09 09:04:31 +01:00
|
|
|
|
2007-01-22 14:43:50 +01:00
|
|
|
def test_app_trace_should_be_empty_when_no_app_frames
|
|
|
|
Exception::TraceSubstitutions << [/\s*hidden.*/, '']
|
|
|
|
e = get_exception RuntimeError, 'RAWR', ['vendor/file.rb some stuff', 'generated/bhal.rb', ' vendor/file.rb some stuff', 'generated/almost all']
|
|
|
|
assert_kind_of Exception, e
|
|
|
|
assert_equal [], e.application_backtrace
|
|
|
|
end
|
|
|
|
end
|