1 ;;;; side-effect-free tests of the condition system
3 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; While most of SBCL is derived from the CMU CL system, the test
7 ;;;; files (like this one) were written from scratch after the fork
10 ;;;; This software is in the public domain and is provided with
11 ;;;; absolutely no warranty. See the COPYING and CREDITS files for
12 ;;;; more information.
14 (cl:in-package
:cl-user
)
16 (load "test-util.lisp")
18 ;;; Until 0.7.7.21, (MAKE-CONDITION 'FILE-ERROR :PATHNAME "FOO")
19 ;;; wasn't printable, because the REPORT function for FILE-ERROR
20 ;;; referred to unbound slots. This was reported and fixed by Antonio
21 ;;; Martinez (sbcl-devel 2002-09-10).
23 "~&printable now: ~A~%"
24 (make-condition 'file-error
:pathname
"foo"))
28 (macrolet ((opaque-error (arg) `(error ,arg
)))
31 (let ((restarts (remove 'res
(compute-restarts c
)
34 (assert (= (length restarts
) 2))
35 (invoke-restart (second restarts
))))))
36 (let ((foo1 (make-condition 'error
))
37 (foo2 (make-condition 'error
)))
39 (with-condition-restarts foo1
(list (find-restart 'res
))
49 (macrolet ((opaque-error (arg) `(error ,arg
)))
50 (let ((foo1 (make-condition 'error
))
51 (foo2 (make-condition 'error
)))
54 (let ((restarts (remove 'res
(compute-restarts foo1
)
57 (assert (= (length restarts
) 1))
58 (invoke-restart (first restarts
))))))
60 (with-condition-restarts foo1
(list (find-restart 'res
))
72 (c1 (make-condition 'error
))
73 (c2 (make-condition 'error
)))
78 (flet ((check-restarts (length)
80 (length (remove 'foo
(compute-restarts c1
)
86 (invoke-restart (find-restart 'foo c1
))))))
91 (foo () :test
(lambda (c) (declare (ignore c
)) visible
)
95 ;;; First argument of CERROR is a format control
99 ((type-error (lambda (c) (return :failed
)))
100 (simple-error (lambda (c)
101 (return (if (find-restart 'continue
)
104 (cerror (formatter "Continue from ~A") "bug ~A" :bug
)))
107 ;;; clauses in HANDLER-CASE are allowed to have declarations (and
108 ;;; indeed, only declarations)
110 (null (handler-case (error "foo") (error () (declare (optimize speed
))))))
113 (handler-bind ((warning #'muffle-warning
))
115 ;; if it's a control error, it had better be printable
116 (control-error (c) (format nil
"~A" c
))
117 ;; there had better be an error
118 (:no-error
(&rest args
) (error "No error: ~S" args
)))
121 (funcall (lambda (x) (check-type x fixnum
) x
) t
)
123 (assert (and (subtypep (type-error-expected-type c
) 'fixnum
)
124 (subtypep 'fixnum
(type-error-expected-type c
))))
125 (assert (eq (type-error-datum c
) t
)))
126 (:no-error
(&rest rest
) (error "no error: ~S" rest
)))
128 ;;; ANSI specifies TYPE-ERROR if datum and arguments of ERROR are not
129 ;;; designators for a condition. Reported by Bruno Haible on cmucl-imp
131 (flet ((test (&rest args
)
132 (multiple-value-bind (res err
)
133 (ignore-errors (apply #'error args
))
135 (assert (typep err
'type-error
))
136 (assert (not (nth-value 1 (ignore-errors
137 (type-error-datum err
)))))
138 (assert (not (nth-value 1 (ignore-errors
139 (type-error-expected-type err
))))))))
140 (test '#:no-such-condition
)
144 (test (make-instance 'standard-object
)))
146 ;;; If CERROR is given a condition, any remaining arguments are only
147 ;;; used for the continue format control.
150 ((simple-error (lambda (c) (incf x
) (continue c
))))
151 (cerror "Continue from ~A at ~A"
152 (make-condition 'simple-error
:format-control
"foo"
153 :format-arguments nil
)
154 'cerror
(get-universal-time))
157 (with-test (:name
:malformed-restart-case-clause
)
160 (macroexpand `(restart-case (error "foo")
161 (foo :report
"quux" (quux))))
163 (assert (equal '(restart-case (foo :report
"quux" (quux)))
164 (simple-condition-format-arguments e
)))
167 (with-test (:name
:simple-condition-without-args
)
168 (let ((sc (make-condition 'simple-condition
)))
169 (assert (not (simple-condition-format-control sc
)))
170 (assert (not (simple-condition-format-arguments sc
)))
171 (assert (stringp (prin1-to-string sc
)))
177 (when (and (equal "No format-control for ~S"
178 (simple-condition-format-control c
))
180 (simple-condition-format-arguments c
))))
183 (with-test (:name
:malformed-simple-condition-printing-type-error
)
184 (assert (eq :type-error
187 (make-condition 'simple-error
:format-control
"" :format-arguments
8))
189 (when (and (eq 'list
(type-error-expected-type e
))
190 (eql 8 (type-error-datum e
)))
193 (with-test (:name
(:printing-unintitialized-condition
:bug-1184586
))
194 (prin1-to-string (make-condition 'simple-type-error
)))
196 (with-test (:name
(:print-undefined-function-condition
))
197 (handler-case (funcall '#:foo
)
198 (undefined-function (c) (princ c
))))