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 ;;; Until 0.7.7.21, (MAKE-CONDITION 'FILE-ERROR :PATHNAME "FOO")
17 ;;; wasn't printable, because the REPORT function for FILE-ERROR
18 ;;; referred to unbound slots. This was reported and fixed by Antonio
19 ;;; Martinez (sbcl-devel 2002-09-10).
21 "~&printable now: ~A~%"
22 (make-condition 'file-error :pathname "foo"))
26 (macrolet ((opaque-error (arg) `(error ,arg)))
29 (let ((restarts (remove 'res (compute-restarts c)
32 (assert (= (length restarts) 2))
33 (invoke-restart (second restarts))))))
34 (let ((foo1 (make-condition 'error))
35 (foo2 (make-condition 'error)))
37 (with-condition-restarts foo1 (list (find-restart 'res))
47 (macrolet ((opaque-error (arg) `(error ,arg)))
48 (let ((foo1 (make-condition 'error))
49 (foo2 (make-condition 'error)))
52 (let ((restarts (remove 'res (compute-restarts foo1)
55 (assert (= (length restarts) 1))
56 (invoke-restart (first restarts))))))
58 (with-condition-restarts foo1 (list (find-restart 'res))
70 (c1 (make-condition 'error))
71 (c2 (make-condition 'error)))
76 (flet ((check-restarts (length)
78 (length (remove 'foo (compute-restarts c1)
84 (invoke-restart (find-restart 'foo c1))))))
89 (foo () :test (lambda (c) (declare (ignore c)) visible)
93 ;;; First argument of CERROR is a format control
97 ((type-error (lambda (c) (return :failed)))
98 (simple-error (lambda (c)
99 (return (if (find-restart 'continue)
102 (cerror (formatter "Continue from ~A") "bug ~A" :bug)))
105 ;;; clauses in HANDLER-CASE are allowed to have declarations (and
106 ;;; indeed, only declarations)
108 (null (handler-case (error "foo") (error () (declare (optimize speed))))))
111 (handler-bind ((warning #'muffle-warning))
113 ;; if it's a control error, it had better be printable
114 (control-error (c) (format nil "~A" c))
115 ;; there had better be an error
116 (:no-error (&rest args) (error "No error: ~S" args)))
119 (funcall (lambda (x) (check-type x fixnum) x) t)
121 (assert (and (subtypep (type-error-expected-type c) 'fixnum)
122 (subtypep 'fixnum (type-error-expected-type c))))
123 (assert (eq (type-error-datum c) t)))
124 (:no-error (&rest rest) (error "no error: ~S" rest)))
126 ;;; ANSI specifies TYPE-ERROR if datum and arguments of ERROR are not
127 ;;; designators for a condition. Reported by Bruno Haible on cmucl-imp
129 (flet ((test (&rest args)
130 (multiple-value-bind (res err)
131 (ignore-errors (apply #'error args))
133 (assert (typep err 'type-error))
134 (assert (not (nth-value 1 (ignore-errors
135 (type-error-datum err)))))
136 (assert (not (nth-value 1 (ignore-errors
137 (type-error-expected-type err))))))))
138 (test '#:no-such-condition)
142 (test (make-instance 'standard-object)))
144 ;;; If CERROR is given a condition, any remaining arguments are only
145 ;;; used for the continue format control.
148 ((simple-error (lambda (c) (incf x) (continue c))))
149 (cerror "Continue from ~A at ~A"
150 (make-condition 'simple-error :format-control "foo"
151 :format-arguments nil)
152 'cerror (get-universal-time))