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
=$
(mktemp
-d $TMPDIR/globtest-dir.XXXXXX
)
32 testout
=$
(mktemp
$TMPDIR/globtest-out.XXXXXX
)
34 trap 'chmod 777 $testdir/noread; rm -fr $testdir $testout' 1 2 3 15
36 echo 1 > $testdir/file1
37 echo 2 > $testdir/file2
38 echo 3 > $testdir/-file3
39 echo 4 > $testdir/~file4
40 echo 5 > $testdir/.file5
41 echo 6 > $testdir/'*file6'
42 echo 7 > $testdir/'{file7,}'
43 echo 8 > $testdir/'\{file8\}'
44 echo 9 > $testdir/'\{file9\,file9b\}'
45 echo 9 > $testdir/'\file9b\' #'
46 echo a
> $testdir/'filea,'
47 echo a
> $testdir/'fileb}c'
50 test -d $testdir/noread || mkdir
$testdir/noread
51 chmod a-r
$testdir/noread
52 echo 1_1
> $testdir/dir
1/file1_1
53 echo 1_2
> $testdir/dir
1/file1_2
54 ln -fs dir1
$testdir/link1
62 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
63 ${common_objpfx}posix
/globtest
"$testdir" "*" |
65 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
82 if test $failed -ne 0; then
83 echo "Normal test failed" >> $logfile
87 # Don't let glob sort it
89 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
90 ${common_objpfx}posix/globtest -s "$testdir" "*" |
92 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
109 if test $failed -ne 0; then
110 echo "No sort test failed" >> $logfile
116 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
117 ${common_objpfx}posix/globtest -m "$testdir" "*" |
119 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
136 if test $failed -ne 0; then
137 echo "Mark directories test failed" >> $logfile
141 # Find files starting with .
143 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
144 ${common_objpfx}posix
/globtest
-p "$testdir" "*" |
146 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
166 if test $failed -ne 0; then
167 echo "Leading period test failed" >> $logfile
173 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
174 ${common_objpfx}posix/globtest -b "$testdir" "file{1,2}" |
176 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
180 if test $failed -ne 0; then
181 echo "Braces test failed" >> $logfile
186 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
187 ${common_objpfx}posix/globtest -b "$testdir" "{file{1,2},-file3}" |
189 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
194 if test $failed -ne 0; then
195 echo "Braces test 2 failed" >> $logfile
200 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
201 ${common_objpfx}posix/globtest -b "$testdir" "{" |
203 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
206 if test $failed -ne 0; then
207 echo "Braces test 3 failed" >> $logfile
213 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
214 ${common_objpfx}posix/globtest -c "$testdir" "abc" |
216 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
219 if test $failed -ne 0; then
220 echo "No check test failed" >> $logfile
224 # Test NOMAGIC without magic characters
226 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
227 ${common_objpfx}posix
/globtest
-g "$testdir" "abc" |
229 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
232 if test $failed -ne 0; then
233 echo "No magic test failed" >> $logfile
237 # Test NOMAGIC with magic characters
239 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
240 ${common_objpfx}posix/globtest -g "$testdir" "abc*" |
242 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
245 if test $failed -ne 0; then
246 echo "No magic w/ magic chars test failed" >> $logfile
250 # Test NOMAGIC for subdirs
252 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
253 ${common_objpfx}posix
/globtest
-g "$testdir" "*/does-not-exist" |
255 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
258 if test $failed -ne 0; then
259 echo "No magic in subdir test failed" >> $logfile
263 # Test subdirs correctly
265 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
266 ${common_objpfx}posix/globtest "$testdir" "*/*" |
268 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
274 if test $failed -ne 0; then
275 echo "Subdirs test failed" >> $logfile
279 # Test subdirs for invalid names
281 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
282 ${common_objpfx}posix/globtest "$testdir" "*/1" |
284 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
287 if test $failed -ne 0; then
288 echo "Invalid subdir test failed" >> $logfile
292 # Test subdirs with wildcard
294 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
295 ${common_objpfx}posix/globtest "$testdir" "*/*1_1" |
297 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
301 if test $failed -ne 0; then
302 echo "Wildcard subdir test failed" >> $logfile
306 # Test subdirs with ?
308 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
309 ${common_objpfx}posix
/globtest
"$testdir" "*/*?_?" |
311 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
317 if test $failed -ne 0; then
318 echo "Wildcard2 subdir test failed" >> $logfile
323 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
324 ${common_objpfx}posix/globtest "$testdir" "*/file1_1" |
326 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
330 if test $failed -ne 0; then
331 echo "Wildcard3 subdir test failed" >> $logfile
336 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
337 ${common_objpfx}posix/globtest "$testdir" "*-/*" |
339 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
342 if test $failed -ne 0; then
343 echo "Wildcard4 subdir test failed" >> $logfile
348 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
349 ${common_objpfx}posix/globtest "$testdir" "*-" |
351 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
354 if test $failed -ne 0; then
355 echo "Wildcard5 subdir test failed" >> $logfile
359 # Test subdirs with ?
361 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
362 ${common_objpfx}posix/globtest "$testdir" "*/*?_?" |
364 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
370 if test $failed -ne 0; then
371 echo "Wildcard6 subdir test failed" >> $logfile
375 # Test subdirs with [ .. ]
377 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
378 ${common_objpfx}posix
/globtest
"$testdir" "*/file1_[12]" |
380 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
386 if test $failed -ne 0; then
387 echo "Brackets test failed" >> $logfile
391 # Test ']' inside bracket expression
393 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
394 ${common_objpfx}posix/globtest "$testdir" "dir1/file1_[]12]" |
396 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
400 if test $failed -ne 0; then
401 echo "Brackets2 test failed" >> $logfile
405 # Test tilde expansion
407 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
408 ${common_objpfx}posix/globtest -q -t "$testdir" "~" |
410 echo ~ | $CMP - $testout >> $logfile || failed=1
411 if test $failed -ne 0; then
413 echo "Tilde test failed" >> $logfile
416 echo "Tilde test could not be run" >> $logfile
420 # Test tilde expansion with trailing slash
422 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
423 ${common_objpfx}posix/globtest -q -t "$testdir" "~/" |
425 # Some shell incorrectly(?) convert ~/ into // if ~ expands to /.
426 if test ~/ = //; then
427 echo / | $CMP - $testout >> $logfile || failed=1
429 echo ~/ | $CMP - $testout >> $logfile || failed=1
431 if test $failed -ne 0; then
433 echo "Tilde2 test failed" >> $logfile
436 echo "Tilde2 test could not be run" >> $logfile
440 # Test tilde expansion with username
442 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
443 ${common_objpfx}posix/globtest -q -t "$testdir" "~"$USER |
445 eval echo ~$USER | $CMP - $testout >> $logfile || failed=1
446 if test $failed -ne 0; then
447 if eval test -d ~$USER; then
448 echo "Tilde3 test failed" >> $logfile
451 echo "Tilde3 test could not be run" >> $logfile
455 # Tilde expansion shouldn't match a
file
457 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
458 ${common_objpfx}posix
/globtest
-T "$testdir" "~file4" |
460 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
463 if test $failed -ne 0; then
464 echo "Tilde4 test failed" >> $logfile
468 # Matching \** should only find *file6
470 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
471 ${common_objpfx}posix/globtest "$testdir" "\**" |
473 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
476 if test $failed -ne 0; then
477 echo "Star test failed" >> $logfile
481 # ... unless NOESCAPE is used, in which case it should entries with a
484 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
485 ${common_objpfx}posix/globtest -e "$testdir" "\**" |
487 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
492 if test $failed -ne 0; then
493 echo "Star2 test failed" >> $logfile
497 # Matching \*file6 should find *file6
499 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
500 ${common_objpfx}posix/globtest "$testdir" "\*file6" |
502 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
505 if test $failed -ne 0; then
506 echo "Star3 test failed" >> $logfile
512 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
513 ${common_objpfx}posix
/globtest
-b "$testdir" '\{file7\,\}' |
515 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
518 if test $failed -ne 0; then
519 echo "Brace4 test failed" >> $logfile
523 # GLOB_BRACE and GLOB_NOESCAPE
525 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
526 ${common_objpfx}posix/globtest -b -e "$testdir" '\{file9\,file9b\}' |
528 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
531 if test $failed -ne 0; then
532 echo "Brace5 test failed" >> $logfile
538 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
539 ${common_objpfx}posix/globtest -b "$testdir" '{filea\,}' |
541 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
544 if test $failed -ne 0; then
545 echo "Brace6 test failed" >> $logfile
549 # Escaped closing brace
551 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
552 ${common_objpfx}posix/globtest -b "$testdir" '{fileb\
}c
}' |
554 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
557 if test $failed -ne 0; then
558 echo "Brace7 test failed" >> $logfile
562 # Try a recursive failed search
564 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
565 ${common_objpfx}posix
/globtest
-e "$testdir" "a*/*" |
567 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
570 if test $failed -ne 0; then
571 echo "Star4 test failed" >> $logfile
577 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
578 ${common_objpfx}posix/globtest -E "$testdir" "a*/*" |
580 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
583 if test $failed -ne 0; then
584 echo "Star5 test failed" >> $logfile
588 # Try a recursive search in unreadable directory
590 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
591 ${common_objpfx}posix
/globtest
"$testdir" "noread/*" |
593 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
596 if test $failed -ne 0; then
597 echo "Star6 test failed" >> $logfile
602 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
603 ${common_objpfx}posix/globtest "$testdir" "noread*/*" |
605 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
608 if test $failed -ne 0; then
609 echo "Star6 test failed" >> $logfile
613 # The following tests will fail if run as root.
614 user
=`id -un 2> /dev/null`
615 if test -z "$user"; then
618 if test "$user" != root
; then
620 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
621 ${common_objpfx}posix
/globtest
-E "$testdir" "noread/*" |
623 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
627 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
628 ${common_objpfx}posix/globtest -E "$testdir" "noread*/*" |
630 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
633 if test $failed -ne 0; then
634 echo "GLOB_ERR test failed" >> $logfile
639 # Try multiple patterns (GLOB_APPEND)
641 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
642 ${common_objpfx}posix
/globtest
"$testdir" "file1" "*/*" |
644 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
651 if test $failed -ne 0; then
652 echo "GLOB_APPEND test failed" >> $logfile
656 # Try multiple patterns (GLOB_APPEND) with offset (GLOB_DOOFFS)
658 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
659 ${common_objpfx}posix/globtest -o "$testdir" "file1" "*/*" |
661 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
669 if test $failed -ne 0; then
670 echo "GLOB_APPEND2 test failed" >> $logfile
674 # Test NOCHECK with non-existing file in subdir.
676 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
677 ${common_objpfx}posix
/globtest
-c "$testdir" "*/blahblah" |
679 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
682 if test $failed -ne 0; then
683 echo "No check2 test failed" >> $logfile
687 # Test [[:punct:]] not matching leading period.
689 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
690 ${common_objpfx}posix/globtest -c "$testdir" "[[:punct:]]*" |
692 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
701 if test $failed -ne 0; then
702 echo "Punct test failed" >> $logfile
706 mkdir
$testdir/'dir3*'
707 echo 1 > $testdir/'dir3*'/file1
708 mkdir
$testdir/'dir4[a'
709 echo 2 > $testdir/'dir4[a'/file1
710 echo 3 > $testdir/'dir4[a'/file2
711 mkdir
$testdir/'dir5[ab]'
712 echo 4 > $testdir/'dir5[ab]'/file1
713 echo 5 > $testdir/'dir5[ab]'/file2
715 echo 6 > $testdir/dir
6/'file1[a'
716 echo 7 > $testdir/dir
6/'file1[ab]'
718 v
=`${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
719 ${common_objpfx}posix/globtest "$testdir" 'dir3\*/file2'`
720 test "$v" != 'GLOB_NOMATCH' && echo "$v" >> $logfile && failed
=1
721 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
722 ${common_objpfx}posix
/globtest
-c "$testdir" \
723 'dir3\*/file1' 'dir3\*/file2' 'dir1/file\1_1' 'dir1/file\1_9' \
724 'dir2\/' 'nondir\/' 'dir4[a/fil*1' 'di*r4[a/file2' 'dir5[ab]/file[12]' \
725 'dir6/fil*[a' 'dir*6/file1[a' 'dir6/fi*l[ab]' 'dir*6/file1[ab]' |
727 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
743 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
744 ${common_objpfx}posix/globtest -ct "$testdir" \
745 '~/dir1/file1_1' '~/dir1/file1_9' '~/dir3\*/file1' '~/dir3\*/file2' \
748 cat <<EOF | $CMP - $testout >> $logfile || failed=1
749 \`$testdir/dir1/file1_1'
750 \`$testdir/dir1/file1_2'
751 \`$testdir/dir3*/file1'
755 if eval test -d ~"$USER"/; then
756 user=`echo "$USER" | sed -n -e 's/^\([^\\]\)\([^\\][^\\]*\)$/~\1\\\\\2/p'`
757 if test -n "$user"; then
758 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
759 ${common_objpfx}posix/globtest -ctq "$testdir" "$user/" |
761 eval echo ~$USER/ | $CMP - $testout >> $logfile || failed=1
762 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
763 ${common_objpfx}posix/globtest -ctq "$testdir" "$user\\/" |
765 eval echo ~$USER/ | $CMP - $testout >> $logfile || failed=1
766 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
767 ${common_objpfx}posix/globtest -ctq "$testdir" "$user" |
769 eval echo ~$USER | $CMP - $testout >> $logfile || failed=1
772 if test $failed -ne 0; then
773 echo "Escape tests failed" >> $logfile
777 if test $result -eq 0; then
778 chmod 777 $testdir/noread
779 rm -fr $testdir $testout
780 echo "All OK." > $logfile
785 # Preserve executable bits for this shell script.
787 eval:(defun frobme () (set-file-modes buffer-file-name file-mode))
788 eval:(make-local-variable 'file-mode)
789 eval:(setq file-mode (file-modes (buffer-file-name)))
790 eval:(make-local-variable 'after-save-hook)
791 eval:(add-hook 'after-save-hook 'frobme)