X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=tests%2Fclos.impure.lisp;h=12a028e505486892726decef24d52538d24bdf19;hb=d25e3478acccec70402ff32554669a982be8e281;hp=e5cc14046c91e46398bd169339a95da3e9636a25;hpb=71922347ca66f2a3ad4c55092ccb3ad86a14c754;p=sbcl.git diff --git a/tests/clos.impure.lisp b/tests/clos.impure.lisp index e5cc140..12a028e 100644 --- a/tests/clos.impure.lisp +++ b/tests/clos.impure.lisp @@ -11,8 +11,6 @@ ;;;; absolutely no warranty. See the COPYING and CREDITS files for ;;;; more information. -(load "assertoid.lisp") - (defpackage "CLOS-IMPURE" (:use "CL" "ASSERTOID" "TEST-UTIL")) (in-package "CLOS-IMPURE") @@ -63,9 +61,7 @@ (ignore-errors (progn ,@body)) (declare (ignore res)) (typep condition 'error)))) -(assert (expect-error - (macroexpand-1 - '(defmethod foo0 ((x t) &rest) nil)))) +(assert (expect-error (defmethod foo0 ((x t) &rest) nil))) (assert (expect-error (defgeneric foo1 (x &rest)))) (assert (expect-error (defgeneric foo2 (x a &rest)))) (defgeneric foo3 (x &rest y)) @@ -73,7 +69,7 @@ (defmethod foo4 ((x t) &rest z &key y) nil) (defgeneric foo4 (x &rest z &key y)) (assert (expect-error (defgeneric foo5 (x &rest)))) -(assert (expect-error (macroexpand-1 '(defmethod foo6 (x &rest))))) +(assert (expect-error (defmethod foo6 (x &rest)))) ;;; more lambda-list checking ;;; @@ -654,6 +650,7 @@ (assert (= (bug222 t) 1)) ;;; also, a test case to guard against bogus environment hacking: + (eval-when (:compile-toplevel :load-toplevel :execute) (setq bug222-b 3)) ;;; this should at the least compile: @@ -664,8 +661,10 @@ ;;; and it would be nice (though not specified by ANSI) if the answer ;;; were as follows: (let ((x (make-string-output-stream))) - ;; not specified by ANSI - (assert (= (bug222-b t x) 3)) + (let ((value (bug222-b t x))) + ;; not specified by ANSI + #+#.(cl:if (cl:eq sb-ext:*evaluator-mode* :compile) '(and) '(or)) + (assert (= value 3))) ;; specified. (assert (char= (char (get-output-stream-string x) 0) #\1))) @@ -914,6 +913,31 @@ (assert (= (slot-value *yao-super* 'obs) 3)) (assert (= (slot-value *yao-sub* 'obs) 3)) +;;; one more MIO test: variable slot names +(defclass mio () ((x :initform 42))) +(defvar *mio-slot* 'x) +(defparameter *mio-counter* 0) +(defmethod update-instance-for-redefined-class ((instance mio) new old plist &key) + (incf *mio-counter*)) + +(let ((x (make-instance 'mio))) + (make-instances-obsolete 'mio) + (slot-value x *mio-slot*)) + +(let ((x (make-instance 'mio))) + (make-instances-obsolete 'mio) + (setf (slot-value x *mio-slot*) 13)) + +(let ((x (make-instance 'mio))) + (make-instances-obsolete 'mio) + (slot-boundp x *mio-slot*)) + +(let ((x (make-instance 'mio))) + (make-instances-obsolete 'mio) + (slot-makunbound x *mio-slot*)) + +(assert (= 4 *mio-counter*)) + ;;; shared -> local slot transfers of inherited slots, reported by ;;; Bruno Haible (let (i) @@ -1320,7 +1344,7 @@ (defclass class-with-odd-class-name-method () ((a :accessor class-name))) -;;; another case where precomputing (this time on PRINT-OBJET) and +;;; another case where precomputing (this time on PRINT-OBJECT) and ;;; lazily-finalized classes caused problems. (report from James Y ;;; Knight sbcl-devel 20-07-2006) @@ -1392,13 +1416,296 @@ (loop until (null x) do (incf result) (setq x (slot-value x 'cdroid))) result)) -(with-test (:name ((:setq :method-parameter) slot-value) :fails-on :sbcl) +(with-test (:name ((:setq :method-parameter) slot-value)) (assert (= (lengthoid (make-instance 'listoid)) 1)) - (error "the failure mode is an infinite loop") (assert (= (lengthoid (make-instance 'listoid :cdroid (make-instance 'listoid :cdroid (make-instance 'listoid)))) 3))) + + + +;;;; Tests for argument parsing in fast-method-functions. + +(defvar *foo* 0) + +(eval-when (:compile-toplevel :load-toplevel :execute) + (setf (symbol-value 'a) 'invalid)) + +(defmacro test1 (lambda-list values args &key declarations cnm) + `(progn + (fmakunbound 'll-method) + (fmakunbound 'll-function) + (defmethod ll-method ,lambda-list + ,@declarations + ,@(when cnm + `((when nil (call-next-method)))) + (list ,@values)) + (defun ll-function ,lambda-list + ,@declarations + (list ,@values)) + (dotimes (i 2) + (assert (equal (ll-method ,@args) + (ll-function ,@args)))))) + +(defmacro test (&rest args) + `(progn + (test1 ,@args :cnm nil) + (test1 ,@args :cnm t))) + +;; Just plain arguments + +(test (a) (a) (1)) +(test (a b c d e f g h i) (a b c d e f g h i) (1 2 3 4 5 6 7 8 9)) + +(test (*foo*) (*foo* (symbol-value '*foo*)) (1)) + +(test (a) (a (symbol-value 'a)) (1) + :declarations ((declare (special a)))) + +;; Optionals + +(test (a &optional b c) (a b c) (1)) +(test (a &optional b c) (a b c) (1 2)) +(test (a &optional b c) (a b c) (1 2 3)) + +(test (a &optional (b 'b b-p) (c 'c c-p)) (a b c b-p c-p) (1)) +(test (a &optional (b 'b b-p) (c 'c c-p)) (a b c b-p c-p) (1 2)) +(test (a &optional (b 'b b-p) (c 'c c-p)) (a b c b-p c-p) (1 2 3)) + +(test (&optional *foo*) (*foo* (symbol-value '*foo*)) ()) +(test (&optional *foo*) (*foo* (symbol-value '*foo*)) (1)) + +(test (&optional (*foo* 'z foo-p)) (*foo* (symbol-value '*foo*) foo-p) ()) +(test (&optional (*foo* 'z foo-p)) (*foo* (symbol-value '*foo*) foo-p) (1)) + +(test (&optional a) (a (symbol-value 'a)) () + :declarations ((declare (special a)))) +(test (&optional a) (a (symbol-value 'a)) (1) + :declarations ((declare (special a)))) + +(test (&optional (a 'z a-p)) (a (symbol-value 'a) a-p) () + :declarations ((declare (special a)))) +(test (&optional (a 'z a-p)) (a (symbol-value 'a) a-p) (1) + :declarations ((declare (special a)))) + +(defparameter *count* 0) + +(test (&optional (a (incf *count*)) (b (incf *count*))) + (a b *count* (setf *count* 0)) + ()) + +;; Keywords with some &RESTs thrown in + +(dolist (args '((1) + (1 :b 2) + (1 :c 3) + (1 :b 2 :c 3) + (1 :c 3 :b 2) + (1 :c 3 :c 1 :b 2 :b 4))) + (eval `(test (a &key b c) (a b c) ,args)) + (eval `(test (a &key (b 'b b-p) (c 'c c-p)) + (a b c b-p c-p) + ,args)) + (eval `(test (a &rest rest &key (b 'b b-p) (c 'c c-p)) + (a b c b-p c-p rest) + ,args)) + (eval `(test (a &rest *foo* &key (b 'b b-p) (c 'c c-p)) + (a b c b-p c-p *foo* (symbol-value '*foo*)) + ,args)) + (eval `(test (a &rest *foo* &key (b 'b b-p) (c 'c c-p)) + (a b c b-p c-p *foo* (symbol-value '*foo*)) + ,args + :declarations ((declare (special b-p)))))) + +(dolist (args '(() + (:*foo* 1) + (:*foo* 1 :*foo* 2))) + (eval `(test (&key *foo*) (*foo* (symbol-value '*foo*)) ,args)) + (eval `(test (&key (*foo* 'z foo-p)) (*foo* (symbol-value '*foo*) foo-p) + ,args)) + (eval `(test (&key ((:*foo* a) 'z foo-p)) (a (symbol-value 'a) foo-p) + ,args)) + (eval `(test (&key ((:*foo* a) 'z foo-p)) (a (symbol-value 'a) foo-p) + ,args + :declarations ((declare (special a)))))) + +(defparameter *count* 0) + +(test (&key (a (incf *count*)) (b (incf *count*))) + (a b *count* (setf *count* 0)) + ()) + +(test (&key a b &allow-other-keys) (a b) (:a 1 :b 2 :c 3)) + +(defmethod clim-style-lambda-list-test (a b &optional c d &key x y) + (list a b c d x y)) + +(clim-style-lambda-list-test 1 2) + +(setf *count* 0) + +(test (&aux (a (incf *count*)) (b (incf *count*))) + (a b *count* (setf *count* 0)) + ()) + +;;;; long-form method combination with &rest in :arguments +;;;; (this had a bug what with fixed in 1.0.4.something) +(define-method-combination long-form-with-&rest () + ((methods *)) + (:arguments x &rest others) + `(progn + ,@(mapcar (lambda (method) + `(call-method ,method)) + methods) + (list ,x (length ,others)))) + +(defgeneric test-long-form-with-&rest (x &rest others) + (:method-combination long-form-with-&rest)) + +(defmethod test-long-form-with-&rest (x &rest others) + nil) + +(assert (equal '(:foo 13) + (apply #'test-long-form-with-&rest :foo (make-list 13)))) + +;;;; slot-missing for non-standard classes on SLOT-VALUE +;;;; +;;;; FIXME: This is arguably not right, actually: CLHS seems to say +;;;; we should just signal an error at least for built-in classes, but +;;;; for a while we were hitting NO-APPLICABLE-METHOD, which is definitely +;;;; wrong -- so test this for now at least. + +(defvar *magic-symbol* (gensym "MAGIC")) + +(set *magic-symbol* 42) + +(defmethod slot-missing (class instance (slot-name (eql *magic-symbol*)) op + &optional new) + (if (eq 'setf op) + (setf (symbol-value *magic-symbol*) new) + (symbol-value *magic-symbol*))) + +(assert (eql 42 (slot-value (cons t t) *magic-symbol*))) +(assert (eql 13 (setf (slot-value 123 *magic-symbol*) 13))) +(assert (eql 13 (slot-value 'foobar *magic-symbol*))) + +;;;; Built-in structure and condition layouts should have NIL in +;;;; LAYOUT-FOR-STD-CLASS-P, and classes should have T. + +(assert (not (sb-pcl::layout-for-std-class-p (sb-pcl::find-layout 'warning)))) +(assert (not (sb-pcl::layout-for-std-class-p (sb-pcl::find-layout 'hash-table)))) +(assert (eq t (sb-pcl::layout-for-std-class-p (sb-pcl::find-layout 'standard-object)))) + +;;;; bug 402: PCL used to warn about non-standard declarations +(declaim (declaration bug-402-d)) +(defgeneric bug-402-gf (x)) +(with-test (:name :bug-402) + (handler-bind ((warning #'error)) + (eval '(defmethod bug-402-gf (x) + (declare (bug-402-d x)) + x)))) + +;;;; non-keyword :default-initargs + :before method on shared initialize +;;;; interacted badly with CTOR optimizations +(defclass ctor-default-initarg-problem () + ((slot :initarg slotto)) + (:default-initargs slotto 123)) +(defmethod shared-initialize :before ((instance ctor-default-initarg-problem) slot-names &rest initargs) + (format t "~&Rock on: ~A~%" initargs)) +(defun provoke-ctor-default-initarg-problem () + (make-instance 'ctor-default-initarg-problem)) +(handler-bind ((warning #'error)) + (assert (= 123 (slot-value (provoke-ctor-default-initarg-problem) 'slot)))) + +;;;; discriminating net on streams used to generate code deletion notes on +;;;; first call +(defgeneric stream-fd (stream direction)) +(defmethod stream-fd ((stream sb-sys:fd-stream) direction) + (declare (ignore direction)) + (sb-sys:fd-stream-fd stream)) +(defmethod stream-fd ((stream synonym-stream) direction) + (stream-fd (symbol-value (synonym-stream-symbol stream)) direction)) +(defmethod stream-fd ((stream two-way-stream) direction) + (ecase direction + (:input + (stream-fd + (two-way-stream-input-stream stream) direction)) + (:output + (stream-fd + (two-way-stream-output-stream stream) direction)))) +(with-test (:name (:discriminating-name :code-deletion-note)) + (handler-bind ((compiler-note #'error)) + (stream-fd sb-sys:*stdin* :output) + (stream-fd sb-sys:*stdin* :output))) + +(with-test (:name :bug-380) + (defclass bug-380 () + ((slot :accessor bug380-slot))) + (fmakunbound 'foo-slot) + (defgeneric foo-slot (x y z)) + (defclass foo () + ((slot :accessor foo-slot-value)))) + +;;; SET and (SETF SYMBOL-VALUE) used to confuse permuation vector +;;; optimizations +(defclass fih () + ((x :initform :fih))) +(defclass fah () + ((x :initform :fah))) +(declaim (special *fih*)) +(defmethod fihfah ((*fih* fih)) + (set '*fih* (make-instance 'fah)) + (list (slot-value *fih* 'x) + (eval '(slot-value *fih* 'x)))) +(defmethod fihfah ((fah fah)) + (declare (special fah)) + (set 'fah (make-instance 'fih)) + (list (slot-value fah 'x) + (eval '(slot-value fah 'x)))) +(with-test (:name :set-of-a-method-specializer) + (assert (equal '(:fah :fah) (fihfah (make-instance 'fih)))) + (assert (equal '(:fih :fih) (fihfah (make-instance 'fah))))) + +(defmethod no-implicit-declarations-for-local-specials ((faax double-float)) + (declare (special faax)) + (set 'faax (when (< faax 0) (- faax))) + faax) +(with-test (:name :no-implicit-declarations-for-local-specials) + (assert (not (no-implicit-declarations-for-local-specials 1.0d0)))) + +(defstruct bug-357-a + slot1 + (slot2 t) + (slot3 (coerce pi 'single-float) :type single-float)) +(defclass bug-357-b (bug-357-a) + ((slot2 :initform 't2) + (slot4 :initform -44) + (slot5) + (slot6 :initform t) + (slot7 :initform (floor (* pi pi))) + (slot8 :initform 88)) + (:metaclass structure-class)) +(defstruct (bug-357-c (:include bug-357-b (slot8 -88) (slot5 :ok))) + slot9 + (slot10 t) + (slot11 (floor (exp 3)))) +(with-test (:name :bug-357) + (flet ((slots (x) + (list (bug-357-c-slot1 x) + (bug-357-c-slot2 x) + (bug-357-c-slot3 x) + (bug-357-c-slot4 x) + (bug-357-c-slot5 x) + (bug-357-c-slot6 x) + (bug-357-c-slot7 x) + (bug-357-c-slot8 x) + (bug-357-c-slot9 x) + (bug-357-c-slot10 x) + (bug-357-c-slot11 x)))) + (let ((base (slots (make-bug-357-c)))) + (assert (equal base (slots (make-instance 'bug-357-c)))) + (assert (equal base '(nil t2 3.1415927 -44 :ok t 9 -88 nil t 20)))))) ;;;; success