2 require_relative 'envutil'
4 class TestException < Test::Unit::TestCase
7 raise "this must be handled"
15 raise "this must be handled no.2"
25 # exception in rescue clause
26 $string = "this must be handled no.3"
27 e = assert_raises(RuntimeError) do
29 raise "exception in rescue clause"
35 assert_equal($string, e.message)
37 # exception in ensure clause
38 $string = "exception in ensure clause"
39 e = assert_raises(RuntimeError) do
41 raise "this must be handled no.4"
43 assert_instance_of(RuntimeError, $!)
44 assert_equal("this must be handled no.4", $!.message)
45 raise "exception in ensure clause"
49 assert_equal($string, e.message)
54 raise "this must be handled no.5"
65 raise "this must be handled no.6"
90 assert(false) # should no reach here
189 def test_raise_with_wrong_number_of_arguments
190 assert_raise(TypeError) { raise nil }
191 assert_raise(TypeError) { raise 1, 1 }
192 assert_raise(ArgumentError) { raise 1, 1, 1, 1 }
196 assert_in_out_err([], "p $@", %w(nil), [])
198 assert_in_out_err([], "$@ = 1", [], /\$! not set \(ArgumentError\)$/)
200 assert_in_out_err([], <<-INPUT, [], /backtrace must be Array of String \(TypeError\)$/)
208 assert_in_out_err([], <<-INPUT, [], /^foo: unhandled exception$/)
217 assert_in_out_err([], <<-INPUT, [], /^foo: unhandled exception\s+from bar\s+from baz$/)