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 (in-package "CL-USER")
19 (load "assertoid.lisp")
21 (setf (logical-pathname-translations "demo0")
22 '(("**;*.*.*" "/tmp/")))
24 ;;; In case of a parse error we want to get a condition of type
25 ;;; CL:PARSE-ERROR (or more specifically, of type
26 ;;; SB-KERNEL:NAMESTRING-PARSE-ERROR).
28 (typep (grab-condition (translate-logical-pathname "demo0::bla;file.lisp"))
31 ;;; some things SBCL-0.6.9 used not to parse correctly:
33 ;;; SBCL used to throw an error saying there's no translation.
34 (assert (equal (namestring (translate-logical-pathname "demo0:file.lisp"))
36 ;;; We do not match a null directory to every wild path:
37 (assert (not (pathname-match-p "demo0:file.lisp"
38 (logical-pathname "demo0:tmp;**;*.*.*"))))
39 ;;; Remove "**" from our resulting pathname when the source-dir is NIL:
40 (setf (logical-pathname-translations "demo1")
41 '(("**;*.*.*" "/tmp/**/*.*") (";**;*.*.*" "/tmp/rel/**/*.*")))
42 (assert (not (equal (namestring (translate-logical-pathname "demo1:foo.lisp"))
44 ;;; That should be correct:
45 (assert (equal (namestring (translate-logical-pathname "demo1:foo.lisp"))
47 ;;; Check for absolute/relative path confusion:
48 (assert (not (equal (namestring (translate-logical-pathname "demo1:;foo.lisp"))
50 (assert (equal (namestring (translate-logical-pathname "demo1:;foo.lisp"))
53 ;;; Under SBCL: new function #'UNPARSE-ENOUGH-NAMESTRING, to
54 ;;; handle the following case exactly (otherwise we get an error:
55 ;;; "#'IDENTITY CALLED WITH 2 ARGS."
56 (setf (logical-pathname-translations "demo2")
57 '(("test;**;*.*" "/tmp/demo2/test")))
58 (enough-namestring "demo2:test;foo.lisp")
60 ;;; When a pathname comes from a logical host, it should be in upper
61 ;;; case. (This doesn't seem to be specifically required in the ANSI
62 ;;; spec, but it's left up to the implementors, and the arguments made
63 ;;; in the cleanup issue PATHNAME-LOGICAL:ADD seem to be a pretty
64 ;;; compelling reason for the implementors to choose case
65 ;;; insensitivity and a canonical case.)
66 (setf (logical-pathname-translations "FOO")
67 '(("**;*.*.*" "/full/path/to/foo/**/*.*.*")))
68 (let* ((pn1 (make-pathname :host "FOO" :directory "etc" :name "INETD"
70 (pn2 (make-pathname :host "foo" :directory "ETC" :name "inetd"
72 (pn3 (read-from-string (prin1-to-string pn1))))
73 (assert (equal pn1 pn2))
74 (assert (equal pn1 pn3)))
76 ;;; In addition to the upper-case constraint above, if the logical-pathname
77 ;;; contains a string component in e.g. the directory, name and type slot,
78 ;;; these should be valid "WORDS", according to CLHS 19.3.1.
79 ;;; FIXME: currently SBCL throws NAMESTRING-PARSE-ERROR: should this be
82 ;;; FIXME: These fail in sbcl-0.pre7.15 because of some problem with
83 ;;; interpreted UNLESS, so that e.g.
84 ;;; (ignore-errors (make-pathname :host "FOO" :directory "!bla" :name "bar"))
85 ;;; => NIL, #<SIMPLE-TYPE-ERROR {500C945D}>
86 ;;; (not (ignore-errors (make-pathname :host "FOO"
87 ;;; :directory "!bla" :name "bar")))
89 ;;; (unless (not (ignore-errors (make-pathname :host "FOO"
97 ;; error: directory-component not valid
98 (assert (not (ignore-errors
99 (make-pathname :host "FOO" :directory "!bla" :name "bar"))))
101 ;; error: name-component not valid
102 (assert (not (ignore-errors
103 (make-pathname :host "FOO" :directory "bla" :name "!bar"))))
105 ;; error: type-component not valid.
106 (assert (not (ignore-errors
107 (make-pathname :host "FOO" :directory "bla" :name "bar"
110 ;;; We may need to parse the host as a LOGICAL-NAMESTRING HOST. The
111 ;;; HOST in PARSE-NAMESTRING can be either a string or :UNSPECIFIC
112 ;;; without actually requiring the system to signal an error (apart
113 ;;; from host mismatches).
114 (assert (equal (namestring (parse-namestring "" "FOO")) "FOO:"))
115 (assert (equal (namestring (parse-namestring "" :unspecific)) ""))
118 ;;; The third would work if the call were (and it should continue to
122 (translate-logical-pathname
125 ;;; ANSI says PARSE-NAMESTRING returns TYPE-ERROR on host mismatch.
126 (let ((cond (grab-condition (parse-namestring "foo:jeamland" "demo2"))))
127 (assert (typep cond 'type-error)))
129 ;;; turning one logical pathname into another:
130 (setf (logical-pathname-translations "foo")
131 '(("tohome;*.*.*" "home:*.*.*")))
132 (assert (equal (namestring (translate-logical-pathname "foo:tohome;x.y"))
135 ;;; ANSI, in its wisdom, specifies that it's an error (specifically a
136 ;;; TYPE-ERROR) to query the system about the translations of a string
137 ;;; which doesn't have any translations. It's not clear why we don't
138 ;;; just return NIL in that case, but they make the rules..
139 (let ((cond (grab-condition (logical-pathname-translations "unregistered-host"))))
140 (assert (typep cond 'type-error)))
142 ;;; FIXME: A comment on this section up to sbcl-0.6.11.30 or so said
143 ;;; examples from CLHS: Section 19.4, LOGICAL-PATHNAME-TRANSLATIONS
144 ;;; (sometimes converted to the Un*x way of things)
145 ;;; but when I looked it up I didn't see the connection. Presumably
146 ;;; there's some code in this section which should be attributed
147 ;;; to something in the ANSI spec, but I don't know what code it is
148 ;;; or what section of the specification has the related code.
149 (setf (logical-pathname-translations "test0")
150 '(("**;*.*.*" "/library/foo/**/")))
151 (assert (equal (namestring (translate-logical-pathname
152 "test0:foo;bar;baz;mum.quux"))
153 "/library/foo/foo/bar/baz/mum.quux"))
154 (setf (logical-pathname-translations "prog")
155 '(("RELEASED;*.*.*" "MY-UNIX:/sys/bin/my-prog/")
156 ("RELEASED;*;*.*.*" "MY-UNIX:/sys/bin/my-prog/*/")
157 ("EXPERIMENTAL;*.*.*" "MY-UNIX:/usr/Joe/development/prog/")
158 ("EXPERIMENTAL;*;*.*.*" "MY-UNIX:/usr/Joe/development/prog/*/")))
159 (setf (logical-pathname-translations "prog")
160 '(("CODE;*.*.*" "/lib/prog/")))
161 (assert (equal (namestring (translate-logical-pathname
162 "prog:code;documentation.lisp"))
163 "/lib/prog/documentation.lisp"))
164 (setf (logical-pathname-translations "prog")
165 '(("CODE;DOCUMENTATION.*.*" "/lib/prog/docum.*")
166 ("CODE;*.*.*" "/lib/prog/")))
167 (assert (equal (namestring (translate-logical-pathname
168 "prog:code;documentation.lisp"))
169 "/lib/prog/docum.lisp"))
171 ;;; ANSI section 19.3.1.1.5 specifies that translation to a filesystem
172 ;;; which doesn't have versions should ignore the version slot. CMU CL
173 ;;; didn't ignore this as it should, but we do.
174 (assert (equal (namestring (translate-logical-pathname
175 "test0:foo;bar;baz;mum.quux.3"))
176 "/library/foo/foo/bar/baz/mum.quux"))
178 ;;;; MERGE-PATHNAME tests
180 ;;;; There are some things we don't bother testing, just because they're
181 ;;;; not meaningful on the underlying filesystem anyway.
183 ;;;; Mostly that means that we don't do devices, we don't do versions
184 ;;;; except minimally in LPNs (they get lost in the translation to
185 ;;;; physical hosts, so it's not much of an issue), and we don't do
186 ;;;; hosts except for LPN hosts
188 ;;;; Although these tests could conceivably be useful in principle for
189 ;;;; other implementations, they depend quite heavily on the rules for
190 ;;;; namestring parsing, which are implementation-specific. So, success
191 ;;;; or failure in these tests doesn't tell you anything about
192 ;;;; ANSI-compliance unless your PARSE-NAMESTRING works like ours.
194 (setf (logical-pathname-translations "scratch")
195 '(("**;*.*.*" "/usr/local/doc/**/*")))
197 (loop for (expected-result . params) in
199 (#P"/usr/local/doc/foo" #p"foo" #p"/usr/local/doc/")
200 ;; If pathname does not specify a host, device, directory,
201 ;; name, or type, each such component is copied from
203 ;; 1) no name, no type
204 (#p"/supplied-dir/name.type" #p"/supplied-dir/" #p"/dir/name.type")
205 ;; 2) no directory, no type
206 (#p"/dir/supplied-name.type" #p"supplied-name" #p"/dir/name.type")
207 ;; 3) no name, no dir (must use make-pathname as ".foo" is parsed
209 (#p"/dir/name.supplied-type"
210 ,(make-pathname :type "supplied-type")
212 ;; If (pathname-directory pathname) is a list whose car is
213 ;; :relative, and (pathname-directory default-pathname) is a
214 ;; list, then the merged directory is [...]
215 (#p"/aaa/bbb/ccc/ddd/qqq/www" #p"qqq/www" #p"/aaa/bbb/ccc/ddd/eee")
216 ;; except that if the resulting list contains a string or
217 ;; :wild immediately followed by :back, both of them are
219 (#P"/aaa/bbb/ccc/blah/eee"
220 ;; "../" in a namestring is parsed as :up not :back, so make-pathname
221 ,(make-pathname :directory '(:relative :back "blah"))
222 #p"/aaa/bbb/ccc/ddd/eee")
223 ;; If (pathname-directory default-pathname) is not a list or
224 ;; (pathname-directory pathname) is not a list whose car is
225 ;; :relative, the merged directory is (or (pathname-directory
226 ;; pathname) (pathname-directory default-pathname))
227 (#P"/absolute/path/name.type"
228 #p"/absolute/path/name"
229 #p"/dir/default-name.type")
230 ;; === logical pathnames ===
231 ;; recognizes a logical pathname namestring when
232 ;; default-pathname is a logical pathname
233 ;; FIXME: 0.6.12.23 fails this one.
234 #+nil (#P"scratch:foo;name1" #p"name1" #p"scratch:foo;")
235 ;; or when the namestring begins with the name of a defined
236 ;; logical host followed by a colon [I assume that refers to pathname
237 ;; rather than default-pathname]
238 (#p"SCRATCH:FOO;NAME2" #p"scratch:;name2" #p"scratch:foo;")
239 ;; conduct the previous set of tests again, with a lpn first argument
240 (#P"SCRATCH:USR;LOCAL;DOC;FOO" #p"scratch:;foo" #p"/usr/local/doc/")
241 (#p"SCRATCH:SUPPLIED-DIR;NAME.TYPE"
242 #p"scratch:supplied-dir;"
244 (#p"SCRATCH:DIR;SUPPLIED-NAME.TYPE"
245 #p"scratch:;supplied-name"
247 (#p"SCRATCH:DIR;NAME.SUPPLIED-TYPE"
248 ,(make-pathname :host "scratch" :type "supplied-type")
250 (#p"SCRATCH:AAA;BBB;CCC;DDD;FOO;BAR"
251 ,(make-pathname :host "scratch"
252 :directory '(:relative "foo")
254 #p"/aaa/bbb/ccc/ddd/eee")
255 (#p"SCRATCH:AAA;BBB;CCC;FOO;BAR"
256 ,(make-pathname :host "scratch"
257 :directory '(:relative :back "foo")
259 #p"/aaa/bbb/ccc/ddd/eee")
260 (#p"SCRATCH:ABSOLUTE;PATH;NAME.TYPE"
261 #p"scratch:absolute;path;name" #p"/dir/default-name.type")
263 ;; FIXME: test version handling in LPNs
265 do (assert (string= (namestring (apply #'merge-pathnames params))
266 (namestring expected-result))))
269 (quit :unix-status 104)