source: trunk/tests/ansi-tests/read-byte.lsp @ 9045

Last change on this file since 9045 was 9045, checked in by gz, 12 years ago

Assorted cleanup:

In infrastructure:

  • add *test-verbose* and :verbose argument to do-test and do-tests. Avoid random output if false, only show failures
  • muffle-wawrnings and/or bind *suppress-compiler-warnings* in some tests that unavoidably generate them (mainly with duplicate typecase/case clauses)
  • Add record-source-file for tests so meta-. can find them
  • If *catch-errors* (or the :catch-errors arg) is :break, enter a breakloop when catch an error
  • Make test fns created by *compile-tests* have names, so can find them in backtraces
  • fix misc compiler warnings
  • Fixed cases of duplicate test numbers
  • Disable note :make-condition-with-compound-name for openmcl.

In tests themselves:

I commented out the following tests with #+bogus-test, because they just seemed wrong to me:

lambda.47
lambda.50
upgraded-array-element-type.8
upgraded-array-element-type.nil.1
pathname-match-p.5
load.17
load.18
macrolet.47
ctypecase.15

In addition, I commented out the following tests with #+bogus-test because I was too lazy to make a note
for "doesn't signal underflow":

exp.error.8 exp.error.9 exp.error.10 exp.error.11 expt.error.8 expt.error.9 expt.error.10 expt.error.11

Finally, I entered bug reports in trac, and then commented out the tests
below with #+known-bug-NNN, where nnn is the ticket number in trac:

ticket#268: encode-universal-time.3 encode-universal-time.3.1
ticket#269: macrolet.36
ticket#270: values.20 values.21
ticket#271: defclass.error.13 defclass.error.22
ticket#272: phase.10 phase.12 asin.5 asin.6 asin.8
ticket#273: phase.18 phase.19 acos.8
ticket#274: exp.error.4 exp.error.5 exp.error.6 exp.error.7
ticket#275: car.error.2 cdr.error.2
ticket#276: map.error.11
ticket#277: subtypep.cons.43
ticket#278: subtypep-function.3
ticket#279: subtypep-complex.8
ticket#280: open.output.19 open.io.19 file-position.8 file-length.4 file-length.5 read-byte.4 stream-element-type.2 stream-element-type.3
ticket#281: open.65
ticket#288: set-syntax-from-char.sharp.1

