3 # Copyright (C) 1997-2014 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.
47 testdir
=${common_objpfx}posix
/globtest-dir
48 testout
=${common_objpfx}posix
/globtest-out
49 rm -rf $testdir $testout
52 trap 'chmod 777 $testdir/noread; rm -fr $testdir $testout' 1 2 3 15
54 echo 1 > $testdir/file1
55 echo 2 > $testdir/file2
56 echo 3 > $testdir/-file3
57 echo 4 > $testdir/~file4
58 echo 5 > $testdir/.file5
59 echo 6 > $testdir/'*file6'
60 echo 7 > $testdir/'{file7,}'
61 echo 8 > $testdir/'\{file8\}'
62 echo 9 > $testdir/'\{file9\,file9b\}'
63 echo 9 > $testdir/'\file9b\' #'
64 echo a
> $testdir/'filea,'
65 echo a
> $testdir/'fileb}c'
68 test -d $testdir/noread || mkdir
$testdir/noread
69 chmod a-r
$testdir/noread
70 echo 1_1
> $testdir/dir
1/file1_1
71 echo 1_2
> $testdir/dir
1/file1_2
72 ln -fs dir1
$testdir/link1
80 ${test_program_prefix} \
81 ${common_objpfx}posix
/globtest
"$testdir" "*" |
83 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
100 if test $failed -ne 0; then
101 echo "Normal test failed" >> $logfile
105 # Don't let glob sort it
107 ${test_program_prefix} \
108 ${common_objpfx}posix/globtest -s "$testdir" "*" |
110 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
127 if test $failed -ne 0; then
128 echo "No sort test failed" >> $logfile
134 ${test_program_prefix} \
135 ${common_objpfx}posix/globtest -m "$testdir" "*" |
137 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
154 if test $failed -ne 0; then
155 echo "Mark directories test failed" >> $logfile
159 # Find files starting with .
161 ${test_program_prefix} \
162 ${common_objpfx}posix
/globtest
-p "$testdir" "*" |
164 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
184 if test $failed -ne 0; then
185 echo "Leading period test failed" >> $logfile
191 ${test_program_prefix} \
192 ${common_objpfx}posix/globtest -b "$testdir" "file{1,2}" |
194 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
198 if test $failed -ne 0; then
199 echo "Braces test failed" >> $logfile
204 ${test_program_prefix} \
205 ${common_objpfx}posix/globtest -b "$testdir" "{file{1,2},-file3}" |
207 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
212 if test $failed -ne 0; then
213 echo "Braces test 2 failed" >> $logfile
218 ${test_program_prefix} \
219 ${common_objpfx}posix/globtest -b "$testdir" "{" |
221 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
224 if test $failed -ne 0; then
225 echo "Braces test 3 failed" >> $logfile
231 ${test_program_prefix} \
232 ${common_objpfx}posix/globtest -c "$testdir" "abc" |
234 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
237 if test $failed -ne 0; then
238 echo "No check test failed" >> $logfile
242 # Test NOMAGIC without magic characters
244 ${test_program_prefix} \
245 ${common_objpfx}posix
/globtest
-g "$testdir" "abc" |
247 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
250 if test $failed -ne 0; then
251 echo "No magic test failed" >> $logfile
255 # Test NOMAGIC with magic characters
257 ${test_program_prefix} \
258 ${common_objpfx}posix/globtest -g "$testdir" "abc*" |
260 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
263 if test $failed -ne 0; then
264 echo "No magic w/ magic chars test failed" >> $logfile
268 # Test NOMAGIC for subdirs
270 ${test_program_prefix} \
271 ${common_objpfx}posix
/globtest
-g "$testdir" "*/does-not-exist" |
273 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
276 if test $failed -ne 0; then
277 echo "No magic in subdir test failed" >> $logfile
281 # Test subdirs correctly
283 ${test_program_prefix} \
284 ${common_objpfx}posix/globtest "$testdir" "*/*" |
286 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
292 if test $failed -ne 0; then
293 echo "Subdirs test failed" >> $logfile
297 # Test subdirs for invalid names
299 ${test_program_prefix} \
300 ${common_objpfx}posix/globtest "$testdir" "*/1" |
302 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
305 if test $failed -ne 0; then
306 echo "Invalid subdir test failed" >> $logfile
310 # Test subdirs with wildcard
312 ${test_program_prefix} \
313 ${common_objpfx}posix/globtest "$testdir" "*/*1_1" |
315 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
319 if test $failed -ne 0; then
320 echo "Wildcard subdir test failed" >> $logfile
324 # Test subdirs with ?
326 ${test_program_prefix} \
327 ${common_objpfx}posix
/globtest
"$testdir" "*/*?_?" |
329 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
335 if test $failed -ne 0; then
336 echo "Wildcard2 subdir test failed" >> $logfile
341 ${test_program_prefix} \
342 ${common_objpfx}posix/globtest "$testdir" "*/file1_1" |
344 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
348 if test $failed -ne 0; then
349 echo "Wildcard3 subdir test failed" >> $logfile
354 ${test_program_prefix} \
355 ${common_objpfx}posix/globtest "$testdir" "*-/*" |
357 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
360 if test $failed -ne 0; then
361 echo "Wildcard4 subdir test failed" >> $logfile
366 ${test_program_prefix} \
367 ${common_objpfx}posix/globtest "$testdir" "*-" |
369 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
372 if test $failed -ne 0; then
373 echo "Wildcard5 subdir test failed" >> $logfile
377 # Test subdirs with ?
379 ${test_program_prefix} \
380 ${common_objpfx}posix/globtest "$testdir" "*/*?_?" |
382 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
388 if test $failed -ne 0; then
389 echo "Wildcard6 subdir test failed" >> $logfile
393 # Test subdirs with [ .. ]
395 ${test_program_prefix} \
396 ${common_objpfx}posix
/globtest
"$testdir" "*/file1_[12]" |
398 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
404 if test $failed -ne 0; then
405 echo "Brackets test failed" >> $logfile
409 # Test ']' inside bracket expression
411 ${test_program_prefix} \
412 ${common_objpfx}posix/globtest "$testdir" "dir1/file1_[]12]" |
414 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
418 if test $failed -ne 0; then
419 echo "Brackets2 test failed" >> $logfile
423 # Test tilde expansion
425 ${test_program_prefix} \
426 ${common_objpfx}posix/globtest -q -t "$testdir" "~" |
428 echo ~ | $CMP - $testout >> $logfile || failed=1
429 if test $failed -ne 0; then
431 echo "Tilde test failed" >> $logfile
434 echo "Tilde test could not be run" >> $logfile
438 # Test tilde expansion with trailing slash
440 ${test_program_prefix} \
441 ${common_objpfx}posix/globtest -q -t "$testdir" "~/" |
443 # Some shell incorrectly(?) convert ~/ into // if ~ expands to /.
444 if test ~/ = //; then
445 echo / | $CMP - $testout >> $logfile || failed=1
447 echo ~/ | $CMP - $testout >> $logfile || failed=1
449 if test $failed -ne 0; then
451 echo "Tilde2 test failed" >> $logfile
454 echo "Tilde2 test could not be run" >> $logfile
458 # Test tilde expansion with username
460 ${test_program_prefix} \
461 ${common_objpfx}posix/globtest -q -t "$testdir" "~"$USER |
463 eval echo ~$USER | $CMP - $testout >> $logfile || failed=1
464 if test $failed -ne 0; then
465 if eval test -d ~$USER; then
466 echo "Tilde3 test failed" >> $logfile
469 echo "Tilde3 test could not be run" >> $logfile
473 # Tilde expansion shouldn't match a
file
475 ${test_program_prefix} \
476 ${common_objpfx}posix
/globtest
-T "$testdir" "~file4" |
478 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
481 if test $failed -ne 0; then
482 echo "Tilde4 test failed" >> $logfile
486 # Matching \** should only find *file6
488 ${test_program_prefix} \
489 ${common_objpfx}posix/globtest "$testdir" "\**" |
491 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
494 if test $failed -ne 0; then
495 echo "Star test failed" >> $logfile
499 # ... unless NOESCAPE is used, in which case it should entries with a
502 ${test_program_prefix} \
503 ${common_objpfx}posix/globtest -e "$testdir" "\**" |
505 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
510 if test $failed -ne 0; then
511 echo "Star2 test failed" >> $logfile
515 # Matching \*file6 should find *file6
517 ${test_program_prefix} \
518 ${common_objpfx}posix/globtest "$testdir" "\*file6" |
520 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
523 if test $failed -ne 0; then
524 echo "Star3 test failed" >> $logfile
530 ${test_program_prefix} \
531 ${common_objpfx}posix
/globtest
-b "$testdir" '\{file7\,\}' |
533 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
536 if test $failed -ne 0; then
537 echo "Brace4 test failed" >> $logfile
541 # GLOB_BRACE and GLOB_NOESCAPE
543 ${test_program_prefix} \
544 ${common_objpfx}posix/globtest -b -e "$testdir" '\{file9\,file9b\}' |
546 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
549 if test $failed -ne 0; then
550 echo "Brace5 test failed" >> $logfile
556 ${test_program_prefix} \
557 ${common_objpfx}posix/globtest -b "$testdir" '{filea\,}' |
559 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
562 if test $failed -ne 0; then
563 echo "Brace6 test failed" >> $logfile
567 # Escaped closing brace
569 ${test_program_prefix} \
570 ${common_objpfx}posix/globtest -b "$testdir" '{fileb\
}c
}' |
572 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
575 if test $failed -ne 0; then
576 echo "Brace7 test failed" >> $logfile
580 # Try a recursive failed search
582 ${test_program_prefix} \
583 ${common_objpfx}posix
/globtest
-e "$testdir" "a*/*" |
585 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
588 if test $failed -ne 0; then
589 echo "Star4 test failed" >> $logfile
595 ${test_program_prefix} \
596 ${common_objpfx}posix/globtest -E "$testdir" "a*/*" |
598 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
601 if test $failed -ne 0; then
602 echo "Star5 test failed" >> $logfile
606 # Try a recursive search in unreadable directory
608 ${test_program_prefix} \
609 ${common_objpfx}posix
/globtest
"$testdir" "noread/*" |
611 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
614 if test $failed -ne 0; then
615 echo "Star6 test failed" >> $logfile
620 ${test_program_prefix} \
621 ${common_objpfx}posix/globtest "$testdir" "noread*/*" |
623 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
626 if test $failed -ne 0; then
627 echo "Star6 test failed" >> $logfile
631 # The following tests will fail if run as root.
632 user
=`id -un 2> /dev/null`
633 if test -z "$user"; then
636 if test "$user" != root
; then
638 ${test_program_prefix} \
639 ${common_objpfx}posix
/globtest
-E "$testdir" "noread/*" |
641 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
645 ${test_program_prefix} \
646 ${common_objpfx}posix/globtest -E "$testdir" "noread*/*" |
648 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
651 if test $failed -ne 0; then
652 echo "GLOB_ERR test failed" >> $logfile
657 # Try multiple patterns (GLOB_APPEND)
659 ${test_program_prefix} \
660 ${common_objpfx}posix
/globtest
"$testdir" "file1" "*/*" |
662 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
669 if test $failed -ne 0; then
670 echo "GLOB_APPEND test failed" >> $logfile
674 # Try multiple patterns (GLOB_APPEND) with offset (GLOB_DOOFFS)
676 ${test_program_prefix} \
677 ${common_objpfx}posix/globtest -o "$testdir" "file1" "*/*" |
679 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
687 if test $failed -ne 0; then
688 echo "GLOB_APPEND2 test failed" >> $logfile
692 # Test NOCHECK with non-existing file in subdir.
694 ${test_program_prefix} \
695 ${common_objpfx}posix
/globtest
-c "$testdir" "*/blahblah" |
697 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
700 if test $failed -ne 0; then
701 echo "No check2 test failed" >> $logfile
705 # Test [[:punct:]] not matching leading period.
707 ${test_program_prefix} \
708 ${common_objpfx}posix/globtest -c "$testdir" "[[:punct:]]*" |
710 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
719 if test $failed -ne 0; then
720 echo "Punct test failed" >> $logfile
724 mkdir
$testdir/'dir3*'
725 echo 1 > $testdir/'dir3*'/file1
726 mkdir
$testdir/'dir4[a'
727 echo 2 > $testdir/'dir4[a'/file1
728 echo 3 > $testdir/'dir4[a'/file2
729 mkdir
$testdir/'dir5[ab]'
730 echo 4 > $testdir/'dir5[ab]'/file1
731 echo 5 > $testdir/'dir5[ab]'/file2
733 echo 6 > $testdir/dir
6/'file1[a'
734 echo 7 > $testdir/dir
6/'file1[ab]'
736 v
=`${test_program_prefix} \
737 ${common_objpfx}posix/globtest "$testdir" 'dir3\*/file2'`
738 test "$v" != 'GLOB_NOMATCH' && echo "$v" >> $logfile && failed
=1
739 ${test_program_prefix} \
740 ${common_objpfx}posix
/globtest
-c "$testdir" \
741 'dir3\*/file1' 'dir3\*/file2' 'dir1/file\1_1' 'dir1/file\1_9' \
742 'dir2\/' 'nondir\/' 'dir4[a/fil*1' 'di*r4[a/file2' 'dir5[ab]/file[12]' \
743 'dir6/fil*[a' 'dir*6/file1[a' 'dir6/fi*l[ab]' 'dir*6/file1[ab]' \
744 'dir6/file1[[.a.]*' |
746 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
763 ${test_wrapper_env} \
765 ${test_via_rtld_prefix} \
766 ${common_objpfx}posix/globtest -ct "$testdir" \
767 '~/dir1/file1_1' '~/dir1/file1_9' '~/dir3\*/file1' '~/dir3\*/file2' \
770 cat <<EOF | $CMP - $testout >> $logfile || failed=1
771 \`$testdir/dir1/file1_1'
772 \`$testdir/dir1/file1_2'
773 \`$testdir/dir3*/file1'
777 if eval test -d ~"$USER"/; then
778 user=`echo "$USER" | sed -n -e 's/^\([^\\]\)\([^\\][^\\]*\)$/~\1\\\\\2/p'`
779 if test -n "$user"; then
780 ${test_program_prefix} \
781 ${common_objpfx}posix/globtest -ctq "$testdir" "$user/" |
783 eval echo ~$USER/ | $CMP - $testout >> $logfile || failed=1
784 ${test_program_prefix} \
785 ${common_objpfx}posix/globtest -ctq "$testdir" "$user\\/" |
787 eval echo ~$USER/ | $CMP - $testout >> $logfile || failed=1
788 ${test_program_prefix} \
789 ${common_objpfx}posix/globtest -ctq "$testdir" "$user" |
791 eval echo ~$USER | $CMP - $testout >> $logfile || failed=1
794 if test $failed -ne 0; then
795 echo "Escape tests failed" >> $logfile
799 if test $result -eq 0; then
800 chmod 777 $testdir/noread
801 rm -fr $testdir $testout
802 echo "All OK." > $logfile
807 # Preserve executable bits for this shell script.
809 eval:(defun frobme () (set-file-modes buffer-file-name file-mode))
810 eval:(make-local-variable 'file-mode)
811 eval:(setq file-mode (file-modes (buffer-file-name)))
812 eval:(make-local-variable 'after-save-hook)
813 eval:(add-hook 'after-save-hook 'frobme)