2612bf38604fb2b167bdc3a6eba72731490b0b98
[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
16 (load "test-util.lisp")
17 (load "compiler-test-util.lisp")
18 (use-package :test-util)
19 \f
20 ;;;; properties of symbols, e.g. presence of doc strings for public symbols
21
22 ;;; FIXME: It would probably be good to require here that every
23 ;;; external symbol either has a doc string or has some good excuse
24 ;;; (like being an accessor for a structure which has a doc string).
25 \f
26 ;;;; tests of interface machinery
27
28 ;;; APROPOS should accept a package designator, not just a package, and
29 ;;; furthermore do the right thing when it gets a package designator.
30 ;;; (bug reported and fixed by Alexey Dejneka sbcl-devel 2001-10-17)
31 (assert (< 0
32            (length (apropos-list "PRINT" :cl))
33            (length (apropos-list "PRINT"))))
34 ;;; Further, it should correctly deal with the external-only flag (bug
35 ;;; reported by cliini on #lisp IRC 2003-05-30, fixed in sbcl-0.8.0.1x
36 ;;; by CSR)
37 (assert (= (length (apropos-list "" "CL"))
38            (length (apropos-list "" "CL" t))))
39 (assert (< 0
40            (length (apropos-list "" "SB-VM" t))
41            (length (apropos-list "" "SB-VM"))))
42 \f
43 ;;; DESCRIBE shouldn't fail on rank-0 arrays (bug reported and fixed
44 ;;; by Lutz Euler sbcl-devel 2002-12-03)
45 (describe #0a0)
46 (describe #(1 2 3))
47 (describe #2a((1 2) (3 4)))
48
49 ;;; TYPEP, SUBTYPEP, UPGRADED-ARRAY-ELEMENT-TYPE and
50 ;;; UPGRADED-COMPLEX-PART-TYPE should be able to deal with NIL as an
51 ;;; environment argument
52 (typep 1 'fixnum nil)
53 (subtypep 'fixnum 'integer nil)
54 (upgraded-array-element-type '(mod 5) nil)
55 (upgraded-complex-part-type '(single-float 0.0 1.0) nil)
56
57 ;;; We should have documentation for our extension package:
58 (assert (documentation (find-package "SB-EXT") t))
59
60 ;;; DECLARE should not be a special operator
61 (assert (not (special-operator-p 'declare)))
62
63 ;;; WITH-TIMEOUT should accept more than one form in its body.
64 (with-test (:name :with-timeout-forms)
65   (handler-bind ((sb-ext:timeout #'continue))
66     (sb-ext:with-timeout 3
67       (sleep 2)
68       (sleep 2))))
69
70 ;;; SLEEP should not cons except on 32-bit platforms when
71 ;;; (> (mod seconds 1) (* most-positive-fixnum 1e-9))
72 (with-test (:name (sleep :non-consing) :fails-on :win32)
73   (ctu:assert-no-consing (sleep 0.00001s0))
74   (locally (declare (notinline sleep))
75     (ctu:assert-no-consing (sleep 0.00001s0))
76     (ctu:assert-no-consing (sleep 0.00001d0))
77     (ctu:assert-no-consing (sleep 1/100000003))))
78
79 ;;; Changes to make SLEEP cons less led to SLEEP
80 ;;; not sleeping at all on 32-bit platforms when
81 ;;; (> (mod seconds 1) (* most-positive-fixnum 1e-9)).
82 (with-test (:name :bug-1194673)
83   (assert (eq :timeout
84               (handler-case
85                   (with-timeout 0.01
86                     (sleep 0.6))
87                 (timeout ()
88                   :timeout)))))
89
90 ;;; SLEEP should work with large integers as well
91 (with-test (:name (sleep pretty-much-forever))
92   (assert (eq :timeout
93               (handler-case
94                   (sb-ext:with-timeout 1
95                     (sleep (ash 1 (* 2 sb-vm:n-word-bits))))
96                 (sb-ext:timeout ()
97                   :timeout)))))
98
99 ;;; DOCUMENTATION should return nil, not signal slot-unbound
100 (documentation 'fixnum 'type)
101 (documentation 'class 'type)
102 (documentation (find-class 'class) 'type)
103 (documentation 'foo 'structure)
104
105 ;;; DECODE-UNIVERSAL-TIME should accept second-resolution time-zones.
106 (macrolet ((test (ut time-zone list)
107              (destructuring-bind (sec min hr date mon yr day tz)
108                  list
109                `(multiple-value-bind (sec min hr date mon yr day dst tz)
110                     (decode-universal-time ,ut ,time-zone)
111                   (declare (ignore dst))
112                   (assert (= sec ,sec))
113                   (assert (= min ,min))
114                   (assert (= hr ,hr))
115                   (assert (= date ,date))
116                   (assert (= mon ,mon))
117                   (assert (= yr ,yr))
118                   (assert (= day ,day))
119                   (assert (= tz ,tz))))))
120   (test (* 86400 365) -1/3600 (1 0 0 1 1 1901 1 -1/3600))
121   (test (* 86400 365) 0 (0 0 0 1 1 1901 1 0))
122   (test (* 86400 365) 1/3600 (59 59 23 31 12 1900 0 1/3600)))
123
124 ;;; DECODE-UNIVERSAL-TIME shouldn't fail when the time is outside UNIX
125 ;;; 32-bit time_t and a timezone wasn't passed
126 (decode-universal-time 0 nil)
127
128 ;;; ENCODE-UNIVERSAL-TIME should be able to encode the universal time
129 ;;; 0 when passed a representation in a timezone where the
130 ;;; representation of 0 as a decoded time is in 1899.
131 (encode-universal-time 0 0 23 31 12 1899 1)
132
133 ;;; DISASSEMBLE shouldn't fail on purified functions
134 (disassemble 'cl:+)
135 (disassemble 'sb-ext:run-program)
136
137 ;;; minimal test of GC: see stress-gc.{sh,lisp} for a more
138 ;;; comprehensive test.
139 (loop repeat 2
140       do (compile nil '(lambda (x) x))
141       do (sb-ext:gc :full t))
142
143 ;;; On x86-64, the instruction definitions for CMP*[PS][SD] were broken
144 ;;; so that the disassembler threw an error when they were used with
145 ;;; one operand in memory.
146 (with-test (:name :bug-814702)
147   (disassemble (lambda (x)
148                  (= #C(2.0f0 3.0f0)
149                     (the (complex single-float) x))))
150   (disassemble (lambda (x y)
151                  (= (the (complex single-float) x)
152                     (the (complex single-float) y)))))
153
154 ;;; Check that SLEEP called with ratios (with no common factors with
155 ;;; 1000000000, and smaller than 1/1000000000) works more or less as
156 ;;; expected.
157 (with-test (:name :sleep-ratios)
158   (let ((fun0a (compile nil '(lambda () (sleep 1/7))))
159         (fun0b (compile nil '(lambda () (sleep 1/100000000000000000000000000))))
160         (fun1 (compile nil '(lambda (x) (sleep x))))
161         (start-time (get-universal-time)))
162     (sleep 1/7)
163     (sleep 1/100000000000000000000000000)
164     (funcall fun0a)
165     (funcall fun0b)
166     (funcall fun1 1/7)
167     (funcall fun1 1/100000000000000000000000000)
168     (assert (< (- (get-universal-time) start-time) 2))))