3 common_objpfx
=$1; shift
5 rtld_installed_name
=$1; shift
6 logfile
=$common_objpfx/posix
/globtest.out
11 # We have to make the paths `common_objpfx' absolute.
12 case "$common_objpfx" in
14 common_objpfx
="`pwd`/$common_objpfx"
20 # We have to find the libc and the NSS modules.
21 library_path
=${common_objpfx}:${common_objpfx}nss:${common_objpfx}nis:${common_objpfx}db2:${common_objpfx}hesiod
23 # Since we use `sort' we must make sure to use the same locale everywhere.
31 testdir
=$TMPDIR/globtest-dir
32 testout
=$TMPDIR/globtest-out
34 trap 'chmod 777 $testdir/noread; rm -fr $testdir $testout' 1 2 3 15
36 test -d $testdir/noread
&& chmod 777 $testdir/noread
37 rm -fr $testdir 2>/dev
/null
39 echo 1 > $testdir/file1
40 echo 2 > $testdir/file2
41 echo 3 > $testdir/-file3
42 echo 4 > $testdir/~file4
43 echo 5 > $testdir/.file5
44 echo 6 > $testdir/'*file6'
45 echo 7 > $testdir/'{file7,}'
46 echo 8 > $testdir/'\{file8\}'
47 echo 9 > $testdir/'\{file9\,file9b\}'
48 echo 9 > $testdir/'\file9b\' #'
49 echo a
> $testdir/'filea,'
50 echo a
> $testdir/'fileb}c'
53 test -d $testdir/noread || mkdir
$testdir/noread
54 chmod a-r
$testdir/noread
55 echo 1_1
> $testdir/dir
1/file1_1
56 echo 1_2
> $testdir/dir
1/file1_2
57 ln -fs dir1
$testdir/link1
65 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
66 ${common_objpfx}posix
/globtest
"$testdir" "*" |
68 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
85 if test $failed -ne 0; then
86 echo "Normal test failed" >> $logfile
90 # Don't let glob sort it
92 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
93 ${common_objpfx}posix/globtest -s "$testdir" "*" |
95 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
112 if test $failed -ne 0; then
113 echo "No sort test failed" >> $logfile
119 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
120 ${common_objpfx}posix/globtest -m "$testdir" "*" |
122 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
139 if test $failed -ne 0; then
140 echo "Mark directories test failed" >> $logfile
144 # Find files starting with .
146 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
147 ${common_objpfx}posix
/globtest
-p "$testdir" "*" |
149 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
169 if test $failed -ne 0; then
170 echo "Leading period test failed" >> $logfile
176 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
177 ${common_objpfx}posix/globtest -b "$testdir" "file{1,2}" |
179 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
183 if test $failed -ne 0; then
184 echo "Braces test failed" >> $logfile
189 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
190 ${common_objpfx}posix/globtest -b "$testdir" "{file{1,2},-file3}" |
192 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
197 if test $failed -ne 0; then
198 echo "Braces test 2 failed" >> $logfile
203 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
204 ${common_objpfx}posix/globtest -b "$testdir" "{" |
206 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
209 if test $failed -ne 0; then
210 echo "Braces test 3 failed" >> $logfile
216 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
217 ${common_objpfx}posix/globtest -c "$testdir" "abc" |
219 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
222 if test $failed -ne 0; then
223 echo "No check test failed" >> $logfile
227 # Test NOMAGIC without magic characters
229 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
230 ${common_objpfx}posix
/globtest
-g "$testdir" "abc" |
232 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
235 if test $failed -ne 0; then
236 echo "No magic test failed" >> $logfile
240 # Test NOMAGIC with magic characters
242 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
243 ${common_objpfx}posix/globtest -g "$testdir" "abc*" |
245 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
248 if test $failed -ne 0; then
249 echo "No magic w/ magic chars test failed" >> $logfile
253 # Test NOMAGIC for subdirs
255 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
256 ${common_objpfx}posix
/globtest
-g "$testdir" "*/does-not-exist" |
258 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
261 if test $failed -ne 0; then
262 echo "No magic in subdir test failed" >> $logfile
266 # Test subdirs correctly
268 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
269 ${common_objpfx}posix/globtest "$testdir" "*/*" |
271 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
277 if test $failed -ne 0; then
278 echo "Subdirs test failed" >> $logfile
282 # Test subdirs for invalid names
284 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
285 ${common_objpfx}posix/globtest "$testdir" "*/1" |
287 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
290 if test $failed -ne 0; then
291 echo "Invalid subdir test failed" >> $logfile
295 # Test subdirs with wildcard
297 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
298 ${common_objpfx}posix/globtest "$testdir" "*/*1_1" |
300 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
304 if test $failed -ne 0; then
305 echo "Wildcard subdir test failed" >> $logfile
309 # Test subdirs with ?
311 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
312 ${common_objpfx}posix
/globtest
"$testdir" "*/*?_?" |
314 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
320 if test $failed -ne 0; then
321 echo "Wildcard2 subdir test failed" >> $logfile
326 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
327 ${common_objpfx}posix/globtest "$testdir" "*/file1_1" |
329 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
333 if test $failed -ne 0; then
334 echo "Wildcard3 subdir test failed" >> $logfile
339 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
340 ${common_objpfx}posix/globtest "$testdir" "*-/*" |
342 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
345 if test $failed -ne 0; then
346 echo "Wildcard4 subdir test failed" >> $logfile
351 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
352 ${common_objpfx}posix/globtest "$testdir" "*-" |
354 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
357 if test $failed -ne 0; then
358 echo "Wildcard5 subdir test failed" >> $logfile
362 # Test subdirs with ?
364 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
365 ${common_objpfx}posix/globtest "$testdir" "*/*?_?" |
367 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
373 if test $failed -ne 0; then
374 echo "Wildcard6 subdir test failed" >> $logfile
378 # Test subdirs with [ .. ]
380 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
381 ${common_objpfx}posix
/globtest
"$testdir" "*/file1_[12]" |
383 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
389 if test $failed -ne 0; then
390 echo "Brackets test failed" >> $logfile
394 # Test ']' inside bracket expression
396 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
397 ${common_objpfx}posix/globtest "$testdir" "dir1/file1_[]12]" |
399 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
403 if test $failed -ne 0; then
404 echo "Brackets2 test failed" >> $logfile
408 # Test tilde expansion
410 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
411 ${common_objpfx}posix/globtest -q -t "$testdir" "~" |
413 echo ~ | $CMP - $testout >> $logfile || failed=1
414 if test $failed -ne 0; then
416 echo "Tilde test failed" >> $logfile
419 echo "Tilde test could not be run" >> $logfile
423 # Test tilde expansion with trailing slash
425 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
426 ${common_objpfx}posix/globtest -q -t "$testdir" "~/" |
428 # Some shell incorrectly(?) convert ~/ into // if ~ expands to /.
429 if test ~/ = //; then
430 echo / | $CMP - $testout >> $logfile || failed=1
432 echo ~/ | $CMP - $testout >> $logfile || failed=1
434 if test $failed -ne 0; then
436 echo "Tilde2 test failed" >> $logfile
439 echo "Tilde2 test could not be run" >> $logfile
443 # Test tilde expansion with username
445 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
446 ${common_objpfx}posix/globtest -q -t "$testdir" "~"$USER |
448 eval echo ~$USER | $CMP - $testout >> $logfile || failed=1
449 if test $failed -ne 0; then
450 if eval test -d ~$USER; then
451 echo "Tilde3 test failed" >> $logfile
454 echo "Tilde3 test could not be run" >> $logfile
458 # Tilde expansion shouldn't match a
file
460 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
461 ${common_objpfx}posix
/globtest
-T "$testdir" "~file4" |
463 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
466 if test $failed -ne 0; then
467 echo "Tilde4 test failed" >> $logfile
471 # Matching \** should only find *file6
473 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
474 ${common_objpfx}posix/globtest "$testdir" "\**" |
476 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
479 if test $failed -ne 0; then
480 echo "Star test failed" >> $logfile
484 # ... unless NOESCAPE is used, in which case it should entries with a
487 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
488 ${common_objpfx}posix/globtest -e "$testdir" "\**" |
490 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
495 if test $failed -ne 0; then
496 echo "Star2 test failed" >> $logfile
500 # Matching \*file6 should find *file6
502 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
503 ${common_objpfx}posix/globtest "$testdir" "\*file6" |
505 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
508 if test $failed -ne 0; then
509 echo "Star3 test failed" >> $logfile
515 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
516 ${common_objpfx}posix
/globtest
-b "$testdir" '\{file7\,\}' |
518 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
521 if test $failed -ne 0; then
522 echo "Brace4 test failed" >> $logfile
526 # GLOB_BRACE and GLOB_NOESCAPE
528 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
529 ${common_objpfx}posix/globtest -b -e "$testdir" '\{file9\,file9b\}' |
531 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
534 if test $failed -ne 0; then
535 echo "Brace5 test failed" >> $logfile
541 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
542 ${common_objpfx}posix/globtest -b "$testdir" '{filea\,}' |
544 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
547 if test $failed -ne 0; then
548 echo "Brace6 test failed" >> $logfile
552 # Escaped closing brace
554 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
555 ${common_objpfx}posix/globtest -b "$testdir" '{fileb\
}c
}' |
557 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
560 if test $failed -ne 0; then
561 echo "Brace7 test failed" >> $logfile
565 # Try a recursive failed search
567 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
568 ${common_objpfx}posix
/globtest
-e "$testdir" "a*/*" |
570 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
573 if test $failed -ne 0; then
574 echo "Star4 test failed" >> $logfile
580 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
581 ${common_objpfx}posix/globtest -E "$testdir" "a*/*" |
583 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
586 if test $failed -ne 0; then
587 echo "Star5 test failed" >> $logfile
591 # Try a recursive search in unreadable directory
593 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
594 ${common_objpfx}posix
/globtest
"$testdir" "noread/*" |
596 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
599 if test $failed -ne 0; then
600 echo "Star6 test failed" >> $logfile
605 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
606 ${common_objpfx}posix/globtest "$testdir" "noread*/*" |
608 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
611 if test $failed -ne 0; then
612 echo "Star6 test failed" >> $logfile
616 # The following tests will fail if run as root.
617 user
=`id -un 2> /dev/null`
618 if test -z "$user"; then
621 if test "$user" != root
; then
623 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
624 ${common_objpfx}posix
/globtest
-E "$testdir" "noread/*" |
626 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
630 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
631 ${common_objpfx}posix/globtest -E "$testdir" "noread*/*" |
633 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
636 if test $failed -ne 0; then
637 echo "GLOB_ERR test failed" >> $logfile
642 # Try multiple patterns (GLOB_APPEND)
644 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
645 ${common_objpfx}posix
/globtest
"$testdir" "file1" "*/*" |
647 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
654 if test $failed -ne 0; then
655 echo "GLOB_APPEND test failed" >> $logfile
659 # Try multiple patterns (GLOB_APPEND) with offset (GLOB_DOOFFS)
661 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
662 ${common_objpfx}posix/globtest -o "$testdir" "file1" "*/*" |
664 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
672 if test $failed -ne 0; then
673 echo "GLOB_APPEND2 test failed" >> $logfile
677 # Test NOCHECK with non-existing file in subdir.
679 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
680 ${common_objpfx}posix
/globtest
-c "$testdir" "*/blahblah" |
682 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
685 if test $failed -ne 0; then
686 echo "No check2 test failed" >> $logfile
690 # Test [[:punct:]] not matching leading period.
692 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
693 ${common_objpfx}posix/globtest -c "$testdir" "[[:punct:]]*" |
695 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
704 if test $failed -ne 0; then
705 echo "Punct test failed" >> $logfile
709 mkdir
$testdir/'dir3*'
710 echo 1 > $testdir/'dir3*'/file1
711 mkdir
$testdir/'dir4[a'
712 echo 2 > $testdir/'dir4[a'/file1
713 echo 3 > $testdir/'dir4[a'/file2
714 mkdir
$testdir/'dir5[ab]'
715 echo 4 > $testdir/'dir5[ab]'/file1
716 echo 5 > $testdir/'dir5[ab]'/file2
718 echo 6 > $testdir/dir
6/'file1[a'
719 echo 7 > $testdir/dir
6/'file1[ab]'
721 v
=`${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
722 ${common_objpfx}posix/globtest "$testdir" 'dir3\*/file2'`
723 test "$v" != 'GLOB_NOMATCH' && echo "$v" >> $logfile && failed
=1
724 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
725 ${common_objpfx}posix
/globtest
-c "$testdir" \
726 'dir3\*/file1' 'dir3\*/file2' 'dir1/file\1_1' 'dir1/file\1_9' \
727 'dir2\/' 'nondir\/' 'dir4[a/fil*1' 'di*r4[a/file2' 'dir5[ab]/file[12]' \
728 'dir6/fil*[a' 'dir*6/file1[a' 'dir6/fi*l[ab]' 'dir*6/file1[ab]' |
730 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
746 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
747 ${common_objpfx}posix/globtest -ct "$testdir" \
748 '~/dir1/file1_1' '~/dir1/file1_9' '~/dir3\*/file1' '~/dir3\*/file2' \
751 cat <<EOF | $CMP - $testout >> $logfile || failed=1
752 \`$testdir/dir1/file1_1'
753 \`$testdir/dir1/file1_2'
754 \`$testdir/dir3*/file1'
758 if eval test -d ~"$USER"/; then
759 user=`echo "$USER" | sed -n -e 's/^\([^\\]\)\([^\\][^\\]*\)$/~\1\\\\\2/p'`
760 if test -n "$user"; then
761 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
762 ${common_objpfx}posix/globtest -ctq "$testdir" "$user/" |
764 eval echo ~$USER/ | $CMP - $testout >> $logfile || failed=1
765 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
766 ${common_objpfx}posix/globtest -ctq "$testdir" "$user\\/" |
768 eval echo ~$USER/ | $CMP - $testout >> $logfile || failed=1
769 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
770 ${common_objpfx}posix/globtest -ctq "$testdir" "$user" |
772 eval echo ~$USER | $CMP - $testout >> $logfile || failed=1
775 if test $failed -ne 0; then
776 echo "Escape tests failed" >> $logfile
780 if test $result -eq 0; then
781 chmod 777 $testdir/noread
782 rm -fr $testdir $testout
783 echo "All OK." > $logfile
788 # Preserve executable bits for this shell script.
790 eval:(defun frobme () (set-file-modes buffer-file-name file-mode))
791 eval:(make-local-variable 'file-mode)
792 eval:(setq file-mode (file-modes (buffer-file-name)))
793 eval:(make-local-variable 'after-save-hook)
794 eval:(add-hook 'after-save-hook 'frobme)