Update.
[glibc.git] / posix / globtest.sh
blob806b481c7eb1aad4b280e440c2492ee4a698f25d
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 `sort' 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
21 trap 'rm -fr $testdir $testout' 1 2 3 15
23 rm -fr $testdir
24 mkdir $testdir
25 echo 1 > $testdir/file1
26 echo 2 > $testdir/file2
27 echo 3 > $testdir/-file3
28 echo 4 > $testdir/~file4
29 echo 5 > $testdir/.file5
30 echo 6 > $testdir/'*file6'
31 mkdir $testdir/dir1
32 mkdir $testdir/dir2
33 echo 1_1 > $testdir/dir1/file1_1
34 echo 1_2 > $testdir/dir1/file1_2
36 # Run some tests.
37 result=0
39 # Normal test
40 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
41 ${common_objpfx}posix/globtest "$testdir" "*" |
42 sort > $testout
43 cat <<"EOF" | cmp - $testout || result=1
44 `*file6'
45 `-file3'
46 `dir1'
47 `dir2'
48 `file1'
49 `file2'
50 `~file4'
51 EOF
53 # Don't let glob sort it
54 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
55 ${common_objpfx}posix/globtest -s "$testdir" "*" |
56 sort > $testout
57 cat <<"EOF" | cmp - $testout || result=1
58 `*file6'
59 `-file3'
60 `dir1'
61 `dir2'
62 `file1'
63 `file2'
64 `~file4'
65 EOF
67 # Mark directories
68 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
69 ${common_objpfx}posix/globtest -m "$testdir" "*" |
70 sort > $testout
71 cat <<"EOF" | cmp - $testout || result=1
72 `*file6'
73 `-file3'
74 `dir1/'
75 `dir2/'
76 `file1'
77 `file2'
78 `~file4'
79 EOF
81 # Find files starting with .
82 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
83 ${common_objpfx}posix/globtest -p "$testdir" "*" |
84 sort > $testout
85 cat <<"EOF" | cmp - $testout || result=1
86 `*file6'
87 `-file3'
88 `.'
89 `..'
90 `.file5'
91 `dir1'
92 `dir2'
93 `file1'
94 `file2'
95 `~file4'
96 EOF
98 # Test braces
99 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
100 ${common_objpfx}posix/globtest -b "$testdir" "file{1,2}" |
101 sort > $testout
102 cat <<"EOF" | cmp - $testout || result=1
103 `file1'
104 `file2'
107 # Test NOCHECK
108 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
109 ${common_objpfx}posix/globtest -c "$testdir" "abc" |
110 sort > $testout
111 cat <<"EOF" | cmp - $testout || result=1
112 `abc'
115 # Test NOMAGIC without magic characters
116 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
117 ${common_objpfx}posix/globtest -g "$testdir" "abc" |
118 sort > $testout
119 cat <<"EOF" | cmp - $testout || result=1
120 `abc'
123 # Test NOMAGIC with magic characters
124 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
125 ${common_objpfx}posix/globtest -g "$testdir" "abc*" |
126 sort > $testout
127 cat <<"EOF" | cmp - $testout || result=1
128 GLOB_NOMATCH
131 # Test subdirs correctly
132 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
133 ${common_objpfx}posix/globtest "$testdir" "*/*" |
134 sort > $testout
135 cat <<"EOF" | cmp - $testout || result=1
136 `dir1/file1_1'
137 `dir1/file1_2'
140 # Test subdirs for invalid names
141 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
142 ${common_objpfx}posix/globtest "$testdir" "*/1" |
143 sort > $testout
144 cat <<"EOF" | cmp - $testout || result=1
145 GLOB_NOMATCH
148 # Test subdirs with wildcard
149 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
150 ${common_objpfx}posix/globtest "$testdir" "*/*1_1" |
151 sort > $testout
152 cat <<"EOF" | cmp - $testout || result=1
153 `dir1/file1_1'
156 # Test subdirs with ?
157 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
158 ${common_objpfx}posix/globtest "$testdir" "*/*?_?" |
159 sort > $testout
160 cat <<"EOF" | cmp - $testout || result=1
161 `dir1/file1_1'
162 `dir1/file1_2'
165 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
166 ${common_objpfx}posix/globtest "$testdir" "*/file1_1" |
167 sort > $testout
168 cat <<"EOF" | cmp - $testout || result=1
169 `dir1/file1_1'
172 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
173 ${common_objpfx}posix/globtest "$testdir" "*-/*" |
174 sort > $testout
175 cat <<"EOF" | cmp - $testout || result=1
176 GLOB_NOMATCH
179 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
180 ${common_objpfx}posix/globtest "$testdir" "*-" |
181 sort > $testout
182 cat <<"EOF" | cmp - $testout || result=1
183 GLOB_NOMATCH
186 # Test subdirs with ?
187 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
188 ${common_objpfx}posix/globtest "$testdir" "*/*?_?" |
189 sort > $testout
190 cat <<"EOF" | cmp - $testout || result=1
191 `dir1/file1_1'
192 `dir1/file1_2'
195 # Test tilde expansion
196 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
197 ${common_objpfx}posix/globtest -q -t "$testdir" "~" |
198 sort >$testout
199 echo ~ | cmp - $testout || result=1
201 # Test tilde expansion with trailing slash
202 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
203 ${common_objpfx}posix/globtest -q -t "$testdir" "~/" |
204 sort > $testout
205 echo ~/ | cmp - $testout || result=1
207 # Test tilde expansion with username
208 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
209 ${common_objpfx}posix/globtest -q -t "$testdir" "~"$USER |
210 sort > $testout
211 eval echo ~$USER | cmp - $testout || result=1
213 # Tilde expansion shouldn't match a file
214 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
215 ${common_objpfx}posix/globtest -T "$testdir" "~file4" |
216 sort > $testout
217 cat <<"EOF" | cmp - $testout || result=1
218 GLOB_NOMATCH
221 # Matching \** should only find *file6
222 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
223 ${common_objpfx}posix/globtest "$testdir" "\**" |
224 sort > $testout
225 cat <<"EOF" | cmp - $testout || result=1
226 `*file6'
229 # ... unless NOESCAPE is used, in which case it shouldn't match anything.
230 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
231 ${common_objpfx}posix/globtest -e "$testdir" "\**" |
232 sort > $testout
233 cat <<"EOF" | cmp - $testout || result=1
234 GLOB_NOMATCH
237 # Try a recursive failed search
238 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
239 ${common_objpfx}posix/globtest -e "$testdir" "a*/*" |
240 sort > $testout
241 cat <<"EOF" | cmp - $testout || result=1
242 GLOB_NOMATCH
245 # Try multiple patterns (GLOB_APPEND)
246 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
247 ${common_objpfx}posix/globtest "$testdir" "file1" "*/*" |
248 sort > $testout
249 cat <<"EOF" | cmp - $testout || result=1
250 `dir1/file1_1'
251 `dir1/file1_2'
252 `file1'
255 # Try multiple patterns (GLOB_APPEND) with offset (GLOB_DOOFFS)
256 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
257 ${common_objpfx}posix/globtest -o "$testdir" "file1" "*/*" |
258 sort > $testout
259 cat <<"EOF" | cmp - $testout || result=1
260 `abc'
261 `dir1/file1_1'
262 `dir1/file1_2'
263 `file1'
266 # Test NOCHECK with non-existing file in subdir.
267 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
268 ${common_objpfx}posix/globtest -c "$testdir" "*/blahblah" |
269 sort > $testout
270 cat <<"EOF" | cmp - $testout || result=1
271 `dir1/blahblah'
272 `dir2/blahblah'
275 if test $result -eq 0; then
276 rm -fr $testdir $testout
279 exit $result
281 # Preserve executable bits for this shell script.
282 Local Variables:
283 eval:(defun frobme () (set-file-modes buffer-file-name file-mode))
284 eval:(make-local-variable 'file-mode)
285 eval:(setq file-mode (file-modes (buffer-file-name)))
286 eval:(make-local-variable 'after-save-hook)
287 eval:(add-hook 'after-save-hook 'frobme)
288 End: