0.6.9.8:
[sbcl.git] / tests / pathnames.impure.lisp
1 ;;;; miscellaneous tests of pathname-related stuff
2
3 ;;;; This file is naturally impure because we mess with
4 ;;;; LOGICAL-PATHNAME-TRANSLATIONS.
5
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.
16
17 (in-package "CL-USER")
18
19 (eval-when (:compile-toplevel :load-toplevel :execute)
20   (defmacro grab-condition (&body body)
21     `(nth-value 1
22       (ignore-errors ,@body))))
23
24 (setf (logical-pathname-translations "demo0")
25       '(("**;*.*.*" "/tmp/")))
26
27 ;;; In case of a parse error we want to get a condition of type
28 ;;; CL:PARSE-ERROR (or more specifically, of type
29 ;;; SB-KERNEL:NAMESTRING-PARSE-ERROR).
30 (assert
31   (typep (grab-condition (translate-logical-pathname "demo0::bla;file.lisp"))
32          'parse-error))
33
34 ;;; some things SBCL-0.6.9 used not to parse correctly:
35 ;;;
36 ;;; SBCL used to throw an error saying there's no translation.
37 (assert (equal (namestring (translate-logical-pathname "demo0:file.lisp"))
38                "/tmp/file.lisp"))
39 ;;; We do not match a null directory to every wild path:
40 (assert (not (pathname-match-p "demo0:file.lisp"
41                                (logical-pathname "demo0:tmp;**;*.*.*"))))
42 ;;; Remove "**" from our resulting pathname when the source-dir is NIL:
43 (setf (logical-pathname-translations "demo1")
44       '(("**;*.*.*" "/tmp/**/*.*") (";**;*.*.*" "/tmp/rel/**/*.*")))
45 (assert (not (equal (namestring (translate-logical-pathname "demo1:foo.lisp"))
46                     "/tmp/**/foo.lisp")))
47 ;;; That should be correct:
48 (assert (equal (namestring (translate-logical-pathname "demo1:foo.lisp"))
49                "/tmp/foo.lisp"))
50 ;;; Check for absolute/relative path confusion:
51 (assert (not (equal (namestring (translate-logical-pathname "demo1:;foo.lisp"))
52                      "tmp/rel/foo.lisp")))
53 (assert (equal (namestring (translate-logical-pathname "demo1:;foo.lisp"))
54                "/tmp/rel/foo.lisp"))
55                      
56 ;;; Under SBCL: new function #'UNPARSE-ENOUGH-NAMESTRING, to
57 ;;; handle the following case exactly (otherwise we get an error:
58 ;;; "#'IDENTITY CALLED WITH 2 ARGS."
59 (setf (logical-pathname-translations "demo2")
60         '(("test;**;*.*" "/tmp/demo2/test/")))
61 (enough-namestring "demo2:test;foo.lisp")
62
63 ;;; When a pathname comes from a logical host, it should be in upper
64 ;;; case. (This doesn't seem to be specifically required in the ANSI
65 ;;; spec, but it's left up to the implementors, and the arguments made
66 ;;; in the cleanup issue PATHNAME-LOGICAL:ADD seem to be a pretty
67 ;;; compelling reason for the implementors to choose case
68 ;;; insensitivity and a canonical case.)
69 (setf (logical-pathname-translations "FOO") 
70       '(("**;*.*.*" "/full/path/to/foo/**/*.*.*")))
71 (let* ((pn1 (make-pathname :host "FOO" :directory "etc" :name "INETD" 
72                            :type "conf"))
73        (pn2 (make-pathname :host "foo" :directory "ETC" :name "inetd" 
74                            :type "CONF"))
75        (pn3 (read-from-string (prin1-to-string pn1))))
76   (assert (equal pn1 pn2))
77   (assert (equal pn1 pn3)))
78
79 ;;; We may need to parse the host as a LOGICAL-NAMESTRING HOST. The
80 ;;; HOST in PARSE-NAMESTRING can be either a string or :UNSPECIFIC
81 ;;; without actually requiring the system to signal an error (apart
82 ;;; from host mismatches).
83 (assert (equal (namestring (parse-namestring "" "FOO")) "FOO:"))
84 (assert (equal (namestring (parse-namestring "" :unspecific)) ""))
85
86 ;;; The third would work if the call were (and it should continue to
87 ;;; work ...)
88 (parse-namestring ""
89                   (pathname-host
90                    (translate-logical-pathname
91                     "FOO:")))
92
93 ;;; ANSI, in its wisdom, specifies that it's an error (specifically a
94 ;;; TYPE-ERROR) to query the system about the translations of a string
95 ;;; which doesn't have any translations. It's not clear why we don't
96 ;;; just return NIL in that case, but they make the rules..
97 (let ((cond (grab-condition (logical-pathname-translations "unregistered-host"))))
98   (assert (typep cond 'type-error)))
99
100 ;;; examples from CLHS: Section 19.4, Logical Pathname Translations
101 ;;; (sometimes converted to the Un*x way of things)
102 (setf (logical-pathname-translations "test0")
103         '(("**;*.*.*"              "/library/foo/**/")))
104 (assert (equal (namestring (translate-logical-pathname
105                             "test0:foo;bar;baz;mum.quux.3"))
106                "/library/foo/foo/bar/baz/mum.quux.3"))
107 (setf (logical-pathname-translations "prog")
108         '(("RELEASED;*.*.*"        "MY-UNIX:/sys/bin/my-prog/")
109           ("RELEASED;*;*.*.*"      "MY-UNIX:/sys/bin/my-prog/*/")
110           ("EXPERIMENTAL;*.*.*"    "MY-UNIX:/usr/Joe/development/prog/")
111           ("EXPERIMENTAL;*;*.*.*"  "MY-UNIX:/usr/Joe/development/prog/*/")))
112 (setf (logical-pathname-translations "prog")
113         '(("CODE;*.*.*"             "/lib/prog/")))
114 (assert (equal (namestring (translate-logical-pathname
115                             "prog:code;documentation.lisp"))
116                "/lib/prog/documentation.lisp"))
117 (setf (logical-pathname-translations "prog")
118         '(("CODE;DOCUMENTATION.*.*" "/lib/prog/docum.*")
119           ("CODE;*.*.*"             "/lib/prog/")))
120 (assert (equal (namestring (translate-logical-pathname
121                             "prog:code;documentation.lisp"))
122                "/lib/prog/docum.lisp"))
123
124 ;;; success
125 (quit :unix-status 104)
126 (in-package :cl-user)