1.0.19.30: muffle code deletion note from destructuring-bind
[sbcl/eslaughter.git] / tests / interface.impure.lisp
blob60795ad665ce27712d40ea73212404951dee0a6c
1 ;;;; tests for problems in the interface presented to the user/programmer
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.
14 (load "assertoid.lisp")
15 (use-package "ASSERTOID")
17 (defun (setf foo) (x)
18 "(setf foo) documentation"
21 (assert (string= (documentation '(setf foo) 'function)
22 "(setf foo) documentation"))
23 (assert (string= (documentation #'(setf foo) 'function)
24 "(setf foo) documentation"))
26 (assert (string= (documentation '(setf foo) 'function)
27 "(setf foo) documentation"))
28 (assert (string= (documentation #'(setf foo) 'function)
29 "(setf foo) documentation"))
31 ;;; DISASSEMBLE shouldn't fail on closures or unpurified functions
32 (defun disassemble-fun (x) x)
33 (disassemble 'disassemble-fun)
35 (let ((x 1)) (defun disassemble-closure (y) (if y (setq x y) x)))
36 (disassemble 'disassemble-closure)
38 #+sb-eval
39 (progn
40 ;; Nor should it fail on interpreted functions
41 (let ((sb-ext:*evaluator-mode* :interpret))
42 (eval `(defun disassemble-eval (x) x))
43 (disassemble 'disassemble-eval))
45 ;; disassemble-eval should still be an interpreted function.
46 ;; clhs disassemble: "(If that function is an interpreted function,
47 ;; it is first compiled but the result of this implicit compilation
48 ;; is not installed.)"
49 (assert (sb-eval:interpreted-function-p #'disassemble-eval)))
51 ;; nor should it fail on generic functions or other funcallable instances
52 (defgeneric disassemble-generic (x))
53 (disassemble 'disassemble-generic)
54 (let ((fin (sb-mop:make-instance 'sb-mop:funcallable-standard-object)))
55 (disassemble fin))
57 ;;; while we're at it, much the same applies to
58 ;;; FUNCTION-LAMBDA-EXPRESSION:
59 (defun fle-fun (x) x)
60 (function-lambda-expression #'fle-fun)
62 (let ((x 1)) (defun fle-closure (y) (if y (setq x y) x)))
63 (function-lambda-expression #'fle-closure)
65 #+sb-eval
66 (progn
67 ;; Nor should it fail on interpreted functions
68 (let ((sb-ext:*evaluator-mode* :interpret))
69 (eval `(defun fle-eval (x) x))
70 (function-lambda-expression #'fle-eval))
72 ;; fle-eval should still be an interpreted function.
73 (assert (sb-eval:interpreted-function-p #'fle-eval)))
75 ;; nor should it fail on generic functions or other funcallable instances
76 (defgeneric fle-generic (x))
77 (function-lambda-expression #'fle-generic)
78 (let ((fin (sb-mop:make-instance 'sb-mop:funcallable-standard-object)))
79 (function-lambda-expression fin))
81 ;;; support for DESCRIBE tests
82 (defstruct to-be-described a b)
83 (defclass forward-describe-class (forward-describe-ref) (a))
85 ;;; DESCRIBE should run without signalling an error.
86 (describe (make-to-be-described))
87 (describe 12)
88 (describe "a string")
89 (describe 'symbolism)
90 (describe (find-package :cl))
91 (describe '(a list))
92 (describe #(a vector))
94 ;;; The DESCRIBE-OBJECT methods for built-in CL stuff should do
95 ;;; FRESH-LINE and TERPRI neatly.
96 (dolist (i (list (make-to-be-described :a 14) 12 "a string"
97 #0a0 #(1 2 3) #2a((1 2) (3 4)) 'sym :keyword
98 (find-package :keyword) (list 1 2 3)
99 nil (cons 1 2) (make-hash-table)
100 (let ((h (make-hash-table)))
101 (setf (gethash 10 h) 100
102 (gethash 11 h) 121)
104 (make-condition 'simple-error)
105 (make-condition 'simple-error :format-control "fc")
106 #'car #'make-to-be-described (lambda (x) (+ x 11))
107 (constantly 'foo) #'(setf to-be-described-a)
108 #'describe-object (find-class 'to-be-described)
109 (find-class 'forward-describe-class)
110 (find-class 'forward-describe-ref) (find-class 'cons)))
111 (let ((s (with-output-to-string (s)
112 (write-char #\x s)
113 (describe i s))))
114 (unless (and (char= #\x (char s 0))
115 ;; one leading #\NEWLINE from FRESH-LINE or the like, no more
116 (char= #\newline (char s 1))
117 (char/= #\newline (char s 2))
118 ;; one trailing #\NEWLINE from TERPRI or the like, no more
119 (let ((n (length s)))
120 (and (char= #\newline (char s (- n 1)))
121 (char/= #\newline (char s (- n 2))))))
122 (error "misbehavior in DESCRIBE of ~S" i))))
125 ;;; Tests of documentation on types and classes
126 (defclass foo ()
128 (:documentation "FOO"))
129 (defstruct bar "BAR")
130 (define-condition baz ()
132 (:documentation "BAZ"))
133 (deftype quux ()
134 "QUUX"
136 (defstruct (frob (:type vector)) "FROB")
137 (macrolet
138 ((do-class (name expected &optional structurep)
139 `(progn
140 (assert (string= (documentation ',name 'type) ,expected))
141 (assert (string= (documentation (find-class ',name) 'type) ,expected))
142 (assert (string= (documentation (find-class ',name) 't) ,expected))
143 ,@(when structurep
144 `((assert (string= (documentation ',name 'structure) ,expected))))
145 (let ((new1 (symbol-name (gensym "NEW1")))
146 (new2 (symbol-name (gensym "NEW2")))
147 (new3 (symbol-name (gensym "NEW3")))
148 (new4 (symbol-name (gensym "NEW4"))))
149 (declare (ignorable new4))
150 (setf (documentation ',name 'type) new1)
151 (assert (string= (documentation (find-class ',name) 'type) new1))
152 (setf (documentation (find-class ',name) 'type) new2)
153 (assert (string= (documentation (find-class ',name) 't) new2))
154 (setf (documentation (find-class ',name) 't) new3)
155 (assert (string= (documentation ',name 'type) new3))
156 ,@(when structurep
157 `((assert (string= (documentation ',name 'structure) new3))
158 (setf (documentation ',name 'structure) new4)
159 (assert (string= (documentation ',name 'structure) new4))))))))
160 (do-class foo "FOO")
161 (do-class bar "BAR" t)
162 (do-class baz "BAZ"))
164 (assert (string= (documentation 'quux 'type) "QUUX"))
165 (setf (documentation 'quux 'type) "NEW4")
166 (assert (string= (documentation 'quux 'type) "NEW4"))
168 (assert (string= (documentation 'frob 'structure) "FROB"))
169 (setf (documentation 'frob 'structure) "NEW5")
170 (assert (string= (documentation 'frob 'structure) "NEW5"))
172 ;;;; success