1 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; While most of SBCL is derived from the CMU CL system, the test
5 ;;;; files (like this one) were written from scratch after the fork
8 ;;;; This software is in the public domain and is provided with
9 ;;;; absolutely no warranty. See the COPYING and CREDITS files for
10 ;;;; more information.
12 (in-package "CL-USER")
14 ;;; In sbcl-0.6.9 FOO-NAMESTRING functions returned "" instead of NIL.
15 (with-test (:name
(file-namestring directory-namestring
:name
))
16 (let ((pathname0 (make-pathname :host nil
19 *default-pathname-defaults
*)
21 (pathname1 (make-pathname :host nil
24 (assert (equal (file-namestring pathname0
) "getty"))
25 (assert (equal (directory-namestring pathname0
)
26 (directory-namestring *default-pathname-defaults
*)))
27 (assert (equal (file-namestring pathname1
) ""))
28 (assert (equal (directory-namestring pathname1
) ""))))
30 ;;; In sbcl-0.6.9 DIRECTORY failed on paths with :WILD or
31 ;;; :WILD-INFERIORS in their directory components.
32 (with-test (:name
(directory :wild-inferiors
))
33 (let ((dir (directory "../**/*.*")))
34 ;; We know a little bit about the structure of this result;
35 ;; let's test to make sure that this test file is in it.
36 (assert (find-if (lambda (pathname)
37 (search "tests/filesys.pure.lisp"
38 (namestring pathname
)))
40 ;;; In sbcl-0.9.7 DIRECTORY failed on pathnames with character-set
42 (with-test (:name
(directory :character-set
:pattern
) )
43 (let ((dir (directory "[f]*.*")))
44 ;; We know a little bit about the structure of this result;
45 ;; let's test to make sure that this test file is in it.
46 (assert (find-if (lambda (pathname)
47 (search "filesys.pure.lisp"
48 (namestring pathname
)))
51 ;;; Set *default-pathname-defaults* to something other than the unix
52 ;;; cwd, to catch functions which access the filesystem without
53 ;;; merging properly. We should test more functions than just OPEN
56 (with-test (:name
(open *default-pathname-defaults
*))
57 (let ((*default-pathname-defaults
*
58 (make-pathname :directory
60 (pathname-directory *default-pathname-defaults
*))
61 :defaults
*default-pathname-defaults
*)))
62 ;; SBCL 0.7.1.2 failed to merge on OPEN
63 (with-open-file (i "tests/filesys.pure.lisp")
66 ;;; OPEN, LOAD and friends should signal an error of type FILE-ERROR
67 ;;; if they are fed wild pathname designators; firstly, with wild
68 ;;; pathnames that don't correspond to any files:
69 (with-test (:name
(open :wild file-error
1))
70 (assert (typep (nth-value 1 (ignore-errors (open "non-existent*.lisp")))
72 (with-test (:name
(load :wild file-error
1))
73 (assert (typep (nth-value 1 (ignore-errors (load "non-existent*.lisp")))
75 ;;; then for pathnames that correspond to precisely one:
76 (with-test (:name
(open :wild file-error
2))
77 (assert (typep (nth-value 1 (ignore-errors (open "filesys.pur*.lisp")))
79 (with-test (:name
(load :wild file-error
2))
80 (assert (typep (nth-value 1 (ignore-errors (load "filesys.pur*.lisp")))
82 ;;; then for pathnames corresponding to many:
83 (with-test (:name
(open :wild file-error
3))
84 (assert (typep (nth-value 1 (ignore-errors (open "*.lisp")))
86 (with-test (:name
(load :wild file-error
3))
87 (assert (typep (nth-value 1 (ignore-errors (load "*.lisp")))
90 ;;; ANSI: FILE-LENGTH should signal an error of type TYPE-ERROR if
91 ;;; STREAM is not a stream associated with a file.
93 ;;; (Peter Van Eynde's ansi-test suite caught this, and Eric Marsden
94 ;;; reported a fix for CMU CL, which was ported to sbcl-0.6.12.35.)
95 (with-test (:name
(file-length *terminal-io
* type-error
))
96 (assert (typep (nth-value 1 (ignore-errors (file-length *terminal-io
*)))
99 ;;; A few cases Windows does have enough marbles to pass right now
100 (with-test (:name
(sb-ext:native-namestring
:win32
)
101 :skipped-on
'(not :win32
))
102 (assert (equal "C:\\FOO" (native-namestring "C:\\FOO")))
103 (assert (equal "C:\\FOO" (native-namestring "C:/FOO")))
104 (assert (equal "C:\\FOO\\BAR" (native-namestring "C:\\FOO\\BAR")))
105 (assert (equal "C:\\FOO\\BAR" (native-namestring "C:\\FOO\\BAR\\" :as-file t
))))
107 (with-test (:name
(sb-ext:parse-native-namestring
:as-directory
:junk-allowed
))
110 (parse-native-namestring "foo.lisp" nil
*default-pathname-defaults
*
112 (parse-native-namestring "foo.lisp" nil
*default-pathname-defaults
*
116 ;;; Test for NATIVE-PATHNAME / NATIVE-NAMESTRING stuff
118 ;;; given only safe characters in the namestring, NATIVE-PATHNAME will
119 ;;; never error, and NATIVE-NAMESTRING on the result will return the
120 ;;; original namestring.
121 (with-test (:name
(sb-ext:native-namestring sb-ext
:native-pathname
:random
))
125 (loop for x from
32 to
127 collect
(code-char x
)))
126 'simple-base-string
))
127 (tricky-sequences #("/../" "../" "/.." "." "/." "./" "/./"
128 "[]" "*" "**" "/**" "**/" "/**/" "?"
129 "\\*" "\\[]" "\\?" "\\*\\*" "*\\*")))
131 for length
= (random 32)
132 for native-namestring
= (coerce
136 (random (length safe-chars
))))
138 for pathname
= (native-pathname native-namestring
)
139 for nnn
= (native-namestring pathname
)
141 ;; We canonicalize to \ as the directory separator
142 ;; on windows -- though both \ and / are legal.
143 (setf native-namestring
(substitute #\\ #\
/ native-namestring
))
144 (unless (string= nnn native-namestring
)
145 (error "1: wanted ~S, got ~S" native-namestring nnn
)))
147 for native-namestring
= (with-output-to-string (s)
148 (write-string "mu" s
)
150 (let ((r (random 1.0)))
152 ((< r
1/20) (return))
156 (random (length safe-chars
)))
159 (aref tricky-sequences
161 (length tricky-sequences
)))
163 for pathname
= (native-pathname native-namestring
)
164 for tricky-nnn
= (native-namestring pathname
)
166 ;; We canonicalize to \ as the directory separator
167 ;; on windows -- though both \ and / are legal.
168 (setf native-namestring
(substitute #\\ #\
/ native-namestring
))
169 (unless (string= tricky-nnn native-namestring
)
170 (error "2: wanted ~S, got ~S" native-namestring tricky-nnn
)))))
172 ;;; USER-HOMEDIR-PATHNAME and the extension SBCL-HOMEDIR-PATHNAME both
173 ;;; used to call PARSE-NATIVE-NAMESTRING without supplying a HOST
174 ;;; argument, and so would lose when *DEFAULT-PATHNAME-DEFAULTS* was a
175 ;;; logical pathname.
176 (with-test (:name
(user-homedir-pathname :robustness
))
177 (let ((*default-pathname-defaults
* (pathname "SYS:")))
178 (assert (not (typep (user-homedir-pathname)
179 'logical-pathname
)))))
181 (with-test (:name
(sb-int:sbcl-homedir-pathname
:robustness
))
182 (let ((*default-pathname-defaults
* (pathname "SYS:")))
183 (assert (not (typep (sb-int:sbcl-homedir-pathname
)
184 'logical-pathname
)))))
186 (with-test (:name
(file-author stringp
))
188 (assert (stringp (file-author (user-homedir-pathname))))
190 (assert (not (file-author (user-homedir-pathname)))))
191 (with-test (:name
(file-write-date integerp
))
192 (assert (integerp (file-write-date (user-homedir-pathname)))))
194 ;;; Canonicalization of pathnames for DIRECTORY
195 (with-test (:name
(directory :/.
))
196 (assert (equal (directory #p
".") (directory #p
"./")))
197 (assert (equal (directory #p
".") (directory #p
""))))
198 (with-test (:name
(directory :/..
))
199 (assert (equal (directory #p
"..") (directory #p
"../"))))
200 (with-test (:name
(directory :unspecific
))
201 (assert (equal (directory #p
".")
202 (directory (make-pathname
204 :type
:unspecific
)))))
206 ;;; This used to signal a TYPE-ERROR.
207 (with-test (:name
(directory :..
*))
208 (directory "somedir/..*"))
210 ;;; DIRECTORY used to treat */** as **.
211 (with-test (:name
(directory :*/**))
212 (assert (equal (directory "*/**/*.*")
213 (mapcan (lambda (directory)
214 (directory (merge-pathnames "**/*.*" directory
)))
218 ;;; (loop for exist in '(nil t)
220 ;;; (loop for (if-exists if-does-not-exist) in '((nil :error)
224 ;;; collect (list 'do-open exist if-exists if-does-not-exist)))
225 (with-test (:name
(open :never-openning
))
226 (flet ((do-open (existing if-exists if-does-not-exist
227 &optional
(direction :output
))
229 #.
(or *compile-file-truename
* *load-truename
*)
230 "a-really-non-existing-file")
232 :if-exists if-exists
:if-does-not-exist if-does-not-exist
)))
234 (do-open nil nil
:error
))
236 (do-open nil
:error nil
)))
238 (do-open t nil
:error
)))
240 (do-open t
:error nil
))
242 (do-open nil nil nil
)))
244 (do-open nil
:error
:error
))
246 (do-open t nil nil
)))
247 (assert-error (do-open t
:error
:error
))
250 (do-open nil nil
:error
:io
))
252 (do-open nil
:error nil
:io
)))
254 (do-open t nil
:error
:io
)))
256 (do-open t
:error nil
:io
))
258 (do-open nil nil nil
:io
)))
260 (do-open nil
:error
:error
:io
))
262 (do-open t nil nil
:io
)))
263 (assert-error (do-open t
:error
:error
:io
))))
265 (with-test (:name
(open :new-version
))
266 (multiple-value-bind (value error
)
267 (ignore-errors (open #.
(or *compile-file-truename
* *load-truename
*)
269 :if-exists
:new-version
))
272 (assert (equal (simple-condition-format-control error
)
273 "OPEN :IF-EXISTS :NEW-VERSION is not supported ~
274 when a new version must be created."))))