1.0.10.8: correct nested DX implementation
[sbcl.git] / contrib / sb-cltl2 / tests.lisp
blobac775c9c08afa6c6a8ce8ac54f9a328bc0e89091
1 ;;;; This software is part of the SBCL system. See the README file for
2 ;;;; more information.
3 ;;;;
4 ;;;; The software is in the public domain and is provided with
5 ;;;; absolutely no warranty. See the COPYING and CREDITS files for
6 ;;;; more information.
8 (defpackage :sb-cltl2-tests
9 (:use :sb-cltl2 :cl :sb-rt))
11 (in-package :sb-cltl2-tests)
13 (rem-all-tests)
15 (defmacro *x*-value ()
16 (declare (special *x*))
17 *x*)
19 (deftest compiler-let.1
20 (let ((*x* :outer))
21 (compiler-let ((*x* :inner))
22 (list *x* (*x*-value))))
23 (:outer :inner))
25 (defvar *expansions* nil)
26 (defmacro macroexpand-macro (arg)
27 (push arg *expansions*)
28 arg)
30 (deftest macroexpand-all.1
31 (progn
32 (macroexpand-all '(defmethod foo ((x fixnum)) (1+ x)))
36 (deftest macroexpand-all.2
37 (let ((*expansions* nil))
38 (macroexpand-all '(list (macroexpand-macro 1)
39 (let (macroexpand-macro :no)
40 (macroexpand-macro 2))))
41 (remove-duplicates (sort *expansions* #'<)))
42 (1 2))
44 (deftest macroexpand-all.3
45 (let ((*expansions* nil))
46 (compile nil '(lambda ()
47 (macrolet ((foo (key &environment env)
48 (macroexpand-all `(bar ,key) env)))
49 (foo
50 (macrolet ((bar (key)
51 (push key *expansions*)
52 key))
53 (foo 1))))))
54 (remove-duplicates *expansions*))
55 (1))
57 (defun smv (env)
58 (multiple-value-bind (expansion macro-p)
59 (macroexpand 'srlt env)
60 (when macro-p (eval expansion))))
61 (defmacro testr (&environment env)
62 `',(getf (smv env) nil))
64 (deftest macroexpand-all.4
65 (macroexpand-all '(symbol-macrolet ((srlt '(nil zool))) (testr)))
66 (symbol-macrolet ((srlt '(nil zool))) 'zool))
68 (defmacro dinfo (thing &environment env)
69 `',(declaration-information thing env))
71 (macrolet ((def (x)
72 `(macrolet ((frob (suffix answer &optional declaration)
73 `(deftest ,(intern (concatenate 'string
74 "DECLARATION-INFORMATION."
75 (symbol-name ',x)
76 suffix))
77 (locally (declare ,@(when declaration
78 (list declaration)))
79 (cadr (assoc ',',x (dinfo optimize))))
80 ,answer)))
81 (frob ".DEFAULT" 1)
82 (frob ".0" 0 (optimize (,x 0)))
83 (frob ".1" 1 (optimize (,x 1)))
84 (frob ".2" 2 (optimize (,x 2)))
85 (frob ".3" 3 (optimize (,x 3)))
86 (frob ".IMPLICIT" 3 (optimize ,x)))))
87 (def speed)
88 (def safety)
89 (def debug)
90 (def compilation-speed)
91 (def space))
93 (deftest declaration-information.muffle-conditions.default
94 (dinfo sb-ext:muffle-conditions)
95 nil)
96 (deftest declaration-information.muffle-conditions.1
97 (locally (declare (sb-ext:muffle-conditions warning))
98 (dinfo sb-ext:muffle-conditions))
99 warning)
100 (deftest declaration-information.muffle-conditions.2
101 (locally (declare (sb-ext:muffle-conditions warning))
102 (locally (declare (sb-ext:unmuffle-conditions style-warning))
103 (let ((dinfo (dinfo sb-ext:muffle-conditions)))
104 (not
105 (not
106 (and (subtypep dinfo '(and warning (not style-warning)))
107 (subtypep '(and warning (not style-warning)) dinfo)))))))
110 ;;;; VARIABLE-INFORMATION
112 (defvar *foo*)
114 (defmacro var-info (var &environment env)
115 (list 'quote (multiple-value-list (variable-information var env))))
117 (deftest variable-info.global-special/unbound
118 (var-info *foo*)
119 (:special nil nil))
121 (deftest variable-info.global-special/unbound/extra-decl
122 (locally (declare (special *foo*))
123 (var-info *foo*))
124 (:special nil nil))
126 (deftest variable-info.global-special/bound
127 (let ((*foo* t))
128 (var-info *foo*))
129 (:special nil nil))
131 (deftest variable-info.global-special/bound/extra-decl
132 (let ((*foo* t))
133 (declare (special *foo*))
134 (var-info *foo*))
135 (:special nil nil))
137 (deftest variable-info.local-special/unbound
138 (locally (declare (special x))
139 (var-info x))
140 (:special nil nil))
142 (deftest variable-info.local-special/bound
143 (let ((x 13))
144 (declare (special x))
145 (var-info x))
146 (:special nil nil))
148 (deftest variable-info.local-special/shadowed
149 (let ((x 3))
150 (declare (special x))
152 (let ((x 3))
154 (var-info x)))
155 (:lexical t nil))
157 (deftest variable-info.local-special/shadows-lexical
158 (let ((x 3))
159 (let ((x 3))
160 (declare (special x))
161 (var-info x)))
162 (:special nil nil))
164 (deftest variable-info.lexical
165 (let ((x 8))
166 (var-info x))
167 (:lexical t nil))
169 (deftest variable-info.ignore
170 (let ((x 8))
171 (declare (ignore x))
172 (var-info x))
173 (:lexical t ((ignore . t))))
175 (deftest variable-info.symbol-macro/local
176 (symbol-macrolet ((x 8))
177 (var-info x))
178 (:symbol-macro t nil))
180 (define-symbol-macro my-symbol-macro t)
182 (deftest variable-info.symbol-macro/global
183 (var-info my-symbol-macro)
184 (:symbol-macro nil nil))
186 (deftest variable-info.undefined
187 (var-info #:undefined)
188 (nil nil nil))
190 ;;;; FUNCTION-INFORMATION
192 (defmacro fun-info (var &environment env)
193 (list 'quote (multiple-value-list (function-information var env))))
195 (defun my-global-fun (x) x)
197 (deftest function-info.global/no-ftype
198 (fun-info my-global-fun)
199 (:function nil nil))
201 (declaim (ftype (function (cons) (values t &optional)) my-global-fun-2))
203 (defun my-global-fun-2 (x) x)
205 (deftest function-info.global/ftype
206 (fun-info my-global-fun-2)
207 (:function nil ((ftype function (cons) (values t &optional)))))
209 (defmacro my-macro (x) x)
211 (deftest function-info.macro
212 (fun-info my-macro)
213 (:macro nil nil))
215 (deftest function-info.macrolet
216 (macrolet ((thingy () nil))
217 (fun-info thingy))
218 (:macro t nil))
220 (deftest function-info.special-form
221 (fun-info progn)
222 (:special-form nil nil))
224 (deftest function-info.notinline/local
225 (flet ((x (y) y))
226 (declare (notinline x))
227 (x 1)
228 (fun-info x))
229 (:function t ((inline . notinline))))
231 (declaim (notinline my-notinline))
232 (defun my-notinline (x) x)
234 (deftest function-info.notinline/global
235 (fun-info my-notinline)
236 (:function nil ((inline . notinline))))
238 (declaim (inline my-inline))
239 (defun my-inline (x) x)
241 (deftest function-info.inline/global
242 (fun-info my-inline)
243 (:function nil ((inline . inline))))
245 (deftest function-information.known-inline
246 (locally (declare (inline identity))
247 (fun-info identity))
248 (:function nil ((inline . inline)
249 (ftype function (t) (values t &optional)))))