File size: 4.1 KB
Line 
1;-*- Mode:     Lisp -*-
2;;;; Author:   Paul Dietz
3;;;; Created:  Sat Jan 17 17:30:49 2004
4;;;; Contains: Tests of READ-BYTE, WRITE-BYTE
5
6(in-package :cl-test)
7
8(deftest read-byte.1
9  (let ((s (open "foo.txt"
10                 :direction :output
11                 :if-exists :supersede
12                 :element-type '(unsigned-byte 8))))
13    (values
14     (write-byte 17 s)
15     (close s)
16     (progn
17       (setq s (open "foo.txt"
18                     :direction :input
19                     :element-type '(unsigned-byte 8)))
20       (read-byte s))
21     (close s)))
22  17 t 17 t)
23
24(deftest read-byte.2
25  (let ((s (open "foo.txt"
26                 :direction :output
27                 :if-exists :supersede
28                 :element-type '(unsigned-byte 8))))
29    (values
30     (close s)
31     (progn
32        (setq s (open "foo.txt"
33                     :direction :input
34                     :element-type '(unsigned-byte 8)))
35        (read-byte s nil 'foo))
36     (read-byte s nil)
37     (close s)))
38  t foo nil t)
39
40(deftest read-byte.3
41  (loop with b1 = 0
42        and b2 = 0
43        for i from 1 to 32
44        do (let ((s (open "foo.txt"
45                          :direction :output
46                          :if-exists :supersede
47                          :element-type `(unsigned-byte ,i))))
48             (write-byte (1- (ash 1 i)) s)
49             (write-byte 1 s)
50             (close s))
51        unless (let ((s (open "foo.txt"
52                              :direction :input
53                              :element-type `(unsigned-byte ,i))))
54                 (prog1
55                   (and (eql (setq b1 (read-byte s)) (1- (ash 1 i)))
56                        (eql (setq b2 (read-byte s)) 1))
57                   (close s)))
58        collect (list i b1 b2))
59  nil)
60
61#+known-bug-280
62(deftest read-byte.4
63  (loop with b1 = 0
64        and b2 = 0
65        for i from 33 to 200 by 7
66        do (let ((s (open "foo.txt"
67                          :direction :output
68                          :if-exists :supersede
69                          :element-type `(unsigned-byte ,i))))
70             (write-byte (1- (ash 1 i)) s)
71             (write-byte 1 s)
72             (close s))
73        unless (let ((s (open "foo.txt"
74                              :direction :input
75                              :element-type `(unsigned-byte ,i))))
76                 (prog1
77                     (and (eql (setq b1 (read-byte s)) (1- (ash 1 i)))
78                          (eql (setq b2 (read-byte s)) 1))
79                   (close s)))
80        collect (list i b1 b2))
81  nil)
82
83;;; Error tests
84
85(deftest read-byte.error.1
86  (signals-error (read-byte) program-error)
87  t)
88
89(deftest read-byte.error.2
90  (progn
91    (let ((s (open "foo.txt"
92                   :direction :output
93                   :if-exists :supersede
94                  :element-type `(unsigned-byte 8))))
95      (close s))
96    (signals-error
97     (let ((s (open "foo.txt"
98                   :direction :input
99                   :element-type '(unsigned-byte 8))))
100       (read-byte s))
101     end-of-file))
102  t)
103
104(deftest read-byte.error.3
105  (progn
106    (let ((s (open "foo.txt"
107                   :direction :output
108                   :if-exists :supersede)))
109      (close s))
110    (signals-error
111     (let ((s (open "foo.txt" :direction :input)))
112       (unwind-protect
113           (read-byte s)
114         (close s)))
115     error))
116  t)
117
118(deftest read-byte.error.4
119  (signals-error-always
120   (progn
121     (let ((s (open "foo.txt"
122                    :direction :output
123                    :if-exists :supersede
124                    :element-type '(unsigned-byte 8))))
125       (close s))
126     (let ((s (open "foo.txt"
127                    :direction :input
128                    :element-type '(unsigned-byte 8))))
129       (unwind-protect
130           (read-byte s t)
131         (close s))))
132   end-of-file)
133  t t)
134
135(deftest read-byte.error.5
136  (check-type-error #'read-byte #'streamp)
137  nil)
138
139(deftest read-byte.error.6
140  (progn
141    (let ((s (open "foo.txt"
142                   :direction :output
143                   :if-exists :supersede
144                  :element-type '(unsigned-byte 8))))
145      (close s))
146    (signals-error
147     (let ((s (open "foo.txt"
148                   :direction :input
149                   :element-type '(unsigned-byte 8))))
150       (unwind-protect
151           (read-byte s t t nil)
152         (close s)))
153     program-error))
154  t)
155
156       
157(deftest write-byte.error.1
158  (signals-error (write-byte) program-error)
159  t)
160
161(deftest write-byte.error.2
162  (signals-error (write-byte 0) program-error)
163  t)
164
165(deftest write-byte.error.3
166  (signals-error
167   (let ((s (open "foo.txt"
168                  :direction :output
169                  :if-exists :supersede
170                  :element-type '(unsigned-byte 8))))
171     (unwind-protect
172         (write 1 s nil)
173       (close s)))
174   program-error)
175  t)
176
177(deftest write-byte.error.4
178  (check-type-error #'(lambda (x) (write-byte 0 x)) #'streamp)
179  nil)
180
181(deftest write-byte.error.5
182   (signals-error
183    (let ((s (open "foo.txt"
184                   :direction :output
185                   :if-exists :supersede)))
186      (unwind-protect
187          (write 1 s)
188        (close s)))
189    error)
190   t)
191
192
193
194   
195   
Note: See TracBrowser for help on using the repository browser.