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

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

More SILLY tests.

File size: 51.7 KB
Line 
1;;; pathname-tests.lisp
2;;;
3;;; Copyright (C) 2005 Peter Graves
4;;; $Id: pathname-tests.lisp,v 1.50 2005-11-04 19:33:02 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)
396  (string= (namestring (make-pathname :name "..")) "..")
397  #+allegro
398  (string= (namestring (make-pathname :name ".."))
399           #-windows "../"
400           #+windows "..\\")
401  t)
402
403(deftest physical.31
404  (string= (namestring (make-pathname :directory '(:relative :up)))
405           #+windows "..\\"
406           #-windows "../")
407  t)
408
409#+windows
410(deftest windows.1
411  (equal #p"/foo/bar/baz" #p"\\foo\\bar\\baz")
412  t)
413
414#+windows
415(deftest windows.2
416  (let ((pathname #p"foo.bar"))
417    (check-windows-pathname pathname nil nil nil "foo" "bar"))
418  t)
419
420#+windows
421(deftest windows.3
422  (let ((pathname #p"\\foo.bar"))
423    (check-windows-pathname pathname nil nil '(:absolute) "foo" "bar"))
424  t)
425
426#+windows
427(deftest windows.4
428  (let ((pathname #p"c:\\foo.bar"))
429    #+(or abcl allegro)
430    (check-windows-pathname pathname nil "c" '(:absolute) "foo" "bar")
431    #+clisp
432    (check-windows-pathname pathname nil "C" '(:absolute) "foo" "bar")
433    #+lispworks
434    (check-windows-pathname pathname "c" nil '(:absolute) "foo" "bar"))
435  t)
436
437#+windows
438(deftest windows.5
439  (equal #p"c:\\foo.bar" #p"C:\\FOO.BAR")
440  t)
441
442(deftest wild.1
443  (check-physical-pathname #p"foo.*" nil "foo" :wild)
444  t)
445
446(deftest wild.2
447  (check-physical-pathname #p"*.*" nil :wild :wild)
448  t)
449
450(deftest wild.3
451  #-(or cmu sbcl)
452  (check-physical-pathname #p"abc*" nil "abc*" nil)
453  #+(or cmu sbcl)
454  (wild-pathname-p #p"abc*")
455  t)
456
457(deftest wild.4
458  #-(or cmu sbcl)
459  (check-physical-pathname #p"abc?" nil "abc?" nil)
460  #+(or cmu sbcl)
461  (wild-pathname-p #p"abc?")
462  t)
463
464(deftest wild.5
465  #-(or cmu sbcl)
466  (check-physical-pathname #p"abc[d-h]" nil "abc[d-h]" nil)
467  #+(or cmu sbcl)
468  (wild-pathname-p #p"abc[d-h]")
469  t)
470
471;; Lots of dots.
472#+(or allegro abcl cmu)
473(deftest lots-of-dots.1
474  (check-physical-pathname #p"..." nil "..." nil)
475  t)
476#+cmu
477(pushnew 'lots-of-dots.1 *expected-failures*)
478
479#+(or allegro abcl cmu)
480(deftest lots-of-dots.2
481  (check-physical-pathname #p"......" nil "......" nil)
482  t)
483#+cmu
484(pushnew 'lots-of-dots.2 *expected-failures*)
485
486;; Silly names.
487#-(or allegro sbcl)
488(deftest silly.1
489  #+(or abcl clisp)
490  (signals-error (make-pathname :name "abc/def") 'error)
491  #-(or abcl clisp)
492  (check-readable (make-pathname :name "abc/def"))
493  t)
494#+(or cmu lispworks)
495(pushnew 'silly.1 *expected-failures*)
496
497(deftest silly.2
498  (signals-error (make-pathname :name "abc/def") 'error)
499  t)
500
501(deftest silly.3
502  (check-readable-or-signals-error (make-pathname :name ".foo"))
503  t)
504
505(deftest silly.4
506  (check-readable-or-signals-error (make-pathname :type ".foo"))
507  t)
508
509(deftest silly.5
510  (check-readable-or-signals-error (make-pathname :name "abc.def"))
511  t)
512
513(deftest silly.6
514  (check-readable-or-signals-error (make-pathname :type "abc.def"))
515  t)
516
517;; LOGICAL-PATHNAME-TRANSLATIONS
518#-allegro
519(deftest logical-pathname-translations.1
520  #+(or sbcl cmu lispworks)
521  (equal (logical-pathname-translations "effluvia")
522         '(("**;*.*.*" "/usr/local/**/*.*")))
523  #+clisp
524  (equal (logical-pathname-translations "effluvia")
525         '((#p"EFFLUVIA:**;*.*.*" "/usr/local/**/*.*")))
526  #+abcl
527  (equal (logical-pathname-translations "effluvia")
528         '((#p"EFFLUVIA:**;*.*.*" #p"/usr/local/**/*.*")))
529  t)
530
531;; "The null string, "", is not a valid value for any component of a logical
532;; pathname." 19.3.2.2
533(deftest logical-pathname.1
534  #-clisp
535  (signals-error (logical-pathname ":") 'error)
536  #+clisp
537  (check-logical-pathname (logical-pathname ":") "" '(:absolute) nil nil nil)
538  t)
539
540;; Parse error.
541(deftest logical-pathname.2
542  (signals-error (logical-pathname "effluvia::foo.bar")
543                 #-(or allegro clisp) 'parse-error
544                 #+(or allegro clisp) 'type-error)
545  t)
546
547;; If the prefix isn't a defined logical host, it's not a logical pathname.
548#-(or cmu (and clisp windows))
549;; CMUCL parses this as (:ABSOLUTE #<SEARCH-LIST foo>) "bar.baz" "42".
550;; CLISP signals a parse error reading #p"foo:bar.baz.42".
551(deftest logical.1
552  (let ((pathname #p"foo:bar.baz.42"))
553    #+allegro
554    ;; Except in Allegro.
555    (check-logical-pathname pathname "foo" nil "bar" "baz" nil)
556    #-allegro
557    (check-physical-pathname pathname nil "foo:bar.baz" "42"))
558  t)
559#+lispworks
560(pushnew 'logical.1 *expected-failures*)
561
562#+sbcl
563(deftest logical.2
564  ;; Even though "effluvia" is defined as a logical host, "bop" is not a valid
565  ;; logical pathname version, so this can't be a logical pathname.
566  (check-physical-pathname #p"effluvia:bar.baz.bop" nil "effluvia:bar.baz" "bop")
567  t)
568
569(deftest logical.3
570  #-allegro
571  (check-logical-pathname (make-pathname :defaults "effluvia:foo.lisp")
572                          "EFFLUVIA" '(:absolute) "FOO" "LISP" nil)
573  #+allegro
574  (check-logical-pathname (make-pathname :defaults "effluvia:foo.lisp")
575                          "effluvia" nil "foo" "lisp" nil)
576  t)
577
578#-allegro
579(deftest logical.4
580  (check-logical-pathname #p"effluvia:bar.baz.42" "EFFLUVIA" '(:absolute) "BAR" "BAZ" 42)
581  t)
582
583#-allegro
584(deftest logical.5
585  (string= (write-to-string #p"effluvia:bar.baz.42" :escape t)
586           "#P\"EFFLUVIA:BAR.BAZ.42\"")
587  t)
588
589#+allegro
590;; Allegro returns NIL for the device and directory and drops the version
591;; entirely (even from the namestring).
592(deftest logical.6
593  (check-logical-pathname #p"effluvia:bar.baz.42" "effluvia" nil "bar" "baz" nil)
594  t)
595
596#+allegro
597(deftest logical.7
598  (string= (write-to-string #p"effluvia:bar.baz" :escape t)
599           #+allegro-v6.2 "#p\"effluvia:bar.baz\""
600           #+allegro-v7.0 "#P\"effluvia:bar.baz\"")
601  t)
602
603(deftest logical.8
604  (typep (parse-namestring "**;*.*.*" "effluvia") 'logical-pathname)
605  t)
606
607(deftest logical.9
608  (check-namestring (parse-namestring "**;*.*.*" "effluvia")
609                    #-(or allegro lispworks)
610                    "EFFLUVIA:**;*.*.*"
611                    #+allegro
612                    ;; Allegro preserves case and drops the version component.
613                    "effluvia:**;*.*"
614                    #+lispworks
615                    "effluvia:**;*.*.*")
616  t)
617
618#-allegro
619;; The version can be a bignum.
620(deftest logical.10
621  (check-logical-pathname #p"effluvia:bar.baz.2147483648" "EFFLUVIA" '(:absolute) "BAR" "BAZ" 2147483648)
622  t)
623
624#-allegro
625(deftest logical.11
626  (check-namestring #p"effluvia:bar.baz.2147483648" "EFFLUVIA:BAR.BAZ.2147483648")
627  t)
628#+sbcl
629;; SBCL has a bug when the version is a bignum.
630(pushnew 'logical.11 *expected-failures*)
631
632(deftest logical.12
633  (check-namestring #p"effluvia:foo.bar.newest"
634                    #-allegro "EFFLUVIA:FOO.BAR.NEWEST"
635                    #+allegro "effluvia:foo.bar")
636  t)
637
638(deftest logical.13
639  #-allegro
640  (check-logical-pathname #p"effluvia:foo.*" "EFFLUVIA" '(:absolute) "FOO" :wild nil)
641  #+allegro
642  (check-logical-pathname #p"effluvia:foo.*" "effluvia" nil "foo" :wild nil)
643  t)
644
645(deftest logical.14
646  #-allegro
647  (check-logical-pathname #p"effluvia:*.lisp" "EFFLUVIA" '(:absolute) :wild "LISP" nil)
648  #+allegro
649  (check-logical-pathname #p"effluvia:*.lisp" "effluvia" nil :wild "lisp" nil)
650  t)
651
652(deftest logical.15
653  #-allegro
654  (check-logical-pathname #p"effluvia:bar.baz.newest" "EFFLUVIA" '(:absolute) "BAR" "BAZ" :newest)
655  #+allegro
656  (check-logical-pathname #p"effluvia:bar.baz.newest" "effluvia" nil "bar" "baz" nil)
657  t)
658
659(deftest logical.16
660  #-allegro
661  (check-logical-pathname #p"EFFLUVIA:BAR.BAZ.NEWEST" "EFFLUVIA" '(:absolute) "BAR" "BAZ" :newest)
662  #+allegro
663  (check-logical-pathname #p"EFFLUVIA:BAR.BAZ.NEWEST" "EFFLUVIA" nil "BAR" "BAZ" nil)
664  t)
665
666;; The directory component.
667(deftest logical.17
668  (check-logical-pathname #p"effluvia:foo;bar.baz" "EFFLUVIA" '(:absolute "FOO") "BAR" "BAZ" nil)
669  t)
670
671(deftest logical.18
672  (check-namestring #p"effluvia:foo;bar.baz"
673                    #-allegro "EFFLUVIA:FOO;BAR.BAZ"
674                    #+allegro "effluvia:foo;bar.baz")
675  t)
676
677(deftest logical.19
678  #-allegro
679  (check-logical-pathname #p"effluvia:;bar.baz" "EFFLUVIA" '(:relative) "BAR" "BAZ" nil)
680  #+allegro
681  ;; Allegro drops the directory component and removes the semicolon from the
682  ;; namestring.
683  (check-logical-pathname #p"effluvia:;bar.baz" "EFFLUVIA" nil "BAR" "BAZ" nil)
684  t)
685
686(deftest logical.20
687  (check-namestring #p"effluvia:;bar.baz"
688                    #+allegro "effluvia:bar.baz"
689                    #-allegro "EFFLUVIA:;BAR.BAZ")
690  t)
691
692;; "If a relative-directory-marker precedes the directories, the directory
693;; component parsed is as relative; otherwise, the directory component is
694;; parsed as absolute."
695(deftest logical.21
696  (equal (pathname-directory #p"effluvia:foo.baz")
697         #-allegro '(:absolute)
698         #+allegro nil)
699  t)
700
701(deftest logical.22
702  (typep  #p"effluvia:" 'logical-pathname)
703  t)
704
705(deftest logical.23
706  (equal (pathname-directory #p"effluvia:")
707         #-allegro '(:absolute)
708         #+allegro nil)
709  t)
710
711;; PARSE-NAMESTRING
712(deftest parse-namestring.1
713  #-allegro
714  (check-logical-pathname (parse-namestring "effluvia:foo.bar")
715                          "EFFLUVIA" '(:absolute) "FOO" "BAR" nil)
716  #+allegro
717  (check-logical-pathname (parse-namestring "effluvia:foo.bar")
718                          "effluvia" nil "foo" "bar" nil)
719  t)
720
721(deftest parse-namestring.2
722  (let ((pathname (parse-namestring "foo.bar" "effluvia")))
723    #-(or allegro lispworks)
724    (check-logical-pathname pathname "EFFLUVIA" '(:absolute) "FOO" "BAR" nil)
725    #+allegro
726    (check-logical-pathname pathname "effluvia" nil "foo" "bar" nil)
727    #+lispworks
728    (check-logical-pathname pathname "effluvia" '(:absolute) "FOO" "BAR" nil))
729  t)
730
731(deftest parse-namestring.3
732  (let ((pathname (parse-namestring "foo;bar;baz.fas.3" "effluvia")))
733    #-(or allegro lispworks)
734    (check-logical-pathname pathname "EFFLUVIA" '(:absolute "FOO" "BAR") "BAZ" "FAS" 3)
735    #+allegro
736    (check-logical-pathname pathname "effluvia" '(:absolute "foo" "bar") "baz" "fas" nil)
737    #+lispworks
738    (check-logical-pathname pathname "effluvia" '(:absolute "FOO" "BAR") "BAZ" "FAS" 3)
739    )
740  t)
741
742(deftest parse-namestring.4
743  #-(or abcl clisp cmu lispworks (and allegro windows))
744  (check-physical-pathname (parse-namestring "effluvia:foo.bar" "")
745                           nil "effluvia:foo" "bar")
746  #+abcl
747  ;; Invalid logical host name: ""
748  (signals-error (parse-namestring "effluvia:foo.bar" "") 'error)
749  #+(or clisp lispworks)
750  ;; Host mismatch.
751  (signals-error (parse-namestring "effluvia:foo.bar" "") 'error)
752  #+cmu
753  (signals-error (parse-namestring "effluvia:foo.bar" "") 'error)
754  #+(and allegro windows)
755  ;; "effluvia" is the device
756  (check-physical-pathname (parse-namestring "effluvia:foo.bar" "")
757                           nil "foo" "bar")
758  t)
759
760;; "If host is nil and thing is a syntactically valid logical pathname
761;; namestring containing an explicit host, then it is parsed as a logical
762;; pathname namestring."
763(deftest parse-namestring.5
764  #-allegro
765  (check-logical-pathname (parse-namestring "effluvia:foo.bar" nil)
766                          "EFFLUVIA" '(:absolute) "FOO" "BAR" nil)
767  #+allegro
768  (check-logical-pathname (parse-namestring "effluvia:foo.bar" nil)
769                          "effluvia" nil "foo" "bar" nil)
770  t)
771
772;; "If host is nil, default-pathname is a logical pathname, and thing is a
773;; syntactically valid logical pathname namestring without an explicit host,
774;; then it is parsed as a logical pathname namestring on the host that is the
775;; host component of default-pathname."
776(deftest parse-namestring.6
777  #-allegro
778  (check-logical-pathname (parse-namestring "foo" nil #p"effluvia:bar")
779                          "EFFLUVIA" '(:absolute) "FOO" nil nil)
780  #+allegro
781  (check-logical-pathname (parse-namestring "foo" nil #p"effluvia:bar")
782                          "effluvia" nil "foo" nil nil)
783  t)
784
785(deftest parse-namestring.7
786  (let* ((*default-pathname-defaults* (logical-pathname "EFFLUVIA:"))
787         (pathname (parse-namestring "foo.bar")))
788    #-allegro
789    (check-logical-pathname pathname "EFFLUVIA" '(:absolute) "FOO" "BAR" nil)
790    #+allegro
791    (check-logical-pathname pathname "effluvia" nil "foo" "bar" nil))
792  t)
793
794(deftest parse-namestring.8
795  (let* ((*default-pathname-defaults* #p"effluvia:bar")
796         (pathname (parse-namestring "foo" nil)))
797    #-allegro
798    (check-logical-pathname pathname "EFFLUVIA" '(:absolute) "FOO" nil nil)
799    #+allegro
800    (check-logical-pathname pathname "effluvia" nil "foo" nil nil))
801  t)
802
803;; WILD-PATHNAME-P
804(deftest wild-pathname-p.1
805  (wild-pathname-p #p"effluvia:;*.baz")
806  #+(or cmu sbcl) (:wild :wild-inferiors)
807  #-(or cmu sbcl) t)
808
809;; PATHNAME-MATCH-P
810(deftest pathname-match-p.1
811  (pathname-match-p "/foo/bar/baz" "/*/*/baz")
812  t)
813
814(deftest pathname-match-p.2
815  (pathname-match-p "/foo/bar/baz" "/**/baz")
816  t)
817
818(deftest pathname-match-p.3
819  (pathname-match-p "/foo/bar/quux/baz" "/**/baz")
820  t)
821
822(deftest pathname-match-p.4
823  (pathname-match-p "foo.bar" "/**/*.*")
824  t)
825
826(deftest pathname-match-p.5
827  (pathname-match-p "/usr/local/bin/foo.bar" "/**/foo.bar")
828  t)
829
830(deftest pathname-match-p.6
831  (pathname-match-p "/usr/local/bin/foo.bar" "**/foo.bar")
832  nil)
833
834(deftest pathname-match-p.7
835  (pathname-match-p "/foo/bar.txt" "/**/*.*")
836  t)
837
838(deftest pathname-match-p.8
839  (pathname-match-p "/foo/bar.txt" "**/*.*")
840  nil)
841
842(deftest pathname-match-p.9
843  (pathname-match-p #p"effluvia:foo.bar" #p"effluvia:**;*.*.*")
844  t)
845
846(deftest pathname-match-p.10
847  (pathname-match-p "foo" "foo.*")
848  t)
849
850;; TRANSLATE-PATHNAME
851(deftest translate-pathname.1
852  #-clisp
853  (equal (translate-pathname "foo" "*" "bar") #p"bar")
854  #+clisp
855  (signals-error (translate-pathname "foo" "*" "bar") 'error)
856  t)
857
858(deftest translate-pathname.2
859  (equal (translate-pathname "foo" "*" "*")   #p"foo")
860  t)
861
862(deftest translate-pathname.3
863  #-abcl
864  (string= (pathname-name (translate-pathname "foobar" "*" "foo*"))
865           #-allegro-v7.0 "foofoobar"
866           #+allegro-v7.0 "foo*")
867  #+abcl
868  ;; ABCL doesn't implement this translation. Verify that it signals an error.
869  (signals-error (translate-pathname "foobar" "*" "foo*") 'error)
870  t)
871
872(deftest translate-pathname.4
873  #-abcl
874  (equal (translate-pathname "foobar" "foo*" "*baz")
875         #-allegro-v7.0 #p"barbaz"
876         #+allegro-v7.0 #p"*baz")
877  #+abcl
878  ;; ABCL doesn't implement this translation. Verify that it signals an error.
879  (signals-error (translate-pathname "foobar" "foo*" "*baz") 'error)
880  t)
881
882(deftest translate-pathname.5
883  #-abcl
884  (equal (translate-pathname "foobar" "foo*" "")
885         #+(or allegro clisp) #p"bar"
886         #+(or cmu sbcl lispworks) #p"foobar")
887  #+abcl
888  ;; ABCL doesn't implement this translation. Verify that it signals an error.
889  (signals-error (translate-pathname "foobar" "foo*" "") 'error)
890  t)
891
892(deftest translate-pathname.6
893  (equal (translate-pathname "foo/bar" "*/bar" "*/baz") #p"foo/baz")
894  t)
895
896(deftest translate-pathname.7
897  (equal (translate-pathname "bar/foo" "bar/*" "baz/*") #p"baz/foo")
898  t)
899
900(deftest translate-pathname.8
901  (equal (translate-pathname "foo/bar" "*/bar" "*/baz") #p"foo/baz")
902  t)
903
904(deftest translate-pathname.9
905  (string= (namestring (translate-pathname "test.txt" "*.txt" "*.text"))
906           "test.text")
907  t)
908
909(deftest translate-pathname.10
910  (equal (translate-pathname "foo" "foo.*" "bar") #p"bar")
911  t)
912
913(deftest translate-pathname.11
914  (equal (translate-pathname "foo" "foo.*" "bar.*") #p"bar")
915  t)
916
917(deftest translate-pathname.12
918  (string= (namestring (translate-pathname "foo.bar" "*.*" "/usr/local/*.*"))
919           #-windows "/usr/local/foo.bar"
920           #+windows "\\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 "/tmp/x.y"
1253         #+windows "\\tmp\\x.y")
1254  t)
1255
1256#-(or allegro clisp)
1257(deftest sbcl.19
1258  (equal (namestring (translate-logical-pathname "bazooka:todemo;x.y"))
1259         (namestring (translate-logical-pathname "demo0:x.y")))
1260  t)
1261
1262;; "If HOST is incorrectly supplied, an error of type TYPE-ERROR is signaled."
1263(deftest sbcl.20
1264  (signals-error (logical-pathname-translations "unregistered-host")
1265                 #+(or clisp lispworks) 'error ;; BUG
1266                 #+cmu 'file-error ;; BUG
1267                 #-(or clisp lispworks cmu) 'type-error)
1268  t)
1269
1270(deftest sbcl.21
1271  (string-equal (host-namestring (parse-namestring "OTHER-HOST:ILLEGAL/LPN")) "OTHER-HOST")
1272  nil)
1273#+(or lispworks (and clisp windows))
1274(pushnew 'sbcl.21 *expected-failures*)
1275
1276(deftest sbcl.22
1277  (string= (pathname-name (parse-namestring "OTHER-HOST:ILLEGAL/LPN")) "LPN")
1278  t)
1279#+(and clisp windows)
1280(pushnew 'sbcl.22 *expected-failures*)
1281
1282(setf (logical-pathname-translations "test0")
1283      '(("**;*.*.*"              "/library/foo/**/")))
1284
1285(deftest sbcl.23
1286  (check-namestring (translate-logical-pathname "test0:foo;bar;baz;mum.quux")
1287                    "/library/foo/foo/bar/baz/mum.quux")
1288  t)
1289
1290(setf (logical-pathname-translations "prog")
1291      '(("CODE;*.*.*"             "/lib/prog/")))
1292
1293#-allegro
1294(deftest sbcl.24
1295  (check-namestring (translate-logical-pathname "prog:code;documentation.lisp")
1296                    "/lib/prog/documentation.lisp")
1297  t)
1298
1299(setf (logical-pathname-translations "prog1")
1300      '(("CODE;DOCUMENTATION.*.*" "/lib/prog/docum.*")
1301        ("CODE;*.*.*"             "/lib/prog/")))
1302
1303#-allegro
1304(deftest sbcl.25
1305  (check-namestring (translate-logical-pathname "prog1:code;documentation.lisp")
1306                    "/lib/prog/docum.lisp")
1307  t)
1308
1309;; "ANSI section 19.3.1.1.5 specifies that translation to a filesystem which
1310;; doesn't have versions should ignore the version slot. CMU CL didn't ignore
1311;; this as it should, but we [i.e. SBCL] do."
1312;; "Some file systems do not have versions. Logical pathname translation to
1313;; such a file system ignores the version." 19.3.1.1.5
1314#-cmu
1315;; CMUCL supports emacs-style versions.
1316(deftest sbcl.26
1317  (check-namestring (translate-logical-pathname "test0:foo;bar;baz;mum.quux.3")
1318                    "/library/foo/foo/bar/baz/mum.quux")
1319  t)
1320#+lispworks
1321(pushnew 'sbcl.26 *expected-failures*)
1322
1323(setf (logical-pathname-translations "scratch")
1324      '(("**;*.*.*" "/usr/local/doc/**/*")))
1325
1326;; Trivial merge.
1327(deftest sbcl.27
1328  (check-merge-pathnames #p"foo" #p"/usr/local/doc/" #p"/usr/local/doc/foo")
1329  t)
1330
1331;; If pathname does not specify a host, device, directory, name, or type, each
1332;; such component is copied from default-pathname.
1333;; 1) no name, no type
1334(deftest sbcl.28
1335  (check-merge-pathnames #p"/supplied-dir/" #p"/dir/name.type"
1336                         #p"/supplied-dir/name.type")
1337  t)
1338
1339;; 2) no directory, no type
1340(deftest sbcl.29
1341  (check-merge-pathnames #p"supplied-name" #p"/dir/name.type"
1342                         #p"/dir/supplied-name.type")
1343  t)
1344
1345;; 3) no name, no dir (must use make-pathname as ".foo" is parsed
1346;; as a name)
1347(deftest sbcl.30
1348  (check-merge-pathnames (make-pathname :type "supplied-type")
1349                         #p"/dir/name.type"
1350                         #p"/dir/name.supplied-type")
1351  t)
1352
1353;; If (pathname-directory pathname) is a list whose car is
1354;; :relative, and (pathname-directory default-pathname) is a
1355;; list, then the merged directory is [...]
1356(deftest sbcl.31
1357  (check-merge-pathnames #p"qqq/www" #p"/aaa/bbb/ccc/ddd/eee"
1358                         #p"/aaa/bbb/ccc/ddd/qqq/www")
1359  t)
1360
1361;; except that if the resulting list contains a string or
1362;; :wild immediately followed by :back, both of them are
1363;; removed.
1364(deftest sbcl.32
1365  (check-merge-pathnames
1366   ;; "../" in a namestring is parsed as :up not :back, so MAKE-PATHNAME.
1367   (make-pathname :directory '(:relative :back "blah"))
1368   #p"/aaa/bbb/ccc/ddd/eee" #P"/aaa/bbb/ccc/blah/eee")
1369  t)
1370
1371;; If (pathname-directory default-pathname) is not a list or
1372;; (pathname-directory pathname) is not a list whose car is
1373;; :relative, the merged directory is (or (pathname-directory
1374;; pathname) (pathname-directory default-pathname))
1375(deftest sbcl.33
1376  (check-merge-pathnames #p"/absolute/path/name" #p"/dir/default-name.type"
1377                         #P"/absolute/path/name.type")
1378  t)
1379
1380(deftest sbcl.34
1381  (check-merge-pathnames #p"scratch:;name2" #p"scratch:foo;"
1382                         #p"SCRATCH:FOO;NAME2")
1383  t)
1384
1385(deftest sbcl.35
1386  (check-merge-pathnames #p"scratch:;foo" #p"/usr/local/doc/"
1387                         #-(or allegro clisp lispworks) #P"SCRATCH:USR;LOCAL;DOC;FOO"
1388                         #+(and allegro unix) #p"/usr/local/doc/foo"
1389                         #+(and allegro windows) #p"scratch:usr;local;doc;foo"
1390                         #+clisp #p"SCRATCH:;FOO"
1391                         #+lispworks #p"SCRATCH:FOO")
1392  t)
1393
1394(deftest sbcl.36
1395  (check-merge-pathnames #p"scratch:supplied-dir;" #p"/dir/name.type"
1396                         #-clisp #p"SCRATCH:SUPPLIED-DIR;NAME.TYPE"
1397                         #+clisp
1398                         ;; #p"SCRATCH:SUPPLIED-DIR;name.type.NEWEST"
1399                         (make-pathname :host "SCRATCH"
1400                                        :directory '(:absolute "SUPPLIED-DIR")
1401                                        :name "name"
1402                                        :type "type"))
1403  t)
1404
1405(deftest sbcl.37
1406  (check-merge-pathnames #p"scratch:;supplied-name" #p"/dir/name.type"
1407                         #-(or allegro clisp lispworks)
1408                         #p"SCRATCH:DIR;SUPPLIED-NAME.TYPE"
1409                         #+(and allegro unix)
1410                         #p"/usr/local/doc/supplied-name.type"
1411                         #+(and allegro windows)
1412                         #P"scratch:dir;supplied-name.type"
1413                         #+clisp
1414                         ;; #P"SCRATCH:;SUPPLIED-NAME.type.NEWEST"
1415                         (make-pathname :host "SCRATCH"
1416                                        :directory '(:relative)
1417                                        :name "SUPPLIED-NAME"
1418                                        :type "type")
1419                         #+lispworks
1420                         ;; #P"SCRATCH:SUPPLIED-NAME.TYPE.NEWEST"
1421                         (make-pathname :host "SCRATCH"
1422                                        :directory '(:absolute)
1423                                        :name "SUPPLIED-NAME"
1424                                        :type "TYPE"))
1425  t)
1426
1427(deftest sbcl.38
1428  (check-merge-pathnames (make-pathname :host "scratch" :type "supplied-type")
1429                         #p"/dir/name.type"
1430                         #-(or allegro clisp lispworks)
1431                         #p"SCRATCH:DIR;NAME.SUPPLIED-TYPE"
1432                         #+(and allegro unix)
1433                         #p"/usr/local/doc/name.supplied-type"
1434                         #+(and allegro windows)
1435                         #P"scratch:dir;name.supplied-type"
1436                         #+clisp
1437                         ;; #P"SCRATCH:dir;name.supplied-type.NEWEST"
1438                         (make-pathname :host "SCRATCH"
1439                                        :directory '(:absolute "dir")
1440                                        :name "name"
1441                                        :type "supplied-type")
1442                         #+lispworks
1443                         ;; #P"SCRATCH:NAME.SUPPLIED-TYPE.NEWEST"
1444                         (make-pathname :host "SCRATCH"
1445                                        :directory '(:absolute)
1446                                        :name "NAME"
1447                                        :type "SUPPLIED-TYPE"))
1448  t)
1449
1450(deftest sbcl.39
1451  (let ((pathname (make-pathname :host "scratch"
1452                                        :directory '(:relative "foo")
1453                                        :name "bar"))
1454        (default-pathname #p"/aaa/bbb/ccc/ddd/eee"))
1455    #-allegro
1456    (check-merge-pathnames pathname default-pathname
1457                           #-(or clisp lispworks)
1458                           #p"SCRATCH:AAA;BBB;CCC;DDD;FOO;BAR"
1459                           #+clisp
1460                           ;; #P"SCRATCH:;foo;bar"
1461                           (make-pathname :host "SCRATCH"
1462                                          :directory '(:relative "foo")
1463                                          :name "bar")
1464                           #+lispworks
1465                           #p"SCRATCH:FOO;BAR")
1466    #+(and allegro unix)
1467    (signals-error (merge-pathnames pathname default-pathname) 'error)
1468    #+(and allegro windows)
1469    (check-merge-pathnames pathname default-pathname
1470                           #P"scratch:aaa;bbb;ccc;ddd;foo;bar"))
1471  t)
1472
1473#-lispworks
1474(deftest sbcl.40
1475  (let ((pathname (make-pathname :host "scratch"
1476                                 :directory '(:relative :back "foo")
1477                                 :name "bar"))
1478        (default-pathname #p"/aaa/bbb/ccc/ddd/eee"))
1479    #-allegro
1480    (check-merge-pathnames pathname default-pathname
1481                           #-clisp #p"SCRATCH:AAA;BBB;CCC;FOO;BAR"
1482                           #+clisp
1483                           ;; #P"SCRATCH:;..;foo;bar.NEWEST"
1484                           (make-pathname :host "SCRATCH"
1485                                          :directory '(:relative :back "foo")
1486                                          :name "bar"))
1487    #+(and allegro unix)
1488    (signals-error (merge-pathnames pathname default-pathname) 'error)
1489    #+(and allegro windows)
1490    (check-merge-pathnames pathname default-pathname
1491                           #P"scratch:aaa;bbb;ccc;foo;bar"))
1492  t)
1493
1494#+lispworks
1495;; "Illegal logical pathname directory component: :BACK."
1496(deftest sbcl.40
1497  (signals-error (make-pathname :host "scratch"
1498                                :directory '(:relative :back "foo")
1499                                :name "bar")
1500                 'error)
1501  t)
1502
1503(deftest sbcl.41
1504  (check-merge-pathnames #p"scratch:absolute;path;name"
1505                         #p"/dir/default-name.type"
1506                         #-clisp #p"SCRATCH:ABSOLUTE;PATH;NAME.TYPE"
1507                         #+clisp
1508                         ;; #P"SCRATCH:ABSOLUTE;PATH;NAME.type.NEWEST"
1509                         (make-pathname :host "SCRATCH"
1510                                        :directory '(:absolute "ABSOLUTE" "PATH")
1511                                        :name "NAME"
1512                                        :type "type"))
1513  t)
1514
1515(deftest sbcl.42
1516  (check-namestring (parse-namestring "/foo" (host-namestring #p"/bar")) "/foo")
1517  t)
1518#+lispworks
1519(pushnew 'sbcl.42 *expected-failures*)
1520
1521(deftest sbcl.43
1522  (string= (namestring (parse-namestring "FOO" (host-namestring #p"SCRATCH:BAR")))
1523           "SCRATCH:FOO")
1524  t)
1525
1526#-(or allegro clisp cmu lispworks)
1527(deftest sbcl.44
1528  ;; "The null string, "", is not a valid value for any component of a logical
1529  ;; pathname." 19.3.2.2
1530  (signals-error (setf (logical-pathname-translations "")
1531                       (list '("**;*.*.*" "/**/*.*")))
1532                 'error)
1533  t)
1534
1535#-clisp
1536(deftest sbcl.45
1537  (check-namestring (translate-logical-pathname "/") "/")
1538  t)
1539
1540(deftest sbcl.46
1541  (signals-error (pathname (make-string-input-stream "FOO"))
1542                 #-(or allegro-v6.2 cmu) 'type-error
1543                 #+allegro-v6.2     'stream-error
1544                 #+cmu              'error)
1545  t)
1546
1547(deftest sbcl.47
1548  (signals-error (merge-pathnames (make-string-output-stream))
1549                 #-allegro-v6.2 'type-error
1550                 #+allegro-v6.2 'stream-error)
1551  t)
1552
1553(deftest sbcl.48
1554  (check-readable-or-signals-error (make-pathname :name "foo" :type "txt" :version :newest))
1555  t)
1556#+lispworks
1557(pushnew 'sbcl.48 *expected-failures*)
1558
1559#-allegro
1560(deftest sbcl.49
1561  (check-readable-or-signals-error (make-pathname :name "foo" :type "txt" :version 1))
1562  t)
1563#+lispworks
1564(pushnew 'sbcl.49 *expected-failures*)
1565
1566(deftest sbcl.50
1567  #-clisp
1568  (check-readable-or-signals-error (make-pathname :name "foo" :type ".txt"))
1569  #+clisp
1570  (signals-error (make-pathname :name "foo" :type ".txt") 'error)
1571  t)
1572#+(or allegro cmu lispworks)
1573(pushnew 'sbcl.50 *expected-failures*)
1574
1575(deftest sbcl.51
1576  (check-readable-or-signals-error (make-pathname :name "foo." :type "txt"))
1577  t)
1578
1579(deftest sbcl.52
1580  (check-readable-or-signals-error (parse-namestring "SCRATCH:FOO.TXT.1"))
1581  t)
1582
1583(deftest sbcl.53
1584  (check-readable-or-signals-error (parse-namestring "SCRATCH:FOO.TXT.NEWEST"))
1585  t)
1586
1587(deftest sbcl.54
1588  (check-readable-or-signals-error (parse-namestring "SCRATCH:FOO.TXT"))
1589  t)
1590
1591(deftest sbcl.55
1592  (equal (parse-namestring "foo" nil "/")
1593         (parse-namestring "foo" nil #p"/"))
1594  t)
1595
1596#-allegro
1597(deftest sbcl.56
1598  (let ((test "parse-namestring-test.tmp"))
1599    (unwind-protect
1600        (with-open-file (f test :direction :output)
1601          ;; FIXME: This test is a bit flaky, since we only check that
1602          ;; no error is signalled. The dilemma here is "what is the
1603          ;; correct result when defaults is a _file_, not a
1604          ;; directory". Currently (0.8.10.73) we get #P"foo" here (as
1605          ;; opposed to eg. #P"/path/to/current/foo"), which is
1606          ;; possibly mildly surprising but probably conformant.
1607          (equal (parse-namestring "foo" nil f) #p"foo"))
1608      (when (probe-file test)
1609        (delete-file test))))
1610  t)
1611
1612;;; ENOUGH-NAMESTRING should probably not fail when the namestring in
1613;;; question has a :RELATIVE pathname.
1614(deftest sbcl.57
1615  (equal (enough-namestring #p"foo" #p"./") "foo")
1616  t)
1617
1618;;; bug reported by Artem V. Andreev: :WILD not handled in unparsing
1619;;; directory lists.
1620(deftest sbcl.58
1621  (check-namestring #p"/tmp/*/" "/tmp/*/")
1622  t)
1623
1624#-allegro
1625(deftest sbcl.59
1626  (string= (with-standard-io-syntax (write-to-string #p"/foo"))
1627           #-windows "#P\"/foo\""
1628           #+(and windows (not lispworks)) "#P\"\\\\foo\""
1629           #+(and windows lispworks) "#P\"/foo\"")
1630  t)
1631
1632#-allegro
1633(deftest sbcl.60
1634  (string= (with-standard-io-syntax (write-to-string #p"/foo" :readably nil))
1635           #-windows "#P\"/foo\""
1636           #+(and windows (not lispworks)) "#P\"\\\\foo\""
1637           #+(and windows lispworks) "#P\"/foo\"")
1638  t)
1639
1640#-allegro
1641(deftest sbcl.61
1642  (string= (with-standard-io-syntax (write-to-string #p"/foo" :escape nil))
1643           #-windows "#P\"/foo\""
1644           #+(and windows (not lispworks)) "#P\"\\\\foo\""
1645           #+(and windows lispworks) "#P\"/foo\"")
1646  t)
1647
1648(deftest sbcl.62
1649  (string= (with-standard-io-syntax (write-to-string #p"/foo" :readably nil :escape nil))
1650           #-windows "/foo"
1651           #+windows "\\foo")
1652  t)
1653
1654(do-tests)
Note: See TracBrowser for help on using the repository browser.