source: trunk/abcl/test/lisp/abcl/jar-pathname.lisp @ 12949

Last change on this file since 12949 was 12949, checked in by ehuelsmann, 11 years ago

Remove debug print.

File size: 10.6 KB
Line 
1(in-package #:abcl.test.lisp)
2
3(defvar *jar-file-init* nil)
4
5;;; From CL-FAD
6(defvar *stream-buffer-size* 8192)
7(defun cl-fad-copy-stream (from to &optional (checkp t))
8  "Copies into TO \(a stream) from FROM \(also a stream) until the end
9of FROM is reached, in blocks of *stream-buffer-size*.  The streams
10should have the same element type.  If CHECKP is true, the streams are
11checked for compatibility of their types."
12  (when checkp
13    (unless (subtypep (stream-element-type to) (stream-element-type from))
14      (error "Incompatible streams ~A and ~A." from to)))
15  (let ((buf (make-array *stream-buffer-size*
16                         :element-type (stream-element-type from))))
17    (loop
18     (let ((pos (read-sequence buf from)))
19       (when (zerop pos) (return))
20       (write-sequence buf to :end pos))))
21  (values))
22
23(defun cl-fad-copy-file (from to &key overwrite)
24  "Copies the file designated by the non-wild pathname designator FROM
25to the file designated by the non-wild pathname designator TO.  If
26OVERWRITE is true overwrites the file designtated by TO if it exists."
27  (let ((element-type '(unsigned-byte 8)))
28    (with-open-file (in from :element-type element-type)
29      (with-open-file (out to :element-type element-type
30                              :direction :output
31                              :if-exists (if overwrite
32                                           :supersede :error))
33        (cl-fad-copy-stream in out))))
34  (values))
35
36(defun jar-file-init ()
37  (let* ((*default-pathname-defaults*  *abcl-test-directory*)
38         (asdf::*verbose-out* *standard-output*))
39    (compile-file "foo.lisp")
40    (compile-file "bar.lisp")
41    (compile-file "eek.lisp")
42    (let* ((dir (merge-pathnames "tmp/" *abcl-test-directory*))
43           (sub (merge-pathnames "a/b/" dir)))
44      (when (probe-directory dir)
45        (delete-directory-and-files dir))
46      (ensure-directories-exist sub)
47      (sys:unzip (merge-pathnames "foo.abcl")
48                 dir)
49      (sys:unzip (merge-pathnames "foo.abcl")
50                 sub)
51      (cl-fad-copy-file (merge-pathnames "bar.abcl")
52                 (merge-pathnames "bar.abcl" dir))
53      (cl-fad-copy-file (merge-pathnames "bar.abcl")
54                 (merge-pathnames "bar.abcl" sub))
55      (cl-fad-copy-file (merge-pathnames "eek.lisp")
56                 (merge-pathnames "eek.lisp" dir))
57      (cl-fad-copy-file (merge-pathnames "eek.lisp")
58                 (merge-pathnames "eek.lisp" sub))
59      (sys:zip (merge-pathnames "baz.jar")
60               (append
61                (directory (merge-pathnames "*" dir))
62                (directory (merge-pathnames "*" sub)))
63               dir)
64      (delete-directory-and-files dir)))
65  (setf *jar-file-init* t))
66
67(defmacro with-jar-file-init (&rest body)
68  `(let ((*default-pathname-defaults* *abcl-test-directory*))
69     (progn
70       (unless *jar-file-init*
71         (jar-file-init))
72       ,@body)))
73
74(deftest jar-pathname.load.1
75    (with-jar-file-init
76      (load "jar:file:baz.jar!/foo"))
77  t)
78
79(deftest jar-pathname.load.2
80    (with-jar-file-init
81      (load "jar:file:baz.jar!/bar"))
82  t)
83
84(deftest jar-pathname.load.3
85    (with-jar-file-init
86      (load "jar:file:baz.jar!/bar.abcl"))
87  t)
88
89(deftest jar-pathname.load.4
90    (with-jar-file-init
91      (load "jar:file:baz.jar!/eek"))
92  t)
93
94(deftest jar-pathname.load.5
95    (with-jar-file-init
96      (load "jar:file:baz.jar!/eek.lisp"))
97  t)
98
99(deftest jar-pathname.load.6
100    (with-jar-file-init
101      (load "jar:file:baz.jar!/a/b/foo"))
102  t)
103
104(deftest jar-pathname.load.7
105    (with-jar-file-init
106      (load "jar:file:baz.jar!/a/b/bar"))
107  t)
108
109(deftest jar-pathname.load.8
110    (with-jar-file-init
111      (load "jar:file:baz.jar!/a/b/bar.abcl"))
112  t)
113
114(deftest jar-pathname.load.9
115    (with-jar-file-init
116      (load "jar:file:baz.jar!/a/b/eek"))
117  t)
118
119(deftest jar-pathname.load.10
120    (with-jar-file-init
121      (load "jar:file:baz.jar!/a/b/eek.lisp"))
122  t)
123
124;;; wrapped in PROGN for easy disabling without a network connection
125;;; XXX come up with a better abstraction
126
127(defvar *url-jar-pathname-base*
128  "jar:http://abcl-dynamic-install.googlecode.com/files/baz-20100505a.jar!/")
129
130(defmacro load-url-relative (path) 
131  `(load (format nil "~A~A" *url-jar-pathname-base* ,path)))
132
133(progn 
134  (deftest jar-pathname.load.11
135      (load-url-relative "foo")
136    t)
137
138  (deftest jar-pathname.load.12
139      (load-url-relative "bar")
140    t)
141
142  (deftest jar-pathname.load.13
143      (load-url-relative "bar.abcl")
144    t)
145
146  (deftest jar-pathname.load.14
147      (load-url-relative "eek")
148    t)
149
150  (deftest jar-pathname.load.15
151      (load-url-relative "eek.lisp")
152    t)
153
154  (deftest jar-pathname.load.16
155      (load-url-relative "a/b/foo")
156    t)
157
158  (deftest jar-pathname.load.17
159      (load-url-relative "a/b/bar")
160    t)
161
162  (deftest jar-pathname.load.18
163      (load-url-relative "a/b/bar.abcl")
164    t)
165
166  (deftest jar-pathname.load.19
167      (load-url-relative "a/b/eek")
168    t)
169
170  (deftest jar-pathname.load.20
171      (load-url-relative "a/b/eek.lisp")
172    t))
173
174(deftest jar-pathname.probe-file.1
175    (with-jar-file-init
176        (probe-file "jar:file:baz.jar!/eek.lisp"))
177  #p#.(format nil "jar:file:~A/baz.jar!/eek.lisp" 
178              (namestring *abcl-test-directory*)))
179
180(deftest jar-pathname.probe-file.2
181    (with-jar-file-init
182        (probe-file "jar:file:baz.jar!/a/b/bar.abcl"))
183  #p#.(format nil "jar:file:~A/baz.jar!/a/b/bar.abcl"
184              (namestring *abcl-test-directory*)))
185
186(deftest jar-pathname.probe-file.3
187    (with-jar-file-init
188        (probe-file "jar:jar:file:baz.jar!/a/b/bar.abcl!/bar._"))
189   #p#.(format nil "jar:jar:file:~Abaz.jar!/a/b/bar.abcl!/bar._"
190                       (namestring *abcl-test-directory*)))
191
192(deftest jar-pathname.probe-file.4
193    (with-jar-file-init
194        (probe-file "jar:file:baz.jar!/a/b"))
195  nil)
196
197(deftest jar-pathname.probe-file.5
198    (with-jar-file-init
199        (probe-file "jar:file:baz.jar!/a/b/"))
200  #p#.(format nil "jar:file:~Abaz.jar!/a/b/"
201                       (namestring *abcl-test-directory*)))
202
203(deftest jar-pathname.merge-pathnames.1
204    (merge-pathnames 
205     "/bar.abcl" #p"jar:file:baz.jar!/foo")
206  #p"jar:file:baz.jar!/bar.abcl")
207
208(deftest jar-pathname.merge-pathnames.2
209    (merge-pathnames 
210     "bar.abcl" #p"jar:file:baz.jar!/foo/")
211  #p"jar:file:baz.jar!/foo/bar.abcl")
212
213(deftest jar-pathname.merge-pathnames.3
214    (merge-pathnames 
215     "jar:file:baz.jar!/foo" "bar")
216  #p"jar:file:baz.jar!/foo")
217
218(deftest jar-pathname.merge-pathnames.4
219    (merge-pathnames 
220     "jar:file:baz.jar!/foo" "/a/b/c")
221  #p"jar:file:/a/b/baz.jar!/foo")
222
223
224;;; Under win32, we get the device in the merged path
225#+windows 
226(push 'jar-pathname.merge-pathnames.5 *expected-failures*)
227
228(deftest jar-pathname.merge-pathnames.5
229    (merge-pathnames "jar:file:/a/b/c/foo.jar!/bar/baz.lisp")
230  #p"jar:file:/a/b/c/foo.jar!/bar/baz.lisp")
231
232(deftest jar-pathname.truename.1
233    (signals-error (truename "jar:file:baz.jar!/foo")
234                   'file-error)
235  t)
236
237(deftest jar-pathname.1
238    (let* ((p #p"jar:file:foo/baz.jar!/")
239           (d (first (pathname-device p))))
240      (values
241       (pathname-directory d) (pathname-name d) (pathname-type d)))
242  (:relative "foo") "baz" "jar")
243
244(deftest jar-pathname.2
245    (let* ((p #p"jar:file:baz.jar!/foo.abcl")
246           (d (first (pathname-device p))))
247      (values
248       (pathname-name d) (pathname-type d) 
249       (pathname-directory p) (pathname-name p) (pathname-type p)))
250  "baz" "jar"
251   (:absolute) "foo" "abcl")
252   
253(deftest jar-pathname.3
254    (let* ((p #p"jar:jar:file:baz.jar!/foo.abcl!/")
255           (d0 (first (pathname-device p)))
256           (d1 (second (pathname-device p))))
257      (values 
258       (pathname-name d0) (pathname-type d0)
259       (pathname-name d1) (pathname-type d1)))
260  "baz" "jar"
261  "foo" "abcl")
262
263(deftest jar-pathname.4
264    (let* ((p #p"jar:jar:file:a/baz.jar!/b/c/foo.abcl!/this/that/foo-20.cls")
265           (d0 (first (pathname-device p)))
266           (d1 (second (pathname-device p))))
267      (values 
268       (pathname-directory d0) (pathname-name d0) (pathname-type d0)
269       (pathname-directory d1) (pathname-name d1) (pathname-type d1)
270       (pathname-directory p) (pathname-name p) (pathname-type p)))
271  (:relative "a") "baz" "jar"
272  (:relative "b" "c") "foo" "abcl"
273  (:absolute "this" "that") "foo-20" "cls")
274
275(deftest jar-pathname.5
276    (let* ((p #p"jar:jar:file:a/foo/baz.jar!/b/c/foo.abcl!/armed/bear/bar-1.cls")
277           (d0 (first (pathname-device p)))
278           (d1 (second (pathname-device p))))
279      (values 
280       (pathname-directory d0) (pathname-name d0) (pathname-type d0)
281       (pathname-directory d1) (pathname-name d1) (pathname-type d1)
282       (pathname-directory p) (pathname-name p) (pathname-type p)))
283  (:relative "a" "foo" ) "baz" "jar"
284  (:relative "b" "c") "foo" "abcl"
285  (:absolute "armed" "bear") "bar-1" "cls")
286
287(deftest jar-pathname.6
288    (let* ((p #p"jar:http://example.org/abcl.jar!/org/armedbear/lisp/Version.class")
289           (d (first (pathname-device p))))
290      (values 
291       (ext:pathname-url-p d)
292       (namestring d)
293       (pathname-directory p) (pathname-name p) (pathname-type p)))
294  t
295  "http://example.org/abcl.jar" 
296  (:absolute "org" "armedbear" "lisp") "Version" "class")
297
298(deftest jar-pathname.7
299    (let* ((p #p"jar:jar:http://example.org/abcl.jar!/foo.abcl!/foo-1.cls")
300           (d (pathname-device p))
301           (d0 (first d))
302           (d1 (second d)))
303      (values
304       (ext:pathname-url-p d0)
305       (namestring d0)
306       (pathname-name d1) (pathname-type d1)
307       (pathname-name p) (pathname-type p)))
308  t
309  "http://example.org/abcl.jar"
310  "foo" "abcl"
311  "foo-1" "cls")
312
313(deftest jar-pathname.8
314    (let* ((p #p"jar:file:/a/b/foo.jar!/")
315           (d (first (pathname-device p))))
316      (values
317       (pathname-directory d) (pathname-name d) (pathname-type d)))
318  (:ABSOLUTE "a" "b") "foo" "jar")
319
320(deftest jar-pathname.9
321    (let* ((p #p"jar:file:a/b/foo.jar!/c/d/foo.lisp")
322           (d (first (pathname-device p))))
323      (values
324       (pathname-directory d) (pathname-name d) (pathname-type d)
325       (pathname-directory p) (pathname-name p) (pathname-type p)))
326  (:relative "a" "b") "foo" "jar"
327  (:absolute "c" "d") "foo" "lisp")
328
329(deftest jar-pathname.match-p.1
330    (pathname-match-p "jar:file:/a/b/some.jar!/a/system/def.asd"
331                      "jar:file:/**/*.jar!/**/*.asd")
332  t)
333
334(deftest jar-pathname.match-p.2
335    (pathname-match-p "/a/system/def.asd"
336                      "jar:file:/**/*.jar!/**/*.asd")
337  nil)
338
339(deftest jar-pathname.match-p.3
340    (pathname-match-p "jar:file:/a/b/some.jar!/a/system/def.asd"
341                      "/**/*.asd")
342  nil)
343
344(deftest jar-pathname.translate.1
345    (translate-pathname "jar:file:/a/b/c.jar!/d/e/f.lisp" 
346      "jar:file:/**/*.jar!/**/*.*" 
347      "/foo/**/*.*")
348  #p"/foo/d/e/f.lisp")
349
350     
351
352       
353
354 
Note: See TracBrowser for help on using the repository browser.