1 ;; Tests for sb-aclrepl
3 (defpackage #:aclrepl-tests
4 (:use
#:sb-aclrepl
#:cl
#:sb-rt
))
5 (in-package #:aclrepl-tests
)
7 (declaim (special sb-aclrepl
::*skip-address-display
*
8 sb-aclrepl
::*inspect-unbound-object-marker
*))
10 (setf sb-rt
::*catch-errors
* nil
)
14 (deftest hook
.1 (boundp 'sb-impl
::*inspect-fun
*) t
)
15 (deftest hook
.2 (boundp 'sb-int
:*repl-prompt-fun
*) t
)
16 (deftest hook
.3 (boundp 'sb-int
:*repl-read-form-fun
*) t
)
17 ;(deftest (boundp 'sb-debug::*invoke-debugger-fun*) t)
21 (defclass empty-class
()
23 (defparameter *empty-class
* (make-instance 'empty-class
))
25 (defclass empty-class
()
28 (defclass simple-class
()
31 (really-long-slot-name :initform
"abc")))
33 (defstruct empty-struct
36 (defstruct tiny-struct
39 (defstruct simple-struct
42 (really-long-struct-slot-name "defg"))
44 (defparameter *empty-class
* (make-instance 'empty-class
))
45 (defparameter *simple-class
* (make-instance 'simple-class
))
46 (defparameter *empty-struct
* (make-empty-struct))
47 (defparameter *tiny-struct
* (make-tiny-struct))
48 (defparameter *simple-struct
* (make-simple-struct))
49 (defparameter *normal-list
* '(a b
3))
50 (defparameter *dotted-list
* '(a b .
3))
51 (defparameter *cons-pair
* '(#c
(1 2) . a-symbol
))
52 (defparameter *complex
* #c
(1 2))
53 (defparameter *ratio
* 22/7)
54 (defparameter *double
* 5.5d0
)
55 (defparameter *bignum
* 1234567890123456789)
56 (defparameter *array
* (make-array '(3 3 2) :initial-element nil
))
57 (defparameter *vector
* (make-array '(20):initial-contents
59 10 11 12 13 14 15 16 17 18 19)))
60 (eval-when (:compile-toplevel
:load-toplevel
:execute
)
61 (defparameter *circle-list1
* '(a))
62 (setf (car *circle-list1
*) *circle-list1
*)
63 (defparameter *circle-list2
* '(b))
64 (setf (cdr *circle-list2
*) *circle-list2
*)
65 (defparameter *circle-list3
* '(a b c
))
66 (setf (car *circle-list3
*) *circle-list3
*)
67 (defparameter *circle-list4
* '(a b c
))
68 (setf (second *circle-list4
*) *circle-list4
*)
69 (defparameter *circle-list5
* '(a b c
))
70 (setf (cddr *circle-list5
*) *circle-list5
*))
72 (defun find-position (object id
)
73 (nth-value 0 (sb-aclrepl::find-part-id object id
)))
75 (let ((sb-aclrepl::*skip-address-display
* t
))
76 (sb-aclrepl::inspected-parts object
)))
77 (defun description (object)
78 (let ((sb-aclrepl::*skip-address-display
* t
))
79 (sb-aclrepl::inspected-description object
)))
80 (defun elements (object &optional print
(skip 0))
81 (let ((sb-aclrepl::*skip-address-display
* t
))
82 (sb-aclrepl::inspected-elements object print skip
)))
83 (defun elements-components (object &optional print
(skip 0))
84 (nth-value 0 (elements object print skip
)))
85 (defun elements-labels (object &optional print
(skip 0))
86 (nth-value 1 (elements object print skip
)))
87 (defun elements-count (object &optional print
(skip 0))
88 (nth-value 2 (elements object print skip
)))
90 (defun labeled-element (object pos
&optional print
(skip 0))
91 (with-output-to-string (strm)
92 (let ((sb-aclrepl::*skip-address-display
* t
))
93 (sb-aclrepl::display-labeled-element
94 (aref (the simple-vector
(elements-components object print skip
)) pos
)
95 (aref (the simple-vector
(elements-labels object print skip
)) pos
)
98 (defun display (object &optional print
(skip 0))
99 (with-output-to-string (strm)
100 (let ((sb-aclrepl::*skip-address-display
* t
))
101 (sb-aclrepl::display-inspect object strm print skip
))))
103 (defun do-inspect (object)
104 (with-output-to-string (strm)
105 (let ((sb-aclrepl::*skip-address-display
* t
))
106 (sb-aclrepl::inspector
`(quote ,object
) nil strm
))))
109 (with-output-to-string (strm)
110 (let ((sb-aclrepl::*skip-address-display
* t
))
111 (sb-aclrepl::istep args strm
))))
113 (deftest find.list
.0 (find-position *normal-list
* 0) 0)
114 (deftest find.list
.1 (find-position *normal-list
* 0) 0)
115 (deftest find.list
.2 (find-position *normal-list
* 1) 1)
116 (deftest find.list
.3 (find-position *normal-list
* 2) 2)
117 (deftest parts.list
.1 (sb-aclrepl::parts-count
(parts *normal-list
*)) 3)
118 (deftest parts.list
.2 (sb-aclrepl::component-at
(parts *normal-list
*) 0) a
)
119 (deftest parts.list
.3 (sb-aclrepl::component-at
(parts *normal-list
*) 1) b
)
120 (deftest parts.list
.4 (sb-aclrepl::component-at
(parts *normal-list
*) 2) 3)
121 (deftest parts.list
.5 (sb-aclrepl::label-at
(parts *normal-list
*) 0) 0)
122 (deftest parts.list
.6 (sb-aclrepl::label-at
(parts *normal-list
*) 1) 1)
123 (deftest parts.list
.7 (sb-aclrepl::label-at
(parts *normal-list
*) 2) 2)
124 (deftest parts.list
.8 (sb-aclrepl::parts-seq-type
(parts *normal-list
*)) :list
)
126 (eval-when (:compile-toplevel
:load-toplevel
:execute
)
127 (defun basename (id &optional print
(skip 0))
128 (let ((name (typecase id
129 (symbol (symbol-name id
))
130 (string (string-upcase id
))
131 (t (format nil
"~A" id
)))))
133 (string-left-trim "*" (string-right-trim "*" name
))
134 (if print
(format nil
".P~D" print
) "")
135 (if (not (zerop skip
)) (format nil
".S~D" skip
) ""))))
137 (defun elements-tests-name (id ext print skip
)
138 (intern (format nil
"ELEM.~A.~A" (basename id print skip
) ext
))))
140 (defmacro def-elements-tests
(object count components labels
141 &optional
(print nil
) (skip 0))
143 (deftest ,(elements-tests-name object
"COUNT" print skip
)
144 (elements-count ,object
,print
,skip
) ,count
)
145 (unless (eq ,components
:dont-check
)
146 (deftest ,(elements-tests-name object
"COMPONENTS" print skip
)
147 (elements-components ,object
,print
,skip
) ,components
))
148 (deftest ,(elements-tests-name object
"LABELS" print skip
)
149 (elements-labels ,object
,print
,skip
) ,labels
)))
151 (def-elements-tests *normal-list
* 3 #(a b
3) #(0 1 2))
152 (def-elements-tests *dotted-list
* 3 #(a b
3) #(0 1 :tail
))
154 (def-elements-tests *circle-list1
* 2 :dont-check
#((0 .
"car") (1 .
"cdr")))
155 (def-elements-tests *circle-list2
* 2 :dont-check
#(0 :tail
))
156 (def-elements-tests *circle-list3
* 3 :dont-check
#(0 1 2))
157 (def-elements-tests *circle-list4
* 3 :dont-check
#(0 1 2))
158 (def-elements-tests *circle-list5
* 3 :dont-check
#(0 1 :tail
))
160 (deftest circle-list1-components
161 (aref (elements-components *circle-list1
*) 0) #.
*circle-list1
*)
162 (deftest circle-list2-components
.0
163 (aref (elements-components *circle-list2
*) 0) b
)
164 (deftest circle-list2-components
.1
165 (aref (elements-components *circle-list2
*) 1) #.
*circle-list2
*)
166 (deftest circle-list3-components
.0
167 (aref (elements-components *circle-list3
*) 0) #.
*circle-list3
*)
168 (deftest circle-list3-components
.1
169 (aref (elements-components *circle-list3
*) 1) b
)
170 (deftest circle-list3-components
.2
171 (aref (elements-components *circle-list3
*) 2) c
)
172 (deftest circle-list4-components
.0
173 (aref (elements-components *circle-list4
*) 0) a
)
174 (deftest circle-list4-components
.1
175 (aref (elements-components *circle-list4
*) 1) #.
*circle-list4
*)
176 (deftest circle-list4-components
.2
177 (aref (elements-components *circle-list4
*) 2) c
)
178 (deftest circle-list5-components
.0
179 (aref (elements-components *circle-list5
*) 0) a
)
180 (deftest circle-list5-components
.1
181 (aref (elements-components *circle-list5
*) 1) b
)
182 (deftest circle-list5-components
.2
183 (aref (elements-components *circle-list5
*) 2) #.
*circle-list5
*)
185 (def-elements-tests *cons-pair
* 2 #(#c
(1 2) a-symbol
)
186 #((0 .
"car") (1 .
"cdr")))
187 (def-elements-tests *complex
* 2 #(1 2) #((0 .
"real") (1 .
"imag")))
188 (def-elements-tests *ratio
* 2 #(22 7)
189 #((0 .
"numerator") (1 .
"denominator")))
190 (case sb-vm
::n-word-bits
192 (def-elements-tests *bignum
* 2
193 #(2112454933 287445236)
194 #((0 .
:HEX32
) (1 .
:HEX32
))))
196 (def-elements-tests *bignum
* 1
197 #(1234567890123456789)
200 (def-elements-tests *vector
* 20
201 #(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19)
202 #(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19))
203 (def-elements-tests *vector
* 18
204 #(nil 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19)
205 #(:ellipses
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19)
207 (def-elements-tests *vector
* 13
208 #(nil 3 4 5 6 7 8 9 10 11 12 nil
19)
209 #(:ellipses
3 4 5 6 7 8 9 10 11 12 :ellipses
19)
211 (def-elements-tests *vector
* 5
213 #(:ellipses
16 17 18 19)
215 (def-elements-tests *vector
* 5
217 #(:ellipses
16 17 18 19)
219 (def-elements-tests *vector
* 5
221 #(:ellipses
15 16 :ellipses
19)
223 (def-elements-tests *array
* 18
224 #(NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL
226 #((0 .
"[0,0,0]") (1 .
"[0,0,1]") (2 .
"[0,1,0]") (3 .
"[0,1,1]")
227 (4 .
"[0,2,0]") (5 .
"[0,2,1]") (6 .
"[1,0,0]") (7 .
"[1,0,1]")
228 (8 .
"[1,1,0]") (9 .
"[1,1,1]") (10 .
"[1,2,0]")
229 (11 .
"[1,2,1]") (12 .
"[2,0,0]") (13 .
"[2,0,1]")
230 (14 .
"[2,1,0]") (15 .
"[2,1,1]") (16 .
"[2,2,0]")
233 (def-elements-tests *empty-class
* 0 nil nil
)
235 (def-elements-tests *simple-class
* 3
236 #(#.sb-aclrepl
::*inspect-unbound-object-marker
* 0 "abc")
237 #((0 .
"A") (1 .
"SECOND") (2 .
"REALLY-LONG-SLOT-NAME")))
238 (def-elements-tests *empty-struct
* 0 nil nil
)
239 (def-elements-tests *simple-struct
* 3
240 #(nil a-value
"defg")
241 #((0 .
"FIRST") (1 .
"SLOT-2")
242 (2 .
"REALLY-LONG-STRUCT-SLOT-NAME")))
244 (eval-when (:compile-toplevel
:load-toplevel
:execute
)
245 (defun label-test-name (name pos
&optional print
(skip 0))
246 (intern (format nil
"LABEL.~A.~D" (basename name print skip
) pos
))))
248 (defmacro def-label-test
(object pos label
&optional print
(skip 0))
249 `(deftest ,(label-test-name object pos print skip
)
250 (labeled-element ,object
,pos
,print
,skip
) ,label
))
252 (def-label-test *simple-struct
* 0
253 " 0 FIRST ----------> the symbol NIL")
254 (def-label-test *simple-struct
* 1
255 " 1 SLOT-2 ---------> the symbol A-VALUE")
256 (def-label-test *simple-struct
* 2
257 " 2 REALLY-LONG-STRUCT-SLOT-NAME -> a simple-string (4) \"defg\"")
258 (def-label-test *simple-class
* 0
259 " 0 A --------------> ..unbound..")
260 (def-label-test *simple-class
* 1
261 " 1 SECOND ---------> fixnum 0")
262 (def-label-test *simple-class
* 2
263 " 2 REALLY-LONG-SLOT-NAME -> a simple-string (3) \"abc\"")
265 (def-label-test *complex
* 0 " 0 real -----------> fixnum 1")
266 (def-label-test *complex
* 1 " 1 imag -----------> fixnum 2")
268 (def-label-test *ratio
* 0 " 0 numerator ------> fixnum 22")
269 (def-label-test *ratio
* 1 " 1 denominator ----> fixnum 7")
271 (def-label-test *dotted-list
* 0 " 0-> the symbol A")
272 (def-label-test *dotted-list
* 1 " 1-> the symbol B")
273 (def-label-test *dotted-list
* 2 "tail-> fixnum 3")
275 (def-label-test *normal-list
* 0 " 0-> the symbol A")
276 (def-label-test *normal-list
* 1 " 1-> the symbol B")
277 (def-label-test *normal-list
* 2 " 2-> fixnum 3")
279 (def-label-test *vector
* 0 " 0-> fixnum 0")
280 (def-label-test *vector
* 1 " 1-> fixnum 1")
281 (def-label-test *vector
* 0 " ..." nil
2)
282 (def-label-test *vector
* 1" 2-> fixnum 2" nil
2)
284 (def-label-test *cons-pair
* 0
285 " 0 car ------------> complex number #C(1 2)")
286 (def-label-test *cons-pair
* 1
287 " 1 cdr ------------> the symbol A-SYMBOL")
289 (deftest nil.parts
.0 (elements-count nil
) 5)
291 (def-elements-tests *tiny-struct
* 1 #(10) #((0 .
"FIRST")))
292 (def-elements-tests *tiny-struct
* 1
293 #(nil) #(:ellipses
) nil
1)
294 (def-elements-tests *tiny-struct
* 1
295 #(nil) #(:ellipses
) nil
2)
297 (def-elements-tests *double
* 0 nil nil
)
298 (def-elements-tests *double
* 0 nil nil nil
1)
300 (eval-when (:compile-toplevel
:load-toplevel
:execute
)
301 (defun display-test-name (name print skip
)
302 (intern (format nil
"DISPLAY.~A" (basename name print skip
)))))
304 (defmacro def-display-test
(object string
&optional print
(skip 0))
305 `(deftest ,(display-test-name object print skip
)
306 (display ,object
,print
,skip
) ,string
))
308 (def-display-test *cons-pair
*
310 0 car ------------> complex number #C(1 2)
311 1 cdr ------------> the symbol A-SYMBOL")
313 (def-display-test *simple-struct
*
314 "#<STRUCTURE-CLASS ACLREPL-TESTS::SIMPLE-STRUCT>
315 0 FIRST ----------> the symbol NIL
316 1 SLOT-2 ---------> the symbol A-VALUE
317 2 REALLY-LONG-STRUCT-SLOT-NAME -> a simple-string (4) \"defg\"")
319 (def-display-test *simple-struct
*
320 "#<STRUCTURE-CLASS ACLREPL-TESTS::SIMPLE-STRUCT>
322 2 REALLY-LONG-STRUCT-SLOT-NAME -> a simple-string (4) \"defg\""
325 (case sb-vm
::n-word-bits
327 (def-display-test *bignum
*
328 "bignum 1234567890123456789 with 2 32-bit words
332 (def-display-test *bignum
*
333 "bignum 1234567890123456789 with 1 64-bit word
334 0-> #x112210F47DE98115"
337 (def-display-test *vector
*
338 "a simple T vector (20)
349 (def-display-test *circle-list1
*
351 0 car ------------> a cons cell
352 1 cdr ------------> the symbol NIL")
353 (def-display-test *circle-list2
*
354 "a cyclic list with 1 element+tail
356 tail-> a cyclic list with 1 element+tail")
357 (def-display-test *circle-list3
*
358 "a normal list with 3 elements
359 0-> a normal list with 3 elements
362 (def-display-test *circle-list4
*
363 "a normal list with 3 elements
365 1-> a normal list with 3 elements
367 (def-display-test *circle-list5
*
368 "a cyclic list with 2 elements+tail
371 tail-> a cyclic list with 2 elements+tail")
374 ;;; Inspector traversal tests
375 (deftest inspect
.0 (progn (setq * *simple-struct
*)
377 "#<STRUCTURE-CLASS ACLREPL-TESTS::SIMPLE-STRUCT>
378 0 FIRST ----------> the symbol NIL
379 1 SLOT-2 ---------> the symbol A-VALUE
380 2 REALLY-LONG-STRUCT-SLOT-NAME -> a simple-string (4) \"defg\"")
382 (deftest istep
.0 (progn (setq * *simple-struct
*)
385 "#<STRUCTURE-CLASS ACLREPL-TESTS::SIMPLE-STRUCT>
386 0 FIRST ----------> the symbol NIL
387 1 SLOT-2 ---------> the symbol A-VALUE
388 2 REALLY-LONG-STRUCT-SLOT-NAME -> a simple-string (4) \"defg\"")
391 (deftest istep
.1 (progn (setq * *simple-struct
*)
395 0 NAME -----------> a simple-string (3) \"NIL\"
396 1 PACKAGE --------> the COMMON-LISP package
397 2 VALUE ----------> the symbol NIL
398 3 FUNCTION -------> ..unbound..
399 4 PLIST ----------> the symbol NIL")
402 (deftest istep
.2 (progn (setq * *simple-struct
*)
407 0 NAME -----------> a simple-string (7) \"A-VALUE\"
408 1 PACKAGE --------> the ACLREPL-TESTS package
409 2 VALUE ----------> ..unbound..
410 3 FUNCTION -------> ..unbound..
411 4 PLIST ----------> the symbol NIL")
413 (deftest istep
.3 (progn (setq * *simple-struct
*)
419 0 NAME -----------> a simple-string (3) \"NIL\"
420 1 PACKAGE --------> the COMMON-LISP package
421 2 VALUE ----------> the symbol NIL
422 3 FUNCTION -------> ..unbound..
423 4 PLIST ----------> the symbol NIL")
425 (deftest istep
.4 (progn (setq * *simple-struct
*)
431 "The current object is:
432 the symbol NIL, which was selected by FIRST
433 #<STRUCTURE-CLASS ACLREPL-TESTS::SIMPLE-STRUCT>, which was selected by (inspect *)
436 (deftest istep
.5 (progn (setq * *simple-struct
*)
442 "#<STRUCTURE-CLASS ACLREPL-TESTS::SIMPLE-STRUCT>
443 0 FIRST ----------> the symbol NIL
444 1 SLOT-2 ---------> the symbol A-VALUE
445 2 REALLY-LONG-STRUCT-SLOT-NAME -> a simple-string (4) \"defg\"")
447 (deftest istep
.6 (progn (setq * *dotted-list
*)
452 (deftest istep
.7 (progn (setq * *dotted-list
*)
457 (deftest istep
.8 (progn (setq * 5.5d0
)
459 "double-float 5.5d0")
461 (deftest istep
.9 (progn (setq * 5.5d0
)
463 "Object has no parent