1 require 'rubicon_testcase'
3 class TestException < Test::Unit::TestCase
8 e = Exception.exception
9 assert_equal(Exception, e.class)
11 e = Exception.exception(MSG)
12 assert_equal(MSG, e.message)
16 assert_nil(Exception.exception.backtrace)
18 line=__LINE__; file=__FILE__; raise MSG
19 rescue RuntimeError => detail
20 assert_equal(RuntimeError, detail.class)
21 assert_equal(MSG, detail.message)
22 expected = "#{file}:#{line}:in `test_backtrace'"
23 assert_equal(expected, detail.backtrace[0])
29 assert_equal(IOError, e.class)
30 assert_equal(IOError, e.exception.class)
31 assert_equal(e, e.exception)
35 assert_equal(IOError, e1.class)
36 assert_equal(MSG, e1.message)
41 assert_equal(MSG, e.message)
44 def test_set_backtrace
46 a = %w( here there everywhere )
47 assert_equal(a, e.set_backtrace(a))
48 assert_equal(a, e.backtrace)
51 # FIX: this is retardedly complex
52 # exercise bug in Exception#set_backtrace, see [ruby-talk:96273].
53 class Problem # helper class for #test_set_backtrace2
54 STACK = %w(a:0:A b:1:B c:2:C)
56 raise IOError, "got nuked"
58 error = IOError.new("got nuked")
59 error.set_backtrace(STACK)
65 raise "should not happen"
71 def test_set_backtrace2
72 e = Problem.mk_exception
73 assert_equal("got nuked", e.message)
74 # this is how set_backtrace is suppose to work
75 assert_equal(Problem::STACK, e.backtrace)