From 33a91f6afe5d68ea41a649db6e40d93d5896fb45 Mon Sep 17 00:00:00 2001
From: Raymond Toy <toy.raymond@gmail.com>
Date: Fri, 1 Aug 2014 00:01:38 -0700
Subject: [PATCH] Add tests for CLEAR-OUTPUT.

---
 tests/fd-streams.lisp   | 36 ++++++++++++++++++++++++++++++++++++
 tests/gray-streams.lisp | 39 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 75 insertions(+)
 create mode 100644 tests/fd-streams.lisp
 create mode 100644 tests/gray-streams.lisp

diff --git a/tests/fd-streams.lisp b/tests/fd-streams.lisp
new file mode 100644
index 000000000..263ce1fdc
--- /dev/null
+++ b/tests/fd-streams.lisp
@@ -0,0 +1,36 @@
+;;;; -*- Lisp -*-
+
+(defpackage fd-streams-tests
+  (:use #:common-lisp #:lisp-unit))
+
+(in-package #:fd-streams-tests)
+
+(defparameter *test-path*
+  (merge-pathnames (make-pathname :name :unspecific :type :unspecific
+                                  :version :unspecific)
+                   *load-truename*)
+  "Directory for temporary test files.")
+
+(defparameter *test-file*
+  (merge-pathnames #p"test-data.tmp" *test-path*))
+
+(eval-when (:load-toplevel)
+  (ensure-directories-exist *test-path* :verbose t))
+
+(define-test clear-output-1
+  (:tag :trac)
+  (assert-eql
+   0
+   (unwind-protect
+	(let ((s (open *test-file*
+		       :direction :output
+		       :if-exists :supersede)))
+	  ;; Write a character to the (fully buffered) output
+	  ;; stream. Clear the output and close the file. Nothing
+	  ;; should have been written to the file.
+	  (write-char #\a s)
+	  (clear-output s)
+	  (close s)
+	  (setf s (open *test-file*))
+	  (file-length s))
+     (delete-file *test-file*))))
diff --git a/tests/gray-streams.lisp b/tests/gray-streams.lisp
new file mode 100644
index 000000000..6308882ac
--- /dev/null
+++ b/tests/gray-streams.lisp
@@ -0,0 +1,39 @@
+;;;; -*- Lisp -*-
+
+(require :gray-streams)
+
+(defpackage gray-streams-tests
+  (:use #:common-lisp #:lisp-unit))
+
+(in-package #:gray-streams-tests)
+
+(defparameter *test-path*
+  (merge-pathnames (make-pathname :name :unspecific :type :unspecific
+                                  :version :unspecific)
+                   *load-truename*)
+  "Directory for temporary test files.")
+
+(defparameter *test-file*
+  (merge-pathnames #p"test-data.tmp" *test-path*))
+
+(eval-when (:load-toplevel)
+  (ensure-directories-exist *test-path* :verbose t))
+
+(define-test clear-output-1
+  (:tag :trac)
+  ;; Create a Gray stream and make sure that clear-output works.
+  (assert-eql
+   0
+   (unwind-protect
+	(let ((s (open *test-file*
+		       :direction :output
+		       :if-exists :supersede
+		       :class 'lisp::character-output-stream)))
+	  (write-char #\a s)
+	  (clear-output s)
+	  (close s)
+	  (setf s (open *test-file*))
+	  (file-length s))
+     (delete-file *test-file*))))
+		      
+    
\ No newline at end of file
-- 
GitLab