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