-(setf (logical-pathname-translations "scratch")
- '(("**;*.*.*" "/usr/local/doc/**/*")))
-
-(loop for (expected-result . params) in
- `(;; trivial merge
- (#P"/usr/local/doc/foo" #p"foo" #p"/usr/local/doc/")
- ;; If pathname does not specify a host, device, directory,
- ;; name, or type, each such component is copied from
- ;; default-pathname.
- ;; 1) no name, no type
- (#p"/supplied-dir/name.type" #p"/supplied-dir/" #p"/dir/name.type")
- ;; 2) no directory, no type
- (#p"/dir/supplied-name.type" #p"supplied-name" #p"/dir/name.type")
- ;; 3) no name, no dir (must use make-pathname as ".foo" is parsed
- ;; as a name)
- (#p"/dir/name.supplied-type"
- ,(make-pathname :type "supplied-type")
- #p"/dir/name.type")
- ;; If (pathname-directory pathname) is a list whose car is
- ;; :relative, and (pathname-directory default-pathname) is a
- ;; list, then the merged directory is [...]
- (#p"/aaa/bbb/ccc/ddd/qqq/www" #p"qqq/www" #p"/aaa/bbb/ccc/ddd/eee")
- ;; except that if the resulting list contains a string or
- ;; :wild immediately followed by :back, both of them are
- ;; removed.
- (#P"/aaa/bbb/ccc/blah/eee"
- ;; "../" in a namestring is parsed as :up not :back, so make-pathname
- ,(make-pathname :directory '(:relative :back "blah"))
- #p"/aaa/bbb/ccc/ddd/eee")
- ;; If (pathname-directory default-pathname) is not a list or
- ;; (pathname-directory pathname) is not a list whose car is
- ;; :relative, the merged directory is (or (pathname-directory
- ;; pathname) (pathname-directory default-pathname))
- (#P"/absolute/path/name.type"
- #p"/absolute/path/name"
- #p"/dir/default-name.type")
- ;; === logical pathnames ===
- ;; recognizes a logical pathname namestring when
- ;; default-pathname is a logical pathname
- ;; FIXME: 0.6.12.23 fails this one.
- #+nil (#P"scratch:foo;name1" #p"name1" #p"scratch:foo;")
- ;; or when the namestring begins with the name of a defined
- ;; logical host followed by a colon [I assume that refers to pathname
- ;; rather than default-pathname]
- (#p"SCRATCH:FOO;NAME2" #p"scratch:;name2" #p"scratch:foo;")
- ;; conduct the previous set of tests again, with a lpn first argument
- (#P"SCRATCH:USR;LOCAL;DOC;FOO" #p"scratch:;foo" #p"/usr/local/doc/")
- (#p"SCRATCH:SUPPLIED-DIR;NAME.TYPE"
- #p"scratch:supplied-dir;"
- #p"/dir/name.type")
- (#p"SCRATCH:DIR;SUPPLIED-NAME.TYPE"
- #p"scratch:;supplied-name"
- #p"/dir/name.type")
- (#p"SCRATCH:DIR;NAME.SUPPLIED-TYPE"
- ,(make-pathname :host "scratch" :type "supplied-type")
- #p"/dir/name.type")
- (#p"SCRATCH:AAA;BBB;CCC;DDD;FOO;BAR"
- ,(make-pathname :host "scratch"
- :directory '(:relative "foo")
- :name "bar")
- #p"/aaa/bbb/ccc/ddd/eee")
- (#p"SCRATCH:AAA;BBB;CCC;FOO;BAR"
- ,(make-pathname :host "scratch"
- :directory '(:relative :back "foo")
- :name "bar")
- #p"/aaa/bbb/ccc/ddd/eee")
- (#p"SCRATCH:ABSOLUTE;PATH;NAME.TYPE"
- #p"scratch:absolute;path;name" #p"/dir/default-name.type")
-
- ;; FIXME: test version handling in LPNs
- )
- do (assert (string= (namestring (apply #'merge-pathnames params))
- (namestring expected-result))))
+;;; Needs to be done at compile time, so that the #p"" read-macro
+;;; correctly parses things as logical pathnames. This is not a
+;;; problem as was, as this is an impure file and so gets loaded in,
+;;; but just for future proofing...
+(eval-when (:compile-toplevel :load-toplevel :execute)
+ (setf (logical-pathname-translations "scratch")
+ '(("**;*.*.*" "/usr/local/doc/**/*"))))
+
+(with-test (:name (:merge-pathname 1))
+ (loop for (expected-result . params) in
+ `( ;; trivial merge
+ (#P"/usr/local/doc/foo" #p"foo" #p"/usr/local/doc/")
+ ;; If pathname does not specify a host, device, directory,
+ ;; name, or type, each such component is copied from
+ ;; default-pathname.
+ ;; 1) no name, no type
+ (#p"/supplied-dir/name.type" #p"/supplied-dir/" #p"/dir/name.type")
+ ;; 2) no directory, no type
+ (#p"/dir/supplied-name.type" #p"supplied-name" #p"/dir/name.type")
+ ;; 3) no name, no dir (must use make-pathname as ".foo" is parsed
+ ;; as a name)
+ (#p"/dir/name.supplied-type"
+ ,(make-pathname :type "supplied-type")
+ #p"/dir/name.type")
+ ;; If (pathname-directory pathname) is a list whose car is
+ ;; :relative, and (pathname-directory default-pathname) is a
+ ;; list, then the merged directory is [...]
+ (#p"/aaa/bbb/ccc/ddd/qqq/www" #p"qqq/www" #p"/aaa/bbb/ccc/ddd/eee")
+ ;; except that if the resulting list contains a string or
+ ;; :wild immediately followed by :back, both of them are
+ ;; removed.
+ (#P"/aaa/bbb/ccc/blah/eee"
+ ;; "../" in a namestring is parsed as :up not :back, so make-pathname
+ ,(make-pathname :directory '(:relative :back "blah"))
+ #p"/aaa/bbb/ccc/ddd/eee")
+ ;; If (pathname-directory default-pathname) is not a list or
+ ;; (pathname-directory pathname) is not a list whose car is
+ ;; :relative, the merged directory is (or (pathname-directory
+ ;; pathname) (pathname-directory default-pathname))
+ (#P"/absolute/path/name.type"
+ #p"/absolute/path/name"
+ #p"/dir/default-name.type")
+ ;; === logical pathnames ===
+ ;; recognizes a logical pathname namestring when
+ ;; default-pathname is a logical pathname
+ ;; FIXME: 0.6.12.23 fails this one.
+ ;;
+ ;; And, as it happens, it's right to fail it. Because
+ ;; #p"name1" is read in with the ambient *d-p-d* value, which
+ ;; has a physical (Unix) host; therefore, the host of the
+ ;; default-pathname argument to merge-pathnames is
+ ;; irrelevant. The result is (correctly) different if
+ ;; '#p"name1"' is replaced by "name1", below, though it's
+ ;; still not what one might expect... -- CSR, 2002-05-09
+ #+nil (#P"scratch:foo;name1" #p"name1" #p"scratch:foo;")
+ ;; or when the namestring begins with the name of a defined
+ ;; logical host followed by a colon [I assume that refers to pathname
+ ;; rather than default-pathname]
+ (#p"SCRATCH:FOO;NAME2" #p"scratch:;name2" #p"scratch:foo;")
+ ;; conduct the previous set of tests again, with a lpn first argument
+ (#P"SCRATCH:USR;LOCAL;DOC;FOO" #p"scratch:;foo" #p"/usr/local/doc/")
+ (#p"SCRATCH:SUPPLIED-DIR;NAME.TYPE"
+ #p"scratch:supplied-dir;"
+ #p"/dir/name.type")
+ (#p"SCRATCH:DIR;SUPPLIED-NAME.TYPE"
+ #p"scratch:;supplied-name"
+ #p"/dir/name.type")
+ (#p"SCRATCH:DIR;NAME.SUPPLIED-TYPE"
+ ,(make-pathname :host "scratch" :type "supplied-type")
+ #p"/dir/name.type")
+ (#p"SCRATCH:AAA;BBB;CCC;DDD;FOO;BAR"
+ ,(make-pathname :host "scratch"
+ :directory '(:relative "foo")
+ :name "bar")
+ #p"/aaa/bbb/ccc/ddd/eee")
+ (#p"SCRATCH:AAA;BBB;CCC;FOO;BAR"
+ ,(make-pathname :host "scratch"
+ :directory '(:relative :back "foo")
+ :name "bar")
+ #p"/aaa/bbb/ccc/ddd/eee")
+ (#p"SCRATCH:ABSOLUTE;PATH;NAME.TYPE"
+ #p"scratch:absolute;path;name" #p"/dir/default-name.type")
+
+ ;; FIXME: test version handling in LPNs
+ )
+ do (let ((result (apply #'merge-pathnames params)))
+ (macrolet ((frob (op)
+ `(assert (equal (,op result) (,op expected-result)))))
+ (frob pathname-host)
+ (frob pathname-directory)
+ (frob pathname-name)
+ (frob pathname-type)))))
+\f
+;;; host-namestring testing
+(with-test (:name :host-namestring)
+ (assert (string=
+ (namestring (parse-namestring "/foo" (host-namestring #p"/bar")))
+ "/foo"))
+ (assert (string=
+ (namestring (parse-namestring "FOO" (host-namestring #p"SCRATCH:BAR")))
+ "SCRATCH:FOO"))
+ (assert (raises-error?
+ (setf (logical-pathname-translations "")
+ (list '("**;*.*.*" "/**/*.*"))))))
+\f
+;;; Bug 200: translate-logical-pathname is according to the spec supposed
+;;; not to give errors if asked to translate a namestring for a valid
+;;; physical pathname. Failed in 0.7.7.28 and before
+(with-test (:name (:logical-pathname 16))
+ (assert (string= (namestring (translate-logical-pathname "/")) "/")))
+
+\f
+;;; Not strictly pathname logic testing, but until sbcl-0.7.6.19 we
+;;; had difficulty with non-FILE-STREAM stream arguments to pathname
+;;; functions (they would cause memory protection errors). Make sure
+;;; that those errors are gone:
+(with-test (:name (:string-streams-as-pathnames 1))
+ (assert (raises-error? (pathname (make-string-input-stream "FOO"))
+ type-error))
+ (assert (raises-error? (merge-pathnames (make-string-output-stream))
+ type-error)))
+\f
+;;; ensure print-read consistency (or print-not-readable-error) on
+;;; pathnames:
+(with-test (:name :print/read-consistency :fails-on :win32)
+ (let ((pathnames (list
+ (make-pathname :name "foo" :type "txt" :version :newest)
+ (make-pathname :name "foo" :type "txt" :version 1)
+ (make-pathname :name "foo" :type ".txt")
+ (make-pathname :name "foo." :type "txt")
+ (parse-namestring "SCRATCH:FOO.TXT.1")
+ (parse-namestring "SCRATCH:FOO.TXT.NEWEST")
+ (parse-namestring "SCRATCH:FOO.TXT"))))
+ (dolist (p pathnames)
+ (print p)
+ (handler-case
+ (let* ((*print-readably* t)
+ (new (read-from-string (format nil "~S" p))))
+ (unless (equal new p)
+ (let ((*print-readably* nil))
+ (error "oops: host:~S device:~S dir:~S version:~S~% ->~%~
+ host:~S device:~S dir:~S version:~S"
+ (pathname-host p) (pathname-device p)
+ (pathname-directory p) (pathname-version p)
+ (pathname-host new) (pathname-device new)
+ (pathname-directory new) (pathname-version new)))))
+ (print-not-readable ()
+ nil)))))
+\f
+;;; BUG 330: "PARSE-NAMESTRING should accept namestrings as the
+;;; default argument" ...and streams as well
+(with-test (:name :parse-namestring/stream)
+ (assert (equal (parse-namestring "foo" nil "/")
+ (parse-namestring "foo" nil #P"/")))
+ (let ((test "parse-namestring-test.tmp"))
+ (unwind-protect
+ (with-open-file (f test :direction :output)
+ ;; FIXME: This test is a bit flaky, since we only check that
+ ;; no error is signalled. The dilemma here is "what is the
+ ;; correct result when defaults is a _file_, not a
+ ;; directory". Currently (0.8.10.73) we get #P"foo" here (as
+ ;; opposed to eg. #P"/path/to/current/foo"), which is
+ ;; possibly mildly surprising but probably conformant.
+ (assert (parse-namestring "foo" nil f)))
+ (when (probe-file test)
+ (delete-file test)))))
+\f
+;;; ENOUGH-NAMESTRING should probably not fail when the namestring in
+;;; question has a :RELATIVE pathname.
+(with-test (:name :enough-namestring)
+ (assert (equal (enough-namestring #p"foo" #p"./") "foo")))
+\f
+;;; bug reported by Artem V. Andreev: :WILD not handled in unparsing
+;;; directory lists.
+(with-test (:name :unparse-wild)
+ (assert (equal (namestring #p"/tmp/*/") "/tmp/*/")))
+
+;;; Printing of pathnames; see CLHS 22.1.3.1. This section was started
+;;; to confirm that pathnames are printed as their namestrings under
+;;; :escape nil :readably nil.
+(with-test (:name :print-as-namestrings)
+ (loop for (pathname expected . vars) in
+ `((#p"/foo" "#P\"/foo\"")
+ (#p"/foo" "#P\"/foo\"" :readably nil)
+ (#p"/foo" "#P\"/foo\"" :escape nil)
+ (#p"/foo" "/foo" :readably nil :escape nil))
+ for actual = (with-standard-io-syntax
+ (apply #'write-to-string pathname vars))
+ do (assert (string= expected actual)
+ ()
+ "~S should be ~S, was ~S"
+ (list* 'write-to-string pathname vars)
+ expected
+ actual)))
+\f
+;;; we got (truename "/") wrong for about 6 months. Check that it's
+;;; still right.
+(with-test (:name :root-truename :fails-on :win32)
+ (let ((pathname (truename "/")))
+ (assert (equalp pathname #p"/"))
+ (assert (equal (pathname-directory pathname) '(:absolute)))))
+\f
+;;; we failed to unparse logical pathnames with :NAME :WILD :TYPE NIL.
+;;; (Reported by Pascal Bourguignon.
+(with-test (:name :unparse-logical-wild)
+ (let ((pathname (make-pathname :host "SYS" :directory '(:absolute :wild-inferiors)
+ :name :wild :type nil)))
+ (assert (string= (namestring pathname) "SYS:**;*"))
+ (assert (string= (write-to-string pathname :readably t) "#P\"SYS:**;*\""))))
+\f
+;;; reported by James Y Knight on sbcl-devel 2006-05-17
+(with-test (:name :merge-back :fails-on :win32)
+ (let ((p1 (make-pathname :directory '(:relative "bar")))
+ (p2 (make-pathname :directory '(:relative :back "foo"))))
+ (assert (equal (merge-pathnames p1 p2)
+ (make-pathname :directory '(:relative :back "foo" "bar"))))))
+
+;;; construct native namestrings even if the directory is empty (means
+;;; that same as if (:relative))
+(with-test (:name :native-namestring)
+ (assert (equal (sb-ext:native-namestring (make-pathname :directory '(:relative)
+ :name "foo"
+ :type "txt"))
+ (sb-ext:native-namestring (let ((p (make-pathname :directory nil
+ :name "foo"
+ :type "txt")))
+ (assert (not (pathname-directory p)))
+ p)))))
+
+;;; reported by Richard Kreuter: PATHNAME and MERGE-PATHNAMES used to
+;;; be unsafely-flushable. Since they are known to return non-nil values
+;;; only, the test-node of the IF is flushed, and since the function
+;;; is unsafely-flushable, out it goes, and bad pathname designators
+;;; breeze through.
+;;;
+;;; These tests rely on using a stream that appears as a file-stream
+;;; but isn't a valid pathname-designator.
+(with-test (:name :dont-flush-pathnames)
+ (assert (eq :false
+ (if (ignore-errors (pathname sb-sys::*tty*)) :true :false)))
+ (assert (eq :false
+ (if (ignore-errors (merge-pathnames sb-sys::*tty*)) :true :false))))
+
+;;; This used to return "quux/bar.lisp"
+(with-test (:name :dpd-output-file)
+ (assert (equal #p"quux/bar.fasl"
+ (let ((*default-pathname-defaults* #p"quux/"))
+ (compile-file-pathname "foo.lisp" :output-file "bar"))))
+ (assert (equal #p"quux/bar.fasl"
+ (let ((*default-pathname-defaults* #p"quux/"))
+ (compile-file-pathname "bar.lisp")))))
+\f
+(with-test (:name :wild-enough)
+ (enough-namestring #p".a*"))
+\f
+
+(with-test (:name :translated-wild-version)
+ (assert (eq 99
+ (pathname-version
+ (translate-pathname
+ (make-pathname :name "foo" :type "bar" :version 99)
+ (make-pathname :name :wild :type :wild :version :wild)
+ (make-pathname :name :wild :type :wild :version :wild)))))
+
+ (assert (eq 99
+ (pathname-version
+ (translate-pathname
+ (make-pathname :name "foo" :type "bar" :version 99)
+ (make-pathname :name :wild :type :wild :version :wild)
+ (make-pathname :name :wild :type :wild :version nil))))))
+
+;;; enough-namestring relative to root
+(with-test (:name :enough-relative-to-root)
+ (assert (equal "foo" (enough-namestring "/foo" "/"))))