Make INFO's compiler-macro more forgiving.
[sbcl.git] / tests / pathnames.impure.lisp
blob9e84b90b225db0985fdc701589b43926899079da
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
7 ;;;; more information.
8 ;;;;
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
11 ;;;; from CMU CL.
12 ;;;;
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 (load "test-util.lisp")
21 (use-package "TEST-UTIL")
23 (setf (logical-pathname-translations "demo0")
24 '(("**;*.*.*" "/tmp/")))
26 ;;; In case of a parse error we want to get a condition of type TYPE-ERROR,
27 ;;; because ANSI says so. (This used to be PARSE-ERROR.)
28 (assert
29 (typep (grab-condition (logical-pathname "demo0::bla;file.lisp"))
30 'type-error))
32 ;;; some things SBCL-0.6.9 used not to parse correctly:
33 ;;;
34 ;;; SBCL used to throw an error saying there's no translation.
35 (with-test (:name (:logical-pathname 1))
36 (assert (equal (namestring (translate-logical-pathname "demo0:file.lisp"))
37 "/tmp/file.lisp")))
39 ;;; We do not match a null directory to every wild path:
40 (with-test (:name (:logical-pathname 2))
41 (assert (not (pathname-match-p "demo0:file.lisp"
42 (logical-pathname "demo0:tmp;**;*.*.*")))))
44 ;;; Remove "**" from our resulting pathname when the source-dir is NIL:
45 (with-test (:name (:logical-pathname 3))
46 (setf (logical-pathname-translations "demo1")
47 '(("**;*.*.*" "/tmp/**/*.*") (";**;*.*.*" "/tmp/rel/**/*.*")))
48 (assert (not (equal (namestring (translate-logical-pathname "demo1:foo.lisp"))
49 "/tmp/**/foo.lisp"))))
51 ;;; That should be correct:
52 (with-test (:name (:logical-pathname 4))
53 (assert (equal (namestring (translate-logical-pathname "demo1:foo.lisp"))
54 "/tmp/foo.lisp")))
56 ;;; Check for absolute/relative path confusion:
57 (with-test (:name (:logical-pathname 5))
58 (assert (not (equal (namestring (translate-logical-pathname "demo1:;foo.lisp"))
59 "tmp/rel/foo.lisp")))
60 (assert (equal (namestring (translate-logical-pathname "demo1:;foo.lisp"))
61 "/tmp/rel/foo.lisp")))
63 ;;; Under SBCL: new function #'UNPARSE-ENOUGH-NAMESTRING, to
64 ;;; handle the following case exactly (otherwise we get an error:
65 ;;; "#'IDENTITY CALLED WITH 2 ARGS."
66 (with-test (:name (:logical-pathname 6))
67 (setf (logical-pathname-translations "demo2")
68 '(("test;**;*.*" "/tmp/demo2/test")))
69 (enough-namestring "demo2:test;foo.lisp"))
71 ;;; When a pathname comes from a logical host, it should be in upper
72 ;;; case. (This doesn't seem to be specifically required in the ANSI
73 ;;; spec, but it's left up to the implementors, and the arguments made
74 ;;; in the cleanup issue PATHNAME-LOGICAL:ADD seem to be a pretty
75 ;;; compelling reason for the implementors to choose case
76 ;;; insensitivity and a canonical case.)
77 (with-test (:name (:logical-pathname 7))
78 (setf (logical-pathname-translations "FOO")
79 '(("**;*.*.*" "/full/path/to/foo/**/*.*")))
80 (let* ((pn1 (make-pathname :host "FOO" :directory "etc" :name "INETD"
81 :type "conf"))
82 (pn2 (make-pathname :host "foo" :directory "ETC" :name "inetd"
83 :type "CONF"))
84 (pn3 (read-from-string (prin1-to-string pn1))))
85 (assert (equal pn1 pn2))
86 (assert (equal pn1 pn3))))
88 ;;; In addition to the upper-case constraint above, if the logical-pathname
89 ;;; contains a string component in e.g. the directory, name and type slot,
90 ;;; these should be valid "WORDS", according to CLHS 19.3.1.
91 ;;; FIXME: currently SBCL throws NAMESTRING-PARSE-ERROR: should this be
92 ;;; a TYPE-ERROR?
93 (with-test (:name (:logical-pathname 8))
94 (locally
95 ;; MAKE-PATHNAME is UNSAFELY-FLUSHABLE
96 (declare (optimize safety))
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"
108 :type "&baz"))))))
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 (with-test (:name (:logical-pathname 9))
115 (assert (equal (namestring (parse-namestring "" "FOO")) "FOO:"))
116 (assert (equal (namestring (parse-namestring "" :unspecific)) "")))
118 ;;; The third would work if the call were (and it should continue to
119 ;;; work ...)
120 (with-test (:name (:logical-pathname 10))
121 (parse-namestring ""
122 (pathname-host
123 (translate-logical-pathname
124 "FOO:"))))
126 ;;; ANSI says PARSE-NAMESTRING returns TYPE-ERROR on host mismatch.
127 (with-test (:name (:logical-pathname 11))
128 (let ((cond (grab-condition (parse-namestring "foo:jeamland" "demo2"))))
129 (assert (typep cond 'type-error))))
131 ;;; turning one logical pathname into another:
132 (with-test (:name (:logical-pathname 12))
133 (setf (logical-pathname-translations "foo")
134 '(("todemo;*.*.*" "demo0:*.*.*")))
135 (assert (equal (namestring (translate-logical-pathname "foo:todemo;x.y"))
136 (namestring (translate-logical-pathname "demo0:x.y")))))
138 ;;; ANSI, in its wisdom, specifies that it's an error (specifically a
139 ;;; TYPE-ERROR) to query the system about the translations of a string
140 ;;; which doesn't have any translations. It's not clear why we don't
141 ;;; just return NIL in that case, but they make the rules..
142 (with-test (:name (:logical-pathname 13))
143 (let ((cond (grab-condition (logical-pathname-translations "unregistered-host"))))
144 (assert (typep cond 'type-error)))
146 (assert (not (string-equal (host-namestring (parse-namestring "OTHER-HOST:ILLEGAL/LPN")) "OTHER-HOST")))
147 (assert (string-equal (pathname-name (parse-namestring "OTHER-HOST:ILLEGAL/LPN")) "LPN")))
149 ;;; FIXME: A comment on this section up to sbcl-0.6.11.30 or so said
150 ;;; examples from CLHS: Section 19.4, LOGICAL-PATHNAME-TRANSLATIONS
151 ;;; (sometimes converted to the Un*x way of things)
152 ;;; but when I looked it up I didn't see the connection. Presumably
153 ;;; there's some code in this section which should be attributed
154 ;;; to something in the ANSI spec, but I don't know what code it is
155 ;;; or what section of the specification has the related code.
156 (with-test (:name (:logical-pathname 14))
157 (setf (logical-pathname-translations "test0")
158 '(("**;*.*.*" "/library/foo/**/")))
159 (assert (equal (namestring (translate-logical-pathname
160 "test0:foo;bar;baz;mum.quux"))
161 "/library/foo/foo/bar/baz/mum.quux"))
162 (setf (logical-pathname-translations "prog")
163 '(("RELEASED;*.*.*" "MY-UNIX:/sys/bin/my-prog/")
164 ("RELEASED;*;*.*.*" "MY-UNIX:/sys/bin/my-prog/*/")
165 ("EXPERIMENTAL;*.*.*" "MY-UNIX:/usr/Joe/development/prog/")
166 ("EXPERIMENTAL;*;*.*.*" "MY-UNIX:/usr/Joe/development/prog/*/")))
167 (setf (logical-pathname-translations "prog")
168 '(("CODE;*.*.*" "/lib/prog/")))
169 (assert (equal (namestring (translate-logical-pathname
170 "prog:code;documentation.lisp"))
171 "/lib/prog/documentation.lisp"))
172 (setf (logical-pathname-translations "prog")
173 '(("CODE;DOCUMENTATION.*.*" "/lib/prog/docum.*")
174 ("CODE;*.*.*" "/lib/prog/")))
175 (assert (equal (namestring (translate-logical-pathname
176 "prog:code;documentation.lisp"))
177 "/lib/prog/docum.lisp")))
179 ;;; ANSI section 19.3.1.1.5 specifies that translation to a filesystem
180 ;;; which doesn't have versions should ignore the version slot. CMU CL
181 ;;; didn't ignore this as it should, but we do.
182 (with-test (:name (:logical-pathname 15))
183 (assert (equal (namestring (translate-logical-pathname
184 "test0:foo;bar;baz;mum.quux.3"))
185 "/library/foo/foo/bar/baz/mum.quux")))
188 ;;;; MERGE-PATHNAME tests
189 ;;;;
190 ;;;; There are some things we don't bother testing, just because they're
191 ;;;; not meaningful on the underlying filesystem anyway.
192 ;;;;
193 ;;;; Mostly that means that we don't do devices, we don't do versions
194 ;;;; except minimally in LPNs (they get lost in the translation to
195 ;;;; physical hosts, so it's not much of an issue), and we don't do
196 ;;;; hosts except for LPN hosts
197 ;;;;
198 ;;;; Although these tests could conceivably be useful in principle for
199 ;;;; other implementations, they depend quite heavily on the rules for
200 ;;;; namestring parsing, which are implementation-specific. So, success
201 ;;;; or failure in these tests doesn't tell you anything about
202 ;;;; ANSI-compliance unless your PARSE-NAMESTRING works like ours.
204 ;;; Needs to be done at compile time, so that the #p"" read-macro
205 ;;; correctly parses things as logical pathnames. This is not a
206 ;;; problem as was, as this is an impure file and so gets loaded in,
207 ;;; but just for future proofing...
208 (eval-when (:compile-toplevel :load-toplevel :execute)
209 (setf (logical-pathname-translations "scratch")
210 '(("**;*.*.*" "/usr/local/doc/**/*"))))
212 (with-test (:name (:merge-pathname 1))
213 (loop for (expected-result . params) in
214 `( ;; trivial merge
215 (#P"/usr/local/doc/foo" #p"foo" #p"/usr/local/doc/")
216 ;; If pathname does not specify a host, device, directory,
217 ;; name, or type, each such component is copied from
218 ;; default-pathname.
219 ;; 1) no name, no type
220 (#p"/supplied-dir/name.type" #p"/supplied-dir/" #p"/dir/name.type")
221 ;; 2) no directory, no type
222 (#p"/dir/supplied-name.type" #p"supplied-name" #p"/dir/name.type")
223 ;; 3) no name, no dir (must use make-pathname as ".foo" is parsed
224 ;; as a name)
225 (#p"/dir/name.supplied-type"
226 ,(make-pathname :type "supplied-type")
227 #p"/dir/name.type")
228 ;; If (pathname-directory pathname) is a list whose car is
229 ;; :relative, and (pathname-directory default-pathname) is a
230 ;; list, then the merged directory is [...]
231 (#p"/aaa/bbb/ccc/ddd/qqq/www" #p"qqq/www" #p"/aaa/bbb/ccc/ddd/eee")
232 ;; except that if the resulting list contains a string or
233 ;; :wild immediately followed by :back, both of them are
234 ;; removed.
235 (#P"/aaa/bbb/ccc/blah/eee"
236 ;; "../" in a namestring is parsed as :up not :back, so make-pathname
237 ,(make-pathname :directory '(:relative :back "blah"))
238 #p"/aaa/bbb/ccc/ddd/eee")
239 ;; If (pathname-directory default-pathname) is not a list or
240 ;; (pathname-directory pathname) is not a list whose car is
241 ;; :relative, the merged directory is (or (pathname-directory
242 ;; pathname) (pathname-directory default-pathname))
243 (#P"/absolute/path/name.type"
244 #p"/absolute/path/name"
245 #p"/dir/default-name.type")
246 ;; === logical pathnames ===
247 ;; recognizes a logical pathname namestring when
248 ;; default-pathname is a logical pathname
249 ;; FIXME: 0.6.12.23 fails this one.
251 ;; And, as it happens, it's right to fail it. Because
252 ;; #p"name1" is read in with the ambient *d-p-d* value, which
253 ;; has a physical (Unix) host; therefore, the host of the
254 ;; default-pathname argument to merge-pathnames is
255 ;; irrelevant. The result is (correctly) different if
256 ;; '#p"name1"' is replaced by "name1", below, though it's
257 ;; still not what one might expect... -- CSR, 2002-05-09
258 #+nil (#P"scratch:foo;name1" #p"name1" #p"scratch:foo;")
259 ;; or when the namestring begins with the name of a defined
260 ;; logical host followed by a colon [I assume that refers to pathname
261 ;; rather than default-pathname]
262 (#p"SCRATCH:FOO;NAME2" #p"scratch:;name2" #p"scratch:foo;")
263 ;; conduct the previous set of tests again, with a lpn first argument
264 (#P"SCRATCH:USR;LOCAL;DOC;FOO" #p"scratch:;foo" #p"/usr/local/doc/")
265 (#p"SCRATCH:SUPPLIED-DIR;NAME.TYPE"
266 #p"scratch:supplied-dir;"
267 #p"/dir/name.type")
268 (#p"SCRATCH:DIR;SUPPLIED-NAME.TYPE"
269 #p"scratch:;supplied-name"
270 #p"/dir/name.type")
271 (#p"SCRATCH:DIR;NAME.SUPPLIED-TYPE"
272 ,(make-pathname :host "scratch" :type "supplied-type")
273 #p"/dir/name.type")
274 (#p"SCRATCH:AAA;BBB;CCC;DDD;FOO;BAR"
275 ,(make-pathname :host "scratch"
276 :directory '(:relative "foo")
277 :name "bar")
278 #p"/aaa/bbb/ccc/ddd/eee")
279 (#p"SCRATCH:AAA;BBB;CCC;FOO;BAR"
280 ,(make-pathname :host "scratch"
281 :directory '(:relative :back "foo")
282 :name "bar")
283 #p"/aaa/bbb/ccc/ddd/eee")
284 (#p"SCRATCH:ABSOLUTE;PATH;NAME.TYPE"
285 #p"scratch:absolute;path;name" #p"/dir/default-name.type")
287 ;; FIXME: test version handling in LPNs
289 do (let ((result (apply #'merge-pathnames params)))
290 (macrolet ((frob (op)
291 `(assert (equal (,op result) (,op expected-result)))))
292 (frob pathname-host)
293 (frob pathname-directory)
294 (frob pathname-name)
295 (frob pathname-type)))))
297 ;;; host-namestring testing
298 (with-test (:name :host-namestring)
299 (assert (string=
300 (namestring (parse-namestring "/foo" (host-namestring #p"/bar")))
301 "/foo"))
302 (assert (string=
303 (namestring (parse-namestring "FOO" (host-namestring #p"SCRATCH:BAR")))
304 "SCRATCH:FOO"))
305 (assert-error
306 (setf (logical-pathname-translations "")
307 (list '("**;*.*.*" "/**/*.*")))))
309 ;;; Bug 200: translate-logical-pathname is according to the spec supposed
310 ;;; not to give errors if asked to translate a namestring for a valid
311 ;;; physical pathname. Failed in 0.7.7.28 and before
312 (with-test (:name (:logical-pathname 16))
313 (assert (string= (namestring (translate-logical-pathname "/")) "/")))
316 ;;; Not strictly pathname logic testing, but until sbcl-0.7.6.19 we
317 ;;; had difficulty with non-FILE-STREAM stream arguments to pathname
318 ;;; functions (they would cause memory protection errors). Make sure
319 ;;; that those errors are gone:
320 (with-test (:name (:string-streams-as-pathnames 1))
321 (assert-error (pathname (make-string-input-stream "FOO"))
322 type-error)
323 (assert-error (merge-pathnames (make-string-output-stream))
324 type-error))
326 ;;; ensure print-read consistency (or print-not-readable-error) on
327 ;;; pathnames:
328 (with-test (:name :print/read-consistency)
329 (let ((pathnames (list
330 (make-pathname :name "foo" :type "txt" :version :newest)
331 (make-pathname :name "foo" :type "txt" :version 1)
332 (make-pathname :name "foo" :type ".txt")
333 (make-pathname :name "foo." :type "txt")
334 (make-pathname :name "\\" :type "txt")
335 (make-pathname :name "^" :type "txt")
336 (make-pathname :name "foo*" :type "txt")
337 (make-pathname :name "foo[" :type "txt")
338 (parse-namestring "SCRATCH:FOO.TXT.1")
339 (parse-namestring "SCRATCH:FOO.TXT.NEWEST")
340 (parse-namestring "SCRATCH:FOO.TXT"))))
341 (dolist (p pathnames)
342 (print p)
343 (handler-case
344 (let* ((*print-readably* t)
345 (new (read-from-string (format nil "~S" p))))
346 (unless (equal new p)
347 (let ((*print-readably* nil))
348 (error "oops: host:~S device:~S dir:~S version:~S~% ->~%~
349 host:~S device:~S dir:~S version:~S"
350 (pathname-host p) (pathname-device p)
351 (pathname-directory p) (pathname-version p)
352 (pathname-host new) (pathname-device new)
353 (pathname-directory new) (pathname-version new)))))
354 (print-not-readable ()
355 nil)))))
357 ;;; BUG 330: "PARSE-NAMESTRING should accept namestrings as the
358 ;;; default argument" ...and streams as well
359 (with-test (:name :parse-namestring/stream)
360 (assert (equal (parse-namestring "foo" nil "/")
361 (parse-namestring "foo" nil #P"/")))
362 (let ((test "parse-namestring-test.tmp"))
363 (unwind-protect
364 (with-open-file (f test :direction :output)
365 ;; FIXME: This test is a bit flaky, since we only check that
366 ;; no error is signalled. The dilemma here is "what is the
367 ;; correct result when defaults is a _file_, not a
368 ;; directory". Currently (0.8.10.73) we get #P"foo" here (as
369 ;; opposed to eg. #P"/path/to/current/foo"), which is
370 ;; possibly mildly surprising but probably conformant.
371 (assert (parse-namestring "foo" nil f)))
372 (when (probe-file test)
373 (delete-file test)))))
375 ;;; ENOUGH-NAMESTRING should probably not fail when the namestring in
376 ;;; question has a :RELATIVE pathname.
377 (with-test (:name :enough-namestring)
378 (assert (equal (enough-namestring #p"foo" #p"./") "foo")))
380 ;;; bug reported by Artem V. Andreev: :WILD not handled in unparsing
381 ;;; directory lists.
382 (with-test (:name :unparse-wild)
383 (assert (equal (namestring #p"/tmp/*/") "/tmp/*/")))
385 ;;; Printing of pathnames; see CLHS 22.1.3.1. This section was started
386 ;;; to confirm that pathnames are printed as their namestrings under
387 ;;; :escape nil :readably nil.
388 (with-test (:name :print-as-namestrings)
389 (loop for (pathname expected . vars) in
390 `((#p"/foo" "#P\"/foo\"")
391 (#p"/foo" "#P\"/foo\"" :readably nil)
392 (#p"/foo" "#P\"/foo\"" :escape nil)
393 (#p"/foo" "/foo" :readably nil :escape nil))
394 for actual = (with-standard-io-syntax
395 (apply #'write-to-string pathname vars))
396 do (assert (string= expected actual)
398 "~S should be ~S, was ~S"
399 (list* 'write-to-string pathname vars)
400 expected
401 actual)))
403 ;;; we got (truename "/") wrong for about 6 months. Check that it's
404 ;;; still right.
405 (with-test (:name :root-truename)
406 (let ((pathname (truename "/")))
407 (assert (equalp pathname (merge-pathnames #p"/")))
408 (assert (equal (pathname-directory pathname) '(:absolute)))))
410 ;;; we failed to unparse logical pathnames with :NAME :WILD :TYPE NIL.
411 ;;; (Reported by Pascal Bourguignon.
412 (with-test (:name :unparse-logical-wild)
413 (let ((pathname (make-pathname :host "SYS" :directory '(:absolute :wild-inferiors)
414 :name :wild :type nil)))
415 (assert (string= (namestring pathname) "SYS:**;*"))
416 (assert (string= (write-to-string pathname :readably t) "#P\"SYS:**;*\""))))
418 ;;; reported by James Y Knight on sbcl-devel 2006-05-17
419 (with-test (:name :merge-back)
420 (let ((p1 (make-pathname :directory '(:relative "bar")))
421 (p2 (make-pathname :directory '(:relative :back "foo"))))
422 (assert (equal (merge-pathnames p1 p2)
423 (make-pathname :directory '(:relative :back "foo" "bar"))))))
425 ;;; construct native namestrings even if the directory is empty (means
426 ;;; that same as if (:relative))
427 (with-test (:name :native-namestring)
428 (assert (equal (sb-ext:native-namestring (make-pathname :directory '(:relative)
429 :name "foo"
430 :type "txt"))
431 (sb-ext:native-namestring (let ((p (make-pathname :directory nil
432 :name "foo"
433 :type "txt")))
434 (assert (not (pathname-directory p)))
435 p)))))
437 ;;; reported by Richard Kreuter: PATHNAME and MERGE-PATHNAMES used to
438 ;;; be unsafely-flushable. Since they are known to return non-nil values
439 ;;; only, the test-node of the IF is flushed, and since the function
440 ;;; is unsafely-flushable, out it goes, and bad pathname designators
441 ;;; breeze through.
443 ;;; These tests rely on using a stream that appears as a file-stream
444 ;;; but isn't a valid pathname-designator.
445 (with-test (:name :dont-flush-pathnames)
446 (assert (eq :false
447 (if (ignore-errors (pathname sb-sys::*tty*)) :true :false)))
448 (assert (eq :false
449 (if (ignore-errors (merge-pathnames sb-sys::*tty*)) :true :false))))
451 ;;; This used to return "quux/bar.lisp"
452 (with-test (:name :dpd-output-file)
453 (assert (equal #p"quux/bar.fasl"
454 (let ((*default-pathname-defaults* #p"quux/"))
455 (compile-file-pathname "foo.lisp" :output-file "bar"))))
456 (assert (equal #p"quux/bar.fasl"
457 (let ((*default-pathname-defaults* #p"quux/"))
458 (compile-file-pathname "bar.lisp")))))
460 (with-test (:name :wild-enough)
461 (enough-namestring #p".a*"))
464 (with-test (:name :translated-wild-version)
465 (assert (eq 99
466 (pathname-version
467 (translate-pathname
468 (make-pathname :name "foo" :type "bar" :version 99)
469 (make-pathname :name :wild :type :wild :version :wild)
470 (make-pathname :name :wild :type :wild :version :wild)))))
472 (assert (eq 99
473 (pathname-version
474 (translate-pathname
475 (make-pathname :name "foo" :type "bar" :version 99)
476 (make-pathname :name :wild :type :wild :version :wild)
477 (make-pathname :name :wild :type :wild :version nil))))))
479 ;;; enough-namestring relative to root
480 (with-test (:name :enough-relative-to-root)
481 (assert (equal "foo" (enough-namestring "/foo" "/"))))
483 ;;; Check the handling of NIL, :UNSPECIFIC, the empty string, and
484 ;;; non-NIL strings in NATIVE-NAMESTRING implementations. Revised by
485 ;;; RMK 2007-11-28, attempting to preserve the apparent intended
486 ;;; denotation of SBCL's then-current pathname implementation.
487 (with-test (:name (:native-namestring 2))
488 (assert (equal
489 (loop with components = (list nil :unspecific "" "a")
490 for name in components
491 appending (loop for type in components
492 as pathname = (make-pathname
493 #+win32 :device #+win32 "C"
494 :directory '(:absolute "tmp")
495 :name name :type type)
496 collect (ignore-errors
497 (sb-ext:native-namestring pathname))))
498 #-win32
499 #|type NIL :UNSPECIFIC "" "a" |#
500 #|name |#
501 #|NIL |# '("/tmp/" "/tmp/" NIL NIL
502 #|:UNSPECIFIC|# "/tmp/" "/tmp/" NIL NIL
503 #|"" |# "/tmp/" "/tmp/" "/tmp/." "/tmp/.a"
504 #|"a" |# "/tmp/a" "/tmp/a" "/tmp/a." "/tmp/a.a")
506 #+win32
507 #|type NIL :UNSPECIFIC "" "a" |#
508 #|name |#
509 #|NIL |# '("C:\\tmp\\" "C:\\tmp\\" NIL NIL
510 #|:UNSPECIFIC|# "C:\\tmp\\" "C:\\tmp\\" NIL NIL
511 #|"" |# "C:\\tmp\\" "C:\\tmp\\" "C:\\tmp\\." "C:\\tmp\\.a"
512 #|"a" |# "C:\\tmp\\a" "C:\\tmp\\a" "C:\\tmp\\a." "C:\\tmp\\a.a"))))
514 (with-test (:name :delete-file-logical-pathname)
515 (setf (logical-pathname-translations "SB-TEST")
516 (list (list "**;*.*.*" (make-pathname :name :wild
517 :type :wild
518 :defaults (truename ".")))))
519 (let ((test (pathname "SB-TEST:delete-logical-pathname.tmp")))
520 (assert (typep test 'logical-pathname))
521 (with-open-file (f test :direction :output)
522 (write-line "delete me!" f))
523 (assert (probe-file test))
524 (assert (delete-file test))
525 (assert (not (probe-file test)))))
527 (with-test (:name :logical-pathname-type-error)
528 (assert (eq :type-error-ok
529 (handler-case (logical-pathname "FOO.txt")
530 (type-error () :type-error-ok))))
531 (assert (eq :type-error-ok
532 (handler-case (logical-pathname "SYS:%")
533 (type-error () :type-error-ok)))))
535 ;;; Reported by Willem Broekema: Reading #p"\\\\" caused an error due
536 ;;; to insufficient sanity in input testing in EXTRACT-DEVICE (in
537 ;;; src;code;win32-pathname).
538 (with-test (:name :bug-489698 :skipped-on '(not :win32))
539 (assert (equal (make-pathname :directory '(:absolute))
540 (read-from-string "#p\"\\\\\\\\\""))))
542 (with-test (:name :load-logical-pathname-translations)
543 (let* ((cwd (truename "."))
544 (foo (merge-pathnames "llpnt-foo.translations" cwd))
545 (bar (merge-pathnames "llpnt-bar.translations" cwd))
546 (translations (logical-pathname-translations "SYS")))
547 (unwind-protect
548 (progn
549 (with-open-file (f foo :direction :output)
550 (prin1 (list (list "*.TEXT" (make-pathname
551 :directory '(:absolute "my" "foo")
552 :name :wild :type "txt")))
554 (with-open-file (f bar :direction :output)
555 (prin1 (list (list "*.CL" (make-pathname
556 :directory '(:absolute "my" "bar")
557 :name :wild :type "lisp"))) f))
558 (setf (logical-pathname-translations "SYS")
559 (list* (list "SITE;LLPNT-FOO.TRANSLATIONS.NEWEST" foo)
560 (list "SITE;LLPNT-BAR.TRANSLATIONS.NEWEST" bar)
561 translations))
562 (assert (load-logical-pathname-translations "LLPNT-FOO"))
563 (assert (load-logical-pathname-translations "LLPNT-BAR"))
564 (assert
565 (and
566 (equal "/my/bar/quux.lisp"
567 (namestring (translate-logical-pathname "LLPNT-BAR:QUUX.CL")))
568 (equal "/my/foo/quux.txt"
569 (namestring (translate-logical-pathname "LLPNT-FOO:QUUX.TEXT"))))))
570 (ignore-errors (delete-file foo))
571 (ignore-errors (delete-file bar))
572 (setf (logical-pathname-translations "SYS") translations))))
574 (with-test (:name :tilde-expansion)
575 (assert (equal '(:absolute :home "foo") (pathname-directory "~/foo/bar.txt")))
576 (assert (equal '(:absolute (:home "jdoe") "quux") (pathname-directory "~jdoe/quux/")))
577 (assert (equal "~/foo/x" (namestring (make-pathname :directory '(:absolute :home "foo")
578 :name "x"))))
579 (assert (equal (native-namestring (merge-pathnames "a/b.c" (user-homedir-pathname)))
580 (native-namestring #p"~/a/b.c")))
581 ;; Not a directory.
582 (assert (equal (native-namestring #p"~foo") "~foo"))
583 ;; Not at the start of the first directory
584 (assert (equal (native-namestring #p"foo/~/bar")
585 #-win32 "foo/~/bar"
586 #+win32 "foo\\~\\bar"))
587 (equal (native-namestring (merge-pathnames "~/"))
588 (native-namestring (user-homedir-pathname))))
590 ;;; lp#673625
591 (with-test (:name :pathname-escape-first-directory-component
592 :fails-on :win32)
593 ;; ~ / :HOME
594 (assert (equal (pathname-directory #p"\\~/foo/") '(:relative "~" "foo")))
595 (assert (equal (native-namestring #p"\\~/foo/") "~/foo/"))
596 (assert (equal (namestring (make-pathname :directory '(:absolute "~zot")))
597 "\\~zot/"))
598 ;; * / :WILD
599 (assert (equal (pathname-directory #p"\\*/") '(:relative "*"))))
601 (with-test (:name :ensure-directories-exist-with-odd-d-p-d)
602 (let ((*default-pathname-defaults* #p"/tmp/foo"))
603 (ensure-directories-exist "/")))
605 (with-test (:name :long-file-name :skipped-on '(not :win32))
606 (let* ((x '("hint--if-you-are-having-trouble-deleting-this-test-directory"
607 "use-the-7zip-file-manager"))
608 (base (truename
609 (directory-namestring (or *load-pathname* *compile-file-pathname*))))
610 (shallow (make-pathname :directory `(:relative ,(car x))))
611 (shallow (merge-pathnames shallow base))
612 (deep (make-pathname
613 :directory `(:relative ,@(loop repeat 10 appending x))))
614 (deep (merge-pathnames deep base))
615 (native (sb-ext:native-namestring deep)))
616 (assert (> (length native) 260))
617 (assert (eql 3 (mismatch "\\\\?" native)))
618 (assert (not (probe-file shallow)))
619 (unwind-protect
620 (progn
621 (ensure-directories-exist deep)
622 (assert (probe-file deep)))
623 (sb-ext:delete-directory shallow :recursive t))
624 (assert (not (probe-file shallow)))))
626 #+unix
627 (with-test (:name :simplify-namestring)
628 (assert (string= (sb-int:simplify-namestring "./a/b/../c/")
629 "a/c/")))
631 (with-test (:name :back-and-truename)
632 (probe-file (make-pathname :directory '(:absolute "a" "b" :back))))
634 ;;;; success