(SC_GPRS): Fix value following change from 2001-05-30.
[glibc.git] / posix / globtest.sh
blob92f3e3c48824a5eb78fcbf5106dd4b1cd7e53f5b
1 #! /bin/sh
3 common_objpfx=$1; shift
4 elf_objpfx=$1; shift
5 rtld_installed_name=$1; shift
6 logfile=$common_objpfx/posix/globtest.out
8 # We have to make the paths `common_objpfx' absolute.
9 case "$common_objpfx" in
10 .*)
11 common_objpfx="`pwd`/$common_objpfx"
15 esac
17 # We have to find the libc and the NSS modules.
18 library_path=${common_objpfx}:${common_objpfx}nss:${common_objpfx}nis:${common_objpfx}db2:${common_objpfx}hesiod
20 # Since we use `sort' we must make sure to use the same locale everywhere.
21 LC_ALL=C
22 export LC_ALL
23 LANG=C
24 export LANG
26 # Create the arena
27 : ${TMPDIR=/tmp}
28 testdir=$TMPDIR/globtest-dir
29 testout=$TMPDIR/globtest-out
31 trap 'chmod 777 $testdir/noread; rm -fr $testdir $testout' 1 2 3 15
33 rm -fr $testdir 2>/dev/null
34 mkdir $testdir
35 echo 1 > $testdir/file1
36 echo 2 > $testdir/file2
37 echo 3 > $testdir/-file3
38 echo 4 > $testdir/~file4
39 echo 5 > $testdir/.file5
40 echo 6 > $testdir/'*file6'
41 mkdir $testdir/dir1
42 mkdir $testdir/dir2
43 test -d $testdir/noread || mkdir $testdir/noread
44 chmod a-r $testdir/noread
45 echo 1_1 > $testdir/dir1/file1_1
46 echo 1_2 > $testdir/dir1/file1_2
48 # Run some tests.
49 result=0
50 rm -f $logfile
52 # Normal test
53 failed=0
54 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
55 ${common_objpfx}posix/globtest "$testdir" "*" |
56 sort > $testout
57 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
58 `*file6'
59 `-file3'
60 `dir1'
61 `dir2'
62 `file1'
63 `file2'
64 `noread'
65 `~file4'
66 EOF
67 if test $failed -ne 0; then
68 echo "Normal test failed" >> $logfile
69 result=1
72 # Don't let glob sort it
73 failed=0
74 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
75 ${common_objpfx}posix/globtest -s "$testdir" "*" |
76 sort > $testout
77 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
78 `*file6'
79 `-file3'
80 `dir1'
81 `dir2'
82 `file1'
83 `file2'
84 `noread'
85 `~file4'
86 EOF
87 if test $failed -ne 0; then
88 echo "No sort test failed" >> $logfile
89 result=1
92 # Mark directories
93 failed=0
94 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
95 ${common_objpfx}posix/globtest -m "$testdir" "*" |
96 sort > $testout
97 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
98 `*file6'
99 `-file3'
100 `dir1/'
101 `dir2/'
102 `file1'
103 `file2'
104 `noread/'
105 `~file4'
107 if test $failed -ne 0; then
108 echo "Mark directories test failed" >> $logfile
109 result=1
112 # Find files starting with .
113 failed=0
114 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
115 ${common_objpfx}posix/globtest -p "$testdir" "*" |
116 sort > $testout
117 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
118 `*file6'
119 `-file3'
121 `..'
122 `.file5'
123 `dir1'
124 `dir2'
125 `file1'
126 `file2'
127 `noread'
128 `~file4'
130 if test $failed -ne 0; then
131 echo "Leading period test failed" >> $logfile
132 result=1
135 # Test braces
136 failed=0
137 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
138 ${common_objpfx}posix/globtest -b "$testdir" "file{1,2}" |
139 sort > $testout
140 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
141 `file1'
142 `file2'
144 if test $failed -ne 0; then
145 echo "Braces test failed" >> $logfile
146 result=1
149 # Test NOCHECK
150 failed=0
151 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
152 ${common_objpfx}posix/globtest -c "$testdir" "abc" |
153 sort > $testout
154 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
155 `abc'
157 if test $failed -ne 0; then
158 echo "No check test failed" >> $logfile
159 result=1
162 # Test NOMAGIC without magic characters
163 failed=0
164 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
165 ${common_objpfx}posix/globtest -g "$testdir" "abc" |
166 sort > $testout
167 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
168 `abc'
170 if test $failed -ne 0; then
171 echo "No magic test failed" >> $logfile
172 result=1
175 # Test NOMAGIC with magic characters
176 failed=0
177 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
178 ${common_objpfx}posix/globtest -g "$testdir" "abc*" |
179 sort > $testout
180 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
181 GLOB_NOMATCH
183 if test $failed -ne 0; then
184 echo "No magic w/ magic chars test failed" >> $logfile
185 result=1
188 # Test subdirs correctly
189 failed=0
190 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
191 ${common_objpfx}posix/globtest "$testdir" "*/*" |
192 sort > $testout
193 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
194 `dir1/file1_1'
195 `dir1/file1_2'
197 if test $failed -ne 0; then
198 echo "Subdirs test failed" >> $logfile
199 result=1
202 # Test subdirs for invalid names
203 failed=0
204 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
205 ${common_objpfx}posix/globtest "$testdir" "*/1" |
206 sort > $testout
207 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
208 GLOB_NOMATCH
210 if test $failed -ne 0; then
211 echo "Invalid subdir test failed" >> $logfile
212 result=1
215 # Test subdirs with wildcard
216 failed=0
217 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
218 ${common_objpfx}posix/globtest "$testdir" "*/*1_1" |
219 sort > $testout
220 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
221 `dir1/file1_1'
223 if test $failed -ne 0; then
224 echo "Wildcard subdir test failed" >> $logfile
225 result=1
228 # Test subdirs with ?
229 failed=0
230 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
231 ${common_objpfx}posix/globtest "$testdir" "*/*?_?" |
232 sort > $testout
233 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
234 `dir1/file1_1'
235 `dir1/file1_2'
237 if test $failed -ne 0; then
238 echo "Wildcard2 subdir test failed" >> $logfile
239 result=1
242 failed=0
243 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
244 ${common_objpfx}posix/globtest "$testdir" "*/file1_1" |
245 sort > $testout
246 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
247 `dir1/file1_1'
249 if test $failed -ne 0; then
250 echo "Wildcard3 subdir test failed" >> $logfile
251 result=1
254 failed=0
255 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
256 ${common_objpfx}posix/globtest "$testdir" "*-/*" |
257 sort > $testout
258 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
259 GLOB_NOMATCH
261 if test $failed -ne 0; then
262 echo "Wildcard4 subdir test failed" >> $logfile
263 result=1
266 failed=0
267 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
268 ${common_objpfx}posix/globtest "$testdir" "*-" |
269 sort > $testout
270 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
271 GLOB_NOMATCH
273 if test $failed -ne 0; then
274 echo "Wildcard5 subdir test failed" >> $logfile
275 result=1
278 # Test subdirs with ?
279 failed=0
280 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
281 ${common_objpfx}posix/globtest "$testdir" "*/*?_?" |
282 sort > $testout
283 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
284 `dir1/file1_1'
285 `dir1/file1_2'
287 if test $failed -ne 0; then
288 echo "Wildcard6 subdir test failed" >> $logfile
289 result=1
292 # Test subdirs with [ .. ]
293 failed=0
294 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
295 ${common_objpfx}posix/globtest "$testdir" "*/file1_[12]" |
296 sort > $testout
297 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
298 `dir1/file1_1'
299 `dir1/file1_2'
301 if test $failed -ne 0; then
302 echo "Brackets test failed" >> $logfile
303 result=1
306 # Test ']' inside bracket expression
307 failed=0
308 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
309 ${common_objpfx}posix/globtest "$testdir" "dir1/file1_[]12]" |
310 sort > $testout
311 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
312 `dir1/file1_1'
313 `dir1/file1_2'
315 if test $failed -ne 0; then
316 echo "Brackets2 test failed" >> $logfile
317 result=1
320 # Test tilde expansion
321 failed=0
322 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
323 ${common_objpfx}posix/globtest -q -t "$testdir" "~" |
324 sort >$testout
325 echo ~ | cmp - $testout >> $logfile || failed=1
326 if test $failed -ne 0; then
327 echo "Tilde test failed" >> $logfile
328 result=1
331 # Test tilde expansion with trailing slash
332 failed=0
333 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
334 ${common_objpfx}posix/globtest -q -t "$testdir" "~/" |
335 sort > $testout
336 # Some shell incorrectly(?) convert ~/ into // if ~ expands to /.
337 if test ~/ = //; then
338 echo / | cmp - $testout >> $logfile || failed=1
339 else
340 echo ~/ | cmp - $testout >> $logfile || failed=1
342 if test $failed -ne 0; then
343 echo "Tilde2 test failed" >> $logfile
344 result=1
347 # Test tilde expansion with username
348 failed=0
349 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
350 ${common_objpfx}posix/globtest -q -t "$testdir" "~"$USER |
351 sort > $testout
352 eval echo ~$USER | cmp - $testout >> $logfile || failed=1
353 if test $failed -ne 0; then
354 echo "Tilde3 test failed" >> $logfile
355 result=1
358 # Tilde expansion shouldn't match a file
359 failed=0
360 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
361 ${common_objpfx}posix/globtest -T "$testdir" "~file4" |
362 sort > $testout
363 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
364 GLOB_NOMATCH
366 if test $failed -ne 0; then
367 echo "Tilde4 test failed" >> $logfile
368 result=1
371 # Matching \** should only find *file6
372 failed=0
373 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
374 ${common_objpfx}posix/globtest "$testdir" "\**" |
375 sort > $testout
376 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
377 `*file6'
379 if test $failed -ne 0; then
380 echo "Star test failed" >> $logfile
381 result=1
384 # ... unless NOESCAPE is used, in which case it shouldn't match anything.
385 failed=0
386 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
387 ${common_objpfx}posix/globtest -e "$testdir" "\**" |
388 sort > $testout
389 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
390 GLOB_NOMATCH
392 if test $failed -ne 0; then
393 echo "Star2 test failed" >> $logfile
394 result=1
397 # Matching \*file6 should find *file6
398 failed=0
399 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
400 ${common_objpfx}posix/globtest "$testdir" "\*file6" |
401 sort > $testout
402 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
403 `*file6'
405 if test $failed -ne 0; then
406 echo "Star3 test failed" >> $logfile
407 result=1
410 # Try a recursive failed search
411 failed=0
412 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
413 ${common_objpfx}posix/globtest -e "$testdir" "a*/*" |
414 sort > $testout
415 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
416 GLOB_NOMATCH
418 if test $failed -ne 0; then
419 echo "Star4 test failed" >> $logfile
420 result=1
423 # ... with GLOB_ERR
424 failed=0
425 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
426 ${common_objpfx}posix/globtest -E "$testdir" "a*/*" |
427 sort > $testout
428 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
429 GLOB_NOMATCH
431 if test $failed -ne 0; then
432 echo "Star5 test failed" >> $logfile
433 result=1
436 # Try a recursive search in unreadable directory
437 failed=0
438 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
439 ${common_objpfx}posix/globtest "$testdir" "noread/*" |
440 sort > $testout
441 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
442 GLOB_NOMATCH
444 if test $failed -ne 0; then
445 echo "Star6 test failed" >> $logfile
446 result=1
449 failed=0
450 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
451 ${common_objpfx}posix/globtest "$testdir" "noread*/*" |
452 sort > $testout
453 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
454 GLOB_NOMATCH
456 if test $failed -ne 0; then
457 echo "Star6 test failed" >> $logfile
458 result=1
461 # The following tests will fail if run as root.
462 user=`id -un 2> /dev/null`
463 if test -z "$user"; then
464 uid="$USER"
466 if test "$user" != root; then
467 # ... with GLOB_ERR
468 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
469 ${common_objpfx}posix/globtest -E "$testdir" "noread/*" |
470 sort > $testout
471 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
472 GLOB_ABORTED
475 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
476 ${common_objpfx}posix/globtest -E "$testdir" "noread*/*" |
477 sort > $testout
478 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
479 GLOB_ABORTED
481 if test $failed -ne 0; then
482 echo "GLOB_ERR test failed" >> $logfile
483 result=1
485 fi # not run as root
487 # Try multiple patterns (GLOB_APPEND)
488 failed=0
489 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
490 ${common_objpfx}posix/globtest "$testdir" "file1" "*/*" |
491 sort > $testout
492 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
493 `dir1/file1_1'
494 `dir1/file1_2'
495 `file1'
497 if test $failed -ne 0; then
498 echo "GLOB_APPEND test failed" >> $logfile
499 result=1
502 # Try multiple patterns (GLOB_APPEND) with offset (GLOB_DOOFFS)
503 failed=0
504 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
505 ${common_objpfx}posix/globtest -o "$testdir" "file1" "*/*" |
506 sort > $testout
507 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
508 `abc'
509 `dir1/file1_1'
510 `dir1/file1_2'
511 `file1'
513 if test $failed -ne 0; then
514 echo "GLOB_APPEND2 test failed" >> $logfile
515 result=1
518 # Test NOCHECK with non-existing file in subdir.
519 failed=0
520 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
521 ${common_objpfx}posix/globtest -c "$testdir" "*/blahblah" |
522 sort > $testout
523 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
524 `dir1/blahblah'
525 `dir2/blahblah'
526 `noread/blahblah'
528 if test $failed -ne 0; then
529 echo "No check2 test failed" >> $logfile
530 result=1
533 if test $result -eq 0; then
534 chmod 777 $testdir/noread
535 rm -fr $testdir $testout
536 echo "All OK." > $logfile
539 exit $result
541 # Preserve executable bits for this shell script.
542 Local Variables:
543 eval:(defun frobme () (set-file-modes buffer-file-name file-mode))
544 eval:(make-local-variable 'file-mode)
545 eval:(setq file-mode (file-modes (buffer-file-name)))
546 eval:(make-local-variable 'after-save-hook)
547 eval:(add-hook 'after-save-hook 'frobme)
548 End: