File: make-pathname.lsp

package info (click to toggle)
cl-ansi-tests 20071218-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 7,000 kB
  • ctags: 22,025
  • sloc: lisp: 134,798; makefile: 144
file content (171 lines) | stat: -rw-r--r-- 4,377 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Sat Nov 29 05:54:30 2003
;;;; Contains: Tests of MAKE-PATHNAME

(in-package :cl-test)

(defvar *null-pathname*
    (make-pathname))

(defun make-pathname-test
  (&rest args &key (defaults nil)
	 (host (if defaults (pathname-host defaults)
		 (pathname-host *default-pathname-defaults*)))
	 (device (if defaults (pathname-device defaults)
		   (pathname-device *null-pathname*)))
	 (directory (if defaults (pathname-directory defaults)
		      (pathname-directory *null-pathname*)))
	 (name (if defaults (pathname-name defaults)
		 (pathname-name  *null-pathname*)))
	 (type (if defaults (pathname-type defaults)
		 (pathname-type *null-pathname*)))
	 (version (if defaults (pathname-version defaults)
		    (pathname-version *null-pathname*)))
	 case)
  (declare (ignorable case))
  (let* ((vals (multiple-value-list (apply #'make-pathname args)))
	 (pn (first vals)))
    (and (= (length vals) 1)
	 (typep pn 'pathname)
	 (equalp (pathname-host pn) host)
	 (equalp (pathname-device pn) device)
	 ;; (equalp (pathname-directory pn) directory)
	 (let ((pnd (pathname-directory pn)))
	   (if (eq directory :wild)
	       (member pnd '((:absolute :wild-inferiors)
			     (:absolute :wild))
		       :test #'equal)
	     (equalp pnd directory)))	     
	 (equalp (pathname-name pn) name)
	 (equalp (pathname-type pn) type)
	 (equalp (pathname-version pn) version)
	 t)))
  
  

(deftest make-pathname.1
  (make-pathname-test)
  t)

(deftest make-pathname.2
  (make-pathname-test :name "foo")
  t)

(deftest make-pathname.2a
  (do-special-strings
   (s "foo")
   (assert (make-pathname-test :name s)))
  nil)

(deftest make-pathname.3
  (make-pathname-test :name "foo" :type "txt")
  t)

(deftest make-pathname.3a
  (do-special-strings
   (s "txt")
   (assert (make-pathname-test :name "foo" :type s)))
  nil)

(deftest make-pathname.4
  (make-pathname-test :type "lsp")
  t)

(deftest make-pathname.5
  (make-pathname-test :directory :wild)
  t)

(deftest make-pathname.6
  (make-pathname-test :name :wild)
  t)

(deftest make-pathname.7
  (make-pathname-test :type :wild)
  t)

(deftest make-pathname.8
  (make-pathname-test :version :wild)
  t)

(deftest make-pathname.9
  (make-pathname-test :defaults *default-pathname-defaults*)
  t)

(deftest make-pathname.10
  (make-pathname-test :defaults (make-pathname :name "foo" :type "bar"))
  t)

(deftest make-pathname.11
  (make-pathname-test :version :newest)
  t)

(deftest make-pathname.12
  (make-pathname-test :case :local)
  t)

(deftest make-pathname.13
  (make-pathname-test :case :common)
  t)

(deftest make-pathname.14
  (let ((*default-pathname-defaults*
	 (make-pathname :name "foo" :type "lsp" :version :newest)))
    (make-pathname-test))
  t)

;;; Works on the components of actual pathnames
(deftest make-pathname.rebuild
  (loop for p in *pathnames*
	for host = (pathname-host p)
	for device = (pathname-device p)
	for directory = (pathname-directory p)
	for name = (pathname-name p)
	for type = (pathname-type p)
	for version = (pathname-version p)
	for p2 = (make-pathname
		  :host host
		  :device device
		  :directory directory
		  :name name
		  :type type
		  :version version)
	unless (equal p p2)
	collect (list p p2))
  nil)

;;; Various constraints on :directory

(deftest make-pathname-error-absolute-up
  (signals-error (directory (make-pathname :directory '(:absolute :up)))
		 file-error)
  t)

(deftest make-pathname-error-absolute-back
  (signals-error (directory (make-pathname :directory '(:absolute :back)))
		 file-error)
  t)

;; The next test is correct, but was causing very large amounts of time to be spent
;; in buggy implementations
#|
(deftest make-pathname-error-absolute-wild-inferiors-up
  (signals-error (directory (make-pathname :directory '(:absolute :wild-inferiors :up)))
		 file-error)
  t)
|#

(deftest make-pathname-error-relative-wild-inferiors-up
  (signals-error (length (directory (make-pathname :directory '(:relative :wild-inferiors :up))))
		 file-error)
  t)

(deftest make-pathname-error-absolute-wild-inferiors-back
  (signals-error (directory (make-pathname :directory '(:absolute :wild-inferiors :back)))
		 file-error)
  t)

(deftest make-pathname-error-relative-wild-inferiors-back
  (signals-error (directory (make-pathname :directory '(:relative :wild-inferiors :back)))
		 file-error)
  t)