Update.
[glibc.git] / posix / globtest.sh
blob4a009cc92b8d948563d7f0915da05dd9f281ed76
1 #! /bin/sh
3 common_objpfx=$1; shift
4 elf_objpfx=$1; shift
5 rtld_installed_name=$1; shift
7 # We have to make the paths `common_objpfx' absolute.
8 case "$common_objpfx" in
9 .*)
10 common_objpfx="`pwd`/$common_objpfx"
14 esac
16 # We have to find the libc and the NSS modules.
17 library_path=${common_objpfx}:${common_objpfx}nss:${common_objpfx}nis:${common_objpfx}db2:${common_objpfx}hesiod
19 # Since we use `sort' we must make sure to use the same locale everywhere.
20 LC_ALL=C
21 export LC_ALL
22 LANG=C
23 export LANG
25 # Create the arena
26 : ${TMPDIR=/tmp}
27 testdir=$TMPDIR/globtest-dir
28 testout=$TMPDIR/globtest-out
30 trap 'rm -fr $testdir $testout' 1 2 3 15
32 rm -fr $testdir
33 mkdir $testdir
34 echo 1 > $testdir/file1
35 echo 2 > $testdir/file2
36 echo 3 > $testdir/-file3
37 echo 4 > $testdir/~file4
38 echo 5 > $testdir/.file5
39 echo 6 > $testdir/'*file6'
40 mkdir $testdir/dir1
41 mkdir $testdir/dir2
42 echo 1_1 > $testdir/dir1/file1_1
43 echo 1_2 > $testdir/dir1/file1_2
45 # Run some tests.
46 result=0
48 # Normal test
49 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
50 ${common_objpfx}posix/globtest "$testdir" "*" |
51 sort > $testout
52 cat <<"EOF" | cmp - $testout || result=1
53 `*file6'
54 `-file3'
55 `dir1'
56 `dir2'
57 `file1'
58 `file2'
59 `~file4'
60 EOF
62 # Don't let glob sort it
63 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
64 ${common_objpfx}posix/globtest -s "$testdir" "*" |
65 sort > $testout
66 cat <<"EOF" | cmp - $testout || result=1
67 `*file6'
68 `-file3'
69 `dir1'
70 `dir2'
71 `file1'
72 `file2'
73 `~file4'
74 EOF
76 # Mark directories
77 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
78 ${common_objpfx}posix/globtest -m "$testdir" "*" |
79 sort > $testout
80 cat <<"EOF" | cmp - $testout || result=1
81 `*file6'
82 `-file3'
83 `dir1/'
84 `dir2/'
85 `file1'
86 `file2'
87 `~file4'
88 EOF
90 # Find files starting with .
91 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
92 ${common_objpfx}posix/globtest -p "$testdir" "*" |
93 sort > $testout
94 cat <<"EOF" | cmp - $testout || result=1
95 `*file6'
96 `-file3'
97 `.'
98 `..'
99 `.file5'
100 `dir1'
101 `dir2'
102 `file1'
103 `file2'
104 `~file4'
107 # Test braces
108 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
109 ${common_objpfx}posix/globtest -b "$testdir" "file{1,2}" |
110 sort > $testout
111 cat <<"EOF" | cmp - $testout || result=1
112 `file1'
113 `file2'
116 # Test NOCHECK
117 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
118 ${common_objpfx}posix/globtest -c "$testdir" "abc" |
119 sort > $testout
120 cat <<"EOF" | cmp - $testout || result=1
121 `abc'
124 # Test NOMAGIC without 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 `abc'
132 # Test NOMAGIC with magic characters
133 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
134 ${common_objpfx}posix/globtest -g "$testdir" "abc*" |
135 sort > $testout
136 cat <<"EOF" | cmp - $testout || result=1
137 GLOB_NOMATCH
140 # Test subdirs correctly
141 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
142 ${common_objpfx}posix/globtest "$testdir" "*/*" |
143 sort > $testout
144 cat <<"EOF" | cmp - $testout || result=1
145 `dir1/file1_1'
146 `dir1/file1_2'
149 # Test subdirs for invalid names
150 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
151 ${common_objpfx}posix/globtest "$testdir" "*/1" |
152 sort > $testout
153 cat <<"EOF" | cmp - $testout || result=1
154 GLOB_NOMATCH
157 # Test subdirs with wildcard
158 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
159 ${common_objpfx}posix/globtest "$testdir" "*/*1_1" |
160 sort > $testout
161 cat <<"EOF" | cmp - $testout || result=1
162 `dir1/file1_1'
165 # Test subdirs with ?
166 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
167 ${common_objpfx}posix/globtest "$testdir" "*/*?_?" |
168 sort > $testout
169 cat <<"EOF" | cmp - $testout || result=1
170 `dir1/file1_1'
171 `dir1/file1_2'
174 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
175 ${common_objpfx}posix/globtest "$testdir" "*/file1_1" |
176 sort > $testout
177 cat <<"EOF" | cmp - $testout || result=1
178 `dir1/file1_1'
181 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
182 ${common_objpfx}posix/globtest "$testdir" "*-/*" |
183 sort > $testout
184 cat <<"EOF" | cmp - $testout || result=1
185 GLOB_NOMATCH
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 GLOB_NOMATCH
195 # Test subdirs with ?
196 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
197 ${common_objpfx}posix/globtest "$testdir" "*/*?_?" |
198 sort > $testout
199 cat <<"EOF" | cmp - $testout || result=1
200 `dir1/file1_1'
201 `dir1/file1_2'
204 # Test tilde expansion
205 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
206 ${common_objpfx}posix/globtest -q -t "$testdir" "~" |
207 sort >$testout
208 echo ~ | cmp - $testout || result=1
210 # Test tilde expansion with trailing slash
211 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
212 ${common_objpfx}posix/globtest -q -t "$testdir" "~/" |
213 sort > $testout
214 echo ~/ | cmp - $testout || result=1
216 # Test tilde expansion with username
217 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
218 ${common_objpfx}posix/globtest -q -t "$testdir" "~"$USER |
219 sort > $testout
220 eval echo ~$USER | cmp - $testout || result=1
222 # Tilde expansion shouldn't match a file
223 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
224 ${common_objpfx}posix/globtest -T "$testdir" "~file4" |
225 sort > $testout
226 cat <<"EOF" | cmp - $testout || result=1
227 GLOB_NOMATCH
230 # Matching \** should only find *file6
231 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
232 ${common_objpfx}posix/globtest "$testdir" "\**" |
233 sort > $testout
234 cat <<"EOF" | cmp - $testout || result=1
235 `*file6'
238 # ... unless NOESCAPE is used, in which case it shouldn't match anything.
239 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
240 ${common_objpfx}posix/globtest -e "$testdir" "\**" |
241 sort > $testout
242 cat <<"EOF" | cmp - $testout || result=1
243 GLOB_NOMATCH
246 # Try a recursive failed search
247 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
248 ${common_objpfx}posix/globtest -e "$testdir" "a*/*" |
249 sort > $testout
250 cat <<"EOF" | cmp - $testout || result=1
251 GLOB_NOMATCH
254 # Try multiple patterns (GLOB_APPEND)
255 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
256 ${common_objpfx}posix/globtest "$testdir" "file1" "*/*" |
257 sort > $testout
258 cat <<"EOF" | cmp - $testout || result=1
259 `dir1/file1_1'
260 `dir1/file1_2'
261 `file1'
264 # Try multiple patterns (GLOB_APPEND) with offset (GLOB_DOOFFS)
265 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
266 ${common_objpfx}posix/globtest -o "$testdir" "file1" "*/*" |
267 sort > $testout
268 cat <<"EOF" | cmp - $testout || result=1
269 `abc'
270 `dir1/file1_1'
271 `dir1/file1_2'
272 `file1'
275 # Test NOCHECK with non-existing file in subdir.
276 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
277 ${common_objpfx}posix/globtest -c "$testdir" "*/blahblah" |
278 sort > $testout
279 cat <<"EOF" | cmp - $testout || result=1
280 `dir1/blahblah'
281 `dir2/blahblah'
284 if test $result -eq 0; then
285 rm -fr $testdir $testout
288 exit $result
290 # Preserve executable bits for this shell script.
291 Local Variables:
292 eval:(defun frobme () (set-file-modes buffer-file-name file-mode))
293 eval:(make-local-variable 'file-mode)
294 eval:(setq file-mode (file-modes (buffer-file-name)))
295 eval:(make-local-variable 'after-save-hook)
296 eval:(add-hook 'after-save-hook 'frobme)
297 End: