0.6.10.14:
[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 (load "assertoid.lisp")
20
21 (setf (logical-pathname-translations "demo0")
22       '(("**;*.*.*" "/tmp/")))
23
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).
27 (assert
28   (typep (grab-condition (translate-logical-pathname "demo0::bla;file.lisp"))
29          'parse-error))
30
31 ;;; some things SBCL-0.6.9 used not to parse correctly:
32 ;;;
33 ;;; SBCL used to throw an error saying there's no translation.
34 (assert (equal (namestring (translate-logical-pathname "demo0:file.lisp"))
35                "/tmp/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"))
43                     "/tmp/**/foo.lisp")))
44 ;;; That should be correct:
45 (assert (equal (namestring (translate-logical-pathname "demo1:foo.lisp"))
46                "/tmp/foo.lisp"))
47 ;;; Check for absolute/relative path confusion:
48 (assert (not (equal (namestring (translate-logical-pathname "demo1:;foo.lisp"))
49                      "tmp/rel/foo.lisp")))
50 (assert (equal (namestring (translate-logical-pathname "demo1:;foo.lisp"))
51                "/tmp/rel/foo.lisp"))
52                      
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")
59
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" 
69                            :type "conf"))
70        (pn2 (make-pathname :host "foo" :directory "ETC" :name "inetd" 
71                            :type "CONF"))
72        (pn3 (read-from-string (prin1-to-string pn1))))
73   (assert (equal pn1 pn2))
74   (assert (equal pn1 pn3)))
75
76 ;;; We may need to parse the host as a LOGICAL-NAMESTRING HOST. The
77 ;;; HOST in PARSE-NAMESTRING can be either a string or :UNSPECIFIC
78 ;;; without actually requiring the system to signal an error (apart
79 ;;; from host mismatches).
80 (assert (equal (namestring (parse-namestring "" "FOO")) "FOO:"))
81 (assert (equal (namestring (parse-namestring "" :unspecific)) ""))
82
83 ;;; The third would work if the call were (and it should continue to
84 ;;; work ...)
85 (parse-namestring ""
86                   (pathname-host
87                    (translate-logical-pathname
88                     "FOO:")))
89
90 ;;; ANSI says PARSE-NAMESTRING returns TYPE-ERROR on host mismatch.
91 (let ((cond (grab-condition (parse-namestring "foo:jeamland" "demo2"))))
92   (assert (typep cond 'type-error)))
93
94 ;;; ANSI, in its wisdom, specifies that it's an error (specifically a
95 ;;; TYPE-ERROR) to query the system about the translations of a string
96 ;;; which doesn't have any translations. It's not clear why we don't
97 ;;; just return NIL in that case, but they make the rules..
98 (let ((cond (grab-condition (logical-pathname-translations "unregistered-host"))))
99   (assert (typep cond 'type-error)))
100
101 ;;; examples from CLHS: Section 19.4, Logical Pathname Translations
102 ;;; (sometimes converted to the Un*x way of things)
103 (setf (logical-pathname-translations "test0")
104         '(("**;*.*.*"              "/library/foo/**/")))
105 (assert (equal (namestring (translate-logical-pathname
106                             "test0:foo;bar;baz;mum.quux.3"))
107                "/library/foo/foo/bar/baz/mum.quux.3"))
108 (setf (logical-pathname-translations "prog")
109         '(("RELEASED;*.*.*"        "MY-UNIX:/sys/bin/my-prog/")
110           ("RELEASED;*;*.*.*"      "MY-UNIX:/sys/bin/my-prog/*/")
111           ("EXPERIMENTAL;*.*.*"    "MY-UNIX:/usr/Joe/development/prog/")
112           ("EXPERIMENTAL;*;*.*.*"  "MY-UNIX:/usr/Joe/development/prog/*/")))
113 (setf (logical-pathname-translations "prog")
114         '(("CODE;*.*.*"             "/lib/prog/")))
115 (assert (equal (namestring (translate-logical-pathname
116                             "prog:code;documentation.lisp"))
117                "/lib/prog/documentation.lisp"))
118 (setf (logical-pathname-translations "prog")
119         '(("CODE;DOCUMENTATION.*.*" "/lib/prog/docum.*")
120           ("CODE;*.*.*"             "/lib/prog/")))
121 (assert (equal (namestring (translate-logical-pathname
122                             "prog:code;documentation.lisp"))
123                "/lib/prog/docum.lisp"))
124
125 ;;; success
126 (quit :unix-status 104)