X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=tests%2Fcondition.pure.lisp;h=0b071d85cfcbb9ec40f256eaed3cd0305ebe9226;hb=5877e8c2334bd87490be385af21ed9bc494f19e2;hp=f594e99af6f2a9b48102ee70fc6643f2630f2370;hpb=6de1a3e9a75dcf54c6db2d5768afb8e41266a207;p=sbcl.git diff --git a/tests/condition.pure.lisp b/tests/condition.pure.lisp index f594e99..0b071d8 100644 --- a/tests/condition.pure.lisp +++ b/tests/condition.pure.lisp @@ -6,20 +6,22 @@ ;;;; While most of SBCL is derived from the CMU CL system, the test ;;;; files (like this one) were written from scratch after the fork ;;;; from CMU CL. -;;;; +;;;; ;;;; This software is in the public domain and is provided with ;;;; absolutely no warranty. See the COPYING and CREDITS files for ;;;; more information. (cl:in-package :cl-user) +(load "test-util.lisp") + ;;; Until 0.7.7.21, (MAKE-CONDITION 'FILE-ERROR :PATHNAME "FOO") ;;; wasn't printable, because the REPORT function for FILE-ERROR ;;; referred to unbound slots. This was reported and fixed by Antonio ;;; Martinez (sbcl-devel 2002-09-10). (format t - "~&printable now: ~A~%" - (make-condition 'file-error :pathname "foo")) + "~&printable now: ~A~%" + (make-condition 'file-error :pathname "foo")) (assert (eq (block nil @@ -104,5 +106,86 @@ ;;; clauses in HANDLER-CASE are allowed to have declarations (and ;;; indeed, only declarations) -(assert +(assert (null (handler-case (error "foo") (error () (declare (optimize speed)))))) + +(handler-case + (handler-bind ((warning #'muffle-warning)) + (signal 'warning)) + ;; if it's a control error, it had better be printable + (control-error (c) (format nil "~A" c)) + ;; there had better be an error + (:no-error (&rest args) (error "No error: ~S" args))) + +(handler-case + (funcall (lambda (x) (check-type x fixnum) x) t) + (type-error (c) + (assert (and (subtypep (type-error-expected-type c) 'fixnum) + (subtypep 'fixnum (type-error-expected-type c)))) + (assert (eq (type-error-datum c) t))) + (:no-error (&rest rest) (error "no error: ~S" rest))) + +;;; ANSI specifies TYPE-ERROR if datum and arguments of ERROR are not +;;; designators for a condition. Reported by Bruno Haible on cmucl-imp +;;; 2004-10-12. +(flet ((test (&rest args) + (multiple-value-bind (res err) + (ignore-errors (apply #'error args)) + (assert (not res)) + (assert (typep err 'type-error)) + (assert (not (nth-value 1 (ignore-errors + (type-error-datum err))))) + (assert (not (nth-value 1 (ignore-errors + (type-error-expected-type err)))))))) + (test '#:no-such-condition) + (test nil) + (test t) + (test 42) + (test (make-instance 'standard-object))) + +;;; If CERROR is given a condition, any remaining arguments are only +;;; used for the continue format control. +(let ((x 0)) + (handler-bind + ((simple-error (lambda (c) (incf x) (continue c)))) + (cerror "Continue from ~A at ~A" + (make-condition 'simple-error :format-control "foo" + :format-arguments nil) + 'cerror (get-universal-time)) + (assert (= x 1)))) + +(with-test (:name :malformed-restart-case-clause) + (assert (eq :ok + (handler-case + (macroexpand `(restart-case (error "foo") + (foo :report "quux" (quux)))) + (simple-error (e) + (assert (equal '(restart-case (foo :report "quux" (quux))) + (simple-condition-format-arguments e))) + :ok))))) + +(with-test (:name :simple-condition-without-args) + (let ((sc (make-condition 'simple-condition))) + (assert (not (simple-condition-format-control sc))) + (assert (not (simple-condition-format-arguments sc))) + (assert (stringp (prin1-to-string sc))) + (assert + (eq :ok + (handler-case + (princ-to-string sc) + (simple-error (c) + (when (and (equal "No format-control for ~S" + (simple-condition-format-control c)) + (eq sc (car + (simple-condition-format-arguments c)))) + :ok))))))) + +(with-test (:name :malformed-simple-condition-printing-type-error) + (assert (eq :type-error + (handler-case + (princ-to-string + (make-condition 'simple-error :format-control "" :format-arguments 8)) + (type-error (e) + (when (and (eq 'list (type-error-expected-type e)) + (eql 8 (type-error-datum e))) + :type-error))))))