1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
;-*- Mode: Lisp -*-
;;;; Author: Paul Dietz
;;;; Created: Fri Feb 28 22:07:25 2003
;;;; Contains: Tests of HANDLER-BIND
(in-package :cl-test)
(deftest handler-bind.1
(handler-bind ())
nil)
(deftest handler-bind.2
(handler-bind () (values)))
(deftest handler-bind.3
(handler-bind () (values 1 2 3))
1 2 3)
(deftest handler-bind.4
(let ((x 0))
(values
(handler-bind () (incf x) (+ x 10))
x))
11 1)
(deftest handler-bind.5
(block foo
(handler-bind ((error #'(lambda (c) (return-from foo 'good))))
(error "an error")))
good)
(deftest handler-bind.6
(block foo
(handler-bind
((error #'(lambda (c) (return-from foo 'good))))
(handler-bind ((error #'(lambda (c) (error c)))
(error #'(lambda (c) (return-from foo 'bad))))
(error "an error"))))
good)
(defun handler-bind.7-handler-fn (c)
(declare (ignore c))
(throw 'foo 'good))
(deftest handler-bind.7
(catch 'foo
(handler-bind ((simple-error #'handler-bind.7-handler-fn))
(error "simple error")))
good)
(deftest handler-bind.8
(catch 'foo
(handler-bind ((simple-error 'handler-bind.7-handler-fn))
(error "simple error")))
good)
(deftest handler-bind.9
(catch 'foo
(handler-bind ((simple-error #.(symbol-function
'handler-bind.7-handler-fn)))
(error "simple error")))
good)
(deftest handler-bind.10
(block done
(flet ((%foo () (signal "A simple condition"))
(%succeed (c) (declare (ignore c)) (return-from done 'good))
(%fail (c) (declare (ignore c)) (return-from done 'bad)))
(handler-bind
((error #'%fail)
(simple-condition #'%succeed))
(%foo))))
good)
(deftest handler-bind.11
(block done
(handler-bind
((error #'(lambda (c) c))
(error #'(lambda (c) (declare (ignore c)) (return-from done 'good))))
(error "an error")))
good)
(deftest handler-bind.12
(block done
(handler-bind
((error #'(lambda (c) (declare (ignore c)) (return-from done 'good))))
(handler-bind
((error #'(lambda (c) c)))
(error "an error"))))
good)
(deftest handler-bind.13
(handler-bind
((error #'(lambda (c) (declare (ignore c))
(throw 'done 'good))))
(catch 'done
(error "an error")))
good)
(deftest handler-bind.14
(catch 'done
(handler-bind
((symbol #'identity) ;; can never succeed
(error #'(lambda (c) (declare (ignore c))
(throw 'done 'good))))
(error "an error")))
good)
(deftest handler-bind.15
(catch 'done
(handler-bind
((nil #'(lambda (c) (declare (ignore c))
(throw 'done 'bad)))
(error #'(lambda (c) (declare (ignore c))
(throw 'done 'good))))
(error "an error")))
good)
(deftest handler-bind.16
(catch 'done
(handler-bind
(((not error) #'identity)
(error
#'(lambda (c) (declare (ignore c))
(throw 'done 'good))))
(error "an error")))
good)
(deftest handler-bind.17
(catch 'done
(handler-bind
((#.(find-class 'error)
#'(lambda (c) (declare (ignore c))
(throw 'done 'good))))
(error "an error")))
good)
;;; More handler-bind tests elsewhere
|