Update.
[glibc.git] / posix / globtest.sh
blob12635b76d9f7674b526f87a416f16f19f859ba03
1 #! /bin/sh
3 common_objpfx=$1; shift
4 elf_objpfx=$1; shift
5 rtld_installed_name=$1; shift
7 # We have to find the libc and the NSS modules.
8 library_path=${common_objpfx}:${common_objpfx}nss:${common_objpfx}nis
10 # Since we use `osrt' we must make sure to use the same locale everywhere.
11 LC_ALL=C
12 export LC_ALL
13 LANG=C
14 export LANG
16 # Create the arena
17 : ${TMPDIR=/tmp}
18 testdir=$TMPDIR/globtest-dir
19 testout=$TMPDIR/globtest-out
20 testout2=$TMPDIR/globtest-out2
22 trap 'rm -fr $testdir $testout $testout2' 1 2 3 15
24 rm -fr $testdir
25 mkdir $testdir
26 echo 1 > $testdir/file1
27 echo 2 > $testdir/file2
28 echo 3 > $testdir/-file3
29 echo 4 > $testdir/~file4
30 echo 5 > $testdir/.file5
31 echo 6 > $testdir/'*file6'
32 mkdir $testdir/dir1
33 mkdir $testdir/dir2
34 echo 1_1 > $testdir/dir1/file1_1
35 echo 1_2 > $testdir/dir1/file1_2
37 # Run some tests.
38 result=0
40 # Normal test
41 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
42 ${common_objpfx}posix/globtest "$testdir" "*" |
43 sort > $testout
44 cat <<"EOF" | cmp - $testout || result=1
45 `*file6'
46 `-file3'
47 `dir1'
48 `dir2'
49 `file1'
50 `file2'
51 `~file4'
52 EOF
54 # Don't let glob sort it
55 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
56 ${common_objpfx}posix/globtest -s "$testdir" "*" |
57 sort > $testout
58 cat <<"EOF" | cmp - $testout || result=1
59 `*file6'
60 `-file3'
61 `dir1'
62 `dir2'
63 `file1'
64 `file2'
65 `~file4'
66 EOF
68 # Mark directories
69 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
70 ${common_objpfx}posix/globtest -m "$testdir" "*" |
71 sort > $testout
72 cat <<"EOF" | cmp - $testout || result=1
73 `*file6'
74 `-file3'
75 `dir1/'
76 `dir2/'
77 `file1'
78 `file2'
79 `~file4'
80 EOF
82 # Find files starting with .
83 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
84 ${common_objpfx}posix/globtest -p "$testdir" "*" |
85 sort > $testout
86 cat <<"EOF" | cmp - $testout || result=1
87 `*file6'
88 `-file3'
89 `.'
90 `..'
91 `.file5'
92 `dir1'
93 `dir2'
94 `file1'
95 `file2'
96 `~file4'
97 EOF
99 # Test braces
100 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
101 ${common_objpfx}posix/globtest -b "$testdir" "file{1,2}" |
102 sort > $testout
103 cat <<"EOF" | cmp - $testout || result=1
104 `file1'
105 `file2'
108 # Test NOCHECK
109 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
110 ${common_objpfx}posix/globtest -c "$testdir" "abc" |
111 sort > $testout
112 cat <<"EOF" | cmp - $testout || result=1
113 `abc'
116 # Test NOMAGIC without magic characters
117 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
118 ${common_objpfx}posix/globtest -g "$testdir" "abc" |
119 sort > $testout
120 cat <<"EOF" | cmp - $testout || result=1
121 `abc'
124 # Test NOMAGIC with magic characters
125 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
126 ${common_objpfx}posix/globtest -g "$testdir" "abc*" |
127 sort > $testout
128 cat <<"EOF" | cmp - $testout || result=1
129 GLOB_NOMATCH
132 # Test subdirs correctly
133 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
134 ${common_objpfx}posix/globtest "$testdir" "*/*" |
135 sort > $testout
136 cat <<"EOF" | cmp - $testout || result=1
137 `dir1/file1_1'
138 `dir1/file1_2'
141 # Test subdirs for invalid names
142 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
143 ${common_objpfx}posix/globtest "$testdir" "*/1" |
144 sort > $testout
145 cat <<"EOF" | cmp - $testout || result=1
146 GLOB_NOMATCH
149 # Test subdirs with wildcard
150 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
151 ${common_objpfx}posix/globtest "$testdir" "*/*1_1" |
152 sort > $testout
153 cat <<"EOF" | cmp - $testout || result=1
154 `dir1/file1_1'
157 # Test subdirs with ?
158 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
159 ${common_objpfx}posix/globtest "$testdir" "*/*?_?" |
160 sort > $testout
161 cat <<"EOF" | cmp - $testout || result=1
162 `dir1/file1_1'
163 `dir1/file1_2'
166 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
167 ${common_objpfx}posix/globtest "$testdir" "*/file1_1" |
168 sort > $testout
169 cat <<"EOF" | cmp - $testout || result=1
170 `dir1/file1_1'
173 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
174 ${common_objpfx}posix/globtest "$testdir" "*-/*" |
175 sort > $testout
176 cat <<"EOF" | cmp - $testout || result=1
177 GLOB_NOMATCH
180 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
181 ${common_objpfx}posix/globtest "$testdir" "*-" |
182 sort > $testout
183 cat <<"EOF" | cmp - $testout || result=1
184 GLOB_NOMATCH
187 # Test subdirs with ?
188 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
189 ${common_objpfx}posix/globtest "$testdir" "*/*?_?" |
190 sort > $testout
191 cat <<"EOF" | cmp - $testout || result=1
192 `dir1/file1_1'
193 `dir1/file1_2'
196 # Test tilde expansion
197 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
198 ${common_objpfx}posix/globtest -q -t "$testdir" "~" |
199 sort >$testout
200 echo ~ > $testout2
201 cmp $testout2 $testout || result=1
203 # Test tilde expansion with trailing slash
204 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
205 ${common_objpfx}posix/globtest -q -t "$testdir" "~/" |
206 sort > $testout
207 echo ~/ > $testout2
208 cmp $testout2 $testout || result=1
210 # Test tilde expansion with username
211 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
212 ${common_objpfx}posix/globtest -q -t "$testdir" "~"$USER |
213 sort > $testout
214 eval echo ~$USER > $testout2
215 cmp $testout2 $testout || result=1
217 # Tilde expansion shouldn't match a file
218 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
219 ${common_objpfx}posix/globtest -T "$testdir" "~file4" |
220 sort > $testout
221 cat <<"EOF" | cmp - $testout || result=1
222 GLOB_NOMATCH
225 # Matching \** should only find *file6
226 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
227 ${common_objpfx}posix/globtest "$testdir" "\**" |
228 sort > $testout
229 cat <<"EOF" | cmp - $testout || result=1
230 `*file6'
233 # ... unless NOESCAPE is used, in which case it shouldn't match anything.
234 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
235 ${common_objpfx}posix/globtest -e "$testdir" "\**" |
236 sort > $testout
237 cat <<"EOF" | cmp - $testout || result=1
238 GLOB_NOMATCH
241 # Try a recursive failed search
242 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
243 ${common_objpfx}posix/globtest -e "$testdir" "a*/*" |
244 sort > $testout
245 cat <<"EOF" | cmp - $testout || result=1
246 GLOB_NOMATCH
249 # Try multiple patterns (GLOB_APPEND)
250 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
251 ${common_objpfx}posix/globtest "$testdir" "file1" "*/*" |
252 sort > $testout
253 cat <<"EOF" | cmp - $testout || result=1
254 `dir1/file1_1'
255 `dir1/file1_2'
256 `file1'
259 # Try multiple patterns (GLOB_APPEND) with offset (GLOB_DOOFFS)
260 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
261 ${common_objpfx}posix/globtest -o "$testdir" "file1" "*/*" |
262 sort > $testout
263 cat <<"EOF" | cmp - $testout || result=1
264 `abc'
265 `dir1/file1_1'
266 `dir1/file1_2'
267 `file1'
270 # Test NOCHECK with non-existing file in subdir.
271 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
272 ${common_objpfx}posix/globtest -c "$testdir" "*/blahblah" |
273 sort > $testout
274 cat <<"EOF" | cmp - $testout || result=1
275 `dir1/blahblah'
276 `dir2/blahblah'
279 if test $result -eq 0; then
280 rm -fr $testdir $testout
283 exit $result
285 # Preserve executable bits for this shell script.
286 Local Variables:
287 eval:(defun frobme () (set-file-modes buffer-file-name file-mode))
288 eval:(make-local-variable 'file-mode)
289 eval:(setq file-mode (file-modes (buffer-file-name)))
290 eval:(make-local-variable 'after-save-hook)
291 eval:(add-hook 'after-save-hook 'frobme)
292 End: