3 # Copyright (C) 1997-2018 Free Software Foundation, Inc.
4 # This file is part of the GNU C Library.
6 # The GNU C Library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License, or (at your option) any later version.
11 # The GNU C Library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with the GNU C Library; if not, see
18 # <http://www.gnu.org/licenses/>.
22 common_objpfx
=$1; shift
23 test_via_rtld_prefix
=$1; shift
24 test_program_prefix
=$1; shift
25 test_wrapper_env
=$1; shift
26 logfile
=$common_objpfx/posix
/globtest.out
31 # We have to make the paths `common_objpfx' absolute.
32 case "$common_objpfx" in
34 common_objpfx
="`pwd`/$common_objpfx"
40 # Since we use `sort' we must make sure to use the same locale everywhere.
45 testdir
=${common_objpfx}posix
/globtest-dir
46 testout
=${common_objpfx}posix
/globtest-out
47 rm -rf $testdir $testout
51 chmod 777 $testdir/noread
52 rm -fr $testdir $testout
55 trap cleanup
0 HUP INT QUIT TERM
57 echo 1 > $testdir/file1
58 echo 2 > $testdir/file2
59 echo 3 > $testdir/-file3
60 echo 4 > $testdir/~file4
61 echo 5 > $testdir/.file5
62 echo 6 > $testdir/'*file6'
63 echo 7 > $testdir/'{file7,}'
64 echo 8 > $testdir/'\{file8\}'
65 echo 9 > $testdir/'\{file9\,file9b\}'
66 echo 9 > $testdir/'\file9b\' #'
67 echo a
> $testdir/'filea,'
68 echo a
> $testdir/'fileb}c'
71 test -d $testdir/noread || mkdir
$testdir/noread
72 chmod a-r
$testdir/noread
73 echo 1_1
> $testdir/dir
1/file1_1
74 echo 1_2
> $testdir/dir
1/file1_2
75 ln -fs dir1
$testdir/link1
83 ${test_program_prefix} \
84 ${common_objpfx}posix
/globtest
"$testdir" "*" |
86 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
103 if test $failed -ne 0; then
104 echo "Normal test failed" >> $logfile
108 # Don't let glob sort it
110 ${test_program_prefix} \
111 ${common_objpfx}posix/globtest -s "$testdir" "*" |
113 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
130 if test $failed -ne 0; then
131 echo "No sort test failed" >> $logfile
137 ${test_program_prefix} \
138 ${common_objpfx}posix/globtest -m "$testdir" "*" |
140 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
157 if test $failed -ne 0; then
158 echo "Mark directories test failed" >> $logfile
162 # Find files starting with .
164 ${test_program_prefix} \
165 ${common_objpfx}posix
/globtest
-p "$testdir" "*" |
167 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
187 if test $failed -ne 0; then
188 echo "Leading period test failed" >> $logfile
194 ${test_program_prefix} \
195 ${common_objpfx}posix/globtest -b "$testdir" "file{1,2}" |
197 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
201 if test $failed -ne 0; then
202 echo "Braces test failed" >> $logfile
207 ${test_program_prefix} \
208 ${common_objpfx}posix/globtest -b "$testdir" "{file{1,2},-file3}" |
210 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
215 if test $failed -ne 0; then
216 echo "Braces test 2 failed" >> $logfile
221 ${test_program_prefix} \
222 ${common_objpfx}posix/globtest -b "$testdir" "{" |
224 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
227 if test $failed -ne 0; then
228 echo "Braces test 3 failed" >> $logfile
234 ${test_program_prefix} \
235 ${common_objpfx}posix/globtest -c "$testdir" "abc" |
237 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
240 if test $failed -ne 0; then
241 echo "No check test failed" >> $logfile
245 # Test NOMAGIC without magic characters
247 ${test_program_prefix} \
248 ${common_objpfx}posix
/globtest
-g "$testdir" "abc" |
250 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
253 if test $failed -ne 0; then
254 echo "No magic test failed" >> $logfile
258 # Test NOMAGIC with magic characters
260 ${test_program_prefix} \
261 ${common_objpfx}posix/globtest -g "$testdir" "abc*" |
263 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
266 if test $failed -ne 0; then
267 echo "No magic w/ magic chars test failed" >> $logfile
271 # Test NOMAGIC for subdirs
273 ${test_program_prefix} \
274 ${common_objpfx}posix
/globtest
-g "$testdir" "*/does-not-exist" |
276 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
279 if test $failed -ne 0; then
280 echo "No magic in subdir test failed" >> $logfile
284 # Test subdirs correctly
286 ${test_program_prefix} \
287 ${common_objpfx}posix/globtest "$testdir" "*/*" |
289 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
295 if test $failed -ne 0; then
296 echo "Subdirs test failed" >> $logfile
300 # Test subdirs for invalid names
302 ${test_program_prefix} \
303 ${common_objpfx}posix/globtest "$testdir" "*/1" |
305 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
308 if test $failed -ne 0; then
309 echo "Invalid subdir test failed" >> $logfile
313 # Test subdirs with wildcard
315 ${test_program_prefix} \
316 ${common_objpfx}posix/globtest "$testdir" "*/*1_1" |
318 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
322 if test $failed -ne 0; then
323 echo "Wildcard subdir test failed" >> $logfile
327 # Test subdirs with ?
329 ${test_program_prefix} \
330 ${common_objpfx}posix
/globtest
"$testdir" "*/*?_?" |
332 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
338 if test $failed -ne 0; then
339 echo "Wildcard2 subdir test failed" >> $logfile
344 ${test_program_prefix} \
345 ${common_objpfx}posix/globtest "$testdir" "*/file1_1" |
347 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
351 if test $failed -ne 0; then
352 echo "Wildcard3 subdir test failed" >> $logfile
357 ${test_program_prefix} \
358 ${common_objpfx}posix/globtest "$testdir" "*-/*" |
360 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
363 if test $failed -ne 0; then
364 echo "Wildcard4 subdir test failed" >> $logfile
369 ${test_program_prefix} \
370 ${common_objpfx}posix/globtest "$testdir" "*-" |
372 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
375 if test $failed -ne 0; then
376 echo "Wildcard5 subdir test failed" >> $logfile
380 # Test subdirs with ?
382 ${test_program_prefix} \
383 ${common_objpfx}posix/globtest "$testdir" "*/*?_?" |
385 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
391 if test $failed -ne 0; then
392 echo "Wildcard6 subdir test failed" >> $logfile
396 # Test subdirs with [ .. ]
398 ${test_program_prefix} \
399 ${common_objpfx}posix
/globtest
"$testdir" "*/file1_[12]" |
401 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
407 if test $failed -ne 0; then
408 echo "Brackets test failed" >> $logfile
412 # Test ']' inside bracket expression
414 ${test_program_prefix} \
415 ${common_objpfx}posix/globtest "$testdir" "dir1/file1_[]12]" |
417 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
421 if test $failed -ne 0; then
422 echo "Brackets2 test failed" >> $logfile
426 # Test tilde expansion
428 ${test_program_prefix} \
429 ${common_objpfx}posix/globtest -q -t "$testdir" "~" |
431 echo ~ | $CMP - $testout >> $logfile || failed=1
432 if test $failed -ne 0; then
434 echo "Tilde test failed" >> $logfile
437 echo "Tilde test could not be run" >> $logfile
441 # Test tilde expansion with trailing slash
443 ${test_program_prefix} \
444 ${common_objpfx}posix/globtest -q -t "$testdir" "~/" |
446 # Some shell incorrectly(?) convert ~/ into // if ~ expands to /.
447 if test ~/ = //; then
448 echo / | $CMP - $testout >> $logfile || failed=1
450 echo ~/ | $CMP - $testout >> $logfile || failed=1
452 if test $failed -ne 0; then
454 echo "Tilde2 test failed" >> $logfile
457 echo "Tilde2 test could not be run" >> $logfile
461 # Test tilde expansion with username
463 ${test_program_prefix} \
464 ${common_objpfx}posix/globtest -q -t "$testdir" "~"$USER |
466 eval echo ~$USER | $CMP - $testout >> $logfile || failed=1
467 if test $failed -ne 0; then
468 if eval test -d ~$USER; then
469 echo "Tilde3 test failed" >> $logfile
472 echo "Tilde3 test could not be run" >> $logfile
476 # Tilde expansion shouldn't match a
file
478 ${test_program_prefix} \
479 ${common_objpfx}posix
/globtest
-T "$testdir" "~file4" |
481 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
484 if test $failed -ne 0; then
485 echo "Tilde4 test failed" >> $logfile
489 # Matching \** should only find *file6
491 ${test_program_prefix} \
492 ${common_objpfx}posix/globtest "$testdir" "\**" |
494 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
497 if test $failed -ne 0; then
498 echo "Star test failed" >> $logfile
502 # ... unless NOESCAPE is used, in which case it should entries with a
505 ${test_program_prefix} \
506 ${common_objpfx}posix/globtest -e "$testdir" "\**" |
508 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
513 if test $failed -ne 0; then
514 echo "Star2 test failed" >> $logfile
518 # Matching \*file6 should find *file6
520 ${test_program_prefix} \
521 ${common_objpfx}posix/globtest "$testdir" "\*file6" |
523 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
526 if test $failed -ne 0; then
527 echo "Star3 test failed" >> $logfile
533 ${test_program_prefix} \
534 ${common_objpfx}posix
/globtest
-b "$testdir" '\{file7\,\}' |
536 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
539 if test $failed -ne 0; then
540 echo "Brace4 test failed" >> $logfile
544 # GLOB_BRACE and GLOB_NOESCAPE
546 ${test_program_prefix} \
547 ${common_objpfx}posix/globtest -b -e "$testdir" '\{file9\,file9b\}' |
549 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
552 if test $failed -ne 0; then
553 echo "Brace5 test failed" >> $logfile
559 ${test_program_prefix} \
560 ${common_objpfx}posix/globtest -b "$testdir" '{filea\,}' |
562 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
565 if test $failed -ne 0; then
566 echo "Brace6 test failed" >> $logfile
570 # Escaped closing brace
572 ${test_program_prefix} \
573 ${common_objpfx}posix/globtest -b "$testdir" '{fileb\
}c
}' |
575 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
578 if test $failed -ne 0; then
579 echo "Brace7 test failed" >> $logfile
583 # Try a recursive failed search
585 ${test_program_prefix} \
586 ${common_objpfx}posix
/globtest
-e "$testdir" "a*/*" |
588 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
591 if test $failed -ne 0; then
592 echo "Star4 test failed" >> $logfile
598 ${test_program_prefix} \
599 ${common_objpfx}posix/globtest -E "$testdir" "a*/*" |
601 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
604 if test $failed -ne 0; then
605 echo "Star5 test failed" >> $logfile
609 # Try a recursive search in unreadable directory
611 ${test_program_prefix} \
612 ${common_objpfx}posix
/globtest
"$testdir" "noread/*" |
614 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
617 if test $failed -ne 0; then
618 echo "Star6 test failed" >> $logfile
623 ${test_program_prefix} \
624 ${common_objpfx}posix/globtest "$testdir" "noread*/*" |
626 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
629 if test $failed -ne 0; then
630 echo "Star6 test failed" >> $logfile
634 # The following tests will fail if run as root.
635 user
=`id -un 2> /dev/null`
636 if test -z "$user"; then
639 if test "$user" != root
; then
641 ${test_program_prefix} \
642 ${common_objpfx}posix
/globtest
-E "$testdir" "noread/*" |
644 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
648 ${test_program_prefix} \
649 ${common_objpfx}posix/globtest -E "$testdir" "noread*/*" |
651 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
654 if test $failed -ne 0; then
655 echo "GLOB_ERR test failed" >> $logfile
660 # Try multiple patterns (GLOB_APPEND)
662 ${test_program_prefix} \
663 ${common_objpfx}posix
/globtest
"$testdir" "file1" "*/*" |
665 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
672 if test $failed -ne 0; then
673 echo "GLOB_APPEND test failed" >> $logfile
677 # Try multiple patterns (GLOB_APPEND) with offset (GLOB_DOOFFS)
679 ${test_program_prefix} \
680 ${common_objpfx}posix/globtest -o "$testdir" "file1" "*/*" |
682 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
690 if test $failed -ne 0; then
691 echo "GLOB_APPEND2 test failed" >> $logfile
695 # Test NOCHECK with non-existing file in subdir.
697 ${test_program_prefix} \
698 ${common_objpfx}posix
/globtest
-c "$testdir" "*/blahblah" |
700 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
703 if test $failed -ne 0; then
704 echo "No check2 test failed" >> $logfile
708 # Test [[:punct:]] not matching leading period.
710 ${test_program_prefix} \
711 ${common_objpfx}posix/globtest -c "$testdir" "[[:punct:]]*" |
713 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
722 if test $failed -ne 0; then
723 echo "Punct test failed" >> $logfile
727 mkdir
$testdir/'dir3*'
728 echo 1 > $testdir/'dir3*'/file1
729 mkdir
$testdir/'dir4[a'
730 echo 2 > $testdir/'dir4[a'/file1
731 echo 3 > $testdir/'dir4[a'/file2
732 mkdir
$testdir/'dir5[ab]'
733 echo 4 > $testdir/'dir5[ab]'/file1
734 echo 5 > $testdir/'dir5[ab]'/file2
736 echo 6 > $testdir/dir
6/'file1[a'
737 echo 7 > $testdir/dir
6/'file1[ab]'
739 v
=`${test_program_prefix} \
740 ${common_objpfx}posix/globtest "$testdir" 'dir3\*/file2'`
741 test "$v" != 'GLOB_NOMATCH' && echo "$v" >> $logfile && failed
=1
742 ${test_program_prefix} \
743 ${common_objpfx}posix
/globtest
-c "$testdir" \
744 'dir3\*/file1' 'dir3\*/file2' 'dir1/file\1_1' 'dir1/file\1_9' \
745 'dir2\/' 'nondir\/' 'dir4[a/fil*1' 'di*r4[a/file2' 'dir5[ab]/file[12]' \
746 'dir6/fil*[a' 'dir*6/file1[a' 'dir6/fi*l[ab]' 'dir*6/file1[ab]' \
747 'dir6/file1[[.a.]*' |
749 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
766 ${test_wrapper_env} \
768 ${test_via_rtld_prefix} \
769 ${common_objpfx}posix/globtest -ct "$testdir" \
770 '~/dir1/file1_1' '~/dir1/file1_9' '~/dir3\*/file1' '~/dir3\*/file2' \
773 cat <<EOF | $CMP - $testout >> $logfile || failed=1
774 \`$testdir/dir1/file1_1'
775 \`$testdir/dir1/file1_2'
776 \`$testdir/dir3*/file1'
780 if eval test -d ~"$USER"/; then
781 user=`echo "$USER" | sed -n -e 's/^\([^\\]\)\([^\\][^\\]*\)$/~\1\\\\\2/p'`
782 if test -n "$user"; then
783 ${test_program_prefix} \
784 ${common_objpfx}posix/globtest -ctq "$testdir" "$user/" |
786 eval echo ~$USER/ | $CMP - $testout >> $logfile || failed=1
787 ${test_program_prefix} \
788 ${common_objpfx}posix/globtest -ctq "$testdir" "$user\\/" |
790 eval echo ~$USER/ | $CMP - $testout >> $logfile || failed=1
791 ${test_program_prefix} \
792 ${common_objpfx}posix/globtest -ctq "$testdir" "$user" |
794 eval echo ~$USER | $CMP - $testout >> $logfile || failed=1
797 if test $failed -ne 0; then
798 echo "Escape tests failed" >> $logfile
802 # Test GLOB_BRACE and GLIB_DOOFFS with malloc checking
804 ${test_wrapper_env} \
806 ${test_via_rtld_prefix} \
807 ${common_objpfx}posix/globtest -b -o "$testdir" "file{1,2}" > $testout || failed=1
808 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
813 if test $failed -ne 0; then
814 echo "GLOB_BRACE+GLOB_DOOFFS test failed" >> $logfile
818 if test $result -eq 0; then
819 echo "All OK." > $logfile
824 # Preserve executable bits for this shell script.
826 eval:(defun frobme
() (set-file-modes buffer-file-name file-mode
))
827 eval:(make-local-variable
'file-mode)
828 eval:(setq file-mode (file-modes (buffer-file-name)))
829 eval:(make-local-variable 'after-save-hook
)
830 eval:(add-hook
'after-save-hook 'frobme
)