1 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; While most of SBCL is derived from the CMU CL system, the test
5 ;;;; files (like this one) were written from scratch after the fork
8 ;;;; This software is in the public domain and is provided with
9 ;;;; absolutely no warranty. See the COPYING and CREDITS files for
10 ;;;; more information.
12 (load "assertoid.lisp")
13 (use-package '#:assertoid
)
17 (defun test (namespace name state make-body
20 (expected-warning-count '(eql 1))
22 (labels ((search-string (string fragments
)
24 (dolist (fragment fragments
)
25 (let ((match (search fragment string
:start2
(or start
0))))
27 (setf start
(+ match
(length fragment
)))))))
28 (search-string/documentation
(string)
30 string
`(,(string-downcase namespace
) ,(string name
)
31 "deprecated" "as" "of" "some-lib" "version" "1.2.3"))
33 (search-string string
`("Use" ,@replacements
"instead"))))
34 (search-string/describe
(string)
36 string
`(,(string name
) ,(string state
)
37 "deprecation" "since" "some-lib" "version" "1.2.3"))))
38 ;; Check the signaled warning condition.
39 (multiple-value-bind (function failure-p warnings style-warnings
)
40 (checked-compile `(lambda () ,@(funcall make-body name
))
41 :allow-style-warnings t
; undefined types, functions
42 :allow-warnings
'deprecation-condition
)
43 (declare (ignore failure-p
))
44 (let* ((conditions (remove-if-not
46 (typep condition
'deprecation-condition
))
47 (append warnings style-warnings
)))
48 (condition (first conditions
))
49 (count (length conditions
)))
50 (assert (typep count expected-warning-count
))
52 (assert (typep condition
(ecase state
53 (:early
'early-deprecation-warning
)
54 (:late
'late-deprecation-warning
)
55 (:final
'final-deprecation-warning
))))
56 (search-string/documentation
(princ-to-string condition
)))
60 (assert (eq :deprecated
(funcall function
))))
62 (assert-error (funcall function
)
63 (or deprecation-error cell-error
)))))))
64 ;; Check DESCRIBE output.
66 (search-string/describe
(with-output-to-string (stream)
67 (describe name stream
))))
68 ;; Check DOCUMENTATION.
69 (search-string/documentation
(documentation name namespace
))))
71 ;;;; DEPRECATED declaration syntax
73 (with-test (:name
(deprecated :declaration
:syntax
))
74 ;; Some syntax errors.
75 (mapc (lambda (declaration)
76 (assert-error (proclaim declaration
)))
80 (deprecated :early
("1"))
81 (deprecated :early
("a" "b" "c"))
82 (deprecated :early
"1" (function))
83 (deprecated :early
"1" (unsupported-namespace name
))
84 (deprecated :early
"1" (variable 1))
85 (deprecated :early
"1" (variable nil
))
86 (deprecated :early
"1" (variable :foo
))))
89 (mapc (lambda (declaration)
90 (assert-no-signal (proclaim declaration
)))
91 '((deprecated :early
"1")
92 (deprecated :early
("my-software" "1"))
93 (deprecated :early
"1" (variable deprecated.declaration.variable
))
94 (deprecated :early
"1" (function deprecated.declaration.function
))
95 (deprecated :early
"1" (function (setf deprecated.declaration.function
)))
96 (deprecated :early
"1" (type deprecated.declaration.type
))
97 (deprecated :early
"1" (variable deprecated.declaration.thing1
)
98 (variable deprecated.declaration.thing2
))
99 (deprecated :early
"1" (variable deprecated.declaration.replacement
100 :replacement deprecated.declaration.replacement
))
101 (deprecated :early
"1" (variable deprecated.declaration.replacement
102 :replacement
(deprecated.declaration.replacement1
103 deprecated.declaration.replacement2
))))))
105 ;;;; Deprecated variables
108 ((definition.undefined
(variable-name)
109 (declare (ignore variable-name
))
111 (definition.declaimed-special
(variable-name)
112 `(declaim (special ,variable-name
)))
113 (definition.defvar
(variable-name)
114 `(defvar ,variable-name
:deprecated
))
115 (definition.defglobal
(variable-name)
116 `(defglobal ,variable-name
:deprecated
))
117 (definition.defconstant
(variable-name)
118 `(defconstant ,variable-name
:deprecated
))
119 (definition.define-symbol-macro
(variable-name)
120 `(define-symbol-macro ,variable-name
:deprecated
))
121 (define-variable-tests (tag definition-name
&rest args
)
122 (flet ((make-test-case (tag state
127 (let ((variable-name (sb-int::symbolicate
128 '#:variable. tag
'#:. state
))
129 (replacement 'replacement
))
130 `(,@(unless (eq state
:final
)
131 `((,definition-name
,variable-name
)))
133 ,state
("some-lib" "1.2.3")
134 (variable ,variable-name
135 :replacement
,replacement
)))
137 (with-test (:name
(deprecated variable
,tag
,state
))
139 'variable
',variable-name
,state
140 (lambda (name) `(,name
))
141 :replacements
'(,(string replacement
))
143 :check-describe
,check-describe
)
146 'variable
',variable-name
,state
147 (lambda (name) `((symbol-value ',name
)))
148 :replacements
'(,(string replacement
))
150 :check-describe
,check-describe
)
152 'variable
',variable-name
,state
153 (lambda (name) `((symbol-global-value ',name
)))
154 :replacements
'(,(string replacement
))
156 :check-describe
,check-describe
))))))))
158 ,@(apply #'make-test-case tag
:early args
)
159 ,@(apply #'make-test-case tag
:late args
)
160 ,@(apply #'make-test-case tag
:final
:check-describe t args
)))))
162 (define-variable-tests :undefined definition.undefined
163 :call nil
:check-describe nil
)
164 (define-variable-tests :declaimed-special definition.declaimed-special
166 (define-variable-tests defvar definition.defvar
)
167 (define-variable-tests defglobal definition.defglobal
)
168 (define-variable-tests defconstant definition.defconstant
)
169 (define-variable-tests define-symbol-macro definition.define-symbol-macro
172 ;;;; Deprecated functions
175 ((definition.undefined
(function-name)
176 (declare (ignore function-name
))
178 (definition.declaimed-ftype
(function-name)
179 `(declaim (ftype (function () (values keyword
&optional
))
181 (definition.defun
(function-name)
182 `(defun ,function-name
() :deprecated
))
183 (definition.defmacro
(function-name)
184 `(defmacro ,function-name
() :deprecated
))
185 (define-function-tests (tag definition-name
&rest args
)
186 (flet ((make-test-case (tag state
190 (let ((function-name (sb-int::symbolicate
191 '#:function. tag
'#:. state
))
192 (replacement 'replacement
))
193 `(,@(unless (eq state
:final
)
194 `((,definition-name
,function-name
)))
196 ,state
("some-lib" "1.2.3")
197 (function ,function-name
198 :replacement
,replacement
)))
200 (with-test (:name
(deprecated function
,tag
,state
))
202 'function
',function-name
,state
203 (lambda (name) `((,name
)))
204 :replacements
'(,(string replacement
))
206 :check-describe
,check-describe
))))))
208 ,@(apply #'make-test-case tag
:early args
)
209 ,@(apply #'make-test-case tag
:late args
)
210 ,@(apply #'make-test-case tag
:final
:check-describe t args
)))))
212 (define-function-tests :undefined definition.undefined
213 :call nil
:check-describe nil
)
214 (define-function-tests :declaimed-ftype definition.declaimed-ftype
215 :call nil
:check-describe nil
)
216 (define-function-tests defun
definition.defun
)
217 (define-function-tests defmacro definition.defmacro
))
219 ;;;; Deprecated types
222 ((definition.undefined
(type-name)
223 (declare (ignore type-name
))
225 (definition.deftype.empty-body
(type-name)
226 `(deftype ,type-name
()))
227 (definition.deftype.t-body
(type-name)
228 `(deftype ,type-name
() t
))
229 (definition.defclass
(type-name)
230 `(defclass ,type-name
() ()))
231 (definition.defstruct
(type-name)
232 `(defstruct ,type-name
))
233 (definition.define-condition
(type-name)
234 `(define-condition ,type-name
() ()))
235 (define-type-tests (tag definition-name method class
&rest args
)
236 (flet ((make-test-case (tag state
&key check-describe
)
237 (let* ((method (and method
(not (eq state
:final
))))
238 (class (and class
(not (eq state
:final
))))
239 (type-name (apply #'sb-int
::symbolicate
241 (sb-int:ensure-list tag
)
242 (list '#:. state
(gensym)))))
243 (extra-warning-count (+ (if method
1 0) (if class
1 0)))
244 (replacement 'replacement
))
245 `(,@(unless (eq state
:final
)
246 `((,definition-name
,type-name
)))
248 ,state
("some-lib" "1.2.3")
250 :replacement
,replacement
)))
252 (test-util:with-test
(:name
(deprecated type
253 ,@(sb-int:ensure-list tag
)
256 'type
',type-name
,state
259 (declare (type (or null
,name
) x
)
263 '`((defmethod ,(gensym) ((x ,name
)))))
265 '`((defclass ,(gensym) (,name
) ())))))
266 :replacements
'(,(string replacement
))
268 :expected-warning-count
'(integer
269 ,(+ 2 extra-warning-count
)
270 ,(+ 4 extra-warning-count
))
271 :check-describe
,check-describe
))))))
273 ,@(apply #'make-test-case tag
:early args
)
274 ,@(apply #'make-test-case tag
:late args
)
275 ,@(apply #'make-test-case tag
:final
:check-describe t args
)))))
277 (define-type-tests :undefined definition.undefined nil nil
279 (define-type-tests (deftype :empty-body
) definition.deftype.empty-body nil nil
)
280 (define-type-tests (deftype :t-body
) definition.deftype.t-body nil nil
)
281 (define-type-tests defclass definition.defclass t t
)
282 (define-type-tests defstruct definition.defstruct t nil
)
283 (define-type-tests define-condition definition.define-condition t nil
))
285 (with-test (:name
(deprecated type
:unrelated-class
))
286 (let ((name (gensym)))
288 (deftype ,name
() 'integer
)
289 (declaim (deprecated :early
("some-lib" "1.2.3") (type ,name
)))))
290 ;; Make sure the deprecation declaration works.
296 ;; Check that the declaration does not apply to an unrelated class
301 `((make-instance ,(make-instance 'standard-class
:name name
))))
303 :expected-warning-count
'(eql 0))))
306 ;;;; Loader deprecation warnings
308 (defun please-dont-use-this (x)
310 (declaim (deprecated :early
"1.2.10"
311 (function please-dont-use-this
312 :replacement moar-better-function
)))
314 (defun really-dont-do-it (x)
316 (declaim (deprecated :late
"1.2.10"
317 (function really-dont-do-it
318 :replacement use-other-thing-instead
)))
320 (defun you-cant-use-this (x)
322 (declaim (deprecated :final
"1.2.10"
323 (function you-cant-use-this
324 :replacement replacement-fn
)))
326 (with-test (:name
:introspect-deprecation-stage
)
327 (assert (eq (sb-int:deprecated-thing-p
'function
'please-dont-use-this
)
329 (assert (eq (sb-int:deprecated-thing-p
'function
'really-dont-do-it
)
331 (assert (eq (sb-int:deprecated-thing-p
'function
'you-cant-use-this
)
334 (with-test (:name
(:late-deprecated-fun-doc
:bug-1439151
)
335 :skipped-on
(not :sb-doc
))
336 (assert (string= (documentation 'you-cant-use-this
'function
)
337 (documentation #'you-cant-use-this
'function
)))
338 (assert (string= (documentation 'function.defun.late
'function
)
339 (documentation #'function.defun.late
'function
)))
340 (assert (string/= (documentation 'you-cant-use-this
'function
)
341 (documentation 'function.defun.late
'function
))))
343 (with-test (:name
:load-time-deprecation-warning
)
344 (let ((source "load-test.tmp") fasl
)
345 (with-open-file (f source
:direction
:output
346 :if-does-not-exist
:create
:if-exists
:supersede
)
347 (write-string "(defun a () (sb-unix:unix-exit))" f
)
348 ;; a full warning even though the PLEASE-DONT- function is only :early
349 (write-string "(defun b () (please-dont-use-this 1) (really-dont-do-it 2))" f
)
350 (write-string "(defun c () (you-cant-use-this 3))" f
))
351 ;; We expect four deprecation warnings from compiling the source
352 ;; (four uses of deprecated things) and three from loading it
353 ;; (loading three functions that contain uses of deprecated
358 (compile-file source
:verbose nil
:print nil
)
359 (or early-deprecation-warning
360 late-deprecation-warning
361 final-deprecation-warning
)
363 (assert-signal (load fasl
) warning
3))
365 (delete-file source
))))