3 common_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
11 common_objpfx="`pwd`/$common_objpfx"
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.
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
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'
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
54 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
55 ${common_objpfx}posix/globtest "$testdir" "*" |
57 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
67 if test $failed -ne 0; then
68 echo "Normal test failed" >> $logfile
72 # Don't let glob sort it
74 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
75 ${common_objpfx}posix/globtest -s "$testdir" "*" |
77 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
87 if test $failed -ne 0; then
88 echo "No sort test failed" >> $logfile
94 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
95 ${common_objpfx}posix/globtest -m "$testdir" "*" |
97 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
107 if test $failed -ne 0; then
108 echo "Mark directories test failed" >> $logfile
112 # Find files starting with .
114 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
115 ${common_objpfx}posix/globtest -p "$testdir" "*" |
117 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
130 if test $failed -ne 0; then
131 echo "Leading period test failed" >> $logfile
137 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
138 ${common_objpfx}posix/globtest -b "$testdir" "file{1,2}" |
140 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
144 if test $failed -ne 0; then
145 echo "Braces test failed" >> $logfile
150 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
151 ${common_objpfx}posix/globtest -b "$testdir" "{file{1,2},-file3}" |
153 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
158 if test $failed -ne 0; then
159 echo "Braces test 2 failed" >> $logfile
164 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
165 ${common_objpfx}posix/globtest -b "$testdir" "{" |
167 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
170 if test $failed -ne 0; then
171 echo "Braces test 3 failed" >> $logfile
177 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
178 ${common_objpfx}posix/globtest -c "$testdir" "abc" |
180 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
183 if test $failed -ne 0; then
184 echo "No check test failed" >> $logfile
188 # Test NOMAGIC without magic characters
190 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
191 ${common_objpfx}posix/globtest -g "$testdir" "abc" |
193 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
196 if test $failed -ne 0; then
197 echo "No magic test failed" >> $logfile
201 # Test NOMAGIC with magic characters
203 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
204 ${common_objpfx}posix/globtest -g "$testdir" "abc*" |
206 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
209 if test $failed -ne 0; then
210 echo "No magic w/ magic chars test failed" >> $logfile
214 # Test NOMAGIC for subdirs
216 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
217 ${common_objpfx}posix/globtest -g "$testdir" "*/does-not-exist" |
219 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
222 if test $failed -ne 0; then
223 echo "No magic in subdir test failed" >> $logfile
227 # Test subdirs correctly
229 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
230 ${common_objpfx}posix/globtest "$testdir" "*/*" |
232 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
236 if test $failed -ne 0; then
237 echo "Subdirs test failed" >> $logfile
241 # Test subdirs for invalid names
243 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
244 ${common_objpfx}posix/globtest "$testdir" "*/1" |
246 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
249 if test $failed -ne 0; then
250 echo "Invalid subdir test failed" >> $logfile
254 # Test subdirs with wildcard
256 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
257 ${common_objpfx}posix/globtest "$testdir" "*/*1_1" |
259 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
262 if test $failed -ne 0; then
263 echo "Wildcard subdir test failed" >> $logfile
267 # Test subdirs with ?
269 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
270 ${common_objpfx}posix/globtest "$testdir" "*/*?_?" |
272 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
276 if test $failed -ne 0; then
277 echo "Wildcard2 subdir test failed" >> $logfile
282 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
283 ${common_objpfx}posix/globtest "$testdir" "*/file1_1" |
285 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
288 if test $failed -ne 0; then
289 echo "Wildcard3 subdir test failed" >> $logfile
294 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
295 ${common_objpfx}posix/globtest "$testdir" "*-/*" |
297 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
300 if test $failed -ne 0; then
301 echo "Wildcard4 subdir test failed" >> $logfile
306 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
307 ${common_objpfx}posix/globtest "$testdir" "*-" |
309 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
312 if test $failed -ne 0; then
313 echo "Wildcard5 subdir test failed" >> $logfile
317 # Test subdirs with ?
319 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
320 ${common_objpfx}posix/globtest "$testdir" "*/*?_?" |
322 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
326 if test $failed -ne 0; then
327 echo "Wildcard6 subdir test failed" >> $logfile
331 # Test subdirs with [ .. ]
333 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
334 ${common_objpfx}posix/globtest "$testdir" "*/file1_[12]" |
336 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
340 if test $failed -ne 0; then
341 echo "Brackets test failed" >> $logfile
345 # Test ']' inside bracket expression
347 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
348 ${common_objpfx}posix/globtest "$testdir" "dir1/file1_[]12]" |
350 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
354 if test $failed -ne 0; then
355 echo "Brackets2 test failed" >> $logfile
359 # Test tilde expansion
361 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
362 ${common_objpfx}posix/globtest -q -t "$testdir" "~" |
364 echo ~ | cmp - $testout >> $logfile || failed=1
365 if test $failed -ne 0; then
367 echo "Tilde test failed" >> $logfile
370 echo "Tilde test could not be run" >> $logfile
374 # Test tilde expansion with trailing slash
376 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
377 ${common_objpfx}posix/globtest -q -t "$testdir" "~/" |
379 # Some shell incorrectly(?) convert ~/ into // if ~ expands to /.
380 if test ~/ = //; then
381 echo / | cmp - $testout >> $logfile || failed=1
383 echo ~/ | cmp - $testout >> $logfile || failed=1
385 if test $failed -ne 0; then
387 echo "Tilde2 test failed" >> $logfile
390 echo "Tilde2 test could not be run" >> $logfile
394 # Test tilde expansion with username
396 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
397 ${common_objpfx}posix/globtest -q -t "$testdir" "~"$USER |
399 eval echo ~$USER | cmp - $testout >> $logfile || failed=1
400 if test $failed -ne 0; then
401 if eval test -d ~$USER; then
402 echo "Tilde3 test failed" >> $logfile
405 echo "Tilde3 test could not be run" >> $logfile
409 # Tilde expansion shouldn't match a file
411 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
412 ${common_objpfx}posix/globtest -T "$testdir" "~file4" |
414 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
417 if test $failed -ne 0; then
418 echo "Tilde4 test failed" >> $logfile
422 # Matching \** should only find *file6
424 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
425 ${common_objpfx}posix/globtest "$testdir" "\**" |
427 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
430 if test $failed -ne 0; then
431 echo "Star test failed" >> $logfile
435 # ... unless NOESCAPE is used, in which case it shouldn't match anything.
437 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
438 ${common_objpfx}posix/globtest -e "$testdir" "\**" |
440 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
443 if test $failed -ne 0; then
444 echo "Star2 test failed" >> $logfile
448 # Matching \*file6 should find *file6
450 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
451 ${common_objpfx}posix/globtest "$testdir" "\*file6" |
453 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
456 if test $failed -ne 0; then
457 echo "Star3 test failed" >> $logfile
461 # Try a recursive failed search
463 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
464 ${common_objpfx}posix/globtest -e "$testdir" "a*/*" |
466 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
469 if test $failed -ne 0; then
470 echo "Star4 test failed" >> $logfile
476 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
477 ${common_objpfx}posix/globtest -E "$testdir" "a*/*" |
479 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
482 if test $failed -ne 0; then
483 echo "Star5 test failed" >> $logfile
487 # Try a recursive search in unreadable directory
489 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
490 ${common_objpfx}posix/globtest "$testdir" "noread/*" |
492 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
495 if test $failed -ne 0; then
496 echo "Star6 test failed" >> $logfile
501 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
502 ${common_objpfx}posix/globtest "$testdir" "noread*/*" |
504 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
507 if test $failed -ne 0; then
508 echo "Star6 test failed" >> $logfile
512 # The following tests will fail if run as root.
513 user=`id -un 2> /dev/null`
514 if test -z "$user"; then
517 if test "$user" != root; then
519 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
520 ${common_objpfx}posix/globtest -E "$testdir" "noread/*" |
522 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
526 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
527 ${common_objpfx}posix/globtest -E "$testdir" "noread*/*" |
529 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
532 if test $failed -ne 0; then
533 echo "GLOB_ERR test failed" >> $logfile
538 # Try multiple patterns (GLOB_APPEND)
540 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
541 ${common_objpfx}posix/globtest "$testdir" "file1" "*/*" |
543 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
548 if test $failed -ne 0; then
549 echo "GLOB_APPEND test failed" >> $logfile
553 # Try multiple patterns (GLOB_APPEND) with offset (GLOB_DOOFFS)
555 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
556 ${common_objpfx}posix/globtest -o "$testdir" "file1" "*/*" |
558 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
564 if test $failed -ne 0; then
565 echo "GLOB_APPEND2 test failed" >> $logfile
569 # Test NOCHECK with non-existing file in subdir.
571 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
572 ${common_objpfx}posix/globtest -c "$testdir" "*/blahblah" |
574 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
577 if test $failed -ne 0; then
578 echo "No check2 test failed" >> $logfile
582 if test $result -eq 0; then
583 chmod 777 $testdir/noread
584 rm -fr $testdir $testout
585 echo "All OK." > $logfile
590 # Preserve executable bits for this shell script.
592 eval:(defun frobme () (set-file-modes buffer-file-name file-mode))
593 eval:(make-local-variable 'file-mode)
594 eval:(setq file-mode (file-modes (buffer-file-name)))
595 eval:(make-local-variable 'after-save-hook)
596 eval:(add-hook 'after-save-hook 'frobme)