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 (let ((pathname0 (make-pathname :host nil
18 *default-pathname-defaults
*)
20 (pathname1 (make-pathname :host nil
23 (assert (equal (file-namestring pathname0
) "getty"))
24 (assert (equal (directory-namestring pathname0
)
25 (directory-namestring *default-pathname-defaults
*)))
26 (assert (equal (file-namestring pathname1
) ""))
27 (assert (equal (directory-namestring pathname1
) "")))
29 ;;; In sbcl-0.6.9 DIRECTORY failed on paths with :WILD or
30 ;;; :WILD-INFERIORS in their directory components.
31 (let ((dir (directory "../**/*.*")))
32 ;; We know a little bit about the structure of this result;
33 ;; let's test to make sure that this test file is in it.
34 (assert (find-if (lambda (pathname)
35 (search #-win32
"tests/filesys.pure.lisp"
36 #+win32
"tests\\filesys.pure.lisp"
37 (namestring pathname
)))
39 ;;; In sbcl-0.9.7 DIRECTORY failed on pathnames with character-set
41 (let ((dir (directory "[f]*.*")))
42 ;; We know a little bit about the structure of this result;
43 ;; let's test to make sure that this test file is in it.
44 (assert (find-if (lambda (pathname)
45 (search "filesys.pure.lisp"
46 (namestring pathname
)))
49 ;;; Set *default-pathname-defaults* to something other than the unix
50 ;;; cwd, to catch functions which access the filesystem without
51 ;;; merging properly. We should test more functions than just OPEN
54 (let ((*default-pathname-defaults
*
55 (make-pathname :directory
57 (pathname-directory *default-pathname-defaults
*))
58 :defaults
*default-pathname-defaults
*)))
59 ;; SBCL 0.7.1.2 failed to merge on OPEN
60 (with-open-file (i "tests/filesys.pure.lisp")
63 ;;; OPEN, LOAD and friends should signal an error of type FILE-ERROR
64 ;;; if they are fed wild pathname designators; firstly, with wild
65 ;;; pathnames that don't correspond to any files:
66 (assert (typep (nth-value 1 (ignore-errors (open "non-existent*.lisp")))
68 (assert (typep (nth-value 1 (ignore-errors (load "non-existent*.lisp")))
70 ;;; then for pathnames that correspond to precisely one:
71 (assert (typep (nth-value 1 (ignore-errors (open "filesys.pur*.lisp")))
73 (assert (typep (nth-value 1 (ignore-errors (load "filesys.pur*.lisp")))
75 ;;; then for pathnames corresponding to many:
76 (assert (typep (nth-value 1 (ignore-errors (open "*.lisp")))
78 (assert (typep (nth-value 1 (ignore-errors (load "*.lisp")))
81 ;;; ANSI: FILE-LENGTH should signal an error of type TYPE-ERROR if
82 ;;; STREAM is not a stream associated with a file.
84 ;;; (Peter Van Eynde's ansi-test suite caught this, and Eric Marsden
85 ;;; reported a fix for CMU CL, which was ported to sbcl-0.6.12.35.)
86 (assert (typep (nth-value 1 (ignore-errors (file-length *terminal-io
*)))
89 ;;; A few cases Windows does have enough marbles to pass right now
92 (assert (equal "C:\\FOO" (native-namestring "C:\\FOO")))
93 (assert (equal "C:\\FOO" (native-namestring "C:/FOO")))
94 (assert (equal "C:\\FOO\\BAR" (native-namestring "C:\\FOO\\BAR")))
95 ;; FIXME: Other platforms don't do this: either fix Windows
96 ;; so that it works even with the same logic others use, or
97 ;; make this official. (Currently just a kludge.)
98 (assert (equal "C:\\FOO\\BAR" (native-namestring "C:\\FOO\\BAR\\"))))
100 ;;; Test for NATIVE-PATHNAME / NATIVE-NAMESTRING stuff
102 ;;; given only safe characters in the namestring, NATIVE-PATHNAME will
103 ;;; never error, and NATIVE-NAMESTRING on the result will return the
104 ;;; original namestring.
105 (with-test (:name
:random-native-namestrings
)
109 (loop for x from
32 to
127 collect
(code-char x
)))
110 'simple-base-string
))
111 (tricky-sequences #("/../" "../" "/.." "." "/." "./" "/./"
112 "[]" "*" "**" "/**" "**/" "/**/" "?"
113 "\\*" "\\[]" "\\?" "\\*\\*" "*\\*")))
115 for length
= (random 32)
116 for native-namestring
= (coerce
120 (random (length safe-chars
))))
122 for pathname
= (native-pathname native-namestring
)
123 for nnn
= (native-namestring pathname
)
124 do
(assert (string= nnn native-namestring
)))
126 for native-namestring
= (with-output-to-string (s)
128 (let ((r (random 1.0)))
130 ((< r
1/20) (return))
134 (random (length safe-chars
)))
137 (aref tricky-sequences
139 (length tricky-sequences
)))
141 for pathname
= (native-pathname native-namestring
)
142 for tricky-nnn
= (native-namestring pathname
)
143 do
(assert (string= tricky-nnn native-namestring
)))))
145 ;;; USER-HOMEDIR-PATHNAME and the extension SBCL-HOMEDIR-PATHNAME both
146 ;;; used to call PARSE-NATIVE-NAMESTRING without supplying a HOST
147 ;;; argument, and so would lose when *DEFAULT-PATHNAME-DEFAULTS* was a
148 ;;; logical pathname.
149 (with-test (:name
:user-homedir-pathname-robustness
)
150 (let ((*default-pathname-defaults
* (pathname "SYS:")))
151 (assert (not (typep (user-homedir-pathname)
152 'logical-pathname
)))))
154 (with-test (:name
:sbcl-homedir-pathname-robustness
)
155 (let ((*default-pathname-defaults
* (pathname "SYS:")))
156 (assert (not (typep (sb-impl::sbcl-homedir-pathname
)
157 'logical-pathname
)))))