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 "\\*" "\\[]" "\\?" "\\*\\*" "*\\*")))
132 ;; We canonicalize to \ as the directory separator
133 ;; on windows -- though both \ and / are legal.
134 (substitute #\\ #\
/ s
)
136 ;; Consecutive separators become a single separator
137 (let ((p (search "//" s
)))
139 (canon (concatenate 'string
(subseq s
0 p
) (subseq s
(1+ p
))))
142 for length
= (random 32)
143 for native-namestring
= (coerce
147 (random (length safe-chars
))))
149 for pathname
= (native-pathname native-namestring
)
150 for nnn
= (native-namestring pathname
)
151 do
(setf native-namestring
(canon native-namestring
))
152 (unless (string= nnn native-namestring
)
153 (error "1: wanted ~S, got ~S" native-namestring nnn
)))
155 for native-namestring
= (with-output-to-string (s)
156 (write-string "mu" s
)
158 (let ((r (random 1.0)))
160 ((< r
1/20) (return))
164 (random (length safe-chars
)))
167 (aref tricky-sequences
169 (length tricky-sequences
)))
171 for pathname
= (native-pathname native-namestring
)
172 for tricky-nnn
= (native-namestring pathname
)
173 do
(setf native-namestring
(canon native-namestring
))
174 (unless (string= tricky-nnn native-namestring
)
175 (error "2: wanted ~S, got ~S" native-namestring tricky-nnn
))))))
177 ;;; USER-HOMEDIR-PATHNAME and the extension SBCL-HOMEDIR-PATHNAME both
178 ;;; used to call PARSE-NATIVE-NAMESTRING without supplying a HOST
179 ;;; argument, and so would lose when *DEFAULT-PATHNAME-DEFAULTS* was a
180 ;;; logical pathname.
181 (with-test (:name
(user-homedir-pathname :robustness
))
182 (let ((*default-pathname-defaults
* (pathname "SYS:")))
183 (assert (not (typep (user-homedir-pathname)
184 'logical-pathname
)))))
186 (with-test (:name
(sb-int:sbcl-homedir-pathname
:robustness
))
187 (let ((*default-pathname-defaults
* (pathname "SYS:")))
188 (assert (not (typep (sb-int:sbcl-homedir-pathname
)
189 'logical-pathname
)))))
191 (with-test (:name
(file-author stringp
))
193 (assert (stringp (file-author (user-homedir-pathname))))
195 (assert (not (file-author (user-homedir-pathname)))))
196 (with-test (:name
(file-write-date integerp
))
197 (assert (integerp (file-write-date (user-homedir-pathname)))))
199 ;;; Canonicalization of pathnames for DIRECTORY
200 (with-test (:name
(directory :/.
))
201 (assert (equal (directory #p
".") (directory #p
"./")))
202 (assert (equal (directory #p
".") (directory #p
""))))
203 (with-test (:name
(directory :/..
))
204 (assert (equal (directory #p
"..") (directory #p
"../"))))
205 (with-test (:name
(directory :unspecific
))
206 (assert (equal (directory #p
".")
207 (directory (make-pathname
209 :type
:unspecific
)))))
211 ;;; This used to signal a TYPE-ERROR.
212 (with-test (:name
(directory :..
*))
213 (directory "somedir/..*"))
215 ;;; DIRECTORY used to treat */** as **.
216 (with-test (:name
(directory :*/**))
217 (assert (equal (directory "*/**/*.*")
218 (mapcan (lambda (directory)
219 (directory (merge-pathnames "**/*.*" directory
)))
223 ;;; (loop for exist in '(nil t)
225 ;;; (loop for (if-exists if-does-not-exist) in '((nil :error)
229 ;;; collect (list 'do-open exist if-exists if-does-not-exist)))
230 (with-test (:name
(open :never-openning
))
231 (flet ((do-open (existing if-exists if-does-not-exist
232 &optional
(direction :output
))
234 #.
(or *compile-file-truename
* *load-truename
*)
235 "a-really-non-existing-file")
237 :if-exists if-exists
:if-does-not-exist if-does-not-exist
)))
239 (do-open nil nil
:error
))
241 (do-open nil
:error nil
)))
243 (do-open t nil
:error
)))
245 (do-open t
:error nil
))
247 (do-open nil nil nil
)))
249 (do-open nil
:error
:error
))
251 (do-open t nil nil
)))
252 (assert-error (do-open t
:error
:error
))
255 (do-open nil nil
:error
:io
))
257 (do-open nil
:error nil
:io
)))
259 (do-open t nil
:error
:io
)))
261 (do-open t
:error nil
:io
))
263 (do-open nil nil nil
:io
)))
265 (do-open nil
:error
:error
:io
))
267 (do-open t nil nil
:io
)))
268 (assert-error (do-open t
:error
:error
:io
))))
270 (with-test (:name
(open :new-version
))
271 (multiple-value-bind (value error
)
272 (ignore-errors (open #.
(or *compile-file-truename
* *load-truename
*)
274 :if-exists
:new-version
))
277 (assert (equal (simple-condition-format-control error
)
278 "OPEN :IF-EXISTS :NEW-VERSION is not supported ~
279 when a new version must be created."))))
281 (with-test (:name
:parse-native-namestring-canon
:skipped-on
'(not :unix
))
282 (let ((pathname (parse-native-namestring "foo/bar//baz")))
283 (assert (string= (car (last (pathname-directory pathname
))) "bar"))))