2 # Copyright (C) 2006-2008, 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.
29 eh = new ['ExceptionHandler']
30 ok(1, 'Instantiated ExceptionHandler')
32 set_addr eh, nonfatal_handler_one
33 eh.'min_severity'(.EXCEPT_NORMAL)
34 eh.'max_severity'(.EXCEPT_WARNING)
37 eh = new ['ExceptionHandler']
38 set_addr eh, error_handler_one
39 eh.'min_severity'(.EXCEPT_ERROR)
40 eh.'max_severity'(.EXCEPT_FATAL)
43 $P0 = new ['Exception']
44 $P0['severity'] = .EXCEPT_NORMAL
47 $P0 = new ['Exception']
48 $P0['severity'] = .EXCEPT_SEVERE
59 ok(1, 'Min and Max severity for exception handlers')
65 ok(1, 'Min and Max severity for exception handlers')
72 eh = new ['ExceptionHandler']
73 set_addr eh, typed_handler_one
74 eh.'handle_types'(.CONTROL_OK, .CONTROL_BREAK)
77 eh = new ['ExceptionHandler']
78 set_addr eh, typed_handler_two
79 eh.'handle_types'(.EXCEPTION_SYNTAX_ERROR, .EXCEPTION_UNEXPECTED_NULL)
82 $P0 = new ['Exception']
83 $P0['type'] = .CONTROL_OK
86 $P0 = new ['Exception']
87 $P0['type'] = .CONTROL_BREAK
97 ok(1, 'Exception Handler type checks work')
103 ok(0, 'Exception Handler type checks work')
109 .local pmc myhandler, myhandlercan
110 myhandler = subclass_exception_handler()
111 myhandlercan = subclass_exception_handler_can()
112 $I0 = subclass_handler_pop(myhandler)
113 ok($I0, 'Exception Handler subclass popped')
114 $I0 = subclass_handler_catches_can(myhandlercan)
115 ok($I0, 'Exception Handler subclass with can_handle method catch exception')
117 # This test is not expected to die now.
118 # Please report to TT #154 if it must be skipped again.
119 #skip(1,'Exception Handler subclass causes segfault: TT #154')
122 $I0 = subclass_handler_catches(myhandler)
124 ok($I0, 'Exception Handler subclass catch exception')
127 .sub subclass_exception_handler
129 myhandler = subclass 'ExceptionHandler', [ 'MyHandler' ]
133 .sub subclass_exception_handler_can
135 myhandler = subclass 'ExceptionHandler', [ 'MyHandlerCan' ]
139 .sub subclass_handler_pop
142 eh = new ['ExceptionHandler']
143 set_addr eh, subclassed_popped
148 set_addr myeh, subclassed_handler
153 $P0 = new ['Exception']
163 .sub subclass_handler_catches_can
166 eh = new ['ExceptionHandler']
167 set_addr eh, subclassed_failed
172 set_addr myeh, subclassed_handler
175 $P0 = new ['Exception']
187 .sub subclass_handler_catches
190 eh = new ['ExceptionHandler']
191 set_addr eh, subclassed_failed
196 set_addr myeh, subclassed_handler
199 $P0 = new ['Exception']
211 .namespace [ 'MyHandler' ]
213 .namespace [ 'MyHandlerCan' ]
215 .sub can_handle :method
217 ok(1, 'MyHandlerCan.can_handle invoked')
225 # vim: expandtab shiftwidth=4 ft=pir: