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 (def-elements-tests *bignum* 2
191 #(2112454933 287445236)
192 #((0 . :HEX32) (1 . :HEX32)))
193 (def-elements-tests *vector* 20
194 #(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19)
195 #(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19))
196 (def-elements-tests *vector* 18
197 #(nil 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19)
198 #(:ellipses 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19)
200 (def-elements-tests *vector* 13
201 #(nil 3 4 5 6 7 8 9 10 11 12 nil 19)
202 #(:ellipses 3 4 5 6 7 8 9 10 11 12 :ellipses 19)
204 (def-elements-tests *vector* 5
206 #(:ellipses 16 17 18 19)
208 (def-elements-tests *vector* 5
210 #(:ellipses 16 17 18 19)
212 (def-elements-tests *vector* 5
214 #(:ellipses 15 16 :ellipses 19)
216 (def-elements-tests *array* 18
217 #(NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL
219 #((0 . "[0,0,0]") (1 . "[0,0,1]") (2 . "[0,1,0]") (3 . "[0,1,1]")
220 (4 . "[0,2,0]") (5 . "[0,2,1]") (6 . "[1,0,0]") (7 . "[1,0,1]")
221 (8 . "[1,1,0]") (9 . "[1,1,1]") (10 . "[1,2,0]")
222 (11 . "[1,2,1]") (12 . "[2,0,0]") (13 . "[2,0,1]")
223 (14 . "[2,1,0]") (15 . "[2,1,1]") (16 . "[2,2,0]")
226 (def-elements-tests *empty-class* 0 nil nil)
228 (def-elements-tests *simple-class* 3
229 #(#.sb-aclrepl::*inspect-unbound-object-marker* 0 "abc")
230 #((0 . "A") (1 . "SECOND") (2 . "REALLY-LONG-SLOT-NAME")))
231 (def-elements-tests *empty-struct* 0 nil nil)
232 (def-elements-tests *simple-struct* 3
233 #(nil a-value "defg")
234 #((0 . "FIRST") (1 . "SLOT-2")
235 (2 . "REALLY-LONG-STRUCT-SLOT-NAME")))
237 (eval-when (:compile-toplevel :load-toplevel :execute)
238 (defun label-test-name (name pos &optional print (skip 0))
239 (intern (format nil "LABEL.~A.~D" (basename name print skip) pos))))
241 (defmacro def-label-test (object pos label &optional print (skip 0))
242 `(deftest ,(label-test-name object pos print skip)
243 (labeled-element ,object ,pos ,print ,skip) ,label))
245 (def-label-test *simple-struct* 0
246 " 0 FIRST ----------> the symbol NIL")
247 (def-label-test *simple-struct* 1
248 " 1 SLOT-2 ---------> the symbol A-VALUE")
249 (def-label-test *simple-struct* 2
250 " 2 REALLY-LONG-STRUCT-SLOT-NAME -> a simple-string (4) \"defg\"")
251 (def-label-test *simple-class* 0
252 " 0 A --------------> ..unbound..")
253 (def-label-test *simple-class* 1
254 " 1 SECOND ---------> fixnum 0")
255 (def-label-test *simple-class* 2
256 " 2 REALLY-LONG-SLOT-NAME -> a simple-string (3) \"abc\"")
258 (def-label-test *complex* 0 " 0 real -----------> fixnum 1")
259 (def-label-test *complex* 1 " 1 imag -----------> fixnum 2")
261 (def-label-test *ratio* 0 " 0 numerator ------> fixnum 22")
262 (def-label-test *ratio* 1 " 1 denominator ----> fixnum 7")
264 (def-label-test *dotted-list* 0 " 0-> the symbol A")
265 (def-label-test *dotted-list* 1 " 1-> the symbol B")
266 (def-label-test *dotted-list* 2 "tail-> fixnum 3")
268 (def-label-test *normal-list* 0 " 0-> the symbol A")
269 (def-label-test *normal-list* 1 " 1-> the symbol B")
270 (def-label-test *normal-list* 2 " 2-> fixnum 3")
272 (def-label-test *vector* 0 " 0-> fixnum 0")
273 (def-label-test *vector* 1 " 1-> fixnum 1")
274 (def-label-test *vector* 0 " ..." nil 2)
275 (def-label-test *vector* 1" 2-> fixnum 2" nil 2)
277 (def-label-test *cons-pair* 0
278 " 0 car ------------> complex number #C(1 2)")
279 (def-label-test *cons-pair* 1
280 " 1 cdr ------------> the symbol A-SYMBOL")
282 (deftest nil.parts.0 (elements-count nil) 5)
284 (def-elements-tests *tiny-struct* 1 #(10) #((0 . "FIRST")))
285 (def-elements-tests *tiny-struct* 1
286 #(nil) #(:ellipses) nil 1)
287 (def-elements-tests *tiny-struct* 1
288 #(nil) #(:ellipses) nil 2)
290 (def-elements-tests *double* 0 nil nil)
291 (def-elements-tests *double* 0 nil nil nil 1)
293 (eval-when (:compile-toplevel :load-toplevel :execute)
294 (defun display-test-name (name print skip)
295 (intern (format nil "DISPLAY.~A" (basename name print skip)))))
297 (defmacro def-display-test (object string &optional print (skip 0))
298 `(deftest ,(display-test-name object print skip)
299 (display ,object ,print ,skip) ,string))
301 (def-display-test *cons-pair*
303 0 car ------------> complex number #C(1 2)
304 1 cdr ------------> the symbol A-SYMBOL")
306 (def-display-test *simple-struct*
307 "#<STRUCTURE-CLASS ACLREPL-TESTS::SIMPLE-STRUCT>
308 0 FIRST ----------> the symbol NIL
309 1 SLOT-2 ---------> the symbol A-VALUE
310 2 REALLY-LONG-STRUCT-SLOT-NAME -> a simple-string (4) \"defg\"")
312 (def-display-test *simple-struct*
313 "#<STRUCTURE-CLASS ACLREPL-TESTS::SIMPLE-STRUCT>
315 2 REALLY-LONG-STRUCT-SLOT-NAME -> a simple-string (4) \"defg\""
318 (def-display-test *bignum*
319 "bignum 1234567890123456789 with 2 32-bit words
323 (def-display-test *vector*
324 "a simple T vector (20)
335 (def-display-test *circle-list1*
337 0 car ------------> a cons cell
338 1 cdr ------------> the symbol NIL")
339 (def-display-test *circle-list2*
340 "a cyclic list with 1 element+tail
342 tail-> a cyclic list with 1 element+tail")
343 (def-display-test *circle-list3*
344 "a normal list with 3 elements
345 0-> a normal list with 3 elements
348 (def-display-test *circle-list4*
349 "a normal list with 3 elements
351 1-> a normal list with 3 elements
353 (def-display-test *circle-list5*
354 "a cyclic list with 2 elements+tail
357 tail-> a cyclic list with 2 elements+tail")
360 ;;; Inspector traversal tests
361 (deftest inspect.0 (progn (setq * *simple-struct*)
363 "#<STRUCTURE-CLASS ACLREPL-TESTS::SIMPLE-STRUCT>
364 0 FIRST ----------> the symbol NIL
365 1 SLOT-2 ---------> the symbol A-VALUE
366 2 REALLY-LONG-STRUCT-SLOT-NAME -> a simple-string (4) \"defg\"")
368 (deftest istep.0 (progn (setq * *simple-struct*)
371 "#<STRUCTURE-CLASS ACLREPL-TESTS::SIMPLE-STRUCT>
372 0 FIRST ----------> the symbol NIL
373 1 SLOT-2 ---------> the symbol A-VALUE
374 2 REALLY-LONG-STRUCT-SLOT-NAME -> a simple-string (4) \"defg\"")
377 (deftest istep.1 (progn (setq * *simple-struct*)
381 0 NAME -----------> a simple-string (3) \"NIL\"
382 1 PACKAGE --------> the COMMON-LISP package
383 2 VALUE ----------> the symbol NIL
384 3 FUNCTION -------> ..unbound..
385 4 PLIST ----------> the symbol NIL")
388 (deftest istep.2 (progn (setq * *simple-struct*)
393 0 NAME -----------> a simple-string (7) \"A-VALUE\"
394 1 PACKAGE --------> the ACLREPL-TESTS package
395 2 VALUE ----------> ..unbound..
396 3 FUNCTION -------> ..unbound..
397 4 PLIST ----------> the symbol NIL")
399 (deftest istep.3 (progn (setq * *simple-struct*)
405 0 NAME -----------> a simple-string (3) \"NIL\"
406 1 PACKAGE --------> the COMMON-LISP package
407 2 VALUE ----------> the symbol NIL
408 3 FUNCTION -------> ..unbound..
409 4 PLIST ----------> the symbol NIL")
411 (deftest istep.4 (progn (setq * *simple-struct*)
417 "The current object is:
418 the symbol NIL, which was selected by FIRST
419 #<STRUCTURE-CLASS ACLREPL-TESTS::SIMPLE-STRUCT>, which was selected by (inspect *)
422 (deftest istep.5 (progn (setq * *simple-struct*)
428 "#<STRUCTURE-CLASS ACLREPL-TESTS::SIMPLE-STRUCT>
429 0 FIRST ----------> the symbol NIL
430 1 SLOT-2 ---------> the symbol A-VALUE
431 2 REALLY-LONG-STRUCT-SLOT-NAME -> a simple-string (4) \"defg\"")
433 (deftest istep.6 (progn (setq * *dotted-list*)
438 (deftest istep.7 (progn (setq * *dotted-list*)
443 (deftest istep.8 (progn (setq * 5.5d0)
445 "double-float 5.5d0")
447 (deftest istep.9 (progn (setq * 5.5d0)
449 "Object has no parent