X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=tests%2Fclos.impure.lisp;h=405a219ad43c8b8dbdd40a3e5b41d9a9d2c34c22;hb=22c1de0a40df83bb5628974010a879cb2c17ff53;hp=8e6d4141c63ccc1bacdfe8d58a0e5c1d5fafed30;hpb=3eedd5a020356291b2c1c2e426ef9fc7dd5928d9;p=sbcl.git diff --git a/tests/clos.impure.lisp b/tests/clos.impure.lisp index 8e6d414..405a219 100644 --- a/tests/clos.impure.lisp +++ b/tests/clos.impure.lisp @@ -433,26 +433,17 @@ form))) 'dmc-test-return)) -;;; DEFMETHOD should signal a PROGRAM-ERROR if an incompatible lambda -;;; list is given: +;;; DEFMETHOD should signal an ERROR if an incompatible lambda list is +;;; given: (defmethod incompatible-ll-test-1 (x) x) -(multiple-value-bind (result error) - (ignore-errors (defmethod incompatible-ll-test-1 (x y) y)) - (assert (null result)) - (assert (typep error 'program-error))) -(multiple-value-bind (result error) - (ignore-errors (defmethod incompatible-ll-test-1 (x &rest y) y)) - (assert (null result)) - (assert (typep error 'program-error))) +(assert (raises-error? (defmethod incompatible-ll-test-1 (x y) y))) +(assert (raises-error? (defmethod incompatible-ll-test-1 (x &rest y) y))) ;;; Sneakily using a bit of MOPness to check some consistency (assert (= (length (sb-pcl:generic-function-methods #'incompatible-ll-test-1)) 1)) (defmethod incompatible-ll-test-2 (x &key bar) bar) -(multiple-value-bind (result error) - (ignore-errors (defmethod incompatible-ll-test-2 (x) x)) - (assert (null result)) - (assert (typep error 'program-error))) +(assert (raises-error? (defmethod incompatible-ll-test-2 (x) x))) (defmethod incompatible-ll-test-2 (x &rest y) y) (assert (= (length (sb-pcl:generic-function-methods #'incompatible-ll-test-2)) 1)) @@ -601,7 +592,9 @@ 'slot-value)) (assert (eq (funcall (lambda (x) (setf (slot-value x 'baz) 'baz)) (make-instance 'class-with-all-slots-missing)) - 'setf)) + ;; SLOT-MISSING's value is specified to be ignored; we + ;; return NEW-VALUE. + 'baz)) ;;; we should be able to specialize on anything that names a class. (defclass name-for-class () ()) @@ -638,5 +631,57 @@ (assert (typep (allocate-instance (find-class 'allocatable-structure)) 'allocatable-structure)) +;;; Bug found by Paul Dietz when devising CPL tests: somewhat +;;; amazingly, calls to CPL would work a couple of times, and then +;;; start returning NIL. A fix was found (relating to the +;;; applicability of constant-dfun optimization) by Gerd Moellmann. +(defgeneric cpl (x) + (:method-combination list) + (:method list ((x broadcast-stream)) 'broadcast-stream) + (:method list ((x integer)) 'integer) + (:method list ((x number)) 'number) + (:method list ((x stream)) 'stream) + (:method list ((x structure-object)) 'structure-object)) +(assert (equal (cpl 0) '(integer number))) +(assert (equal (cpl 0) '(integer number))) +(assert (equal (cpl 0) '(integer number))) +(assert (equal (cpl 0) '(integer number))) +(assert (equal (cpl 0) '(integer number))) +(assert (equal (cpl (make-broadcast-stream)) + '(broadcast-stream stream structure-object))) +(assert (equal (cpl (make-broadcast-stream)) + '(broadcast-stream stream structure-object))) +(assert (equal (cpl (make-broadcast-stream)) + '(broadcast-stream stream structure-object))) + +;;; Bug in CALL-NEXT-METHOD: assignment to the method's formal +;;; parameters shouldn't affect the arguments to the next method for a +;;; no-argument call to CALL-NEXT-METHOD +(defgeneric cnm-assignment (x) + (:method (x) x) + (:method ((x integer)) (setq x 3) + (list x (call-next-method) (call-next-method x)))) +(assert (equal (cnm-assignment 1) '(3 1 3))) + +;;; Bug reported by Istvan Marko 2003-07-09 +(let ((class-name (gentemp))) + (loop for i from 1 to 9 + for slot-name = (intern (format nil "X~D" i)) + for initarg-name = (intern (format nil "X~D" i) :keyword) + collect `(,slot-name :initarg ,initarg-name) into slot-descs + append `(,initarg-name (list 0)) into default-initargs + finally (eval `(defclass ,class-name () + (,@slot-descs) + (:default-initargs ,@default-initargs)))) + (let ((f (compile nil `(lambda () (make-instance ',class-name))))) + (assert (typep (funcall f) class-name)))) + +;;; bug 262: DEFMETHOD failed on a generic function without a lambda +;;; list +(ensure-generic-function 'bug262) +(defmethod bug262 (x y) + (list x y)) +(assert (equal (bug262 1 2) '(1 2))) + ;;;; success (sb-ext:quit :unix-status 104)