0.8.21.16:
[sbcl.git] / tests / external-format.impure.lisp
1 ;;;; This file is for testing external-format functionality, using
2 ;;;; test machinery which might have side effects (e.g.  executing
3 ;;;; DEFUN, writing files).  Note that the tests here reach into
4 ;;;; unexported functionality, and should not be used as a guide for
5 ;;;; users.
6
7 ;;;; This software is part of the SBCL system. See the README file for
8 ;;;; more information.
9 ;;;;
10 ;;;; While most of SBCL is derived from the CMU CL system, the test
11 ;;;; files (like this one) were written from scratch after the fork
12 ;;;; from CMU CL.
13 ;;;; 
14 ;;;; This software is in the public domain and is provided with
15 ;;;; absolutely no warranty. See the COPYING and CREDITS files for
16 ;;;; more information.
17
18 (defmacro do-external-formats ((xf &optional result) &body body)
19   (let ((nxf (gensym)))
20     `(dolist (,nxf sb-impl::*external-formats* ,result)
21        (let ((,xf (first (first ,nxf))))
22          ,@body))))
23
24 (do-external-formats (xf)
25   (with-open-file (s "/dev/null" :direction :input :external-format xf)
26     (assert (eq (read-char s nil s) s))))
27
28 (let ((s (open "external-format-test.lisp" :direction :output
29                :if-exists :supersede :external-format :latin-1)))
30   (unwind-protect
31        (progn
32          (write-string ";;; ABCD" s)
33          (write-char (code-char 233) s)
34          (terpri s)
35          (close s)
36          (compile-file "external-format-test.lisp" :external-format :utf-8))
37     (delete-file s)
38     (let ((p (probe-file (compile-file-pathname "external-format-test.lisp"))))
39       (when p
40         (delete-file p)))))
41
42 (sb-ext:quit :unix-status 104)
43