1 ;;;; tests related to Lisp streams
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")
17 ;;; type errors for inappropriate stream arguments, fixed in
20 (declare (optimize (safety 3)))
21 (assert (raises-error? (make-two-way-stream (make-string-output-stream)
22 (make-string-output-stream))
24 (assert (raises-error? (make-two-way-stream (make-string-input-stream "foo")
25 (make-string-input-stream "bar"))
27 ;; the following two aren't actually guaranteed, because ANSI, as it
28 ;; happens, doesn't say "should signal an error" for
29 ;; MAKE-ECHO-STREAM. It's still good to have, but if future
30 ;; maintenance work causes this test to fail because of these
31 ;; MAKE-ECHO-STREAM clauses, consider simply removing these clauses
32 ;; from the test. -- CSR, 2002-10-06
33 (assert (raises-error? (make-echo-stream (make-string-output-stream)
34 (make-string-output-stream))
36 (assert (raises-error? (make-echo-stream (make-string-input-stream "foo")
37 (make-string-input-stream "bar"))
39 (assert (raises-error? (make-concatenated-stream
40 (make-string-output-stream)
41 (make-string-input-stream "foo"))
44 ;;; bug 225: STRING-STREAM was not a class
45 (eval `(defgeneric bug225 (s)
46 ,@(mapcar (lambda (class)
47 `(:method :around ((s ,class)) (cons ',class (call-next-method))))
48 '(stream string-stream sb-impl::string-input-stream
49 sb-impl::string-output-stream))
50 (:method (class) nil)))
52 (assert (equal (bug225 (make-string-input-stream "hello"))
53 '(sb-impl::string-input-stream string-stream stream)))
54 (assert (equal (bug225 (make-string-output-stream))
55 '(sb-impl::string-output-stream string-stream stream)))
58 ;;; improper buffering on (SIGNED-BYTE 8) streams (fixed by David Lichteblau):
59 (let ((p "signed-byte-8-test.data"))
62 :element-type '(unsigned-byte 8)
63 :if-exists :supersede)
65 (with-open-file (s p :element-type '(signed-byte 8))
66 (assert (= (read-byte s) -1)))
69 ;;; :IF-EXISTS got :ERROR and NIL the wrong way round (reported by
71 (let* ((p "this-file-will-exist")
72 (stream (open p :direction :output :if-exists :error)))
73 (assert (null (with-open-file (s p :direction :output :if-exists nil) s)))
74 (assert (raises-error?
75 (with-open-file (s p :direction :output :if-exists :error))))
79 (assert (raises-error? (read-byte (make-string-input-stream "abc"))
81 (assert (raises-error? (with-open-file (s "/dev/zero")
84 ;;; bidirectional streams getting confused about their position
85 (let ((p "bidirectional-stream-test"))
86 (with-open-file (s p :direction :output :if-exists :supersede)
87 (with-standard-io-syntax
88 (format s "~S ~S ~S~%" 'these 'are 'symbols)))
89 (with-open-file (s p :direction :io :if-exists :overwrite)
91 (with-standard-io-syntax
94 (assert (string= (read-line s) "THESE INSERTMBOLS")))
97 (quit :unix-status 104)