1 ;;;; miscellaneous tests of pathname-related stuff
3 ;;;; This file is naturally impure because we mess with
4 ;;;; LOGICAL-PATHNAME-TRANSLATIONS.
6 ;;;; This software is part of the SBCL system. See the README file for
9 ;;;; While most of SBCL is derived from the CMU CL system, the test
10 ;;;; files (like this one) were written from scratch after the fork
13 ;;;; This software is in the public domain and is provided with
14 ;;;; absolutely no warranty. See the COPYING and CREDITS files for
15 ;;;; more information.
17 (load "assertoid.lisp")
18 (use-package "ASSERTOID")
20 (setf (logical-pathname-translations "demo0")
21 '(("**;*.*.*" "/tmp/")))
23 ;;; In case of a parse error we want to get a condition of type
24 ;;; CL:PARSE-ERROR (or more specifically, of type
25 ;;; SB-KERNEL:NAMESTRING-PARSE-ERROR).
27 (typep (grab-condition (logical-pathname "demo0::bla;file.lisp"))
30 ;;; some things SBCL-0.6.9 used not to parse correctly:
32 ;;; SBCL used to throw an error saying there's no translation.
33 (assert (equal (namestring (translate-logical-pathname "demo0:file.lisp"))
35 ;;; We do not match a null directory to every wild path:
36 (assert (not (pathname-match-p "demo0:file.lisp"
37 (logical-pathname "demo0:tmp;**;*.*.*"))))
38 ;;; Remove "**" from our resulting pathname when the source-dir is NIL:
39 (setf (logical-pathname-translations "demo1")
40 '(("**;*.*.*" "/tmp/**/*.*") (";**;*.*.*" "/tmp/rel/**/*.*")))
41 (assert (not (equal (namestring (translate-logical-pathname "demo1:foo.lisp"))
43 ;;; That should be correct:
44 (assert (equal (namestring (translate-logical-pathname "demo1:foo.lisp"))
46 ;;; Check for absolute/relative path confusion:
47 (assert (not (equal (namestring (translate-logical-pathname "demo1:;foo.lisp"))
49 (assert (equal (namestring (translate-logical-pathname "demo1:;foo.lisp"))
52 ;;; Under SBCL: new function #'UNPARSE-ENOUGH-NAMESTRING, to
53 ;;; handle the following case exactly (otherwise we get an error:
54 ;;; "#'IDENTITY CALLED WITH 2 ARGS."
55 (setf (logical-pathname-translations "demo2")
56 '(("test;**;*.*" "/tmp/demo2/test")))
57 (enough-namestring "demo2:test;foo.lisp")
59 ;;; When a pathname comes from a logical host, it should be in upper
60 ;;; case. (This doesn't seem to be specifically required in the ANSI
61 ;;; spec, but it's left up to the implementors, and the arguments made
62 ;;; in the cleanup issue PATHNAME-LOGICAL:ADD seem to be a pretty
63 ;;; compelling reason for the implementors to choose case
64 ;;; insensitivity and a canonical case.)
65 (setf (logical-pathname-translations "FOO")
66 '(("**;*.*.*" "/full/path/to/foo/**/*.*.*")))
67 (let* ((pn1 (make-pathname :host
"FOO" :directory
"etc" :name
"INETD"
69 (pn2 (make-pathname :host
"foo" :directory
"ETC" :name
"inetd"
71 (pn3 (read-from-string (prin1-to-string pn1
))))
72 (assert (equal pn1 pn2
))
73 (assert (equal pn1 pn3
)))
75 ;;; In addition to the upper-case constraint above, if the logical-pathname
76 ;;; contains a string component in e.g. the directory, name and type slot,
77 ;;; these should be valid "WORDS", according to CLHS 19.3.1.
78 ;;; FIXME: currently SBCL throws NAMESTRING-PARSE-ERROR: should this be
82 ;; MAKE-PATHNAME is UNSAFELY-FLUSHABLE
83 (declare (optimize safety
))
85 (assert (not (ignore-errors
86 (make-pathname :host
"FOO" :directory
"!bla" :name
"bar"))))
88 ;; error: name-component not valid
89 (assert (not (ignore-errors
90 (make-pathname :host
"FOO" :directory
"bla" :name
"!bar"))))
92 ;; error: type-component not valid.
93 (assert (not (ignore-errors
94 (make-pathname :host
"FOO" :directory
"bla" :name
"bar"
97 ;;; We may need to parse the host as a LOGICAL-NAMESTRING HOST. The
98 ;;; HOST in PARSE-NAMESTRING can be either a string or :UNSPECIFIC
99 ;;; without actually requiring the system to signal an error (apart
100 ;;; from host mismatches).
101 (assert (equal (namestring (parse-namestring "" "FOO")) "FOO:"))
102 (assert (equal (namestring (parse-namestring "" :unspecific
)) ""))
104 ;;; The third would work if the call were (and it should continue to
108 (translate-logical-pathname
111 ;;; ANSI says PARSE-NAMESTRING returns TYPE-ERROR on host mismatch.
112 (let ((cond (grab-condition (parse-namestring "foo:jeamland" "demo2"))))
113 (assert (typep cond
'type-error
)))
115 ;;; turning one logical pathname into another:
116 (setf (logical-pathname-translations "foo")
117 '(("todemo;*.*.*" "demo0:*.*.*")))
118 (assert (equal (namestring (translate-logical-pathname "foo:todemo;x.y"))
119 (namestring (translate-logical-pathname "demo0:x.y"))))
121 ;;; ANSI, in its wisdom, specifies that it's an error (specifically a
122 ;;; TYPE-ERROR) to query the system about the translations of a string
123 ;;; which doesn't have any translations. It's not clear why we don't
124 ;;; just return NIL in that case, but they make the rules..
125 (let ((cond (grab-condition (logical-pathname-translations "unregistered-host"))))
126 (assert (typep cond
'type-error
)))
128 (assert (not (string-equal (host-namestring (parse-namestring "OTHER-HOST:ILLEGAL/LPN")) "OTHER-HOST")))
129 (assert (string-equal (pathname-name (parse-namestring "OTHER-HOST:ILLEGAL/LPN")) "LPN"))
131 ;;; FIXME: A comment on this section up to sbcl-0.6.11.30 or so said
132 ;;; examples from CLHS: Section 19.4, LOGICAL-PATHNAME-TRANSLATIONS
133 ;;; (sometimes converted to the Un*x way of things)
134 ;;; but when I looked it up I didn't see the connection. Presumably
135 ;;; there's some code in this section which should be attributed
136 ;;; to something in the ANSI spec, but I don't know what code it is
137 ;;; or what section of the specification has the related code.
138 (setf (logical-pathname-translations "test0")
139 '(("**;*.*.*" "/library/foo/**/")))
140 (assert (equal (namestring (translate-logical-pathname
141 "test0:foo;bar;baz;mum.quux"))
142 "/library/foo/foo/bar/baz/mum.quux"))
143 (setf (logical-pathname-translations "prog")
144 '(("RELEASED;*.*.*" "MY-UNIX:/sys/bin/my-prog/")
145 ("RELEASED;*;*.*.*" "MY-UNIX:/sys/bin/my-prog/*/")
146 ("EXPERIMENTAL;*.*.*" "MY-UNIX:/usr/Joe/development/prog/")
147 ("EXPERIMENTAL;*;*.*.*" "MY-UNIX:/usr/Joe/development/prog/*/")))
148 (setf (logical-pathname-translations "prog")
149 '(("CODE;*.*.*" "/lib/prog/")))
150 (assert (equal (namestring (translate-logical-pathname
151 "prog:code;documentation.lisp"))
152 "/lib/prog/documentation.lisp"))
153 (setf (logical-pathname-translations "prog")
154 '(("CODE;DOCUMENTATION.*.*" "/lib/prog/docum.*")
155 ("CODE;*.*.*" "/lib/prog/")))
156 (assert (equal (namestring (translate-logical-pathname
157 "prog:code;documentation.lisp"))
158 "/lib/prog/docum.lisp"))
160 ;;; ANSI section 19.3.1.1.5 specifies that translation to a filesystem
161 ;;; which doesn't have versions should ignore the version slot. CMU CL
162 ;;; didn't ignore this as it should, but we do.
163 (assert (equal (namestring (translate-logical-pathname
164 "test0:foo;bar;baz;mum.quux.3"))
165 "/library/foo/foo/bar/baz/mum.quux"))
167 ;;;; MERGE-PATHNAME tests
169 ;;;; There are some things we don't bother testing, just because they're
170 ;;;; not meaningful on the underlying filesystem anyway.
172 ;;;; Mostly that means that we don't do devices, we don't do versions
173 ;;;; except minimally in LPNs (they get lost in the translation to
174 ;;;; physical hosts, so it's not much of an issue), and we don't do
175 ;;;; hosts except for LPN hosts
177 ;;;; Although these tests could conceivably be useful in principle for
178 ;;;; other implementations, they depend quite heavily on the rules for
179 ;;;; namestring parsing, which are implementation-specific. So, success
180 ;;;; or failure in these tests doesn't tell you anything about
181 ;;;; ANSI-compliance unless your PARSE-NAMESTRING works like ours.
183 ;;; Needs to be done at compile time, so that the #p"" read-macro
184 ;;; correctly parses things as logical pathnames. This is not a
185 ;;; problem as was, as this is an impure file and so gets loaded in,
186 ;;; but just for future proofing...
187 (eval-when (:compile-toplevel
:load-toplevel
:execute
)
188 (setf (logical-pathname-translations "scratch")
189 '(("**;*.*.*" "/usr/local/doc/**/*"))))
191 (loop for
(expected-result . params
) in
193 (#P
"/usr/local/doc/foo" #p
"foo" #p
"/usr/local/doc/")
194 ;; If pathname does not specify a host, device, directory,
195 ;; name, or type, each such component is copied from
197 ;; 1) no name, no type
198 (#p
"/supplied-dir/name.type" #p
"/supplied-dir/" #p
"/dir/name.type")
199 ;; 2) no directory, no type
200 (#p
"/dir/supplied-name.type" #p
"supplied-name" #p
"/dir/name.type")
201 ;; 3) no name, no dir (must use make-pathname as ".foo" is parsed
203 (#p
"/dir/name.supplied-type"
204 ,(make-pathname :type
"supplied-type")
206 ;; If (pathname-directory pathname) is a list whose car is
207 ;; :relative, and (pathname-directory default-pathname) is a
208 ;; list, then the merged directory is [...]
209 (#p
"/aaa/bbb/ccc/ddd/qqq/www" #p
"qqq/www" #p
"/aaa/bbb/ccc/ddd/eee")
210 ;; except that if the resulting list contains a string or
211 ;; :wild immediately followed by :back, both of them are
213 (#P
"/aaa/bbb/ccc/blah/eee"
214 ;; "../" in a namestring is parsed as :up not :back, so make-pathname
215 ,(make-pathname :directory
'(:relative
:back
"blah"))
216 #p
"/aaa/bbb/ccc/ddd/eee")
217 ;; If (pathname-directory default-pathname) is not a list or
218 ;; (pathname-directory pathname) is not a list whose car is
219 ;; :relative, the merged directory is (or (pathname-directory
220 ;; pathname) (pathname-directory default-pathname))
221 (#P
"/absolute/path/name.type"
222 #p
"/absolute/path/name"
223 #p
"/dir/default-name.type")
224 ;; === logical pathnames ===
225 ;; recognizes a logical pathname namestring when
226 ;; default-pathname is a logical pathname
227 ;; FIXME: 0.6.12.23 fails this one.
229 ;; And, as it happens, it's right to fail it. Because
230 ;; #p"name1" is read in with the ambient *d-p-d* value, which
231 ;; has a physical (Unix) host; therefore, the host of the
232 ;; default-pathname argument to merge-pathnames is
233 ;; irrelevant. The result is (correctly) different if
234 ;; '#p"name1"' is replaced by "name1", below, though it's
235 ;; still not what one might expect... -- CSR, 2002-05-09
236 #+nil
(#P
"scratch:foo;name1" #p
"name1" #p
"scratch:foo;")
237 ;; or when the namestring begins with the name of a defined
238 ;; logical host followed by a colon [I assume that refers to pathname
239 ;; rather than default-pathname]
240 (#p
"SCRATCH:FOO;NAME2" #p
"scratch:;name2" #p
"scratch:foo;")
241 ;; conduct the previous set of tests again, with a lpn first argument
242 (#P
"SCRATCH:USR;LOCAL;DOC;FOO" #p
"scratch:;foo" #p
"/usr/local/doc/")
243 (#p
"SCRATCH:SUPPLIED-DIR;NAME.TYPE"
244 #p
"scratch:supplied-dir;"
246 (#p
"SCRATCH:DIR;SUPPLIED-NAME.TYPE"
247 #p
"scratch:;supplied-name"
249 (#p
"SCRATCH:DIR;NAME.SUPPLIED-TYPE"
250 ,(make-pathname :host
"scratch" :type
"supplied-type")
252 (#p
"SCRATCH:AAA;BBB;CCC;DDD;FOO;BAR"
253 ,(make-pathname :host
"scratch"
254 :directory
'(:relative
"foo")
256 #p
"/aaa/bbb/ccc/ddd/eee")
257 (#p
"SCRATCH:AAA;BBB;CCC;FOO;BAR"
258 ,(make-pathname :host
"scratch"
259 :directory
'(:relative
:back
"foo")
261 #p
"/aaa/bbb/ccc/ddd/eee")
262 (#p
"SCRATCH:ABSOLUTE;PATH;NAME.TYPE"
263 #p
"scratch:absolute;path;name" #p
"/dir/default-name.type")
265 ;; FIXME: test version handling in LPNs
267 do
(assert (string= (namestring (apply #'merge-pathnames params
))
268 (namestring expected-result
))))
270 ;;; host-namestring testing
272 (namestring (parse-namestring "/foo" (host-namestring #p
"/bar")))
275 (namestring (parse-namestring "FOO" (host-namestring #p
"SCRATCH:BAR")))
277 (assert (raises-error?
278 (setf (logical-pathname-translations "")
279 (list '("**;*.*.*" "/**/*.*")))))
281 ;;; Bug 200: translate-logical-pathname is according to the spec supposed
282 ;;; not to give errors if asked to translate a namestring for a valid
283 ;;; physical pathname. Failed in 0.7.7.28 and before
284 (assert (string= (namestring (translate-logical-pathname "/")) "/"))
287 ;;; Not strictly pathname logic testing, but until sbcl-0.7.6.19 we
288 ;;; had difficulty with non-FILE-STREAM stream arguments to pathname
289 ;;; functions (they would cause memory protection errors). Make sure
290 ;;; that those errors are gone:
291 (assert (raises-error?
(pathname (make-string-input-stream "FOO"))
293 (assert (raises-error?
(merge-pathnames (make-string-output-stream))
297 (quit :unix-status
104)