3 # Copyright (C) 1997-2013 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 run_via_rtld_prefix
=$1; shift
24 test_wrapper
=$1; shift
25 test_wrapper_env
=$1; shift
26 run_program_prefix
="${test_wrapper} ${run_via_rtld_prefix}"
27 logfile
=$common_objpfx/posix
/globtest.out
32 # We have to make the paths `common_objpfx' absolute.
33 case "$common_objpfx" in
35 common_objpfx
="`pwd`/$common_objpfx"
41 # Since we use `sort' we must make sure to use the same locale everywhere.
48 testdir
=${common_objpfx}posix
/globtest-dir
49 testout
=${common_objpfx}posix
/globtest-out
50 rm -rf $testdir $testout
53 trap 'chmod 777 $testdir/noread; rm -fr $testdir $testout' 1 2 3 15
55 echo 1 > $testdir/file1
56 echo 2 > $testdir/file2
57 echo 3 > $testdir/-file3
58 echo 4 > $testdir/~file4
59 echo 5 > $testdir/.file5
60 echo 6 > $testdir/'*file6'
61 echo 7 > $testdir/'{file7,}'
62 echo 8 > $testdir/'\{file8\}'
63 echo 9 > $testdir/'\{file9\,file9b\}'
64 echo 9 > $testdir/'\file9b\' #'
65 echo a
> $testdir/'filea,'
66 echo a
> $testdir/'fileb}c'
69 test -d $testdir/noread || mkdir
$testdir/noread
70 chmod a-r
$testdir/noread
71 echo 1_1
> $testdir/dir
1/file1_1
72 echo 1_2
> $testdir/dir
1/file1_2
73 ln -fs dir1
$testdir/link1
81 ${run_program_prefix} \
82 ${common_objpfx}posix
/globtest
"$testdir" "*" |
84 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
101 if test $failed -ne 0; then
102 echo "Normal test failed" >> $logfile
106 # Don't let glob sort it
108 ${run_program_prefix} \
109 ${common_objpfx}posix/globtest -s "$testdir" "*" |
111 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
128 if test $failed -ne 0; then
129 echo "No sort test failed" >> $logfile
135 ${run_program_prefix} \
136 ${common_objpfx}posix/globtest -m "$testdir" "*" |
138 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
155 if test $failed -ne 0; then
156 echo "Mark directories test failed" >> $logfile
160 # Find files starting with .
162 ${run_program_prefix} \
163 ${common_objpfx}posix
/globtest
-p "$testdir" "*" |
165 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
185 if test $failed -ne 0; then
186 echo "Leading period test failed" >> $logfile
192 ${run_program_prefix} \
193 ${common_objpfx}posix/globtest -b "$testdir" "file{1,2}" |
195 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
199 if test $failed -ne 0; then
200 echo "Braces test failed" >> $logfile
205 ${run_program_prefix} \
206 ${common_objpfx}posix/globtest -b "$testdir" "{file{1,2},-file3}" |
208 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
213 if test $failed -ne 0; then
214 echo "Braces test 2 failed" >> $logfile
219 ${run_program_prefix} \
220 ${common_objpfx}posix/globtest -b "$testdir" "{" |
222 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
225 if test $failed -ne 0; then
226 echo "Braces test 3 failed" >> $logfile
232 ${run_program_prefix} \
233 ${common_objpfx}posix/globtest -c "$testdir" "abc" |
235 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
238 if test $failed -ne 0; then
239 echo "No check test failed" >> $logfile
243 # Test NOMAGIC without magic characters
245 ${run_program_prefix} \
246 ${common_objpfx}posix
/globtest
-g "$testdir" "abc" |
248 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
251 if test $failed -ne 0; then
252 echo "No magic test failed" >> $logfile
256 # Test NOMAGIC with magic characters
258 ${run_program_prefix} \
259 ${common_objpfx}posix/globtest -g "$testdir" "abc*" |
261 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
264 if test $failed -ne 0; then
265 echo "No magic w/ magic chars test failed" >> $logfile
269 # Test NOMAGIC for subdirs
271 ${run_program_prefix} \
272 ${common_objpfx}posix
/globtest
-g "$testdir" "*/does-not-exist" |
274 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
277 if test $failed -ne 0; then
278 echo "No magic in subdir test failed" >> $logfile
282 # Test subdirs correctly
284 ${run_program_prefix} \
285 ${common_objpfx}posix/globtest "$testdir" "*/*" |
287 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
293 if test $failed -ne 0; then
294 echo "Subdirs test failed" >> $logfile
298 # Test subdirs for invalid names
300 ${run_program_prefix} \
301 ${common_objpfx}posix/globtest "$testdir" "*/1" |
303 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
306 if test $failed -ne 0; then
307 echo "Invalid subdir test failed" >> $logfile
311 # Test subdirs with wildcard
313 ${run_program_prefix} \
314 ${common_objpfx}posix/globtest "$testdir" "*/*1_1" |
316 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
320 if test $failed -ne 0; then
321 echo "Wildcard subdir test failed" >> $logfile
325 # Test subdirs with ?
327 ${run_program_prefix} \
328 ${common_objpfx}posix
/globtest
"$testdir" "*/*?_?" |
330 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
336 if test $failed -ne 0; then
337 echo "Wildcard2 subdir test failed" >> $logfile
342 ${run_program_prefix} \
343 ${common_objpfx}posix/globtest "$testdir" "*/file1_1" |
345 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
349 if test $failed -ne 0; then
350 echo "Wildcard3 subdir test failed" >> $logfile
355 ${run_program_prefix} \
356 ${common_objpfx}posix/globtest "$testdir" "*-/*" |
358 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
361 if test $failed -ne 0; then
362 echo "Wildcard4 subdir test failed" >> $logfile
367 ${run_program_prefix} \
368 ${common_objpfx}posix/globtest "$testdir" "*-" |
370 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
373 if test $failed -ne 0; then
374 echo "Wildcard5 subdir test failed" >> $logfile
378 # Test subdirs with ?
380 ${run_program_prefix} \
381 ${common_objpfx}posix/globtest "$testdir" "*/*?_?" |
383 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
389 if test $failed -ne 0; then
390 echo "Wildcard6 subdir test failed" >> $logfile
394 # Test subdirs with [ .. ]
396 ${run_program_prefix} \
397 ${common_objpfx}posix
/globtest
"$testdir" "*/file1_[12]" |
399 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
405 if test $failed -ne 0; then
406 echo "Brackets test failed" >> $logfile
410 # Test ']' inside bracket expression
412 ${run_program_prefix} \
413 ${common_objpfx}posix/globtest "$testdir" "dir1/file1_[]12]" |
415 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
419 if test $failed -ne 0; then
420 echo "Brackets2 test failed" >> $logfile
424 # Test tilde expansion
426 ${run_program_prefix} \
427 ${common_objpfx}posix/globtest -q -t "$testdir" "~" |
429 echo ~ | $CMP - $testout >> $logfile || failed=1
430 if test $failed -ne 0; then
432 echo "Tilde test failed" >> $logfile
435 echo "Tilde test could not be run" >> $logfile
439 # Test tilde expansion with trailing slash
441 ${run_program_prefix} \
442 ${common_objpfx}posix/globtest -q -t "$testdir" "~/" |
444 # Some shell incorrectly(?) convert ~/ into // if ~ expands to /.
445 if test ~/ = //; then
446 echo / | $CMP - $testout >> $logfile || failed=1
448 echo ~/ | $CMP - $testout >> $logfile || failed=1
450 if test $failed -ne 0; then
452 echo "Tilde2 test failed" >> $logfile
455 echo "Tilde2 test could not be run" >> $logfile
459 # Test tilde expansion with username
461 ${run_program_prefix} \
462 ${common_objpfx}posix/globtest -q -t "$testdir" "~"$USER |
464 eval echo ~$USER | $CMP - $testout >> $logfile || failed=1
465 if test $failed -ne 0; then
466 if eval test -d ~$USER; then
467 echo "Tilde3 test failed" >> $logfile
470 echo "Tilde3 test could not be run" >> $logfile
474 # Tilde expansion shouldn't match a
file
476 ${run_program_prefix} \
477 ${common_objpfx}posix
/globtest
-T "$testdir" "~file4" |
479 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
482 if test $failed -ne 0; then
483 echo "Tilde4 test failed" >> $logfile
487 # Matching \** should only find *file6
489 ${run_program_prefix} \
490 ${common_objpfx}posix/globtest "$testdir" "\**" |
492 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
495 if test $failed -ne 0; then
496 echo "Star test failed" >> $logfile
500 # ... unless NOESCAPE is used, in which case it should entries with a
503 ${run_program_prefix} \
504 ${common_objpfx}posix/globtest -e "$testdir" "\**" |
506 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
511 if test $failed -ne 0; then
512 echo "Star2 test failed" >> $logfile
516 # Matching \*file6 should find *file6
518 ${run_program_prefix} \
519 ${common_objpfx}posix/globtest "$testdir" "\*file6" |
521 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
524 if test $failed -ne 0; then
525 echo "Star3 test failed" >> $logfile
531 ${run_program_prefix} \
532 ${common_objpfx}posix
/globtest
-b "$testdir" '\{file7\,\}' |
534 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
537 if test $failed -ne 0; then
538 echo "Brace4 test failed" >> $logfile
542 # GLOB_BRACE and GLOB_NOESCAPE
544 ${run_program_prefix} \
545 ${common_objpfx}posix/globtest -b -e "$testdir" '\{file9\,file9b\}' |
547 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
550 if test $failed -ne 0; then
551 echo "Brace5 test failed" >> $logfile
557 ${run_program_prefix} \
558 ${common_objpfx}posix/globtest -b "$testdir" '{filea\,}' |
560 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
563 if test $failed -ne 0; then
564 echo "Brace6 test failed" >> $logfile
568 # Escaped closing brace
570 ${run_program_prefix} \
571 ${common_objpfx}posix/globtest -b "$testdir" '{fileb\
}c
}' |
573 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
576 if test $failed -ne 0; then
577 echo "Brace7 test failed" >> $logfile
581 # Try a recursive failed search
583 ${run_program_prefix} \
584 ${common_objpfx}posix
/globtest
-e "$testdir" "a*/*" |
586 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
589 if test $failed -ne 0; then
590 echo "Star4 test failed" >> $logfile
596 ${run_program_prefix} \
597 ${common_objpfx}posix/globtest -E "$testdir" "a*/*" |
599 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
602 if test $failed -ne 0; then
603 echo "Star5 test failed" >> $logfile
607 # Try a recursive search in unreadable directory
609 ${run_program_prefix} \
610 ${common_objpfx}posix
/globtest
"$testdir" "noread/*" |
612 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
615 if test $failed -ne 0; then
616 echo "Star6 test failed" >> $logfile
621 ${run_program_prefix} \
622 ${common_objpfx}posix/globtest "$testdir" "noread*/*" |
624 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
627 if test $failed -ne 0; then
628 echo "Star6 test failed" >> $logfile
632 # The following tests will fail if run as root.
633 user
=`id -un 2> /dev/null`
634 if test -z "$user"; then
637 if test "$user" != root
; then
639 ${run_program_prefix} \
640 ${common_objpfx}posix
/globtest
-E "$testdir" "noread/*" |
642 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
646 ${run_program_prefix} \
647 ${common_objpfx}posix/globtest -E "$testdir" "noread*/*" |
649 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
652 if test $failed -ne 0; then
653 echo "GLOB_ERR test failed" >> $logfile
658 # Try multiple patterns (GLOB_APPEND)
660 ${run_program_prefix} \
661 ${common_objpfx}posix
/globtest
"$testdir" "file1" "*/*" |
663 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
670 if test $failed -ne 0; then
671 echo "GLOB_APPEND test failed" >> $logfile
675 # Try multiple patterns (GLOB_APPEND) with offset (GLOB_DOOFFS)
677 ${run_program_prefix} \
678 ${common_objpfx}posix/globtest -o "$testdir" "file1" "*/*" |
680 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
688 if test $failed -ne 0; then
689 echo "GLOB_APPEND2 test failed" >> $logfile
693 # Test NOCHECK with non-existing file in subdir.
695 ${run_program_prefix} \
696 ${common_objpfx}posix
/globtest
-c "$testdir" "*/blahblah" |
698 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
701 if test $failed -ne 0; then
702 echo "No check2 test failed" >> $logfile
706 # Test [[:punct:]] not matching leading period.
708 ${run_program_prefix} \
709 ${common_objpfx}posix/globtest -c "$testdir" "[[:punct:]]*" |
711 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
720 if test $failed -ne 0; then
721 echo "Punct test failed" >> $logfile
725 mkdir
$testdir/'dir3*'
726 echo 1 > $testdir/'dir3*'/file1
727 mkdir
$testdir/'dir4[a'
728 echo 2 > $testdir/'dir4[a'/file1
729 echo 3 > $testdir/'dir4[a'/file2
730 mkdir
$testdir/'dir5[ab]'
731 echo 4 > $testdir/'dir5[ab]'/file1
732 echo 5 > $testdir/'dir5[ab]'/file2
734 echo 6 > $testdir/dir
6/'file1[a'
735 echo 7 > $testdir/dir
6/'file1[ab]'
737 v
=`${run_program_prefix} \
738 ${common_objpfx}posix/globtest "$testdir" 'dir3\*/file2'`
739 test "$v" != 'GLOB_NOMATCH' && echo "$v" >> $logfile && failed
=1
740 ${run_program_prefix} \
741 ${common_objpfx}posix
/globtest
-c "$testdir" \
742 'dir3\*/file1' 'dir3\*/file2' 'dir1/file\1_1' 'dir1/file\1_9' \
743 'dir2\/' 'nondir\/' 'dir4[a/fil*1' 'di*r4[a/file2' 'dir5[ab]/file[12]' \
744 'dir6/fil*[a' 'dir*6/file1[a' 'dir6/fi*l[ab]' 'dir*6/file1[ab]' \
745 'dir6/file1[[.a.]*' |
747 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
764 ${test_wrapper_env} \
766 ${run_via_rtld_prefix} \
767 ${common_objpfx}posix/globtest -ct "$testdir" \
768 '~/dir1/file1_1' '~/dir1/file1_9' '~/dir3\*/file1' '~/dir3\*/file2' \
771 cat <<EOF | $CMP - $testout >> $logfile || failed=1
772 \`$testdir/dir1/file1_1'
773 \`$testdir/dir1/file1_2'
774 \`$testdir/dir3*/file1'
778 if eval test -d ~"$USER"/; then
779 user=`echo "$USER" | sed -n -e 's/^\([^\\]\)\([^\\][^\\]*\)$/~\1\\\\\2/p'`
780 if test -n "$user"; then
781 ${run_program_prefix} \
782 ${common_objpfx}posix/globtest -ctq "$testdir" "$user/" |
784 eval echo ~$USER/ | $CMP - $testout >> $logfile || failed=1
785 ${run_program_prefix} \
786 ${common_objpfx}posix/globtest -ctq "$testdir" "$user\\/" |
788 eval echo ~$USER/ | $CMP - $testout >> $logfile || failed=1
789 ${run_program_prefix} \
790 ${common_objpfx}posix/globtest -ctq "$testdir" "$user" |
792 eval echo ~$USER | $CMP - $testout >> $logfile || failed=1
795 if test $failed -ne 0; then
796 echo "Escape tests failed" >> $logfile
800 if test $result -eq 0; then
801 chmod 777 $testdir/noread
802 rm -fr $testdir $testout
803 echo "All OK." > $logfile
808 # Preserve executable bits for this shell script.
810 eval:(defun frobme () (set-file-modes buffer-file-name file-mode))
811 eval:(make-local-variable 'file-mode)
812 eval:(setq file-mode (file-modes (buffer-file-name)))
813 eval:(make-local-variable 'after-save-hook)
814 eval:(add-hook 'after-save-hook 'frobme)