0.9.2.43:
[sbcl.git] / tests / interface.pure.lisp
1 ;;;; tests for problems in the interface presented to the user/programmer
2
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
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
8 ;;;; from CMU CL.
9 ;;;;
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.
13
14 (in-package :cl-user)
15 \f
16 ;;;; properties of symbols, e.g. presence of doc strings for public symbols
17
18 ;;; FIXME: It would probably be good to require here that every
19 ;;; external symbol either has a doc string or has some good excuse
20 ;;; (like being an accessor for a structure which has a doc string).
21 \f
22 ;;;; tests of interface machinery
23
24 ;;; APROPOS should accept a package designator, not just a package, and
25 ;;; furthermore do the right thing when it gets a package designator.
26 ;;; (bug reported and fixed by Alexey Dejneka sbcl-devel 2001-10-17)
27 (assert (< 0
28            (length (apropos-list "PRINT" :cl))
29            (length (apropos-list "PRINT"))))
30 ;;; Further, it should correctly deal with the external-only flag (bug
31 ;;; reported by cliini on #lisp IRC 2003-05-30, fixed in sbcl-0.8.0.1x
32 ;;; by CSR)
33 (assert (= (length (apropos-list "" "CL"))
34            (length (apropos-list "" "CL" t))))
35 (assert (< 0
36            (length (apropos-list "" "SB-VM" t))
37            (length (apropos-list "" "SB-VM"))))
38 \f
39 ;;; DESCRIBE shouldn't fail on rank-0 arrays (bug reported and fixed
40 ;;; by Lutz Euler sbcl-devel 2002-12-03)
41 (describe #0a0)
42 (describe #(1 2 3))
43 (describe #2a((1 2) (3 4)))
44
45 ;;; support for DESCRIBE tests
46 (defstruct to-be-described a b)
47 (defclass forward-describe-class (forward-describe-ref) (a))
48
49 ;;; DESCRIBE should run without signalling an error.
50 (describe (make-to-be-described))
51 (describe 12)
52 (describe "a string")
53 (describe 'symbolism)
54 (describe (find-package :cl))
55 (describe '(a list))
56 (describe #(a vector))
57
58 ;;; The DESCRIBE-OBJECT methods for built-in CL stuff should do
59 ;;; FRESH-LINE and TERPRI neatly.
60 (dolist (i (list (make-to-be-described :a 14) 12 "a string"
61                  #0a0 #(1 2 3) #2a((1 2) (3 4)) 'sym :keyword
62                  (find-package :keyword) (list 1 2 3)
63                  nil (cons 1 2) (make-hash-table)
64                  (let ((h (make-hash-table)))
65                    (setf (gethash 10 h) 100
66                          (gethash 11 h) 121)
67                    h)
68                  (make-condition 'simple-error)
69                  (make-condition 'simple-error :format-control "fc")
70                  #'car #'make-to-be-described (lambda (x) (+ x 11))
71                  (constantly 'foo) #'(setf to-be-described-a)
72                  #'describe-object (find-class 'to-be-described)
73                  (find-class 'forward-describe-class)
74                  (find-class 'forward-describe-ref) (find-class 'cons)))
75   (let ((s (with-output-to-string (s)
76              (write-char #\x s)
77              (describe i s))))
78     (unless (and (char= #\x (char s 0))
79                  ;; one leading #\NEWLINE from FRESH-LINE or the like, no more
80                  (char= #\newline (char s 1))
81                  (char/= #\newline (char s 2))
82                  ;; one trailing #\NEWLINE from TERPRI or the like, no more
83                  (let ((n (length s)))
84                    (and (char= #\newline (char s (- n 1)))
85                         (char/= #\newline (char s (- n 2))))))
86       (error "misbehavior in DESCRIBE of ~S" i))))
87
88 ;;; TYPEP, SUBTYPEP, UPGRADED-ARRAY-ELEMENT-TYPE and
89 ;;; UPGRADED-COMPLEX-PART-TYPE should be able to deal with NIL as an
90 ;;; environment argument
91 (typep 1 'fixnum nil)
92 (subtypep 'fixnum 'integer nil)
93 (upgraded-array-element-type '(mod 5) nil)
94 (upgraded-complex-part-type '(single-float 0.0 1.0) nil)
95
96 ;;; We should have documentation for our extension package:
97 (assert (documentation (find-package "SB-EXT") t))
98
99 ;;; DECLARE should not be a special operator
100 (assert (not (special-operator-p 'declare)))
101
102 ;;; WITH-TIMEOUT should accept more than one form in its body.
103 (handler-bind ((sb-ext:timeout #'continue))
104   (sb-ext:with-timeout 3
105     (sleep 2)
106     (sleep 2)))
107
108 ;;; DOCUMENTATION should return nil, not signal slot-unbound
109 (documentation 'fixnum 'type)
110 (documentation 'class 'type)
111 (documentation (find-class 'class) 'type)
112
113 ;;; DECODE-UNIVERSAL-TIME should accept second-resolution time-zones.
114 (macrolet ((test (ut time-zone list)
115              (destructuring-bind (sec min hr date mon yr day tz)
116                  list
117                `(multiple-value-bind (sec min hr date mon yr day dst tz)
118                     (decode-universal-time ,ut ,time-zone)
119                   (declare (ignore dst))
120                   (assert (= sec ,sec))
121                   (assert (= min ,min))
122                   (assert (= hr ,hr))
123                   (assert (= date ,date))
124                   (assert (= mon ,mon))
125                   (assert (= yr ,yr))
126                   (assert (= day ,day))
127                   (assert (= tz ,tz))))))
128   (test (* 86400 365) -1/3600 (1 0 0 1 1 1901 1 -1/3600))
129   (test (* 86400 365) 0 (0 0 0 1 1 1901 1 0))
130   (test (* 86400 365) 1/3600 (59 59 23 31 12 1900 0 1/3600)))
131
132 ;;; DISASSEMBLE shouldn't fail on purified functions
133 (disassemble 'cl:+)
134 (disassemble 'sb-ext:run-program)
135
136 ;;; minimal test of GC: see stress-gc.{sh,lisp} for a more
137 ;;; comprehensive test.
138 (loop repeat 2
139       do (compile nil '(lambda (x) x))
140       do (sb-ext:gc :full t))