From 383251b0b87df7e833a0245054a907f77d262ad7 Mon Sep 17 00:00:00 2001
From: pfdietz <pfdietz@localhost>
Date: Wed, 28 Jan 2004 03:15:08 +0000
Subject: [PATCH] Add minimal tests for stream-external-form, with-open-file.

---
 ansi-tests/load-streams.lsp           |  2 +-
 ansi-tests/open.lsp                   | 41 +++++++++++++++++++-
 ansi-tests/stream-external-format.lsp | 24 ++++++++++++
 ansi-tests/with-open-file.lsp         | 56 +++++++++++++++++++++++++++
 4 files changed, 121 insertions(+), 2 deletions(-)
 create mode 100644 ansi-tests/stream-external-format.lsp
 create mode 100644 ansi-tests/with-open-file.lsp

diff --git a/ansi-tests/load-streams.lsp b/ansi-tests/load-streams.lsp
index 8fd16dd8..d2d7237b 100644
--- a/ansi-tests/load-streams.lsp
+++ b/ansi-tests/load-streams.lsp
@@ -28,4 +28,4 @@
 (load "file-position.lsp")
 (load "file-string-length.lsp")
 (load "open.lsp")
-
+(load "stream-external-format.lsp")
diff --git a/ansi-tests/open.lsp b/ansi-tests/open.lsp
index 4b770b14..b1e978b4 100644
--- a/ansi-tests/open.lsp
+++ b/ansi-tests/open.lsp
@@ -303,7 +303,46 @@
 	 (notnot (every #'eql seq vals))))))
   t)
 
-;;; Add -- tests for when the filespec is a stream
+;;; FIXME: Add -- tests for when the filespec is a stream
+
+(deftest open.66
+  (let ((pn #p"tmp.dat"))
+    (delete-all-versions pn)
+    (with-open-file
+     (s pn :direction :io :if-exists :rename-and-delete
+	:if-does-not-exist :create)
+     (format s "some stuff~%")
+     (finish-output s)
+     (let ((is (open s :direction :input)))
+       (unwind-protect
+	   (values
+	    (read-char is)
+	    (notnot (file-position s :start))
+	    (read-line is)
+	    (read-line s))
+	 (close is)))))
+  #\s
+  t
+  "ome stuff"
+  "some stuff")
+
+(deftest open.67
+  (let ((pn #p"tmp.dat"))
+    (delete-all-versions pn)
+    (let ((s (open pn :direction :output)))
+      (unwind-protect
+	  (progn
+	    (format s "some stuff~%")
+	    (finish-output s)
+	    (close s)
+	    (let ((is (open s :direction :input)))
+	      (unwind-protect
+		  (values (read-line is))
+		(close is))))
+	(when (open-stream-p s) (close s)))))
+  "some stuff")
+
+;;; FIXME: Add -- tests for when element-type is :default
 
 ;;; Tests of file creation
 
diff --git a/ansi-tests/stream-external-format.lsp b/ansi-tests/stream-external-format.lsp
new file mode 100644
index 00000000..528986c5
--- /dev/null
+++ b/ansi-tests/stream-external-format.lsp
@@ -0,0 +1,24 @@
+;-*- Mode:     Lisp -*-
+;;;; Author:   Paul Dietz
+;;;; Created:  Tue Jan 27 20:53:21 2004
+;;;; Contains: Tests of STREAM-EXTERNAL-FORMAT
+
+(in-package :cl-test)
+
+;;; This is tested in open.lsp
+
+;;; Error tests
+
+(deftest stream-external-format.error.1
+  (signals-error (stream-external-format) program-error)
+  t)
+
+(deftest stream-external-format.error.2
+  (signals-error
+   (let ((pn #p"tmp.dat"))
+     (delete-all-versions pn)
+     (with-open-file
+      (s pn :direction :output :if-exists :supersede)
+      (stream-external-format s nil)))
+   program-error)
+  t)
diff --git a/ansi-tests/with-open-file.lsp b/ansi-tests/with-open-file.lsp
new file mode 100644
index 00000000..5c6b91a5
--- /dev/null
+++ b/ansi-tests/with-open-file.lsp
@@ -0,0 +1,56 @@
+;-*- Mode:     Lisp -*-
+;;;; Author:   Paul Dietz
+;;;; Created:  Tue Jan 27 20:57:05 2004
+;;;; Contains: Tests of WITH-OPEN-FILE
+
+(in-package :cl-test)
+
+;;; For now, omit most of the options combinations, assuming they will
+;;; be tested in OPEN.  The tests of OPEN should be ported to here at some
+;;; point.
+
+(deftest with-open-file.1
+  (let ((pn #p"tmp.dat"))
+    (delete-all-versions pn)
+    (with-open-file (s pn :direction :output)))
+  nil)
+
+(deftest with-open-file.2
+  (let ((pn #p"tmp.dat"))
+    (delete-all-versions pn)
+    (with-open-file
+     (s pn :direction :output)
+     (notnot-mv (output-stream-p s))))
+  t)
+
+(deftest with-open-file.3
+  (let ((pn #p"tmp.dat"))
+    (delete-all-versions pn)
+    (with-open-file
+     (s pn :direction :output)
+     (values))))
+
+(deftest with-open-file.4
+  (let ((pn #p"tmp.dat"))
+    (delete-all-versions pn)
+    (with-open-file
+     (s pn :direction :output)
+     (values 1 2 3 4 5 6 7 8)))
+  1 2 3 4 5 6 7 8)
+
+(deftest with-open-file.5
+  (let ((pn #p"tmp.dat"))
+    (delete-all-versions pn)
+    (with-open-file
+     (s pn :direction :output)
+     (declare (ignore s))))
+  nil)
+
+(deftest with-open-file.6
+  (let ((pn #p"tmp.dat"))
+    (delete-all-versions pn)
+    (with-open-file
+     (s pn (cdr '(nil . :direction)) (car '(:output)))
+     (format s "foo!~%"))
+    (with-open-file (s pn) (read-line s)))
+  "foo!" nil)
-- 
GitLab