2 # Copyright (C) 2006-2010, Parrot Foundation.
7 t/pmc/exception_handler.t - test ExceptionHandler PMC
11 % prove t/pmc/exceptionhandler.t
15 Tests the ExceptionHandler PMC.
19 .include 'except_severity.pasm'
20 .include 'except_types.pasm'
23 .include 'test_more.pir'
25 # If test exited with "bad plan" MyHandlerCan.can_handle wasn't invoked.
32 eh = new ['ExceptionHandler']
33 ok(1, 'Instantiated ExceptionHandler')
35 set_addr eh, nonfatal_handler_one
36 eh.'min_severity'(.EXCEPT_NORMAL)
37 eh.'max_severity'(.EXCEPT_WARNING)
40 eh2 = new ['ExceptionHandler']
41 set_addr eh2, error_handler_one
42 eh2.'min_severity'(.EXCEPT_ERROR)
43 eh2.'max_severity'(.EXCEPT_FATAL)
47 i = eh.'min_severity'()
48 is(i, .EXCEPT_NORMAL, 'get min_severity - 1')
49 i = eh.'max_severity'()
50 is(i, .EXCEPT_WARNING, 'get max_severity - 1')
51 i = eh2.'min_severity'()
52 is(i, .EXCEPT_ERROR, 'get min_severity - 2')
53 i = eh2.'max_severity'()
54 is(i, .EXCEPT_FATAL, 'get max_severity - 2')
56 $P0 = new ['Exception']
57 $P0['severity'] = .EXCEPT_NORMAL
60 $P0 = new ['Exception']
61 $P0['severity'] = .EXCEPT_SEVERE
72 ok(1, 'Min and Max severity for exception handlers')
78 ok(1, 'Min and Max severity for exception handlers')
85 eh = new ['ExceptionHandler']
86 set_addr eh, typed_handler_one
87 eh.'handle_types'(.CONTROL_OK, .CONTROL_BREAK)
90 eh = new ['ExceptionHandler']
91 set_addr eh, typed_handler_two
92 eh.'handle_types'(.EXCEPTION_SYNTAX_ERROR, .EXCEPTION_UNEXPECTED_NULL)
95 $P0 = new ['Exception']
96 $P0['type'] = .CONTROL_OK
99 $P0 = new ['Exception']
100 $P0['type'] = .CONTROL_BREAK
106 test_handle_types_except()
108 goto subclass_handler
112 ok(1, 'Exception Handler type checks work')
118 ok(0, 'Exception Handler type checks work')
124 .local pmc myhandler, myhandlercan
125 myhandler = subclass_exception_handler()
126 myhandlercan = subclass_exception_handler_can()
127 $I0 = subclass_handler_pop(myhandler)
128 ok($I0, 'Exception Handler subclass popped')
129 $I0 = subclass_handler_catches_can(myhandlercan)
130 ok($I0, 'Exception Handler subclass with can_handle method catch exception')
132 # This test is not expected to die now.
133 # Please report to TT #154 if it must be skipped again.
134 #skip(1,'Exception Handler subclass causes segfault: TT #154')
137 $I0 = subclass_handler_catches(myhandler)
139 ok($I0, 'Exception Handler subclass catch exception')
143 $P0 = new 'ExceptionHandler'
144 nok($P0,'ExceptionHandler without address is false')
145 set_addr $P0, _handler
146 ok($P0,'ExceptionHandler with address is true')
151 $P0 = new 'ExceptionHandler'
152 set_addr $P0, _handler
155 ok(1,'get_integer on ExceptionHandler ')
162 .sub subclass_exception_handler
164 myhandler = subclass 'ExceptionHandler', [ 'MyHandler' ]
168 .sub subclass_exception_handler_can
170 myhandler = subclass 'ExceptionHandler', [ 'MyHandlerCan' ]
174 .sub subclass_handler_pop
177 eh = new ['ExceptionHandler']
178 set_addr eh, subclassed_popped
183 set_addr myeh, subclassed_handler
188 $P0 = new ['Exception']
198 .sub subclass_handler_catches_can
201 eh = new ['ExceptionHandler']
202 set_addr eh, subclassed_failed
207 set_addr myeh, subclassed_handler
210 $P0 = new ['Exception']
222 .sub subclass_handler_catches
225 eh = new ['ExceptionHandler']
226 set_addr eh, subclassed_failed
231 set_addr myeh, subclassed_handler
234 $P0 = new ['Exception']
246 .namespace [ 'MyHandler' ]
248 .namespace [ 'MyHandlerCan' ]
250 .sub can_handle :method
252 ok(1, 'MyHandlerCan.can_handle invoked')
258 .sub 'test_handle_types_except'
259 .local pmc badeh, eh, ex
261 .const int TYPEUSED = .EXCEPTION_UNEXPECTED_NULL
262 .const int TYPEOTHER = .EXCEPTION_SYNTAX_ERROR
265 eh = new ['ExceptionHandler']
266 badeh = new ['ExceptionHandler']
267 eh.'handle_types_except'(TYPEUSED)
269 set_addr badeh, badcatch
272 ex = new ['Exception']
273 ex['type'] = TYPEOTHER
283 ok(i, 'type not in except is list is caught')
286 set_addr badeh, catchall
287 set_addr eh, dontcatch
288 ex = new ['Exception']
289 ex['type'] = TYPEUSED
301 ok(i, 'type in except is list is not caught')
308 # vim: expandtab shiftwidth=4 ft=pir: