X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=tests%2Fcondition.impure.lisp;h=7eab70ac401e3083a04691de89cb9731f9d7e547;hb=e57446ab7db28aca5599d8a2c62cfc3b4b9bbffa;hp=4812ba639c4f67224f587d3dc7eddc8575b39cf7;hpb=f9663e4a4c35614fcba5812882f9ed812cbcf62d;p=sbcl.git diff --git a/tests/condition.impure.lisp b/tests/condition.impure.lisp index 4812ba6..7eab70a 100644 --- a/tests/condition.impure.lisp +++ b/tests/condition.impure.lisp @@ -96,7 +96,7 @@ (define-condition my-stream-error-1-0-9 (stream-error) ()) (define-condition parse-foo-error-1-0-9 (parse-error) ()) (define-condition read-bar-error-1-0-9 (reader-error) ()) -(with-test (:name :printable-conditions :fails-on :win32) +(with-test (:name :printable-conditions) (let (;; instances created initializing all the slots specified in ;; ANSI CL (parse-foo-error-1-0-9 (make-condition 'parse-foo-error-1-0-9 @@ -122,6 +122,7 @@ (return-from restart-test-finds-restarts 42)) :test-function (lambda (condition) + (declare (ignore condition)) (find-restart 'qux)))) (when (find-restart 'bar) (invoke-restart 'bar)))) @@ -142,3 +143,130 @@ (assert (eq (eval `(define-condition ,name () ())) name)))) + +;;; bug-1164970 + +(define-condition condition-with-default-initargs (condition) + () + (:default-initargs :foo 1)) + +(with-test (:name (sb-mop:class-direct-default-initargs :for-condition-class + :bug-1164970)) + ;; CLASS-DIRECT-DEFAULT-INITARGS used to return nil for all + ;; condition classes. + (let ((initargs (sb-mop:class-direct-default-initargs + (find-class 'condition-with-default-initargs)))) + (assert (equal (subseq (first initargs) 0 2) '(:foo 1))))) + +;;; bug-539517 + +(defconstant +error-when-called+ (lambda () (error "oops"))) + +(define-condition condition-with-constant-function-initarg () + ((foo :initarg :foo + :reader condition-with-constant-function-initarg-foo)) + (:default-initargs :foo +error-when-called+)) + +(with-test (:name (:condition-with-constant-function-initarg :bug-539517)) + ;; The default initarg handling for condition classes used to + ;; confuse constant functions (thus +ERROR-WHEN-CALLED+) and + ;; initfunctions. This lead to +ERROR-WHEN-CALLED+ being called as + ;; if it was an initfunction. + (assert (functionp + (condition-with-constant-function-initarg-foo + (make-condition 'condition-with-constant-function-initarg)))) + (assert (functionp + (condition-with-constant-function-initarg-foo + (make-instance 'condition-with-constant-function-initarg))))) + +;; Same problem + +(define-condition condition-with-constant-function-initform () + ((foo :initarg :foo + :reader condition-with-constant-function-initform-foo + :initform +error-when-called+))) + +(with-test (:name (:condition-with-constant-function-slot-initform)) + (assert (functionp + (condition-with-constant-function-initform-foo + (make-condition 'condition-with-constant-function-initform)))) + (assert (functionp + (condition-with-constant-function-initform-foo + (make-instance 'condition-with-constant-function-initform))))) + +;;; bug- + +(defvar bar-counter 0) + +(defvar baz-counter 0) + +(define-condition condition-with-non-constant-default-initarg () + ((bar :initarg :bar + :reader condition-with-non-constant-default-initarg-bar) + (baz :initarg :baz + :reader condition-with-non-constant-default-initarg-baz + :initform (incf baz-counter))) + (:default-initargs :bar (incf bar-counter))) +(define-condition condition-with-non-constant-default-initarg () + ((bar :initarg :bar + :reader condition-with-non-constant-default-initarg-bar) + (baz :initarg :baz + :reader condition-with-non-constant-default-initarg-baz + :initform (incf baz-counter))) + (:default-initargs :bar (incf bar-counter))) + +(with-test (:name (:redefining-condition-with-non-constant-default-initarg + :bug-1164969)) + ;; Redefining conditions could lead to multiple evaluations of + ;; initfunctions for slots and default initargs. We need all the + ;; combinations of make-condition/instance and eval/compile because + ;; they failed differently. + (macrolet ((test (case &body body) + `(progn + (setf bar-counter 0 + baz-counter 0) + (let ((instance (progn ,@body))) + (assert + (= 1 (condition-with-non-constant-default-initarg-bar + instance)) + nil + ,(format nil "Assertion failed for default initarg initfunction for ~A" + case)) + (assert + (= 1 (condition-with-non-constant-default-initarg-baz + instance)) + nil + ,(format nil "Assertion failed for slot initfunction for ~A" + case))) + (assert (= 1 bar-counter)) + (assert (= 1 baz-counter))))) + + ;; Go through EVAL to avoid optimizations. + (test :eval+make-condition + (eval '(make-condition + 'condition-with-non-constant-default-initarg))) + (test :eval+make-instance + (eval '(make-instance + 'condition-with-non-constant-default-initarg))) + + ;; Allow optimizations. + (test :compile+make-condition + (make-condition + 'condition-with-non-constant-default-initarg)) + (test :compile+make-instance + (make-instance + 'condition-with-non-constant-default-initarg)))) + +;;; bug-1049404 + +(define-condition condition-with-class-allocation () + ((count :accessor condition-with-class-allocation-count + :initform 0 + :allocation :class))) + +(with-test (:name (:condition-with-class-allocation :bug-1049404)) + (loop repeat 5 do + (incf (condition-with-class-allocation-count + (make-condition 'condition-with-class-allocation)))) + (assert (= 5 (condition-with-class-allocation-count + (make-condition 'condition-with-class-allocation)))))