1 | (in-package :abcl.test.lisp) |
---|
2 | |
---|
3 | ;;; Various tests for PATHNAMES :WILD and :WILD-INFERIORS |
---|
4 | |
---|
5 | (defvar *test-files* |
---|
6 | '("foo.ext" "a/b/c/foo.ext" "a/d/e/foo.ext" "b/foo.ext" "a/foo.ext")) |
---|
7 | |
---|
8 | (defvar *temp-directory-root* |
---|
9 | (ext:make-temp-directory)) |
---|
10 | |
---|
11 | (defun create-wild-test-hierarchy () |
---|
12 | (ensure-directories-exist *temp-directory-root*) |
---|
13 | (dolist (file *test-files*) |
---|
14 | (let ((file (merge-pathnames file *temp-directory-root*))) |
---|
15 | (ensure-directories-exist (directory-namestring file)) |
---|
16 | (unless (probe-file file) |
---|
17 | (touch file))))) |
---|
18 | |
---|
19 | (defun remove-wild-test-hierarchy () |
---|
20 | (ignore-errors |
---|
21 | (delete-directory-and-files *temp-directory-root*))) |
---|
22 | |
---|
23 | (defmacro with-test-directories (&rest body) |
---|
24 | `(prog2 (create-wild-test-hierarchy) |
---|
25 | ,@body |
---|
26 | (remove-wild-test-hierarchy))) |
---|
27 | |
---|
28 | (defun set-equal (a b) |
---|
29 | (and |
---|
30 | (= (length a) (length b)) |
---|
31 | (subsetp a b :test #'equal) |
---|
32 | (subsetp b a :test #'equal))) |
---|
33 | |
---|
34 | (deftest wild-pathnames.1 |
---|
35 | (with-test-directories |
---|
36 | (let ((results |
---|
37 | (directory (merge-pathnames "**/*.ext" |
---|
38 | *temp-directory-root*))) |
---|
39 | (expected |
---|
40 | (loop :for file :in *test-files* |
---|
41 | :collecting (merge-pathnames file |
---|
42 | *temp-directory-root*)))) |
---|
43 | (values |
---|
44 | (eq (length results) (length expected)) |
---|
45 | ;; link --> file is not resolved by change in DIRECTORY to :RESOLVE-SYMLINKS nil |
---|
46 | results |
---|
47 | expected |
---|
48 | (set-equal (mapcar #'truename results) |
---|
49 | (mapcar #'truename expected))))) |
---|
50 | t) |
---|
51 | |
---|
52 | (deftest wild-pathnames.2 |
---|
53 | (check-namestring |
---|
54 | (namestring (first (with-test-directories |
---|
55 | (directory (make-pathname :directory (pathname-directory *temp-directory-root*) |
---|
56 | :name :wild :type "ext" |
---|
57 | :version :newest))))) |
---|
58 | (namestring (merge-pathnames *temp-directory-root* "foo.ext"))) |
---|
59 | t) |
---|
60 | |
---|
61 | |
---|
62 | |
---|