source: trunk/j/src/org/armedbear/lisp/tests/pathname-tests.lisp @ 10981

Last change on this file since 10981 was 10981, checked in by piso, 18 years ago

SILLY.2, PHYSICAL.30: changes for cmucl.

File size: 51.8 KB
Line 
1;;; pathname-tests.lisp
2;;;
3;;; Copyright (C) 2005 Peter Graves
4;;; $Id: pathname-tests.lisp,v 1.51 2006-02-03 17:42:07 piso Exp $
5;;;
6;;; This program is free software; you can redistribute it and/or
7;;; modify it under the terms of the GNU General Public License
8;;; as published by the Free Software Foundation; either version 2
9;;; of the License, or (at your option) any later version.
10;;;
11;;; This program is distributed in the hope that it will be useful,
12;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14;;; GNU General Public License for more details.
15;;;
16;;; You should have received a copy of the GNU General Public License
17;;; along with this program; if not, write to the Free Software
18;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
20(load (merge-pathnames "test-utilities.lisp" *load-truename*))
21
22(in-package #:test)
23
24(defun check-physical-pathname (pathname expected-directory expected-name expected-type)
25  (let* ((directory (pathname-directory pathname))
26         (name (pathname-name pathname))
27         (type (pathname-type pathname))
28         (ok t))
29    (unless (and (pathnamep pathname)
30                 (not (typep pathname 'logical-pathname)))
31      (setf ok nil))
32    (unless (and (equal directory expected-directory)
33                 (equal name expected-name)
34                 (equal type expected-type))
35      (setf ok nil))
36    ok))
37
38(defun check-windows-pathname (pathname expected-host expected-device
39                                        expected-directory expected-name
40                                        expected-type)
41  (let* ((host (pathname-host pathname))
42         (device (pathname-device pathname))
43         (directory (pathname-directory pathname))
44         (name (pathname-name pathname))
45         (type (pathname-type pathname))
46         (ok t))
47    (unless (and (pathnamep pathname)
48                 (not (typep pathname 'logical-pathname)))
49      (setf ok nil))
50    (unless (and (equal host expected-host)
51                 (equal device expected-device)
52                 (equal directory expected-directory)
53                 (equal name expected-name)
54                 (equal type expected-type))
55      (setf ok nil))
56    ok))
57
58(defun check-logical-pathname (pathname expected-host expected-directory
59                                        expected-name expected-type
60                                        expected-version)
61  (let* ((host (pathname-host pathname))
62         (directory (pathname-directory pathname))
63         (name (pathname-name pathname))
64         (type (pathname-type pathname))
65         (version (pathname-version pathname))
66         ;; Allegro's logical pathnames don't canonicalize their string
67         ;; components to upper case.
68         (test #-allegro 'equal
69               #+allegro 'equalp)
70         (ok t))
71    (unless (typep pathname 'logical-pathname)
72      (setf ok nil))
73    ;; "The device component of a logical pathname is always :UNSPECIFIC..." 19.3.2.1
74    #-allegro ;; Except on Allegro, where it's NIL.
75    (unless (eq (pathname-device pathname) :unspecific)
76      (setf ok nil))
77    (unless (and (funcall test (if (stringp host) host
78                                    (host-namestring pathname))
79                          expected-host)
80                 (funcall test directory expected-directory)
81                 (funcall test name expected-name)
82                 (funcall test type expected-type)
83                 (eql version expected-version))
84      (setf ok nil))
85    ok))
86
87(defun check-merge-pathnames (pathname default-pathname expected-result)
88  (let* ((result (merge-pathnames pathname default-pathname))
89         (test #-allegro 'equal
90               #+allegro (if (typep result 'logical-pathname)
91                             'equalp
92                             'equal)))
93    (and (funcall test (pathname-host result) (pathname-host expected-result))
94         (funcall test (pathname-directory result) (pathname-directory expected-result))
95         (funcall test (pathname-name result) (pathname-name expected-result))
96         (funcall test (pathname-type result) (pathname-type expected-result)))))
97
98(defun check-translate-pathname (args expected)
99  (declare (optimize safety))
100  (declare (type list args))
101  (declare (type string expected))
102  (let ((result (namestring (apply 'translate-pathname args))))
103    (equal result
104           #-windows expected
105           #+windows (substitute #\\ #\/ expected))))
106
107(defmacro check-readable (pathname)
108  `(equal ,pathname (read-from-string (write-to-string ,pathname :readably t))))
109
110(defun check-readable-or-signals-error (pathname)
111  (handler-case
112      (equal pathname (read-from-string (write-to-string pathname :readably t)))
113    (print-not-readable () t)))
114
115(defmacro check-namestring (pathname namestring)
116  `(string= (namestring ,pathname)
117            #+windows (substitute #\\ #\/ ,namestring)
118            #-windows ,namestring))
119
120;; Define a logical host.
121(setf (logical-pathname-translations "effluvia")
122      '(("**;*.*.*" "/usr/local/**/*.*")))
123
124(deftest equal.1
125  (equal (make-pathname :name "foo" :type "bar")
126         (make-pathname :name "foo" :type "bar"))
127  t)
128
129(deftest equal.2
130  (equal (make-pathname :name "foo" :type "bar" :version nil)
131         (make-pathname :name "foo" :type "bar" :version :newest))
132  #+(or clisp lispworks) nil
133  #-(or clisp lispworks) t)
134
135(deftest sxhash.1
136  (let* ((p (make-pathname :name "foo" :type "bar" :version nil))
137         (s (sxhash p)))
138    (values (typep s 'fixnum)
139            (>= s 0)))
140  t t)
141
142;; "(equal x y) implies (= (sxhash x) (sxhash y))"
143(deftest sxhash.2
144  (let ((p1 (make-pathname :name "foo" :type "bar" :version nil))
145        (p2 (make-pathname :name "foo" :type "bar" :version :newest)))
146    (if (equal p1 p2)
147        (= (sxhash p1) (sxhash p2))
148        t))
149  t)
150
151;; It's suboptimal if all pathnames return the same SXHASH, but that happens
152;; with SBCL.
153(deftest sxhash.3
154  (= (sxhash #p"/usr/local/bin/sbcl") (sxhash #p"") (sxhash #p"foo.bar"))
155  #+sbcl t
156  #-sbcl nil)
157
158;; "Parsing a null string always succeeds, producing a pathname with all
159;; components (except the host) equal to nil."
160(deftest physical.1
161  (check-physical-pathname #p"" nil nil nil)
162  t)
163
164(deftest physical.2
165  (check-physical-pathname #p"/" '(:absolute) nil nil)
166  t)
167
168(deftest physical.3
169  (check-physical-pathname #p"/foo" '(:absolute) "foo" nil)
170  t)
171
172(deftest physical.4
173  #-lispworks
174  (check-physical-pathname #p"/foo." '(:absolute) "foo" "")
175  #+lispworks
176  (check-physical-pathname #p"/foo." '(:absolute) "foo." nil)
177  t)
178
179(deftest physical.5
180  (check-physical-pathname #p"/foo.bar" '(:absolute) "foo" "bar")
181  t)
182
183(deftest physical.6
184  #-lispworks
185  (check-physical-pathname #p"/foo.bar." '(:absolute) "foo.bar" "")
186  #+lispworks
187  (check-physical-pathname #p"/foo.bar." '(:absolute) "foo.bar." nil)
188  t)
189
190(deftest physical.7
191  (check-physical-pathname #p"/foo.bar.baz" '(:absolute) "foo.bar" "baz")
192  t)
193
194(deftest physical.8
195  (check-physical-pathname #p"/foo/bar" '(:absolute "foo") "bar" nil)
196  t)
197
198(deftest physical.9
199  (check-physical-pathname #p"/foo..bar" '(:absolute) "foo." "bar")
200  t)
201
202(deftest physical.10
203  (check-physical-pathname #p"foo.bar" nil "foo" "bar")
204  t)
205
206(deftest physical.11
207  (check-physical-pathname #p"foo.bar.baz" nil "foo.bar" "baz")
208  t)
209
210(deftest physical.12
211  (check-physical-pathname #p"foo/" '(:relative "foo") nil nil)
212  t)
213
214(deftest physical.13
215  (check-physical-pathname #p"foo/bar" '(:relative "foo") "bar" nil)
216  t)
217
218(deftest physical.14
219  (check-physical-pathname #p"foo/bar/baz" '(:relative "foo" "bar") "baz" nil)
220  t)
221
222(deftest physical.15
223  (check-physical-pathname #p"foo/bar/" '(:relative "foo" "bar") nil nil)
224  t)
225
226#+allegro
227(deftest physical.16
228  ;; This reduction is wrong.
229  (check-physical-pathname #p"foo/bar/.." '(:relative "foo") nil nil)
230  t)
231
232#+allegro
233(deftest physical.17
234  (check-physical-pathname #p"/foo/../" '(:absolute) nil nil)
235  t)
236
237(deftest physical.18
238  #-lispworks
239  (check-physical-pathname #p".lisprc" nil ".lisprc" nil)
240  #+lispworks
241  (check-physical-pathname #p".lisprc" nil "" "lisprc")
242  t)
243
244(deftest physical.19
245  (check-physical-pathname #p"x.lisprc" nil "x" "lisprc")
246  t)
247
248(deftest physical.20
249  #-allegro
250  (check-physical-pathname (make-pathname :name ".") nil "." nil)
251  #+allegro
252  (check-physical-pathname (make-pathname :name ".") '(:relative) nil nil)
253  t)
254
255(deftest physical.21
256  #-cmu
257  (check-readable (make-pathname :name "."))
258  #+cmu
259  (check-readable-or-signals-error (make-pathname :name "."))
260  t)
261#+(or cmu lispworks (and allegro windows))
262(pushnew 'physical.21 *expected-failures*)
263
264;; #p"."
265(deftest physical.22
266  #+(or allegro abcl cmu)
267  (check-physical-pathname #p"." '(:relative) nil nil)
268  #-(or allegro abcl cmu)
269  ;; No trailing separator character means it's a file.
270  (check-physical-pathname #p"." nil "." nil)
271  t)
272#+lispworks
273(pushnew 'physical.22 *expected-failures*)
274
275(deftest namestring.1
276  (check-namestring #p"."
277                    #+(or abcl allegro cmu) "./"
278                    #-(or abcl allegro cmu) ".")
279  t)
280#+lispworks
281(pushnew 'namestring.1 *expected-failures*)
282
283(deftest physical.23
284  (equal #p"." #p"")
285  nil)
286#+lispworks
287(pushnew 'physical.23 *expected-failures*)
288
289;; #p"./"
290;; Trailing separator character means it's a directory.
291(deftest physical.24
292  (let ((pathname #-windows #p"./"
293                  #+windows #p".\\"))
294    #-(or sbcl)
295    (check-physical-pathname pathname '(:relative) nil nil)
296    #+(or sbcl)
297    ;; Is this more exact?
298    (check-physical-pathname pathname '(:relative ".") nil nil))
299  t)
300#+(or lispworks (and allegro windows))
301(pushnew 'physical.24 *expected-failures*)
302
303(deftest namestring.2
304  (check-namestring #-windows #p"./"
305                    #+windows #p".\\"
306                    "./")
307  t)
308#+lispworks
309(pushnew 'namestring.2 *expected-failures*)
310
311(deftest directory-namestring.1
312  (equal (directory-namestring #-windows #p"./"
313                               #+windows #p".\\")
314         #-windows "./"
315         #+windows ".\\")
316  t)
317#+lispworks
318(pushnew 'directory-namestring.1 *expected-failures*)
319
320(deftest physical.25
321  (equal #-windows #p"./"
322         #+windows #p".\\"
323         #p"")
324  nil)
325#+(or lispworks (and allegro windows))
326(pushnew 'physical.25 *expected-failures*)
327
328(deftest physical.26
329  #-allegro
330  (check-physical-pathname (make-pathname :name "..") nil ".." nil)
331  #+allegro
332  (check-physical-pathname (make-pathname :name "..") '(:relative :back) nil nil)
333  t)
334
335#-(or sbcl)
336(deftest physical.27
337  #-cmu
338  (check-readable (make-pathname :name ".."))
339  #+cmu
340  (check-readable-or-signals-error (make-pathname :name ".."))
341  t)
342#+(or clisp cmu lispworks)
343(pushnew 'physical.27 *expected-failures*)
344
345;; #p".."
346(deftest physical.28
347  #+(or allegro (and lispworks windows))
348  (check-physical-pathname #p".." '(:relative :back) nil nil)
349  #+(or abcl cmu (and lispworks unix))
350  (check-physical-pathname #p".." '(:relative :up) nil nil)
351  ;; Other implementations think it's a file.
352  #+(or)
353  ;; If it's a file, to a human its name would be "..". No implementation gets
354  ;; this right.
355  (check-physical-pathname #p".." nil ".." nil)
356  #+(or sbcl clisp)
357  ;; These implementations parse ".." as the name "." followed by another dot and
358  ;; the type string "", which no human would do.
359  (check-physical-pathname #p".." nil "." "")
360  t)
361#+cmu
362(pushnew 'physical.28 *expected-failures*)
363
364(deftest namestring.3
365  (check-namestring #p".."
366                    #+(or abcl allegro cmu lispworks) "../"
367                    #-(or abcl allegro cmu lispworks) "..")
368  t)
369
370;; #p"../"
371(deftest physical.29
372  (let ((pathname #-windows #p"../"
373                  #+windows #p"..\\"))
374    #+(or allegro (and lispworks windows))
375    (check-physical-pathname pathname '(:relative :back) nil nil)
376    #+(or abcl sbcl cmu clisp (and lispworks unix))
377    (check-physical-pathname pathname '(:relative :up) nil nil))
378  t)
379
380(deftest namestring.4
381  (check-namestring #-windows #p"../"
382                    #+windows #p"..\\"
383                    "../")
384  t)
385
386(deftest directory-namestring.2
387  (equal (directory-namestring #-windows #p"../"
388                               #+windows #p"..\\")
389         #-windows "../"
390         #+windows "..\\")
391  t)
392
393#-sbcl
394(deftest physical.30
395  #-(or allegro cmu)
396  (string= (namestring (make-pathname :name "..")) "..")
397  #+allegro
398  (string= (namestring (make-pathname :name ".."))
399           #-windows "../"
400           #+windows "..\\")
401  #+cmu
402  (signals-error (make-pathname :name "..") 'warning)
403  t)
404
405(deftest physical.31
406  (string= (namestring (make-pathname :directory '(:relative :up)))
407           #+windows "..\\"
408           #-windows "../")
409  t)
410
411#+windows
412(deftest windows.1
413  (equal #p"/foo/bar/baz" #p"\\foo\\bar\\baz")
414  t)
415
416#+windows
417(deftest windows.2
418  (let ((pathname #p"foo.bar"))
419    (check-windows-pathname pathname nil nil nil "foo" "bar"))
420  t)
421
422#+windows
423(deftest windows.3
424  (let ((pathname #p"\\foo.bar"))
425    (check-windows-pathname pathname nil nil '(:absolute) "foo" "bar"))
426  t)
427
428#+windows
429(deftest windows.4
430  (let ((pathname #p"c:\\foo.bar"))
431    #+(or abcl allegro)
432    (check-windows-pathname pathname nil "c" '(:absolute) "foo" "bar")
433    #+clisp
434    (check-windows-pathname pathname nil "C" '(:absolute) "foo" "bar")
435    #+lispworks
436    (check-windows-pathname pathname "c" nil '(:absolute) "foo" "bar"))
437  t)
438
439#+windows
440(deftest windows.5
441  (equal #p"c:\\foo.bar" #p"C:\\FOO.BAR")
442  t)
443
444(deftest wild.1
445  (check-physical-pathname #p"foo.*" nil "foo" :wild)
446  t)
447
448(deftest wild.2
449  (check-physical-pathname #p"*.*" nil :wild :wild)
450  t)
451
452(deftest wild.3
453  #-(or cmu sbcl)
454  (check-physical-pathname #p"abc*" nil "abc*" nil)
455  #+(or cmu sbcl)
456  (wild-pathname-p #p"abc*")
457  t)
458
459(deftest wild.4
460  #-(or cmu sbcl)
461  (check-physical-pathname #p"abc?" nil "abc?" nil)
462  #+(or cmu sbcl)
463  (wild-pathname-p #p"abc?")
464  t)
465
466(deftest wild.5
467  #-(or cmu sbcl)
468  (check-physical-pathname #p"abc[d-h]" nil "abc[d-h]" nil)
469  #+(or cmu sbcl)
470  (wild-pathname-p #p"abc[d-h]")
471  t)
472
473;; Lots of dots.
474#+(or allegro abcl cmu)
475(deftest lots-of-dots.1
476  (check-physical-pathname #p"..." nil "..." nil)
477  t)
478#+cmu
479(pushnew 'lots-of-dots.1 *expected-failures*)
480
481#+(or allegro abcl cmu)
482(deftest lots-of-dots.2
483  (check-physical-pathname #p"......" nil "......" nil)
484  t)
485#+cmu
486(pushnew 'lots-of-dots.2 *expected-failures*)
487
488;; Silly names.
489#-(or allegro sbcl)
490(deftest silly.1
491  #+(or abcl clisp)
492  (signals-error (make-pathname :name "abc/def") 'error)
493  #-(or abcl clisp)
494  (check-readable (make-pathname :name "abc/def"))
495  t)
496#+(or cmu lispworks)
497(pushnew 'silly.1 *expected-failures*)
498
499(deftest silly.2
500  (signals-error (make-pathname :name "abc/def")
501                 #-cmu 'error
502                 #+cmu 'warning)
503  t)
504
505(deftest silly.3
506  (check-readable-or-signals-error (make-pathname :name ".foo"))
507  t)
508
509(deftest silly.4
510  (check-readable-or-signals-error (make-pathname :type ".foo"))
511  t)
512
513(deftest silly.5
514  (check-readable-or-signals-error (make-pathname :name "abc.def"))
515  t)
516
517(deftest silly.6
518  (check-readable-or-signals-error (make-pathname :type "abc.def"))
519  t)
520
521;; LOGICAL-PATHNAME-TRANSLATIONS
522#-allegro
523(deftest logical-pathname-translations.1
524  #+(or sbcl cmu lispworks)
525  (equal (logical-pathname-translations "effluvia")
526         '(("**;*.*.*" "/usr/local/**/*.*")))
527  #+clisp
528  (equal (logical-pathname-translations "effluvia")
529         '((#p"EFFLUVIA:**;*.*.*" "/usr/local/**/*.*")))
530  #+abcl
531  (equal (logical-pathname-translations "effluvia")
532         '((#p"EFFLUVIA:**;*.*.*" #p"/usr/local/**/*.*")))
533  t)
534
535;; "The null string, "", is not a valid value for any component of a logical
536;; pathname." 19.3.2.2
537(deftest logical-pathname.1
538  #-clisp
539  (signals-error (logical-pathname ":") 'error)
540  #+clisp
541  (check-logical-pathname (logical-pathname ":") "" '(:absolute) nil nil nil)
542  t)
543
544;; Parse error.
545(deftest logical-pathname.2
546  (signals-error (logical-pathname "effluvia::foo.bar")
547                 #-(or allegro clisp) 'parse-error
548                 #+(or allegro clisp) 'type-error)
549  t)
550
551;; If the prefix isn't a defined logical host, it's not a logical pathname.
552#-(or cmu (and clisp windows))
553;; CMUCL parses this as (:ABSOLUTE #<SEARCH-LIST foo>) "bar.baz" "42".
554;; CLISP signals a parse error reading #p"foo:bar.baz.42".
555(deftest logical.1
556  (let ((pathname #p"foo:bar.baz.42"))
557    #+allegro
558    ;; Except in Allegro.
559    (check-logical-pathname pathname "foo" nil "bar" "baz" nil)
560    #-allegro
561    (check-physical-pathname pathname nil "foo:bar.baz" "42"))
562  t)
563#+lispworks
564(pushnew 'logical.1 *expected-failures*)
565
566#+sbcl
567(deftest logical.2
568  ;; Even though "effluvia" is defined as a logical host, "bop" is not a valid
569  ;; logical pathname version, so this can't be a logical pathname.
570  (check-physical-pathname #p"effluvia:bar.baz.bop" nil "effluvia:bar.baz" "bop")
571  t)
572
573(deftest logical.3
574  #-allegro
575  (check-logical-pathname (make-pathname :defaults "effluvia:foo.lisp")
576                          "EFFLUVIA" '(:absolute) "FOO" "LISP" nil)
577  #+allegro
578  (check-logical-pathname (make-pathname :defaults "effluvia:foo.lisp")
579                          "effluvia" nil "foo" "lisp" nil)
580  t)
581
582#-allegro
583(deftest logical.4
584  (check-logical-pathname #p"effluvia:bar.baz.42" "EFFLUVIA" '(:absolute) "BAR" "BAZ" 42)
585  t)
586
587#-allegro
588(deftest logical.5
589  (string= (write-to-string #p"effluvia:bar.baz.42" :escape t)
590           "#P\"EFFLUVIA:BAR.BAZ.42\"")
591  t)
592
593#+allegro
594;; Allegro returns NIL for the device and directory and drops the version
595;; entirely (even from the namestring).
596(deftest logical.6
597  (check-logical-pathname #p"effluvia:bar.baz.42" "effluvia" nil "bar" "baz" nil)
598  t)
599
600#+allegro
601(deftest logical.7
602  (string= (write-to-string #p"effluvia:bar.baz" :escape t)
603           #+allegro-v6.2 "#p\"effluvia:bar.baz\""
604           #+allegro-v7.0 "#P\"effluvia:bar.baz\"")
605  t)
606
607(deftest logical.8
608  (typep (parse-namestring "**;*.*.*" "effluvia") 'logical-pathname)
609  t)
610
611(deftest logical.9
612  (check-namestring (parse-namestring "**;*.*.*" "effluvia")
613                    #-(or allegro lispworks)
614                    "EFFLUVIA:**;*.*.*"
615                    #+allegro
616                    ;; Allegro preserves case and drops the version component.
617                    "effluvia:**;*.*"
618                    #+lispworks
619                    "effluvia:**;*.*.*")
620  t)
621
622#-allegro
623;; The version can be a bignum.
624(deftest logical.10
625  (check-logical-pathname #p"effluvia:bar.baz.2147483648" "EFFLUVIA" '(:absolute) "BAR" "BAZ" 2147483648)
626  t)
627
628#-allegro
629(deftest logical.11
630  (check-namestring #p"effluvia:bar.baz.2147483648" "EFFLUVIA:BAR.BAZ.2147483648")
631  t)
632#+sbcl
633;; SBCL has a bug when the version is a bignum.
634(pushnew 'logical.11 *expected-failures*)
635
636(deftest logical.12
637  (check-namestring #p"effluvia:foo.bar.newest"
638                    #-allegro "EFFLUVIA:FOO.BAR.NEWEST"
639                    #+allegro "effluvia:foo.bar")
640  t)
641
642(deftest logical.13
643  #-allegro
644  (check-logical-pathname #p"effluvia:foo.*" "EFFLUVIA" '(:absolute) "FOO" :wild nil)
645  #+allegro
646  (check-logical-pathname #p"effluvia:foo.*" "effluvia" nil "foo" :wild nil)
647  t)
648
649(deftest logical.14
650  #-allegro
651  (check-logical-pathname #p"effluvia:*.lisp" "EFFLUVIA" '(:absolute) :wild "LISP" nil)
652  #+allegro
653  (check-logical-pathname #p"effluvia:*.lisp" "effluvia" nil :wild "lisp" nil)
654  t)
655
656(deftest logical.15
657  #-allegro
658  (check-logical-pathname #p"effluvia:bar.baz.newest" "EFFLUVIA" '(:absolute) "BAR" "BAZ" :newest)
659  #+allegro
660  (check-logical-pathname #p"effluvia:bar.baz.newest" "effluvia" nil "bar" "baz" nil)
661  t)
662
663(deftest logical.16
664  #-allegro
665  (check-logical-pathname #p"EFFLUVIA:BAR.BAZ.NEWEST" "EFFLUVIA" '(:absolute) "BAR" "BAZ" :newest)
666  #+allegro
667  (check-logical-pathname #p"EFFLUVIA:BAR.BAZ.NEWEST" "EFFLUVIA" nil "BAR" "BAZ" nil)
668  t)
669
670;; The directory component.
671(deftest logical.17
672  (check-logical-pathname #p"effluvia:foo;bar.baz" "EFFLUVIA" '(:absolute "FOO") "BAR" "BAZ" nil)
673  t)
674
675(deftest logical.18
676  (check-namestring #p"effluvia:foo;bar.baz"
677                    #-allegro "EFFLUVIA:FOO;BAR.BAZ"
678                    #+allegro "effluvia:foo;bar.baz")
679  t)
680
681(deftest logical.19
682  #-allegro
683  (check-logical-pathname #p"effluvia:;bar.baz" "EFFLUVIA" '(:relative) "BAR" "BAZ" nil)
684  #+allegro
685  ;; Allegro drops the directory component and removes the semicolon from the
686  ;; namestring.
687  (check-logical-pathname #p"effluvia:;bar.baz" "EFFLUVIA" nil "BAR" "BAZ" nil)
688  t)
689
690(deftest logical.20
691  (check-namestring #p"effluvia:;bar.baz"
692                    #+allegro "effluvia:bar.baz"
693                    #-allegro "EFFLUVIA:;BAR.BAZ")
694  t)
695
696;; "If a relative-directory-marker precedes the directories, the directory
697;; component parsed is as relative; otherwise, the directory component is
698;; parsed as absolute."
699(deftest logical.21
700  (equal (pathname-directory #p"effluvia:foo.baz")
701         #-allegro '(:absolute)
702         #+allegro nil)
703  t)
704
705(deftest logical.22
706  (typep  #p"effluvia:" 'logical-pathname)
707  t)
708
709(deftest logical.23
710  (equal (pathname-directory #p"effluvia:")
711         #-allegro '(:absolute)
712         #+allegro nil)
713  t)
714
715;; PARSE-NAMESTRING
716(deftest parse-namestring.1
717  #-allegro
718  (check-logical-pathname (parse-namestring "effluvia:foo.bar")
719                          "EFFLUVIA" '(:absolute) "FOO" "BAR" nil)
720  #+allegro
721  (check-logical-pathname (parse-namestring "effluvia:foo.bar")
722                          "effluvia" nil "foo" "bar" nil)
723  t)
724
725(deftest parse-namestring.2
726  (let ((pathname (parse-namestring "foo.bar" "effluvia")))
727    #-(or allegro lispworks)
728    (check-logical-pathname pathname "EFFLUVIA" '(:absolute) "FOO" "BAR" nil)
729    #+allegro
730    (check-logical-pathname pathname "effluvia" nil "foo" "bar" nil)
731    #+lispworks
732    (check-logical-pathname pathname "effluvia" '(:absolute) "FOO" "BAR" nil))
733  t)
734
735(deftest parse-namestring.3
736  (let ((pathname (parse-namestring "foo;bar;baz.fas.3" "effluvia")))
737    #-(or allegro lispworks)
738    (check-logical-pathname pathname "EFFLUVIA" '(:absolute "FOO" "BAR") "BAZ" "FAS" 3)
739    #+allegro
740    (check-logical-pathname pathname "effluvia" '(:absolute "foo" "bar") "baz" "fas" nil)
741    #+lispworks
742    (check-logical-pathname pathname "effluvia" '(:absolute "FOO" "BAR") "BAZ" "FAS" 3)
743    )
744  t)
745
746(deftest parse-namestring.4
747  #-(or abcl clisp cmu lispworks (and allegro windows))
748  (check-physical-pathname (parse-namestring "effluvia:foo.bar" "")
749                           nil "effluvia:foo" "bar")
750  #+abcl
751  ;; Invalid logical host name: ""
752  (signals-error (parse-namestring "effluvia:foo.bar" "") 'error)
753  #+(or clisp lispworks)
754  ;; Host mismatch.
755  (signals-error (parse-namestring "effluvia:foo.bar" "") 'error)
756  #+cmu
757  (signals-error (parse-namestring "effluvia:foo.bar" "") 'error)
758  #+(and allegro windows)
759  ;; "effluvia" is the device
760  (check-physical-pathname (parse-namestring "effluvia:foo.bar" "")
761                           nil "foo" "bar")
762  t)
763
764;; "If host is nil and thing is a syntactically valid logical pathname
765;; namestring containing an explicit host, then it is parsed as a logical
766;; pathname namestring."
767(deftest parse-namestring.5
768  #-allegro
769  (check-logical-pathname (parse-namestring "effluvia:foo.bar" nil)
770                          "EFFLUVIA" '(:absolute) "FOO" "BAR" nil)
771  #+allegro
772  (check-logical-pathname (parse-namestring "effluvia:foo.bar" nil)
773                          "effluvia" nil "foo" "bar" nil)
774  t)
775
776;; "If host is nil, default-pathname is a logical pathname, and thing is a
777;; syntactically valid logical pathname namestring without an explicit host,
778;; then it is parsed as a logical pathname namestring on the host that is the
779;; host component of default-pathname."
780(deftest parse-namestring.6
781  #-allegro
782  (check-logical-pathname (parse-namestring "foo" nil #p"effluvia:bar")
783                          "EFFLUVIA" '(:absolute) "FOO" nil nil)
784  #+allegro
785  (check-logical-pathname (parse-namestring "foo" nil #p"effluvia:bar")
786                          "effluvia" nil "foo" nil nil)
787  t)
788
789(deftest parse-namestring.7
790  (let* ((*default-pathname-defaults* (logical-pathname "EFFLUVIA:"))
791         (pathname (parse-namestring "foo.bar")))
792    #-allegro
793    (check-logical-pathname pathname "EFFLUVIA" '(:absolute) "FOO" "BAR" nil)
794    #+allegro
795    (check-logical-pathname pathname "effluvia" nil "foo" "bar" nil))
796  t)
797
798(deftest parse-namestring.8
799  (let* ((*default-pathname-defaults* #p"effluvia:bar")
800         (pathname (parse-namestring "foo" nil)))
801    #-allegro
802    (check-logical-pathname pathname "EFFLUVIA" '(:absolute) "FOO" nil nil)
803    #+allegro
804    (check-logical-pathname pathname "effluvia" nil "foo" nil nil))
805  t)
806
807;; WILD-PATHNAME-P
808(deftest wild-pathname-p.1
809  (wild-pathname-p #p"effluvia:;*.baz")
810  #+(or cmu sbcl) (:wild :wild-inferiors)
811  #-(or cmu sbcl) t)
812
813;; PATHNAME-MATCH-P
814(deftest pathname-match-p.1
815  (pathname-match-p "/foo/bar/baz" "/*/*/baz")
816  t)
817
818(deftest pathname-match-p.2
819  (pathname-match-p "/foo/bar/baz" "/**/baz")
820  t)
821
822(deftest pathname-match-p.3
823  (pathname-match-p "/foo/bar/quux/baz" "/**/baz")
824  t)
825
826(deftest pathname-match-p.4
827  (pathname-match-p "foo.bar" "/**/*.*")
828  t)
829
830(deftest pathname-match-p.5
831  (pathname-match-p "/usr/local/bin/foo.bar" "/**/foo.bar")
832  t)
833
834(deftest pathname-match-p.6
835  (pathname-match-p "/usr/local/bin/foo.bar" "**/foo.bar")
836  nil)
837
838(deftest pathname-match-p.7
839  (pathname-match-p "/foo/bar.txt" "/**/*.*")
840  t)
841
842(deftest pathname-match-p.8
843  (pathname-match-p "/foo/bar.txt" "**/*.*")
844  nil)
845
846(deftest pathname-match-p.9
847  (pathname-match-p #p"effluvia:foo.bar" #p"effluvia:**;*.*.*")
848  t)
849
850(deftest pathname-match-p.10
851  (pathname-match-p "foo" "foo.*")
852  t)
853
854;; TRANSLATE-PATHNAME
855(deftest translate-pathname.1
856  #-clisp
857  (equal (translate-pathname "foo" "*" "bar") #p"bar")
858  #+clisp
859  (signals-error (translate-pathname "foo" "*" "bar") 'error)
860  t)
861
862(deftest translate-pathname.2
863  (equal (translate-pathname "foo" "*" "*")   #p"foo")
864  t)
865
866(deftest translate-pathname.3
867  #-abcl
868  (string= (pathname-name (translate-pathname "foobar" "*" "foo*"))
869           #-allegro-v7.0 "foofoobar"
870           #+allegro-v7.0 "foo*")
871  #+abcl
872  ;; ABCL doesn't implement this translation. Verify that it signals an error.
873  (signals-error (translate-pathname "foobar" "*" "foo*") 'error)
874  t)
875
876(deftest translate-pathname.4
877  #-abcl
878  (equal (translate-pathname "foobar" "foo*" "*baz")
879         #-allegro-v7.0 #p"barbaz"
880         #+allegro-v7.0 #p"*baz")
881  #+abcl
882  ;; ABCL doesn't implement this translation. Verify that it signals an error.
883  (signals-error (translate-pathname "foobar" "foo*" "*baz") 'error)
884  t)
885
886(deftest translate-pathname.5
887  #-abcl
888  (equal (translate-pathname "foobar" "foo*" "")
889         #+(or allegro clisp) #p"bar"
890         #+(or cmu sbcl lispworks) #p"foobar")
891  #+abcl
892  ;; ABCL doesn't implement this translation. Verify that it signals an error.
893  (signals-error (translate-pathname "foobar" "foo*" "") 'error)
894  t)
895
896(deftest translate-pathname.6
897  (equal (translate-pathname "foo/bar" "*/bar" "*/baz") #p"foo/baz")
898  t)
899
900(deftest translate-pathname.7
901  (equal (translate-pathname "bar/foo" "bar/*" "baz/*") #p"baz/foo")
902  t)
903
904(deftest translate-pathname.8
905  (equal (translate-pathname "foo/bar" "*/bar" "*/baz") #p"foo/baz")
906  t)
907
908(deftest translate-pathname.9
909  (string= (namestring (translate-pathname "test.txt" "*.txt" "*.text"))
910           "test.text")
911  t)
912
913(deftest translate-pathname.10
914  (equal (translate-pathname "foo" "foo.*" "bar") #p"bar")
915  t)
916
917(deftest translate-pathname.11
918  (equal (translate-pathname "foo" "foo.*" "bar.*") #p"bar")
919  t)
920
921(deftest translate-pathname.12
922  (string= (namestring (translate-pathname "foo.bar" "*.*" "/usr/local/*.*"))
923           #-windows "/usr/local/foo.bar"
924           #+windows "\\usr\\local\\foo.bar")
925  t)
926
927(deftest translate-pathname.13
928  (equal (translate-pathname "foo.bar" "*.*" "/usr/local/*.*")
929         #p"/usr/local/foo.bar")
930  t)
931
932(deftest translate-pathname.14
933  (check-translate-pathname '("/foo/" "/*/" "/usr/local/*/") "/usr/local/foo/")
934  t)
935
936(deftest translate-pathname.15
937  (check-translate-pathname '("/foo/baz/bar.txt" "/**/*.*" "/usr/local/**/*.*")
938                            "/usr/local/foo/baz/bar.txt")
939  t)
940
941(deftest translate-pathname.16
942  (equal (translate-pathname "/foo/" "/*/" "/usr/local/*/bar/") #p"/usr/local/foo/bar/")
943  t)
944
945(deftest translate-pathname.17
946  (equal (translate-pathname "/foo/bar.txt" "/*/*.*" "/usr/local/*/*.*")
947         #P"/usr/local/foo/bar.txt")
948  t)
949
950;; "TRANSLATE-PATHNAME translates SOURCE (that matches FROM-WILDCARD)..."
951(deftest pathname-match-p.11
952  (pathname-match-p "/foo/bar.txt" "**/*.*")
953  nil)
954
955;; Since (pathname-match-p "/foo/bar.txt" "**/*.*" ) => NIL...
956(deftest translate-pathname.18
957  #+(or clisp allegro abcl cmu lispworks)
958  ;; This seems to be the correct behavior.
959  (signals-error (translate-pathname "/foo/bar.txt" "**/*.*" "/usr/local/**/*.*") 'error)
960  #+sbcl
961  ;; This appears to be a bug, since SOURCE doesn't match FROM-WILDCARD.
962  (equal (translate-pathname "/foo/bar.txt" "**/*.*" "/usr/local/**/*.*")
963         #p"/usr/local/foo/bar.txt")
964  t)
965
966(deftest pathname-match-p.12
967  (pathname-match-p "/foo/bar.txt" "/**/*.*")
968  t)
969
970(deftest translate-pathname.19
971  (equal (translate-pathname "/foo/bar.txt" "/**/*.*" "/usr/local/**/*.*")
972         #p"/usr/local/foo/bar.txt")
973  t)
974
975#-clisp
976(deftest translate-pathname.20
977  (equal (translate-pathname "foo.bar" "/**/*.*" "/usr/local/") #p"/usr/local/foo.bar")
978  t)
979
980;; TRANSLATE-LOGICAL-PATHNAME
981
982;; "PATHNAME is first coerced to a pathname. If the coerced pathname is a
983;; physical pathname, it is returned."
984(deftest translate-logical-pathname.1
985  (equal (translate-logical-pathname #p"/") #p"/")
986  t)
987
988#+(or abcl clisp)
989(deftest translate-logical-pathname.2
990  (equal (translate-logical-pathname "effluvia:foo.bar") #p"/usr/local/foo.bar")
991  t)
992
993#+(or sbcl cmu)
994(deftest translate-logical-pathname.3
995  ;; Device mismatch.
996  (and (eq (pathname-device (translate-logical-pathname "effluvia:foo.bar"))
997           :unspecific)
998       (eq (pathname-device #p"/usr/local/foo/bar")
999           nil))
1000  t)
1001
1002(deftest translate-logical-pathname.4
1003  (check-namestring (translate-logical-pathname "effluvia:foo.bar")
1004                    "/usr/local/foo.bar")
1005  t)
1006
1007(deftest translate-logical-pathname.5
1008  (check-namestring (translate-logical-pathname "effluvia:foo;bar.txt")
1009                    "/usr/local/foo/bar.txt")
1010  t)
1011
1012(deftest translate-logical-pathname.6
1013  #-allegro
1014  (check-logical-pathname #p"effluvia:Foo.Bar" "EFFLUVIA" '(:absolute) "FOO" "BAR" nil)
1015  #+allegro
1016  ;; Allegro preserves case.
1017  (check-logical-pathname #p"effluvia:Foo.Bar" "effluvia" nil "Foo" "Bar" nil)
1018  t)
1019
1020;; "TRANSLATE-PATHNAME [and thus also TRANSLATE-LOGICAL-PATHNAME] maps
1021;; customary case in SOURCE into customary case in the output pathname."
1022(deftest translate-logical-pathname.7
1023  #-allegro
1024  (check-physical-pathname (translate-logical-pathname #p"effluvia:Foo.Bar")
1025                           '(:absolute "usr" "local") "foo" "bar")
1026  #+allegro
1027  ;; Allegro preserves case.
1028  (check-physical-pathname (translate-logical-pathname #p"effluvia:Foo.Bar")
1029                           '(:absolute "usr" "local") "Foo" "Bar")
1030  t)
1031
1032(deftest merge-pathnames.1
1033  #-allegro
1034  (check-logical-pathname (merge-pathnames "effluvia:foo.bar")
1035                          "EFFLUVIA" '(:absolute) "FOO" "BAR" :newest)
1036  #+allegro
1037  ;; Allegro's MERGE-PATHNAMES apparently calls TRANSLATE-LOGICAL-PATHNAME.
1038  (check-physical-pathname (merge-pathnames "effluvia:foo.bar")
1039                           '(:absolute "usr" "local") "foo" "bar")
1040  t)
1041
1042(deftest merge-pathnames.2
1043  (equal (merge-pathnames (logical-pathname "effluvia:;foo;bar;")
1044                          (logical-pathname "effluvia:baz;quux.lisp.3"))
1045         #-allegro
1046         (make-pathname :host "EFFLUVIA"
1047                        :device :unspecific
1048                        :directory '(:absolute "BAZ" "FOO" "BAR")
1049                        :name "QUUX"
1050                        :type "LISP"
1051                        :version 3)
1052         #+allegro
1053         (make-pathname :host "effluvia"
1054                        :device nil
1055                        :directory '(:absolute "baz" "foo" "bar")
1056                        :name "quux"
1057                        :type "lisp"
1058                        :version nil)
1059         )
1060  t)
1061
1062(deftest compile-file-pathname.1
1063  (equal (compile-file-pathname "effluvia:foo.lisp")
1064         #+abcl
1065         ;; Is this a bug? (Should version be :NEWEST?)
1066         #p"EFFLUVIA:FOO.ABCL"
1067         #+allegro #p"effluvia:foo.fasl"
1068         #+(or cmu sbcl) #p"EFFLUVIA:FOO.FASL.NEWEST"
1069         #+clisp
1070         ;; Is this a bug?
1071         ;; #p"EFFLUVIA:FOO.fas.NEWEST"
1072         (make-pathname :host "EFFLUVIA" :directory '(:absolute)
1073                        :name "FOO" :type "fas" :version :newest)
1074         #+(and lispworks unix) #p"EFFLUVIA:FOO.UFSL.NEWEST"
1075         #+(and lispworks windows) #p"EFFLUVIA:FOO.FSL.NEWEST")
1076  t)
1077
1078(deftest file-namestring.1
1079  (equal (file-namestring #p"")
1080         #+(or abcl allegro cmu)
1081         nil
1082         #+(or clisp lispworks sbcl)
1083         "")
1084  t)
1085
1086(deftest file-namestring.2
1087  (equal (file-namestring #p"foo") "foo")
1088  t)
1089
1090(deftest file-namestring.3
1091  (let ((pathname (make-pathname :type "foo")))
1092    #+abcl
1093    (equal (file-namestring pathname) nil)
1094    #+allegro
1095    (equal (file-namestring pathname) "NIL.foo") ;; bug
1096    #+(or clisp lispworks)
1097    (equal (file-namestring pathname) ".foo")
1098    #+(or cmu sbcl)
1099    (signals-error (file-namestring pathname) 'error))
1100  t)
1101
1102;; A variant of FILE-NAMESTRING.3 that detects Allegro's bug as a bug.
1103(deftest file-namestring.4
1104  (let ((pathname (make-pathname :type "foo")))
1105    #-(or cmu sbcl)
1106    (not (equal (file-namestring pathname) "NIL.foo"))
1107    #+(or cmu sbcl)
1108    (signals-error (file-namestring pathname) 'error))
1109  t)
1110#+allegro
1111(pushnew 'file-namestring.4 *expected-failures*)
1112
1113(deftest enough-namestring.1
1114  (equal (enough-namestring #p"/foo" #p"/") "foo")
1115  t)
1116#+sbcl
1117(pushnew 'enough-namestring.1 *expected-failures*)
1118
1119(deftest enough-namestring.2
1120  #-windows
1121  (equal (enough-namestring #p"foo/bar" #p"foo") "foo/bar")
1122  #+windows
1123  (equal (enough-namestring #p"foo\\bar" #p"foo") "foo\\bar")
1124  t)
1125
1126(deftest enough-namestring.3
1127  (equal (enough-namestring #p"foo/bar" #p"foo/") "bar")
1128  t)
1129#+sbcl
1130(pushnew 'enough-namestring.3 *expected-failures*)
1131
1132;; The following tests are adapted from SBCL's pathnames.impure.lisp.
1133(setf (logical-pathname-translations "demo0")
1134      '(("**;*.*.*" "/tmp/")))
1135(deftest sbcl.1
1136  (pathname-match-p "demo0:file.lisp" (logical-pathname "demo0:tmp;**;*.*.*"))
1137  nil)
1138
1139#-clisp
1140(deftest sbcl.2
1141  (check-namestring (translate-logical-pathname "demo0:file.lisp") "/tmp/file.lisp")
1142  t)
1143
1144(setf (logical-pathname-translations "demo1")
1145      '(("**;*.*.*" "/tmp/**/*.*") (";**;*.*.*" "/tmp/rel/**/*.*")))
1146;; Remove "**" from the resulting pathname when the source directory is NIL.
1147(deftest sbcl.3
1148  (equal (namestring (translate-logical-pathname "demo1:foo.lisp"))
1149         #-windows "/tmp/**/foo.lisp"
1150         #+windows "\\tmp\\**\\foo.lisp")
1151  nil)
1152
1153(deftest sbcl.4
1154  (check-namestring (translate-logical-pathname "demo1:foo.lisp") "/tmp/foo.lisp")
1155  t)
1156
1157;;; Check for absolute/relative path confusion.
1158#-allegro
1159(deftest sbcl.5
1160  (pathname-match-p "demo1:;foo.lisp" "demo1:**;*.*.*")
1161  nil)
1162
1163#+(or sbcl cmu)
1164;; BUG Pathnames should match if the following translation is to work.
1165(deftest sbcl.6
1166  (pathname-match-p "demo1:;foo.lisp" "demo1:;**;*.*.*")
1167  t)
1168
1169#+clisp
1170(deftest sbcl.7
1171  (pathname-match-p "demo1:;foo.lisp" ";**;*.*.*")
1172  t)
1173
1174(deftest sbcl.8
1175  (check-namestring (translate-logical-pathname "demo1:;foo.lisp")
1176                    #+abcl "/tmp/rel/foo.lisp"
1177                    #+allegro "/tmp/foo.lisp"
1178                    #-(or allegro abcl) "/tmp/rel/foo.lisp")
1179  t)
1180
1181(setf (logical-pathname-translations "demo2")
1182      '(("test;**;*.*" "/tmp/demo2/test")))
1183
1184(deftest sbcl.9
1185  (equal (enough-namestring "demo2:test;foo.lisp")
1186         #+sbcl "DEMO2:;TEST;FOO.LISP"
1187         #+(or abcl cmu lispworks) "DEMO2:TEST;FOO.LISP"
1188         #+allegro-v7.0 "demo2:test;foo.lisp"
1189         #+allegro-v6.2 "/test/foo.lisp" ;; BUG
1190         #+(and clisp unix) "TEST;FOO.LISP"
1191         #+(and clisp windows) "DEMO2:TEST;FOO.LISP")
1192  t)
1193
1194#-(or allegro clisp cmu)
1195(deftest sbcl.10
1196  (signals-error (make-pathname :host "EFFLUVIA" :directory "!bla" :name "bar")
1197                 'error)
1198  t)
1199#-(or allegro cmu)
1200(deftest sbcl.11
1201  (signals-error (make-pathname :host "EFFLUVIA" :directory "bla" :name "!bar")
1202                 'error)
1203  t)
1204#-(or allegro cmu)
1205(deftest sbcl.12
1206  (signals-error (make-pathname :host "EFFLUVIA" :directory "bla" :name "bar" :type "&baz")
1207                 'error)
1208  t)
1209
1210(deftest sbcl.13
1211  (equal (namestring (parse-namestring "" "EFFLUVIA")) "EFFLUVIA:")
1212  t)
1213
1214(deftest sbcl.14
1215  #-cmu
1216  (equal (namestring (parse-namestring "" :unspecific)) "")
1217  #+cmu
1218  ;; It seems reasonable to signal an error here, since the HOST argument to
1219  ;; PARSE-NAMESTRING is specified to be "a valid pathname host, a logical host,
1220  ;; or NIL".
1221  (signals-error (parse-namestring "" :unspecific) 'type-error)
1222  t)
1223
1224(deftest sbcl.15
1225  (equal (namestring (parse-namestring ""
1226                                       (pathname-host
1227                                        (translate-logical-pathname
1228                                         "EFFLUVIA:"))))
1229         "")
1230  t)
1231
1232;; PARSE-NAMESTRING host mismatch: "If HOST is supplied and not NIL, and THING
1233;; contains a manifest host name, an error of type ERROR is signaled if the
1234;; hosts do not match."
1235(deftest sbcl.16
1236  (signals-error (parse-namestring "effluvia:foo.bar" "demo2") 'error)
1237  t)
1238
1239(setf (logical-pathname-translations "bazooka")
1240      '(("todemo;*.*.*" "demo0:*.*.*")))
1241
1242(deftest sbcl.17
1243  #+allegro ;; BUG
1244  (check-namestring (translate-logical-pathname "bazooka:todemo;x.y") "/tmp/todemo/x.y")
1245  #+clisp ;; BUG
1246  (signals-error (translate-logical-pathname "bazooka:todemo;x.y") 'error)
1247  #-(or allegro clisp)
1248  (check-namestring (translate-logical-pathname "bazooka:todemo;x.y") "/tmp/x.y")
1249  t)
1250
1251(deftest sbcl.18
1252  #+clisp ;; BUG
1253  (signals-error (translate-logical-pathname "demo0:x.y") 'error)
1254  #-clisp
1255  (equal (namestring (translate-logical-pathname "demo0:x.y"))
1256         #-windows "/tmp/x.y"
1257         #+windows "\\tmp\\x.y")
1258  t)
1259
1260#-(or allegro clisp)
1261(deftest sbcl.19
1262  (equal (namestring (translate-logical-pathname "bazooka:todemo;x.y"))
1263         (namestring (translate-logical-pathname "demo0:x.y")))
1264  t)
1265
1266;; "If HOST is incorrectly supplied, an error of type TYPE-ERROR is signaled."
1267(deftest sbcl.20
1268  (signals-error (logical-pathname-translations "unregistered-host")
1269                 #+(or clisp lispworks) 'error ;; BUG
1270                 #+cmu 'file-error ;; BUG
1271                 #-(or clisp lispworks cmu) 'type-error)
1272  t)
1273
1274(deftest sbcl.21
1275  (string-equal (host-namestring (parse-namestring "OTHER-HOST:ILLEGAL/LPN")) "OTHER-HOST")
1276  nil)
1277#+(or lispworks (and clisp windows))
1278(pushnew 'sbcl.21 *expected-failures*)
1279
1280(deftest sbcl.22
1281  (string= (pathname-name (parse-namestring "OTHER-HOST:ILLEGAL/LPN")) "LPN")
1282  t)
1283#+(and clisp windows)
1284(pushnew 'sbcl.22 *expected-failures*)
1285
1286(setf (logical-pathname-translations "test0")
1287      '(("**;*.*.*"              "/library/foo/**/")))
1288
1289(deftest sbcl.23
1290  (check-namestring (translate-logical-pathname "test0:foo;bar;baz;mum.quux")
1291                    "/library/foo/foo/bar/baz/mum.quux")
1292  t)
1293
1294(setf (logical-pathname-translations "prog")
1295      '(("CODE;*.*.*"             "/lib/prog/")))
1296
1297#-allegro
1298(deftest sbcl.24
1299  (check-namestring (translate-logical-pathname "prog:code;documentation.lisp")
1300                    "/lib/prog/documentation.lisp")
1301  t)
1302
1303(setf (logical-pathname-translations "prog1")
1304      '(("CODE;DOCUMENTATION.*.*" "/lib/prog/docum.*")
1305        ("CODE;*.*.*"             "/lib/prog/")))
1306
1307#-allegro
1308(deftest sbcl.25
1309  (check-namestring (translate-logical-pathname "prog1:code;documentation.lisp")
1310                    "/lib/prog/docum.lisp")
1311  t)
1312
1313;; "ANSI section 19.3.1.1.5 specifies that translation to a filesystem which
1314;; doesn't have versions should ignore the version slot. CMU CL didn't ignore
1315;; this as it should, but we [i.e. SBCL] do."
1316;; "Some file systems do not have versions. Logical pathname translation to
1317;; such a file system ignores the version." 19.3.1.1.5
1318#-cmu
1319;; CMUCL supports emacs-style versions.
1320(deftest sbcl.26
1321  (check-namestring (translate-logical-pathname "test0:foo;bar;baz;mum.quux.3")
1322                    "/library/foo/foo/bar/baz/mum.quux")
1323  t)
1324#+lispworks
1325(pushnew 'sbcl.26 *expected-failures*)
1326
1327(setf (logical-pathname-translations "scratch")
1328      '(("**;*.*.*" "/usr/local/doc/**/*")))
1329
1330;; Trivial merge.
1331(deftest sbcl.27
1332  (check-merge-pathnames #p"foo" #p"/usr/local/doc/" #p"/usr/local/doc/foo")
1333  t)
1334
1335;; If pathname does not specify a host, device, directory, name, or type, each
1336;; such component is copied from default-pathname.
1337;; 1) no name, no type
1338(deftest sbcl.28
1339  (check-merge-pathnames #p"/supplied-dir/" #p"/dir/name.type"
1340                         #p"/supplied-dir/name.type")
1341  t)
1342
1343;; 2) no directory, no type
1344(deftest sbcl.29
1345  (check-merge-pathnames #p"supplied-name" #p"/dir/name.type"
1346                         #p"/dir/supplied-name.type")
1347  t)
1348
1349;; 3) no name, no dir (must use make-pathname as ".foo" is parsed
1350;; as a name)
1351(deftest sbcl.30
1352  (check-merge-pathnames (make-pathname :type "supplied-type")
1353                         #p"/dir/name.type"
1354                         #p"/dir/name.supplied-type")
1355  t)
1356
1357;; If (pathname-directory pathname) is a list whose car is
1358;; :relative, and (pathname-directory default-pathname) is a
1359;; list, then the merged directory is [...]
1360(deftest sbcl.31
1361  (check-merge-pathnames #p"qqq/www" #p"/aaa/bbb/ccc/ddd/eee"
1362                         #p"/aaa/bbb/ccc/ddd/qqq/www")
1363  t)
1364
1365;; except that if the resulting list contains a string or
1366;; :wild immediately followed by :back, both of them are
1367;; removed.
1368(deftest sbcl.32
1369  (check-merge-pathnames
1370   ;; "../" in a namestring is parsed as :up not :back, so MAKE-PATHNAME.
1371   (make-pathname :directory '(:relative :back "blah"))
1372   #p"/aaa/bbb/ccc/ddd/eee" #P"/aaa/bbb/ccc/blah/eee")
1373  t)
1374
1375;; If (pathname-directory default-pathname) is not a list or
1376;; (pathname-directory pathname) is not a list whose car is
1377;; :relative, the merged directory is (or (pathname-directory
1378;; pathname) (pathname-directory default-pathname))
1379(deftest sbcl.33
1380  (check-merge-pathnames #p"/absolute/path/name" #p"/dir/default-name.type"
1381                         #P"/absolute/path/name.type")
1382  t)
1383
1384(deftest sbcl.34
1385  (check-merge-pathnames #p"scratch:;name2" #p"scratch:foo;"
1386                         #p"SCRATCH:FOO;NAME2")
1387  t)
1388
1389(deftest sbcl.35
1390  (check-merge-pathnames #p"scratch:;foo" #p"/usr/local/doc/"
1391                         #-(or allegro clisp lispworks) #P"SCRATCH:USR;LOCAL;DOC;FOO"
1392                         #+(and allegro unix) #p"/usr/local/doc/foo"
1393                         #+(and allegro windows) #p"scratch:usr;local;doc;foo"
1394                         #+clisp #p"SCRATCH:;FOO"
1395                         #+lispworks #p"SCRATCH:FOO")
1396  t)
1397
1398(deftest sbcl.36
1399  (check-merge-pathnames #p"scratch:supplied-dir;" #p"/dir/name.type"
1400                         #-clisp #p"SCRATCH:SUPPLIED-DIR;NAME.TYPE"
1401                         #+clisp
1402                         ;; #p"SCRATCH:SUPPLIED-DIR;name.type.NEWEST"
1403                         (make-pathname :host "SCRATCH"
1404                                        :directory '(:absolute "SUPPLIED-DIR")
1405                                        :name "name"
1406                                        :type "type"))
1407  t)
1408
1409(deftest sbcl.37
1410  (check-merge-pathnames #p"scratch:;supplied-name" #p"/dir/name.type"
1411                         #-(or allegro clisp lispworks)
1412                         #p"SCRATCH:DIR;SUPPLIED-NAME.TYPE"
1413                         #+(and allegro unix)
1414                         #p"/usr/local/doc/supplied-name.type"
1415                         #+(and allegro windows)
1416                         #P"scratch:dir;supplied-name.type"
1417                         #+clisp
1418                         ;; #P"SCRATCH:;SUPPLIED-NAME.type.NEWEST"
1419                         (make-pathname :host "SCRATCH"
1420                                        :directory '(:relative)
1421                                        :name "SUPPLIED-NAME"
1422                                        :type "type")
1423                         #+lispworks
1424                         ;; #P"SCRATCH:SUPPLIED-NAME.TYPE.NEWEST"
1425                         (make-pathname :host "SCRATCH"
1426                                        :directory '(:absolute)
1427                                        :name "SUPPLIED-NAME"
1428                                        :type "TYPE"))
1429  t)
1430
1431(deftest sbcl.38
1432  (check-merge-pathnames (make-pathname :host "scratch" :type "supplied-type")
1433                         #p"/dir/name.type"
1434                         #-(or allegro clisp lispworks)
1435                         #p"SCRATCH:DIR;NAME.SUPPLIED-TYPE"
1436                         #+(and allegro unix)
1437                         #p"/usr/local/doc/name.supplied-type"
1438                         #+(and allegro windows)
1439                         #P"scratch:dir;name.supplied-type"
1440                         #+clisp
1441                         ;; #P"SCRATCH:dir;name.supplied-type.NEWEST"
1442                         (make-pathname :host "SCRATCH"
1443                                        :directory '(:absolute "dir")
1444                                        :name "name"
1445                                        :type "supplied-type")
1446                         #+lispworks
1447                         ;; #P"SCRATCH:NAME.SUPPLIED-TYPE.NEWEST"
1448                         (make-pathname :host "SCRATCH"
1449                                        :directory '(:absolute)
1450                                        :name "NAME"
1451                                        :type "SUPPLIED-TYPE"))
1452  t)
1453
1454(deftest sbcl.39
1455  (let ((pathname (make-pathname :host "scratch"
1456                                        :directory '(:relative "foo")
1457                                        :name "bar"))
1458        (default-pathname #p"/aaa/bbb/ccc/ddd/eee"))
1459    #-allegro
1460    (check-merge-pathnames pathname default-pathname
1461                           #-(or clisp lispworks)
1462                           #p"SCRATCH:AAA;BBB;CCC;DDD;FOO;BAR"
1463                           #+clisp
1464                           ;; #P"SCRATCH:;foo;bar"
1465                           (make-pathname :host "SCRATCH"
1466                                          :directory '(:relative "foo")
1467                                          :name "bar")
1468                           #+lispworks
1469                           #p"SCRATCH:FOO;BAR")
1470    #+(and allegro unix)
1471    (signals-error (merge-pathnames pathname default-pathname) 'error)
1472    #+(and allegro windows)
1473    (check-merge-pathnames pathname default-pathname
1474                           #P"scratch:aaa;bbb;ccc;ddd;foo;bar"))
1475  t)
1476
1477#-lispworks
1478(deftest sbcl.40
1479  (let ((pathname (make-pathname :host "scratch"
1480                                 :directory '(:relative :back "foo")
1481                                 :name "bar"))
1482        (default-pathname #p"/aaa/bbb/ccc/ddd/eee"))
1483    #-allegro
1484    (check-merge-pathnames pathname default-pathname
1485                           #-clisp #p"SCRATCH:AAA;BBB;CCC;FOO;BAR"
1486                           #+clisp
1487                           ;; #P"SCRATCH:;..;foo;bar.NEWEST"
1488                           (make-pathname :host "SCRATCH"
1489                                          :directory '(:relative :back "foo")
1490                                          :name "bar"))
1491    #+(and allegro unix)
1492    (signals-error (merge-pathnames pathname default-pathname) 'error)
1493    #+(and allegro windows)
1494    (check-merge-pathnames pathname default-pathname
1495                           #P"scratch:aaa;bbb;ccc;foo;bar"))
1496  t)
1497
1498#+lispworks
1499;; "Illegal logical pathname directory component: :BACK."
1500(deftest sbcl.40
1501  (signals-error (make-pathname :host "scratch"
1502                                :directory '(:relative :back "foo")
1503                                :name "bar")
1504                 'error)
1505  t)
1506
1507(deftest sbcl.41
1508  (check-merge-pathnames #p"scratch:absolute;path;name"
1509                         #p"/dir/default-name.type"
1510                         #-clisp #p"SCRATCH:ABSOLUTE;PATH;NAME.TYPE"
1511                         #+clisp
1512                         ;; #P"SCRATCH:ABSOLUTE;PATH;NAME.type.NEWEST"
1513                         (make-pathname :host "SCRATCH"
1514                                        :directory '(:absolute "ABSOLUTE" "PATH")
1515                                        :name "NAME"
1516                                        :type "type"))
1517  t)
1518
1519(deftest sbcl.42
1520  (check-namestring (parse-namestring "/foo" (host-namestring #p"/bar")) "/foo")
1521  t)
1522#+lispworks
1523(pushnew 'sbcl.42 *expected-failures*)
1524
1525(deftest sbcl.43
1526  (string= (namestring (parse-namestring "FOO" (host-namestring #p"SCRATCH:BAR")))
1527           "SCRATCH:FOO")
1528  t)
1529
1530#-(or allegro clisp cmu lispworks)
1531(deftest sbcl.44
1532  ;; "The null string, "", is not a valid value for any component of a logical
1533  ;; pathname." 19.3.2.2
1534  (signals-error (setf (logical-pathname-translations "")
1535                       (list '("**;*.*.*" "/**/*.*")))
1536                 'error)
1537  t)
1538
1539#-clisp
1540(deftest sbcl.45
1541  (check-namestring (translate-logical-pathname "/") "/")
1542  t)
1543
1544(deftest sbcl.46
1545  (signals-error (pathname (make-string-input-stream "FOO"))
1546                 #-(or allegro-v6.2 cmu) 'type-error
1547                 #+allegro-v6.2     'stream-error
1548                 #+cmu              'error)
1549  t)
1550
1551(deftest sbcl.47
1552  (signals-error (merge-pathnames (make-string-output-stream))
1553                 #-allegro-v6.2 'type-error
1554                 #+allegro-v6.2 'stream-error)
1555  t)
1556
1557(deftest sbcl.48
1558  (check-readable-or-signals-error (make-pathname :name "foo" :type "txt" :version :newest))
1559  t)
1560#+lispworks
1561(pushnew 'sbcl.48 *expected-failures*)
1562
1563#-allegro
1564(deftest sbcl.49
1565  (check-readable-or-signals-error (make-pathname :name "foo" :type "txt" :version 1))
1566  t)
1567#+lispworks
1568(pushnew 'sbcl.49 *expected-failures*)
1569
1570(deftest sbcl.50
1571  #-clisp
1572  (check-readable-or-signals-error (make-pathname :name "foo" :type ".txt"))
1573  #+clisp
1574  (signals-error (make-pathname :name "foo" :type ".txt") 'error)
1575  t)
1576#+(or allegro cmu lispworks)
1577(pushnew 'sbcl.50 *expected-failures*)
1578
1579(deftest sbcl.51
1580  (check-readable-or-signals-error (make-pathname :name "foo." :type "txt"))
1581  t)
1582
1583(deftest sbcl.52
1584  (check-readable-or-signals-error (parse-namestring "SCRATCH:FOO.TXT.1"))
1585  t)
1586
1587(deftest sbcl.53
1588  (check-readable-or-signals-error (parse-namestring "SCRATCH:FOO.TXT.NEWEST"))
1589  t)
1590
1591(deftest sbcl.54
1592  (check-readable-or-signals-error (parse-namestring "SCRATCH:FOO.TXT"))
1593  t)
1594
1595(deftest sbcl.55
1596  (equal (parse-namestring "foo" nil "/")
1597         (parse-namestring "foo" nil #p"/"))
1598  t)
1599
1600#-allegro
1601(deftest sbcl.56
1602  (let ((test "parse-namestring-test.tmp"))
1603    (unwind-protect
1604        (with-open-file (f test :direction :output)
1605          ;; FIXME: This test is a bit flaky, since we only check that
1606          ;; no error is signalled. The dilemma here is "what is the
1607          ;; correct result when defaults is a _file_, not a
1608          ;; directory". Currently (0.8.10.73) we get #P"foo" here (as
1609          ;; opposed to eg. #P"/path/to/current/foo"), which is
1610          ;; possibly mildly surprising but probably conformant.
1611          (equal (parse-namestring "foo" nil f) #p"foo"))
1612      (when (probe-file test)
1613        (delete-file test))))
1614  t)
1615
1616;;; ENOUGH-NAMESTRING should probably not fail when the namestring in
1617;;; question has a :RELATIVE pathname.
1618(deftest sbcl.57
1619  (equal (enough-namestring #p"foo" #p"./") "foo")
1620  t)
1621
1622;;; bug reported by Artem V. Andreev: :WILD not handled in unparsing
1623;;; directory lists.
1624(deftest sbcl.58
1625  (check-namestring #p"/tmp/*/" "/tmp/*/")
1626  t)
1627
1628#-allegro
1629(deftest sbcl.59
1630  (string= (with-standard-io-syntax (write-to-string #p"/foo"))
1631           #-windows "#P\"/foo\""
1632           #+(and windows (not lispworks)) "#P\"\\\\foo\""
1633           #+(and windows lispworks) "#P\"/foo\"")
1634  t)
1635
1636#-allegro
1637(deftest sbcl.60
1638  (string= (with-standard-io-syntax (write-to-string #p"/foo" :readably nil))
1639           #-windows "#P\"/foo\""
1640           #+(and windows (not lispworks)) "#P\"\\\\foo\""
1641           #+(and windows lispworks) "#P\"/foo\"")
1642  t)
1643
1644#-allegro
1645(deftest sbcl.61
1646  (string= (with-standard-io-syntax (write-to-string #p"/foo" :escape nil))
1647           #-windows "#P\"/foo\""
1648           #+(and windows (not lispworks)) "#P\"\\\\foo\""
1649           #+(and windows lispworks) "#P\"/foo\"")
1650  t)
1651
1652(deftest sbcl.62
1653  (string= (with-standard-io-syntax (write-to-string #p"/foo" :readably nil :escape nil))
1654           #-windows "/foo"
1655           #+windows "\\foo")
1656  t)
1657
1658(do-tests)
Note: See TracBrowser for help on using the repository browser.