1 ;;;; miscellaneous side-effectful tests of the MOP
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 ;;;; Note that the MOP is not in a supported state. Package issues
15 ;;;; (both MOP/SB-PCL and CL/SB-PCL) have yet to be resolved, and
16 ;;;; there is likely to be missing functionality. However, this seems
17 ;;;; a good a way as any of ensuring that we have no regressions.
19 (defpackage "MOP-TEST"
20 ;; eventually, we might want "MOP" as well here.
23 (in-package "MOP-TEST")
25 ;;; Readers for Generic Function Metaobjects (pp. 216--218 of AMOP)
26 (defgeneric fn-with-odd-arg-precedence (a b c)
27 (:argument-precedence-order b c a))
30 (sb-pcl:generic-function-lambda-list #'fn-with-odd-arg-precedence)
33 (sb-pcl:generic-function-argument-precedence-order #'fn-with-odd-arg-precedence)
35 ;;; Test for DOCUMENTATION's order, which was wrong until sbcl-0.7.8.39
37 (sb-pcl:generic-function-argument-precedence-order #'documentation)
38 (let ((ll (sb-pcl:generic-function-lambda-list #'documentation)))
39 (list (nth 1 ll) (nth 0 ll)))))
42 (sb-pcl:generic-function-declarations #'fn-with-odd-arg-precedence)))
43 (defgeneric gf-with-declarations (x)
44 (declare (optimize (speed 3)))
45 (declare (optimize (safety 0))))
46 (let ((decls (sb-pcl:generic-function-declarations #'gf-with-declarations)))
47 (assert (= (length decls) 2))
48 (assert (member '(optimize (speed 3)) decls :test #'equal))
49 (assert (member '(optimize (safety 0)) decls :test #'equal)))
51 ;;; Readers for Slot Definition Metaobjects (pp. 221--224 of AMOP)
53 ;;; Ensure that SLOT-DEFINITION-ALLOCATION returns :INSTANCE/:CLASS as
55 (defclass sdm-test-class ()
56 ((an-instance-slot :accessor an-instance-slot)
57 (a-class-slot :allocation :class :accessor a-class-slot)))
58 (dolist (m (list (list #'an-instance-slot :instance)
59 (list #'a-class-slot :class)))
60 (let ((methods (sb-pcl:generic-function-methods (car m))))
61 (assert (= (length methods) 1))
62 (assert (eq (sb-pcl:slot-definition-allocation
63 (sb-pcl:accessor-method-slot-definition
67 ;;; Class Finalization Protocol (see section 5.5.2 of AMOP)
68 (let ((finalized-count 0))
69 (defmethod sb-pcl:finalize-inheritance :after ((x sb-pcl::standard-class))
70 (incf finalized-count))
71 (defun get-count () finalized-count))
72 (defclass finalization-test-1 () ())
73 (make-instance 'finalization-test-1)
74 (assert (= (get-count) 1))
75 (defclass finalization-test-2 (finalization-test-3) ())
76 (assert (= (get-count) 1))
77 (defclass finalization-test-3 () ())
78 (make-instance 'finalization-test-3)
79 (assert (or (= (get-count) 2) (= (get-count) 3)))
80 (make-instance 'finalization-test-2)
81 (assert (= (get-count) 3))
84 (sb-ext:quit :unix-status 104)