3 # This software is part of the SBCL system. See the README file for
6 # While most of SBCL is derived from the CMU CL system, the test
7 # files (like this one) were written from scratch after the fork
10 # This software is in the public domain and is provided with
11 # absolutely no warranty. See the COPYING and CREDITS files for
14 # Test DIRECTORY and TRUENAME.
15 testdir=`/bin/pwd`"/filesys-test-$$"
17 echo this is a test > $testdir/test-1.tmp
18 echo this is a test > $testdir/test-2.tmp
19 echo this is a test > $testdir/wild\?test.tmp
21 ln -s $testdir dirlinktest
22 ln -s test-1.tmp link-1
23 ln -s `pwd`/test-2.tmp link-2
24 ln -s i-do-not-exist link-3
27 ln -s `pwd`/link-6 link-5
30 #p\"$testdir/link-3\"\
31 #p\"$testdir/link-4\"\
32 #p\"$testdir/link-5\"\
33 #p\"$testdir/link-6\"\
34 #p\"$testdir/test-1.tmp\"\
35 #p\"$testdir/test-2.tmp\"\
36 #p\"$testdir/wild\\\\?test.tmp\")"
39 (let* ((directory (directory "./*.*"))
40 (truenames (sort directory #'string< :key #'pathname-name)))
41 (format t "~&TRUENAMES=~S~%" truenames)
43 (assert (equal truenames $expected_truenames)))
44 (assert (equal (truename "dirlinktest") #p"$testdir/"))
45 (assert (equal (truename "dirlinktest/") #p"$testdir/"))
46 (assert (equal (truename "test-1.tmp") #p"$testdir/test-1.tmp"))
47 (assert (equal (truename "link-1") #p"$testdir/test-1.tmp"))
48 (assert (equal (truename "link-2") #p"$testdir/test-2.tmp"))
49 (assert (equal (truename "link-3") #p"$testdir/link-3"))
50 (assert (equal (truename "link-4") #p"$testdir/link-4"))
51 (assert (equal (truename "link-5") #p"$testdir/link-5"))
52 (assert (equal (truename "link-6") #p"$testdir/link-6"))
53 (sb-ext:quit :unix-status 52)
56 echo DIRECTORY/TRUENAME test part 1 failed, unexpected SBCL return code=$?
62 (let* ((directory (directory "$testdir/*.*"))
63 (truenames (sort directory #'string< :key #'pathname-name)))
64 (format t "~&TRUENAMES=~S~%" truenames)
66 (assert (equal truenames $expected_truenames)))
67 (assert (equal (truename "$testdir/test-1.tmp") #p"$testdir/test-1.tmp"))
68 (assert (equal (truename "$testdir/link-1") #p"$testdir/test-1.tmp"))
69 (assert (equal (truename "$testdir/link-2") #p"$testdir/test-2.tmp"))
70 (assert (equal (truename "$testdir/link-3") #p"$testdir/link-3"))
71 (assert (equal (truename "$testdir/link-4") #p"$testdir/link-4"))
72 (assert (equal (truename "$testdir/link-5") #p"$testdir/link-5"))
73 (assert (equal (truename "$testdir/link-6") #p"$testdir/link-6"))
74 (sb-ext:quit :unix-status 52)
77 echo DIRECTORY/TRUENAME test part 2 failed, unexpected SBCL return code=$?
82 # Test DIRECTORY on a tree structure of directories.
87 mkdir animal/vertebrate animal/invertebrate
88 mkdir animal/vertebrate/mammal
89 mkdir animal/vertebrate/snake
90 mkdir animal/vertebrate/bird
91 mkdir animal/vertebrate/mammal/bear
92 mkdir animal/vertebrate/mammal/mythical
93 mkdir animal/vertebrate/mammal/rodent
94 mkdir animal/vertebrate/mammal/ruminant
95 touch animal/vertebrate/mammal/platypus
96 touch animal/vertebrate/mammal/walrus
97 touch animal/vertebrate/mammal/bear/grizzly
98 touch animal/vertebrate/mammal/mythical/mermaid
99 touch animal/vertebrate/mammal/mythical/unicorn
100 touch animal/vertebrate/mammal/rodent/beaver
101 touch animal/vertebrate/mammal/rodent/mouse
102 touch animal/vertebrate/mammal/rodent/rabbit
103 touch animal/vertebrate/mammal/rodent/rat
104 touch animal/vertebrate/mammal/ruminant/cow
105 touch animal/vertebrate/snake/python
106 touch plant/kingsfoil plant/pipeweed
108 (in-package :cl-user)
109 (defun absolutify (pathname)
110 "Convert a possibly-relative pathname to absolute."
111 (merge-pathnames pathname
112 (make-pathname :directory
114 *default-pathname-defaults*))))
115 (defun sorted-truenamestrings (pathname-designators)
116 "Convert a collection of pathname designators into canonical form
117 using TRUENAME, NAMESTRING, and SORT."
118 (sort (mapcar #'namestring
120 pathname-designators))
122 (defun need-match-1 (directory-pathname result-sorted-truenamestrings)
124 (let ((directory-sorted-truenamestrings (sorted-truenamestrings
125 (directory directory-pathname))))
126 (unless (equal directory-sorted-truenamestrings
127 result-sorted-truenamestrings)
128 (format t "~&~@<DIRECTORY argument = ~_~2I~S~:>~%"
130 (format t "~&~@<DIRECTORY result = ~_~2I~S~:>~%"
131 directory-sorted-truenamestrings)
132 (format t "~&~@<expected result = ~_~2I~S.~:>~%"
133 result-sorted-truenamestrings)
134 (error "mismatch between DIRECTORY and expected result"))))
135 (defun need-match (directory-pathname result-pathnames)
136 "Require that (DIRECTORY DIRECTORY-PATHNAME) return RESULT-PATHNAMES
137 (modulo TRUENAME and NAMESTRING applied to each RESULT-PATHNAME for
138 convenience in e.g. converting Unix filename syntax idiosyncrasies to
139 Lisp filename syntax idiosyncrasies)."
140 (let ((sorted-result-truenamestrings (sorted-truenamestrings
142 ;; Relative and absolute pathnames should give the same result.
143 (need-match-1 directory-pathname
144 sorted-result-truenamestrings)
145 (need-match-1 (absolutify directory-pathname)
146 sorted-result-truenamestrings)))
147 (defun need-matches ()
148 "lotso calls to NEED-MATCH"
149 ;; FIXME: As discussed on sbcl-devel ca. 2001-01-01, DIRECTORY should
150 ;; report Unix directory files contained within its output as e.g.
151 ;; "/usr/bin" instead of the CMU-CL-style "/usr/bin/". In that case,
152 ;; s:/":": in most or all the NEED-MATCHes here.
153 (need-match "./*.*" '("animal/" "dirt" "plant/" "water"))
154 (need-match "*.*" '("animal/" "dirt" "plant/" "water"))
155 (need-match "animal" '("animal/"))
156 (need-match "./animal" '("animal/"))
157 (need-match "animal/*.*" '("animal/invertebrate/" "animal/vertebrate/"))
158 (need-match "animal/*/*.*"
159 '("animal/vertebrate/bird/"
160 "animal/vertebrate/mammal/"
161 "animal/vertebrate/snake/"))
162 (need-match "plant/*.*" '("plant/kingsfoil" "plant/pipeweed"))
163 (need-match "plant/**/*.*" '("plant/kingsfoil" "plant/pipeweed"))
164 (need-match "plant/**/**/*.*" '("plant/kingsfoil" "plant/pipeweed"))
165 (let ((vertebrates (mapcar (lambda (stem)
171 "mammal/bear/" "mammal/bear/grizzly"
172 "mammal/mythical/" "mammal/mythical/mermaid"
173 "mammal/mythical/unicorn"
175 "mammal/rodent/" "mammal/rodent/beaver"
176 "mammal/rodent/mouse" "mammal/rodent/rabbit"
178 "mammal/ruminant/" "mammal/ruminant/cow"
180 "snake/" "snake/python"))))
181 (need-match "animal/vertebrate/**/*.*" vertebrates)
182 (need-match "animal/vertebrate/mammal/../**/*.*" vertebrates)
183 (need-match "animal/vertebrate/mammal/../**/**/*.*" vertebrates)
185 (need-match "animal/vertebrate/mammal/mythical/../**/../**/*.*"
187 (need-match "animal/vertebrate/**/robot.*" nil)
188 (need-match "animal/vertebrate/mammal/../**/*.robot" nil)
189 (need-match "animal/vertebrate/mammal/../**/robot/*.*" nil)
191 (need-match "animal/vertebrate/mammal/robot/../**/../**/*.*" nil))
193 (sb-ext:quit :unix-status 52)
195 if [ $? != 52 ]; then
196 echo DIRECTORY/TRUENAME test part 1 failed, unexpected SBCL return code=$?
202 # success convention for script