Update.
[glibc.git] / posix / globtest.sh
blob956a5e6bb1d639cc26b25a03903c870c1450ae88
1 #! /bin/sh
3 common_objpfx=$1; shift
4 elf_objpfx=$1; shift
5 rtld_installed_name=$1; shift
7 # We have to make the paths `common_objpfx' absolute.
8 case "$common_objpfx" in
9 .*)
10 common_objpfx="`pwd`/$common_objpfx"
14 esac
16 # We have to find the libc and the NSS modules.
17 library_path=${common_objpfx}:${common_objpfx}nss:${common_objpfx}nis:${common_objpfx}db2:${common_objpfx}hesiod
19 # Since we use `sort' we must make sure to use the same locale everywhere.
20 LC_ALL=C
21 export LC_ALL
22 LANG=C
23 export LANG
25 # Create the arena
26 : ${TMPDIR=/tmp}
27 testdir=$TMPDIR/globtest-dir
28 testout=$TMPDIR/globtest-out
30 trap 'chmod 777 $testdir/noread; rm -fr $testdir $testout' 1 2 3 15
32 rm -fr $testdir 2>/dev/null
33 mkdir $testdir
34 echo 1 > $testdir/file1
35 echo 2 > $testdir/file2
36 echo 3 > $testdir/-file3
37 echo 4 > $testdir/~file4
38 echo 5 > $testdir/.file5
39 echo 6 > $testdir/'*file6'
40 mkdir $testdir/dir1
41 mkdir $testdir/dir2
42 test -d $testdir/noread || mkdir $testdir/noread
43 chmod a-r $testdir/noread
44 echo 1_1 > $testdir/dir1/file1_1
45 echo 1_2 > $testdir/dir1/file1_2
47 # Run some tests.
48 result=0
50 # Normal test
51 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
52 ${common_objpfx}posix/globtest "$testdir" "*" |
53 sort > $testout
54 cat <<"EOF" | cmp - $testout || result=1
55 `*file6'
56 `-file3'
57 `dir1'
58 `dir2'
59 `file1'
60 `file2'
61 `noread'
62 `~file4'
63 EOF
65 # Don't let glob sort it
66 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
67 ${common_objpfx}posix/globtest -s "$testdir" "*" |
68 sort > $testout
69 cat <<"EOF" | cmp - $testout || result=1
70 `*file6'
71 `-file3'
72 `dir1'
73 `dir2'
74 `file1'
75 `file2'
76 `noread'
77 `~file4'
78 EOF
80 # Mark directories
81 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
82 ${common_objpfx}posix/globtest -m "$testdir" "*" |
83 sort > $testout
84 cat <<"EOF" | cmp - $testout || result=1
85 `*file6'
86 `-file3'
87 `dir1/'
88 `dir2/'
89 `file1'
90 `file2'
91 `noread/'
92 `~file4'
93 EOF
95 # Find files starting with .
96 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
97 ${common_objpfx}posix/globtest -p "$testdir" "*" |
98 sort > $testout
99 cat <<"EOF" | cmp - $testout || result=1
100 `*file6'
101 `-file3'
103 `..'
104 `.file5'
105 `dir1'
106 `dir2'
107 `file1'
108 `file2'
109 `noread'
110 `~file4'
113 # Test braces
114 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
115 ${common_objpfx}posix/globtest -b "$testdir" "file{1,2}" |
116 sort > $testout
117 cat <<"EOF" | cmp - $testout || result=1
118 `file1'
119 `file2'
122 # Test NOCHECK
123 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
124 ${common_objpfx}posix/globtest -c "$testdir" "abc" |
125 sort > $testout
126 cat <<"EOF" | cmp - $testout || result=1
127 `abc'
130 # Test NOMAGIC without magic characters
131 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
132 ${common_objpfx}posix/globtest -g "$testdir" "abc" |
133 sort > $testout
134 cat <<"EOF" | cmp - $testout || result=1
135 `abc'
138 # Test NOMAGIC with magic characters
139 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
140 ${common_objpfx}posix/globtest -g "$testdir" "abc*" |
141 sort > $testout
142 cat <<"EOF" | cmp - $testout || result=1
143 GLOB_NOMATCH
146 # Test subdirs correctly
147 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
148 ${common_objpfx}posix/globtest "$testdir" "*/*" |
149 sort > $testout
150 cat <<"EOF" | cmp - $testout || result=1
151 `dir1/file1_1'
152 `dir1/file1_2'
155 # Test subdirs for invalid names
156 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
157 ${common_objpfx}posix/globtest "$testdir" "*/1" |
158 sort > $testout
159 cat <<"EOF" | cmp - $testout || result=1
160 GLOB_NOMATCH
163 # Test subdirs with wildcard
164 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
165 ${common_objpfx}posix/globtest "$testdir" "*/*1_1" |
166 sort > $testout
167 cat <<"EOF" | cmp - $testout || result=1
168 `dir1/file1_1'
171 # Test subdirs with ?
172 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
173 ${common_objpfx}posix/globtest "$testdir" "*/*?_?" |
174 sort > $testout
175 cat <<"EOF" | cmp - $testout || result=1
176 `dir1/file1_1'
177 `dir1/file1_2'
180 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
181 ${common_objpfx}posix/globtest "$testdir" "*/file1_1" |
182 sort > $testout
183 cat <<"EOF" | cmp - $testout || result=1
184 `dir1/file1_1'
187 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
188 ${common_objpfx}posix/globtest "$testdir" "*-/*" |
189 sort > $testout
190 cat <<"EOF" | cmp - $testout || result=1
191 GLOB_NOMATCH
194 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
195 ${common_objpfx}posix/globtest "$testdir" "*-" |
196 sort > $testout
197 cat <<"EOF" | cmp - $testout || result=1
198 GLOB_NOMATCH
201 # Test subdirs with ?
202 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
203 ${common_objpfx}posix/globtest "$testdir" "*/*?_?" |
204 sort > $testout
205 cat <<"EOF" | cmp - $testout || result=1
206 `dir1/file1_1'
207 `dir1/file1_2'
210 # Test subdirs with [ .. ]
211 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
212 ${common_objpfx}posix/globtest "$testdir" "*/file1_[12]" |
213 sort > $testout
214 cat <<"EOF" | cmp - $testout || result=1
215 `dir1/file1_1'
216 `dir1/file1_2'
219 # Test ']' inside bracket expression
220 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
221 ${common_objpfx}posix/globtest "$testdir" "dir1/file1_[]12]" |
222 sort > $testout
223 cat <<"EOF" | cmp - $testout || result=1
224 `dir1/file1_1'
225 `dir1/file1_2'
228 # Test tilde expansion
229 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
230 ${common_objpfx}posix/globtest -q -t "$testdir" "~" |
231 sort >$testout
232 echo ~ | cmp - $testout || result=1
234 # Test tilde expansion with trailing slash
235 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
236 ${common_objpfx}posix/globtest -q -t "$testdir" "~/" |
237 sort > $testout
238 # Some shell incorrectly(?) convert ~/ into // if ~ expands to /.
239 if test ~/ = //; then
240 echo / | cmp - $testout || result=1
241 else
242 echo ~/ | cmp - $testout || result=1
245 # Test tilde expansion with username
246 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
247 ${common_objpfx}posix/globtest -q -t "$testdir" "~"$USER |
248 sort > $testout
249 eval echo ~$USER | cmp - $testout || result=1
251 # Tilde expansion shouldn't match a file
252 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
253 ${common_objpfx}posix/globtest -T "$testdir" "~file4" |
254 sort > $testout
255 cat <<"EOF" | cmp - $testout || result=1
256 GLOB_NOMATCH
259 # Matching \** should only find *file6
260 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
261 ${common_objpfx}posix/globtest "$testdir" "\**" |
262 sort > $testout
263 cat <<"EOF" | cmp - $testout || result=1
264 `*file6'
267 # ... unless NOESCAPE is used, in which case it shouldn't match anything.
268 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
269 ${common_objpfx}posix/globtest -e "$testdir" "\**" |
270 sort > $testout
271 cat <<"EOF" | cmp - $testout || result=1
272 GLOB_NOMATCH
275 # Matching \*file6 should find *file6
276 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
277 ${common_objpfx}posix/globtest "$testdir" "\*file6" |
278 sort > $testout
279 cat <<"EOF" | cmp - $testout || result=1
280 `*file6'
283 # Try a recursive failed search
284 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
285 ${common_objpfx}posix/globtest -e "$testdir" "a*/*" |
286 sort > $testout
287 cat <<"EOF" | cmp - $testout || result=1
288 GLOB_NOMATCH
291 # ... with GLOB_ERR
292 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
293 ${common_objpfx}posix/globtest -E "$testdir" "a*/*" |
294 sort > $testout
295 cat <<"EOF" | cmp - $testout || result=1
296 GLOB_NOMATCH
299 # Try a recursive search in unreadable directory
300 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
301 ${common_objpfx}posix/globtest "$testdir" "noread/*" |
302 sort > $testout
303 cat <<"EOF" | cmp - $testout || result=1
304 GLOB_NOMATCH
307 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
308 ${common_objpfx}posix/globtest "$testdir" "noread*/*" |
309 sort > $testout
310 cat <<"EOF" | cmp - $testout || result=1
311 GLOB_NOMATCH
314 # The following tests will fail if run as root.
315 user=`id -un 2> /dev/null`
316 if test -z "$user"; then
317 uid="$USER"
319 if test "$user" != root; then
320 # ... with GLOB_ERR
321 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
322 ${common_objpfx}posix/globtest -E "$testdir" "noread/*" |
323 sort > $testout
324 cat <<"EOF" | cmp - $testout || result=1
325 GLOB_ABORTED
328 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
329 ${common_objpfx}posix/globtest -E "$testdir" "noread*/*" |
330 sort > $testout
331 cat <<"EOF" | cmp - $testout || result=1
332 GLOB_ABORTED
334 fi # not run as root
336 # Try multiple patterns (GLOB_APPEND)
337 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
338 ${common_objpfx}posix/globtest "$testdir" "file1" "*/*" |
339 sort > $testout
340 cat <<"EOF" | cmp - $testout || result=1
341 `dir1/file1_1'
342 `dir1/file1_2'
343 `file1'
346 # Try multiple patterns (GLOB_APPEND) with offset (GLOB_DOOFFS)
347 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
348 ${common_objpfx}posix/globtest -o "$testdir" "file1" "*/*" |
349 sort > $testout
350 cat <<"EOF" | cmp - $testout || result=1
351 `abc'
352 `dir1/file1_1'
353 `dir1/file1_2'
354 `file1'
357 # Test NOCHECK with non-existing file in subdir.
358 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
359 ${common_objpfx}posix/globtest -c "$testdir" "*/blahblah" |
360 sort > $testout
361 cat <<"EOF" | cmp - $testout || result=1
362 `dir1/blahblah'
363 `dir2/blahblah'
364 `noread/blahblah'
367 if test $result -eq 0; then
368 chmod 777 $testdir/noread
369 rm -fr $testdir $testout
372 exit $result
374 # Preserve executable bits for this shell script.
375 Local Variables:
376 eval:(defun frobme () (set-file-modes buffer-file-name file-mode))
377 eval:(make-local-variable 'file-mode)
378 eval:(setq file-mode (file-modes (buffer-file-name)))
379 eval:(make-local-variable 'after-save-hook)
380 eval:(add-hook 'after-save-hook 'frobme)
381 End: