source: trunk/abcl/test/lisp/abcl/pathname-tests.lisp @ 12948

Last change on this file since 12948 was 12948, checked in by ehuelsmann, 12 years ago

Fix test expectations due to us now generating forward slashes
in our printed pathnames, even on Windows.

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