0.7.8.54:
[sbcl.git] / tests / mop.impure.lisp
1 ;;;; miscellaneous side-effectful tests of the MOP
2
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
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
8 ;;;; from CMU CL.
9 ;;;; 
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.
13
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.
18
19 (defpackage "MOP-TEST"
20   ;; eventually, we might want "MOP" as well here.
21   (:use "CL"))
22
23 (in-package "MOP-TEST")
24 \f
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))
28
29 (assert (equal
30          (sb-pcl:generic-function-lambda-list #'fn-with-odd-arg-precedence)
31          '(a b c)))
32 (assert (equal
33          (sb-pcl:generic-function-argument-precedence-order #'fn-with-odd-arg-precedence)
34          '(b c a)))
35 ;;; Test for DOCUMENTATION's order, which was wrong until sbcl-0.7.8.39
36 (assert (equal
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)))))
40 \f
41 ;;; Readers for Slot Definition Metaobjects (pp. 221--224 of AMOP)
42
43 ;;; Ensure that SLOT-DEFINITION-ALLOCATION returns :INSTANCE/:CLASS as
44 ;;; appropriate.
45 (defclass sdm-test-class ()
46   ((an-instance-slot :accessor an-instance-slot)
47    (a-class-slot :allocation :class :accessor a-class-slot)))
48 (dolist (m (list (list #'an-instance-slot :instance)
49                  (list #'a-class-slot :class)))
50   (let ((methods (sb-pcl:generic-function-methods (car m))))
51     (assert (= (length methods) 1))
52     (assert (eq (sb-pcl:slot-definition-allocation
53                  (sb-pcl:accessor-method-slot-definition
54                   (car methods)))
55                 (cadr m)))))
56 \f
57 ;;; Class Finalization Protocol (see section 5.5.2 of AMOP)
58 (let ((finalized-count 0))
59   (defmethod sb-pcl:finalize-inheritance :after ((x sb-pcl::standard-class))
60     (incf finalized-count))
61   (defun get-count () finalized-count))
62 (defclass finalization-test-1 () ())
63 (make-instance 'finalization-test-1)
64 (assert (= (get-count) 1))
65 (defclass finalization-test-2 (finalization-test-3) ())
66 (assert (= (get-count) 1))
67 (defclass finalization-test-3 () ())
68 (make-instance 'finalization-test-3)
69 (assert (or (= (get-count) 2) (= (get-count) 3)))
70 (make-instance 'finalization-test-2)
71 (assert (= (get-count) 3))
72 \f
73 ;;;; success
74 (sb-ext:quit :unix-status 104)