]> sourceware.org Git - glibc.git/blame - posix/globtest.sh
Update.
[glibc.git] / posix / globtest.sh
CommitLineData
61eb22d3
UD
1#! /bin/sh
2
3common_objpfx=$1; shift
dfd2257a
UD
4elf_objpfx=$1; shift
5rtld_installed_name=$1; shift
61eb22d3 6
c277d2e5
UD
7# We have to make the paths `common_objpfx' absolute.
8case "$common_objpfx" in
9 .*)
10 common_objpfx="`pwd`/$common_objpfx"
11 ;;
12 *)
13 ;;
14esac
15
c9243dac 16# We have to find the libc and the NSS modules.
c277d2e5 17library_path=${common_objpfx}:${common_objpfx}nss:${common_objpfx}nis:${common_objpfx}db2:${common_objpfx}hesiod
c9243dac 18
7ce241a0 19# Since we use `sort' we must make sure to use the same locale everywhere.
3f62b69a
UD
20LC_ALL=C
21export LC_ALL
22LANG=C
23export LANG
24
61eb22d3
UD
25# Create the arena
26: ${TMPDIR=/tmp}
27testdir=$TMPDIR/globtest-dir
28testout=$TMPDIR/globtest-out
29
460adbb8 30trap 'chmod 777 $testdir/noread; rm -fr $testdir $testout' 1 2 3 15
61eb22d3 31
460adbb8 32rm -fr $testdir 2>/dev/null
61eb22d3
UD
33mkdir $testdir
34echo 1 > $testdir/file1
35echo 2 > $testdir/file2
3f62b69a
UD
36echo 3 > $testdir/-file3
37echo 4 > $testdir/~file4
38echo 5 > $testdir/.file5
39echo 6 > $testdir/'*file6'
61eb22d3
UD
40mkdir $testdir/dir1
41mkdir $testdir/dir2
460adbb8
UD
42test -d $testdir/noread || mkdir $testdir/noread
43chmod a-r $testdir/noread
61eb22d3
UD
44echo 1_1 > $testdir/dir1/file1_1
45echo 1_2 > $testdir/dir1/file1_2
46
47# Run some tests.
48result=0
61eb22d3 49
3f62b69a 50# Normal test
c9243dac 51${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
14e9dd67 52${common_objpfx}posix/globtest "$testdir" "*" |
61eb22d3
UD
53sort > $testout
54cat <<"EOF" | cmp - $testout || result=1
3f62b69a
UD
55`*file6'
56`-file3'
57`dir1'
58`dir2'
59`file1'
60`file2'
460adbb8 61`noread'
3f62b69a
UD
62`~file4'
63EOF
64
65# Don't let glob sort it
c9243dac 66${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
3f62b69a
UD
67${common_objpfx}posix/globtest -s "$testdir" "*" |
68sort > $testout
69cat <<"EOF" | cmp - $testout || result=1
70`*file6'
71`-file3'
72`dir1'
73`dir2'
74`file1'
75`file2'
460adbb8 76`noread'
3f62b69a
UD
77`~file4'
78EOF
79
80# Mark directories
c9243dac 81${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
3f62b69a
UD
82${common_objpfx}posix/globtest -m "$testdir" "*" |
83sort > $testout
84cat <<"EOF" | cmp - $testout || result=1
85`*file6'
86`-file3'
87`dir1/'
88`dir2/'
89`file1'
90`file2'
460adbb8 91`noread/'
3f62b69a
UD
92`~file4'
93EOF
94
95# Find files starting with .
c9243dac 96${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
3f62b69a
UD
97${common_objpfx}posix/globtest -p "$testdir" "*" |
98sort > $testout
99cat <<"EOF" | cmp - $testout || result=1
100`*file6'
101`-file3'
102`.'
103`..'
104`.file5'
61eb22d3
UD
105`dir1'
106`dir2'
107`file1'
108`file2'
460adbb8 109`noread'
3f62b69a
UD
110`~file4'
111EOF
112
113# Test braces
c9243dac 114${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
3f62b69a
UD
115${common_objpfx}posix/globtest -b "$testdir" "file{1,2}" |
116sort > $testout
117cat <<"EOF" | cmp - $testout || result=1
118`file1'
119`file2'
120EOF
121
122# Test NOCHECK
c9243dac 123${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
3f62b69a
UD
124${common_objpfx}posix/globtest -c "$testdir" "abc" |
125sort > $testout
126cat <<"EOF" | cmp - $testout || result=1
127`abc'
61eb22d3
UD
128EOF
129
3f62b69a 130# Test NOMAGIC without magic characters
c9243dac 131${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
3f62b69a
UD
132${common_objpfx}posix/globtest -g "$testdir" "abc" |
133sort > $testout
134cat <<"EOF" | cmp - $testout || result=1
135`abc'
136EOF
137
138# Test NOMAGIC with magic characters
c9243dac 139${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
3f62b69a
UD
140${common_objpfx}posix/globtest -g "$testdir" "abc*" |
141sort > $testout
142cat <<"EOF" | cmp - $testout || result=1
143GLOB_NOMATCH
144EOF
145
146# Test subdirs correctly
c9243dac 147${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
14e9dd67 148${common_objpfx}posix/globtest "$testdir" "*/*" |
61eb22d3
UD
149sort > $testout
150cat <<"EOF" | cmp - $testout || result=1
151`dir1/file1_1'
152`dir1/file1_2'
61eb22d3
UD
153EOF
154
3f62b69a 155# Test subdirs for invalid names
c9243dac 156${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
14e9dd67 157${common_objpfx}posix/globtest "$testdir" "*/1" |
61eb22d3
UD
158sort > $testout
159cat <<"EOF" | cmp - $testout || result=1
160GLOB_NOMATCH
61eb22d3
UD
161EOF
162
3f62b69a 163# Test subdirs with wildcard
c9243dac 164${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
14e9dd67 165${common_objpfx}posix/globtest "$testdir" "*/*1_1" |
61eb22d3
UD
166sort > $testout
167cat <<"EOF" | cmp - $testout || result=1
168`dir1/file1_1'
3f62b69a
UD
169EOF
170
171# Test subdirs with ?
c9243dac 172${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
3f62b69a
UD
173${common_objpfx}posix/globtest "$testdir" "*/*?_?" |
174sort > $testout
175cat <<"EOF" | cmp - $testout || result=1
176`dir1/file1_1'
177`dir1/file1_2'
61eb22d3
UD
178EOF
179
c9243dac 180${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
14e9dd67 181${common_objpfx}posix/globtest "$testdir" "*/file1_1" |
61eb22d3
UD
182sort > $testout
183cat <<"EOF" | cmp - $testout || result=1
184`dir1/file1_1'
61eb22d3
UD
185EOF
186
c9243dac 187${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
14e9dd67 188${common_objpfx}posix/globtest "$testdir" "*-/*" |
61eb22d3
UD
189sort > $testout
190cat <<"EOF" | cmp - $testout || result=1
191GLOB_NOMATCH
61eb22d3
UD
192EOF
193
c9243dac 194${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
14e9dd67 195${common_objpfx}posix/globtest "$testdir" "*-" |
61eb22d3
UD
196sort > $testout
197cat <<"EOF" | cmp - $testout || result=1
198GLOB_NOMATCH
3f62b69a
UD
199EOF
200
201# Test subdirs with ?
c9243dac 202${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
3f62b69a
UD
203${common_objpfx}posix/globtest "$testdir" "*/*?_?" |
204sort > $testout
205cat <<"EOF" | cmp - $testout || result=1
206`dir1/file1_1'
207`dir1/file1_2'
208EOF
209
460adbb8
UD
210# Test subdirs with [ .. ]
211${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
212${common_objpfx}posix/globtest "$testdir" "*/file1_[12]" |
213sort > $testout
214cat <<"EOF" | cmp - $testout || result=1
215`dir1/file1_1'
216`dir1/file1_2'
217EOF
218
219# Test ']' inside bracket expression
220${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
221${common_objpfx}posix/globtest "$testdir" "dir1/file1_[]12]" |
222sort > $testout
223cat <<"EOF" | cmp - $testout || result=1
224`dir1/file1_1'
225`dir1/file1_2'
226EOF
227
3f62b69a 228# Test tilde expansion
c9243dac
UD
229${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
230${common_objpfx}posix/globtest -q -t "$testdir" "~" |
231sort >$testout
7ce241a0 232echo ~ | cmp - $testout || result=1
3f62b69a
UD
233
234# Test tilde expansion with trailing slash
c9243dac
UD
235${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
236${common_objpfx}posix/globtest -q -t "$testdir" "~/" |
237sort > $testout
7ce241a0 238echo ~/ | cmp - $testout || result=1
3f62b69a
UD
239
240# Test tilde expansion with username
c9243dac
UD
241${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
242${common_objpfx}posix/globtest -q -t "$testdir" "~"$USER |
243sort > $testout
7ce241a0 244eval echo ~$USER | cmp - $testout || result=1
3f62b69a
UD
245
246# Tilde expansion shouldn't match a file
1bc21e7a
UD
247${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
248${common_objpfx}posix/globtest -T "$testdir" "~file4" |
249sort > $testout
250cat <<"EOF" | cmp - $testout || result=1
251GLOB_NOMATCH
252EOF
3f62b69a
UD
253
254# Matching \** should only find *file6
c9243dac 255${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
3f62b69a
UD
256${common_objpfx}posix/globtest "$testdir" "\**" |
257sort > $testout
258cat <<"EOF" | cmp - $testout || result=1
259`*file6'
260EOF
261
262# ... unless NOESCAPE is used, in which case it shouldn't match anything.
c9243dac 263${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
3f62b69a
UD
264${common_objpfx}posix/globtest -e "$testdir" "\**" |
265sort > $testout
266cat <<"EOF" | cmp - $testout || result=1
267GLOB_NOMATCH
268EOF
269
460adbb8
UD
270# Matching \*file6 should find *file6
271${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
272${common_objpfx}posix/globtest "$testdir" "\*file6" |
273sort > $testout
274cat <<"EOF" | cmp - $testout || result=1
275`*file6'
276EOF
277
3f62b69a 278# Try a recursive failed search
c9243dac 279${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
3f62b69a
UD
280${common_objpfx}posix/globtest -e "$testdir" "a*/*" |
281sort > $testout
282cat <<"EOF" | cmp - $testout || result=1
283GLOB_NOMATCH
284EOF
285
460adbb8
UD
286# ... with GLOB_ERR
287${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
288${common_objpfx}posix/globtest -E "$testdir" "a*/*" |
289sort > $testout
290cat <<"EOF" | cmp - $testout || result=1
291GLOB_NOMATCH
292EOF
293
294# Try a recursive search in unreadable directory
295${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
296${common_objpfx}posix/globtest "$testdir" "noread/*" |
297sort > $testout
298cat <<"EOF" | cmp - $testout || result=1
299GLOB_NOMATCH
300EOF
301
302${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
303${common_objpfx}posix/globtest "$testdir" "noread*/*" |
304sort > $testout
305cat <<"EOF" | cmp - $testout || result=1
306GLOB_NOMATCH
307EOF
308
3b690639
UD
309# The following tests will fail if run as root.
310user=`id -un 2> /dev/null`
311if test -z "$user"; then
312 uid="$USER"
313fi
314if test "$user" != root; then
315 # ... with GLOB_ERR
316 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
317 ${common_objpfx}posix/globtest -E "$testdir" "noread/*" |
318 sort > $testout
319 cat <<"EOF" | cmp - $testout || result=1
460adbb8
UD
320GLOB_ABORTED
321EOF
3b690639 322fi # not run as root
460adbb8
UD
323
324${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
325${common_objpfx}posix/globtest -E "$testdir" "noread*/*" |
326sort > $testout
327cat <<"EOF" | cmp - $testout || result=1
328GLOB_ABORTED
329EOF
330
3f62b69a 331# Try multiple patterns (GLOB_APPEND)
c9243dac 332${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
3f62b69a
UD
333${common_objpfx}posix/globtest "$testdir" "file1" "*/*" |
334sort > $testout
335cat <<"EOF" | cmp - $testout || result=1
336`dir1/file1_1'
337`dir1/file1_2'
338`file1'
339EOF
340
341# Try multiple patterns (GLOB_APPEND) with offset (GLOB_DOOFFS)
c9243dac 342${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
3f62b69a
UD
343${common_objpfx}posix/globtest -o "$testdir" "file1" "*/*" |
344sort > $testout
345cat <<"EOF" | cmp - $testout || result=1
346`abc'
347`dir1/file1_1'
348`dir1/file1_2'
349`file1'
61eb22d3
UD
350EOF
351
e852e889
UD
352# Test NOCHECK with non-existing file in subdir.
353${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
354${common_objpfx}posix/globtest -c "$testdir" "*/blahblah" |
355sort > $testout
356cat <<"EOF" | cmp - $testout || result=1
357`dir1/blahblah'
358`dir2/blahblah'
460adbb8 359`noread/blahblah'
e852e889
UD
360EOF
361
61eb22d3 362if test $result -eq 0; then
460adbb8 363 chmod 777 $testdir/noread
3f62b69a 364 rm -fr $testdir $testout
61eb22d3
UD
365fi
366
367exit $result
368
369# Preserve executable bits for this shell script.
370Local Variables:
371eval:(defun frobme () (set-file-modes buffer-file-name file-mode))
372eval:(make-local-variable 'file-mode)
373eval:(setq file-mode (file-modes (buffer-file-name)))
374eval:(make-local-variable 'after-save-hook)
375eval:(add-hook 'after-save-hook 'frobme)
376End:
This page took 0.126202 seconds and 5 git commands to generate.