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.
45 testdir
=${common_objpfx}posix
/globtest-dir
46 testout
=${common_objpfx}posix
/globtest-out
47 rm -rf $testdir $testout
50 trap 'chmod 777 $testdir/noread; rm -fr $testdir $testout' 1 2 3 15
52 echo 1 > $testdir/file1
53 echo 2 > $testdir/file2
54 echo 3 > $testdir/-file3
55 echo 4 > $testdir/~file4
56 echo 5 > $testdir/.file5
57 echo 6 > $testdir/'*file6'
58 echo 7 > $testdir/'{file7,}'
59 echo 8 > $testdir/'\{file8\}'
60 echo 9 > $testdir/'\{file9\,file9b\}'
61 echo 9 > $testdir/'\file9b\' #'
62 echo a
> $testdir/'filea,'
63 echo a
> $testdir/'fileb}c'
66 test -d $testdir/noread || mkdir
$testdir/noread
67 chmod a-r
$testdir/noread
68 echo 1_1
> $testdir/dir
1/file1_1
69 echo 1_2
> $testdir/dir
1/file1_2
70 ln -fs dir1
$testdir/link1
78 ${test_program_prefix} \
79 ${common_objpfx}posix
/globtest
"$testdir" "*" |
81 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
98 if test $failed -ne 0; then
99 echo "Normal test failed" >> $logfile
103 # Don't let glob sort it
105 ${test_program_prefix} \
106 ${common_objpfx}posix/globtest -s "$testdir" "*" |
108 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
125 if test $failed -ne 0; then
126 echo "No sort test failed" >> $logfile
132 ${test_program_prefix} \
133 ${common_objpfx}posix/globtest -m "$testdir" "*" |
135 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
152 if test $failed -ne 0; then
153 echo "Mark directories test failed" >> $logfile
157 # Find files starting with .
159 ${test_program_prefix} \
160 ${common_objpfx}posix
/globtest
-p "$testdir" "*" |
162 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
182 if test $failed -ne 0; then
183 echo "Leading period test failed" >> $logfile
189 ${test_program_prefix} \
190 ${common_objpfx}posix/globtest -b "$testdir" "file{1,2}" |
192 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
196 if test $failed -ne 0; then
197 echo "Braces test failed" >> $logfile
202 ${test_program_prefix} \
203 ${common_objpfx}posix/globtest -b "$testdir" "{file{1,2},-file3}" |
205 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
210 if test $failed -ne 0; then
211 echo "Braces test 2 failed" >> $logfile
216 ${test_program_prefix} \
217 ${common_objpfx}posix/globtest -b "$testdir" "{" |
219 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
222 if test $failed -ne 0; then
223 echo "Braces test 3 failed" >> $logfile
229 ${test_program_prefix} \
230 ${common_objpfx}posix/globtest -c "$testdir" "abc" |
232 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
235 if test $failed -ne 0; then
236 echo "No check test failed" >> $logfile
240 # Test NOMAGIC without magic characters
242 ${test_program_prefix} \
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 test failed" >> $logfile
253 # Test NOMAGIC with magic characters
255 ${test_program_prefix} \
256 ${common_objpfx}posix/globtest -g "$testdir" "abc*" |
258 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
261 if test $failed -ne 0; then
262 echo "No magic w/ magic chars test failed" >> $logfile
266 # Test NOMAGIC for subdirs
268 ${test_program_prefix} \
269 ${common_objpfx}posix
/globtest
-g "$testdir" "*/does-not-exist" |
271 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
274 if test $failed -ne 0; then
275 echo "No magic in subdir test failed" >> $logfile
279 # Test subdirs correctly
281 ${test_program_prefix} \
282 ${common_objpfx}posix/globtest "$testdir" "*/*" |
284 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
290 if test $failed -ne 0; then
291 echo "Subdirs test failed" >> $logfile
295 # Test subdirs for invalid names
297 ${test_program_prefix} \
298 ${common_objpfx}posix/globtest "$testdir" "*/1" |
300 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
303 if test $failed -ne 0; then
304 echo "Invalid subdir test failed" >> $logfile
308 # Test subdirs with wildcard
310 ${test_program_prefix} \
311 ${common_objpfx}posix/globtest "$testdir" "*/*1_1" |
313 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
317 if test $failed -ne 0; then
318 echo "Wildcard subdir test failed" >> $logfile
322 # Test subdirs with ?
324 ${test_program_prefix} \
325 ${common_objpfx}posix
/globtest
"$testdir" "*/*?_?" |
327 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
333 if test $failed -ne 0; then
334 echo "Wildcard2 subdir test failed" >> $logfile
339 ${test_program_prefix} \
340 ${common_objpfx}posix/globtest "$testdir" "*/file1_1" |
342 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
346 if test $failed -ne 0; then
347 echo "Wildcard3 subdir test failed" >> $logfile
352 ${test_program_prefix} \
353 ${common_objpfx}posix/globtest "$testdir" "*-/*" |
355 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
358 if test $failed -ne 0; then
359 echo "Wildcard4 subdir test failed" >> $logfile
364 ${test_program_prefix} \
365 ${common_objpfx}posix/globtest "$testdir" "*-" |
367 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
370 if test $failed -ne 0; then
371 echo "Wildcard5 subdir test failed" >> $logfile
375 # Test subdirs with ?
377 ${test_program_prefix} \
378 ${common_objpfx}posix/globtest "$testdir" "*/*?_?" |
380 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
386 if test $failed -ne 0; then
387 echo "Wildcard6 subdir test failed" >> $logfile
391 # Test subdirs with [ .. ]
393 ${test_program_prefix} \
394 ${common_objpfx}posix
/globtest
"$testdir" "*/file1_[12]" |
396 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
402 if test $failed -ne 0; then
403 echo "Brackets test failed" >> $logfile
407 # Test ']' inside bracket expression
409 ${test_program_prefix} \
410 ${common_objpfx}posix/globtest "$testdir" "dir1/file1_[]12]" |
412 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
416 if test $failed -ne 0; then
417 echo "Brackets2 test failed" >> $logfile
421 # Test tilde expansion
423 ${test_program_prefix} \
424 ${common_objpfx}posix/globtest -q -t "$testdir" "~" |
426 echo ~ | $CMP - $testout >> $logfile || failed=1
427 if test $failed -ne 0; then
429 echo "Tilde test failed" >> $logfile
432 echo "Tilde test could not be run" >> $logfile
436 # Test tilde expansion with trailing slash
438 ${test_program_prefix} \
439 ${common_objpfx}posix/globtest -q -t "$testdir" "~/" |
441 # Some shell incorrectly(?) convert ~/ into // if ~ expands to /.
442 if test ~/ = //; then
443 echo / | $CMP - $testout >> $logfile || failed=1
445 echo ~/ | $CMP - $testout >> $logfile || failed=1
447 if test $failed -ne 0; then
449 echo "Tilde2 test failed" >> $logfile
452 echo "Tilde2 test could not be run" >> $logfile
456 # Test tilde expansion with username
458 ${test_program_prefix} \
459 ${common_objpfx}posix/globtest -q -t "$testdir" "~"$USER |
461 eval echo ~$USER | $CMP - $testout >> $logfile || failed=1
462 if test $failed -ne 0; then
463 if eval test -d ~$USER; then
464 echo "Tilde3 test failed" >> $logfile
467 echo "Tilde3 test could not be run" >> $logfile
471 # Tilde expansion shouldn't match a
file
473 ${test_program_prefix} \
474 ${common_objpfx}posix
/globtest
-T "$testdir" "~file4" |
476 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
479 if test $failed -ne 0; then
480 echo "Tilde4 test failed" >> $logfile
484 # Matching \** should only find *file6
486 ${test_program_prefix} \
487 ${common_objpfx}posix/globtest "$testdir" "\**" |
489 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
492 if test $failed -ne 0; then
493 echo "Star test failed" >> $logfile
497 # ... unless NOESCAPE is used, in which case it should entries with a
500 ${test_program_prefix} \
501 ${common_objpfx}posix/globtest -e "$testdir" "\**" |
503 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
508 if test $failed -ne 0; then
509 echo "Star2 test failed" >> $logfile
513 # Matching \*file6 should find *file6
515 ${test_program_prefix} \
516 ${common_objpfx}posix/globtest "$testdir" "\*file6" |
518 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
521 if test $failed -ne 0; then
522 echo "Star3 test failed" >> $logfile
528 ${test_program_prefix} \
529 ${common_objpfx}posix
/globtest
-b "$testdir" '\{file7\,\}' |
531 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
534 if test $failed -ne 0; then
535 echo "Brace4 test failed" >> $logfile
539 # GLOB_BRACE and GLOB_NOESCAPE
541 ${test_program_prefix} \
542 ${common_objpfx}posix/globtest -b -e "$testdir" '\{file9\,file9b\}' |
544 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
547 if test $failed -ne 0; then
548 echo "Brace5 test failed" >> $logfile
554 ${test_program_prefix} \
555 ${common_objpfx}posix/globtest -b "$testdir" '{filea\,}' |
557 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
560 if test $failed -ne 0; then
561 echo "Brace6 test failed" >> $logfile
565 # Escaped closing brace
567 ${test_program_prefix} \
568 ${common_objpfx}posix/globtest -b "$testdir" '{fileb\
}c
}' |
570 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
573 if test $failed -ne 0; then
574 echo "Brace7 test failed" >> $logfile
578 # Try a recursive failed search
580 ${test_program_prefix} \
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 "Star4 test failed" >> $logfile
593 ${test_program_prefix} \
594 ${common_objpfx}posix/globtest -E "$testdir" "a*/*" |
596 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
599 if test $failed -ne 0; then
600 echo "Star5 test failed" >> $logfile
604 # Try a recursive search in unreadable directory
606 ${test_program_prefix} \
607 ${common_objpfx}posix
/globtest
"$testdir" "noread/*" |
609 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
612 if test $failed -ne 0; then
613 echo "Star6 test failed" >> $logfile
618 ${test_program_prefix} \
619 ${common_objpfx}posix/globtest "$testdir" "noread*/*" |
621 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
624 if test $failed -ne 0; then
625 echo "Star6 test failed" >> $logfile
629 # The following tests will fail if run as root.
630 user
=`id -un 2> /dev/null`
631 if test -z "$user"; then
634 if test "$user" != root
; then
636 ${test_program_prefix} \
637 ${common_objpfx}posix
/globtest
-E "$testdir" "noread/*" |
639 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
643 ${test_program_prefix} \
644 ${common_objpfx}posix/globtest -E "$testdir" "noread*/*" |
646 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
649 if test $failed -ne 0; then
650 echo "GLOB_ERR test failed" >> $logfile
655 # Try multiple patterns (GLOB_APPEND)
657 ${test_program_prefix} \
658 ${common_objpfx}posix
/globtest
"$testdir" "file1" "*/*" |
660 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
667 if test $failed -ne 0; then
668 echo "GLOB_APPEND test failed" >> $logfile
672 # Try multiple patterns (GLOB_APPEND) with offset (GLOB_DOOFFS)
674 ${test_program_prefix} \
675 ${common_objpfx}posix/globtest -o "$testdir" "file1" "*/*" |
677 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
685 if test $failed -ne 0; then
686 echo "GLOB_APPEND2 test failed" >> $logfile
690 # Test NOCHECK with non-existing file in subdir.
692 ${test_program_prefix} \
693 ${common_objpfx}posix
/globtest
-c "$testdir" "*/blahblah" |
695 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
698 if test $failed -ne 0; then
699 echo "No check2 test failed" >> $logfile
703 # Test [[:punct:]] not matching leading period.
705 ${test_program_prefix} \
706 ${common_objpfx}posix/globtest -c "$testdir" "[[:punct:]]*" |
708 cat <<"EOF" |
$CMP - $testout >> $logfile || failed
=1
717 if test $failed -ne 0; then
718 echo "Punct test failed" >> $logfile
722 mkdir
$testdir/'dir3*'
723 echo 1 > $testdir/'dir3*'/file1
724 mkdir
$testdir/'dir4[a'
725 echo 2 > $testdir/'dir4[a'/file1
726 echo 3 > $testdir/'dir4[a'/file2
727 mkdir
$testdir/'dir5[ab]'
728 echo 4 > $testdir/'dir5[ab]'/file1
729 echo 5 > $testdir/'dir5[ab]'/file2
731 echo 6 > $testdir/dir
6/'file1[a'
732 echo 7 > $testdir/dir
6/'file1[ab]'
734 v
=`${test_program_prefix} \
735 ${common_objpfx}posix/globtest "$testdir" 'dir3\*/file2'`
736 test "$v" != 'GLOB_NOMATCH' && echo "$v" >> $logfile && failed
=1
737 ${test_program_prefix} \
738 ${common_objpfx}posix
/globtest
-c "$testdir" \
739 'dir3\*/file1' 'dir3\*/file2' 'dir1/file\1_1' 'dir1/file\1_9' \
740 'dir2\/' 'nondir\/' 'dir4[a/fil*1' 'di*r4[a/file2' 'dir5[ab]/file[12]' \
741 'dir6/fil*[a' 'dir*6/file1[a' 'dir6/fi*l[ab]' 'dir*6/file1[ab]' \
742 'dir6/file1[[.a.]*' |
744 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
761 ${test_wrapper_env} \
763 ${test_via_rtld_prefix} \
764 ${common_objpfx}posix/globtest -ct "$testdir" \
765 '~/dir1/file1_1' '~/dir1/file1_9' '~/dir3\*/file1' '~/dir3\*/file2' \
768 cat <<EOF | $CMP - $testout >> $logfile || failed=1
769 \`$testdir/dir1/file1_1'
770 \`$testdir/dir1/file1_2'
771 \`$testdir/dir3*/file1'
775 if eval test -d ~"$USER"/; then
776 user=`echo "$USER" | sed -n -e 's/^\([^\\]\)\([^\\][^\\]*\)$/~\1\\\\\2/p'`
777 if test -n "$user"; then
778 ${test_program_prefix} \
779 ${common_objpfx}posix/globtest -ctq "$testdir" "$user/" |
781 eval echo ~$USER/ | $CMP - $testout >> $logfile || failed=1
782 ${test_program_prefix} \
783 ${common_objpfx}posix/globtest -ctq "$testdir" "$user\\/" |
785 eval echo ~$USER/ | $CMP - $testout >> $logfile || failed=1
786 ${test_program_prefix} \
787 ${common_objpfx}posix/globtest -ctq "$testdir" "$user" |
789 eval echo ~$USER | $CMP - $testout >> $logfile || failed=1
792 if test $failed -ne 0; then
793 echo "Escape tests failed" >> $logfile
797 if test $result -eq 0; then
798 chmod 777 $testdir/noread
799 rm -fr $testdir $testout
800 echo "All OK." > $logfile
805 # Preserve executable bits for this shell script.
807 eval:(defun frobme () (set-file-modes buffer-file-name file-mode))
808 eval:(make-local-variable 'file-mode)
809 eval:(setq file-mode (file-modes (buffer-file-name)))
810 eval:(make-local-variable 'after-save-hook)
811 eval:(add-hook 'after-save-hook 'frobme)