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
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
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")
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)
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)))
57 ;;; support for DESCRIBE tests
58 (defstruct to-be-described a b)
59 (defclass forward-describe-class (forward-describe-ref) (a))
61 ;;; DESCRIBE should run without signalling an error.
62 (describe (make-to-be-described))
66 (describe (find-package :cl))
68 (describe #(a vector))
70 ;;; The DESCRIBE-OBJECT methods for built-in CL stuff should do
71 ;;; FRESH-LINE and TERPRI neatly.
72 (dolist (i (list (make-to-be-described :a 14) 12 "a string"
73 #0a0 #(1 2 3) #2a((1 2) (3 4)) 'sym :keyword
74 (find-package :keyword) (list 1 2 3)
75 nil (cons 1 2) (make-hash-table)
76 (let ((h (make-hash-table)))
77 (setf (gethash 10 h) 100
80 (make-condition 'simple-error)
81 (make-condition 'simple-error :format-control "fc")
82 #'car #'make-to-be-described (lambda (x) (+ x 11))
83 (constantly 'foo) #'(setf to-be-described-a)
84 #'describe-object (find-class 'to-be-described)
85 (find-class 'forward-describe-class)
86 (find-class 'forward-describe-ref) (find-class 'cons)))
87 (let ((s (with-output-to-string (s)
90 (unless (and (char= #\x (char s 0))
91 ;; one leading #\NEWLINE from FRESH-LINE or the like, no more
92 (char= #\newline (char s 1))
93 (char/= #\newline (char s 2))
94 ;; one trailing #\NEWLINE from TERPRI or the like, no more
96 (and (char= #\newline (char s (- n 1)))
97 (char/= #\newline (char s (- n 2))))))
98 (error "misbehavior in DESCRIBE of ~S" i))))
101 ;;; Tests of documentation on types and classes
104 (:documentation "FOO"))
105 (defstruct bar "BAR")
106 (define-condition baz ()
108 (:documentation "BAZ"))
112 (defstruct (frob (:type vector)) "FROB")
114 ((do-class (name expected &optional structurep)
116 (assert (string= (documentation ',name 'type) ,expected))
117 (assert (string= (documentation (find-class ',name) 'type) ,expected))
118 (assert (string= (documentation (find-class ',name) 't) ,expected))
120 `((assert (string= (documentation ',name 'structure) ,expected))))
121 (let ((new1 (symbol-name (gensym "NEW1")))
122 (new2 (symbol-name (gensym "NEW2")))
123 (new3 (symbol-name (gensym "NEW3")))
124 (new4 (symbol-name (gensym "NEW4"))))
125 (declare (ignorable new4))
126 (setf (documentation ',name 'type) new1)
127 (assert (string= (documentation (find-class ',name) 'type) new1))
128 (setf (documentation (find-class ',name) 'type) new2)
129 (assert (string= (documentation (find-class ',name) 't) new2))
130 (setf (documentation (find-class ',name) 't) new3)
131 (assert (string= (documentation ',name 'type) new3))
133 `((assert (string= (documentation ',name 'structure) new3))
134 (setf (documentation ',name 'structure) new4)
135 (assert (string= (documentation ',name 'structure) new4))))))))
137 (do-class bar "BAR" t)
138 (do-class baz "BAZ"))
140 (assert (string= (documentation 'quux 'type) "QUUX"))
141 (setf (documentation 'quux 'type) "NEW4")
142 (assert (string= (documentation 'quux 'type) "NEW4"))
144 (assert (string= (documentation 'frob 'structure) "FROB"))
145 (setf (documentation 'frob 'structure) "NEW5")
146 (assert (string= (documentation 'frob 'structure) "NEW5"))