Imported from ../bash-2.01.tar.gz.
[platform/upstream/bash.git] / tests / test-tests
1 if (( $UID == 0 )); then
2         echo "test-tests: the test suite should not be run as root" >&2
3 fi
4
5 b()
6 {
7         [ "$@" ]
8         echo $?
9 }
10
11 t()
12 {
13         test "$@"
14         echo $?
15 }
16
17 echo 't -a noexist'
18 t -a noexist
19 echo 't -a run-all'
20 t -a run-all
21
22 echo 't -b run-all'
23 t -b run-all
24 echo 't -b /dev/jb1a'
25 t -b /dev/jb1a
26
27 echo 't -c run-all'
28 t -c run-all
29 echo 't -c /dev/tty'
30 t -c /dev/tty
31
32 echo 't -d run-all'
33 t -d run-all
34 echo 't -d /etc'
35 t -d /etc
36 echo 't -d ""'
37 t -d ""
38 echo 'b -d ""'
39 b -d ""
40
41 echo 't -e noexist'
42 t -e noexist
43 echo 't -e run-all'
44 t -e run-all
45
46 echo 't -f noexist'
47 t -f noexist
48 echo 't -f /dev/tty'
49 t -f /dev/tty
50 echo 't -f run-all'
51 t -f run-all
52
53 echo 't -g run-all'
54 t -g run-all
55
56 touch /tmp/test.setgid
57 chgrp ${GROUPS[0]} /tmp/test.setgid
58 chmod ug+x /tmp/test.setgid
59 chmod g+s /tmp/test.setgid
60 echo 't -g /tmp/test.setgid'
61 t -g /tmp/test.setgid
62 rm -f /tmp/test.setgid
63
64 echo 't -k run-all'
65 t -k run-all
66
67 echo 't -n ""'
68 t -n ""
69 echo 't -n "hello"'
70 t -n "hello"
71
72 echo 't -p run-all'
73 t -p run-all
74
75 echo 't -r noexist'
76 t -r noexist
77
78 if (( $UID != 0 )); then
79         touch /tmp/test.noread
80         chmod a-r /tmp/test.noread
81         echo 't -r /tmp/test.noread'
82         t -r /tmp/test.noread
83         rm -f /tmp/test.noread
84 else
85         echo 't -r /tmp/test.noread'
86         echo 1
87 fi
88
89 echo 't -r run-all'
90 t -r run-all
91
92 echo 't -s noexist'
93 t -s noexist
94 echo 't -s /dev/null'
95 t -s /dev/null
96 echo 't -s run-all'
97 t -s run-all
98
99 echo 't -t 20'
100 t -t 20
101 echo 't -t 0'
102 t -t 0
103
104 echo 't -u noexist'
105 t -u noexist
106
107 echo 't -u run-all'
108 t -u run-all
109
110 touch /tmp/test.setuid
111 chmod u+x /tmp/test.setuid      # some systems require this to turn on setuid bit
112 chmod u+s /tmp/test.setuid
113 echo 't -u /tmp/test.setuid'
114 t -u /tmp/test.setuid
115 rm -f /tmp/test.setuid
116
117 echo 't -w noexist'
118 t -w noexist
119
120 if (( $UID != 0 )); then
121         touch /tmp/test.nowrite
122         chmod a-w /tmp/test.nowrite
123         echo 't -w /tmp/test.nowrite'
124         t -w /tmp/test.nowrite
125         rm -f /tmp/test.nowrite
126 else
127         echo 't -w /tmp/test.nowrite'
128         echo 1
129 fi
130
131 echo 't -w /dev/null'
132 t -w /dev/null
133
134 echo 't -x noexist'
135 t -x noexist
136
137 touch /tmp/test.exec
138 chmod u+x /tmp/test.exec
139 echo 't -x /tmp/test.exec'
140 t -x /tmp/test.exec
141 rm -f /tmp/test.exec
142
143 touch /tmp/test.noexec
144 chmod u-x /tmp/test.noexec
145 echo 't -x /tmp/test.noexec'
146 t -x /tmp/test.noexec
147 rm -f /tmp/test.noexec
148
149 echo 't -z ""'
150 t -z ""
151 echo 't -z "foo"'
152 t -z "foo"
153
154 echo 't "foo"'
155 t "foo"
156 echo 't ""'
157 t ""
158
159 touch /tmp/test.owner
160 echo 't -O /tmp/test.owner'
161 t -O /tmp/test.owner
162 rm -f /tmp/test.owner
163
164 echo 't "hello" = "hello"'
165 t "hello" = "hello"
166 echo 't "hello" = "goodbye"'
167 t "hello" = "goodbye"
168
169 echo 't "hello" == "hello"'
170 t "hello" == "hello"
171 echo 't "hello" == "goodbye"'
172 t "hello" == "goodbye"
173
174 echo 't "hello" != "hello"'
175 t "hello" != "hello"
176 echo 't "hello" != "goodbye"'
177 t "hello" != "goodbye"
178
179 echo 't "hello" < "goodbye"'
180 t "hello" \< "goodbye"
181 echo 't "hello" > "goodbye"'
182 t "hello" \> "goodbye"
183
184 echo 't ! "hello" > "goodbye"'
185 t "! hello" \> "goodbye"
186
187 echo 't 200 -eq 200'
188 t 200 -eq 200
189 echo 't 34 -eq 222'
190 t 34 -eq 222
191 echo 't -32 -eq 32'
192 t -32 -eq 32
193
194 echo 't 200 -ne 200'
195 t 200 -ne 200
196 echo 't 34 -ne 222'
197 t 34 -ne 222
198
199 echo 't 200 -gt 200'
200 t 200 -gt 200
201 echo 't 340 -gt 222'
202 t 340 -gt 222
203
204 echo 't 200 -ge 200'
205 t 200 -ge 200
206 echo 't 34 -ge 222'
207 t 34 -ge 222
208
209 echo 't 200 -lt 200'
210 t 200 -lt 200
211 echo 't 34 -lt 222'
212 t 34 -lt 222
213
214 echo 't 200 -le 200'
215 t 200 -le 200
216 echo 't 340 -le 222'
217 t 340 -le 222
218
219 echo 't 700 -le 1000 -a -n "1" -a "20" = "20"'
220 t 700 -le 1000 -a -n "1" -a "20" = "20"
221 echo 't ! \( 700 -le 1000 -a -n "1" -a "20" = "20" \)'
222 t ! \( 700 -le 1000 -a -n "1" -a "20" = "20" \)
223
224 touch /tmp/abc
225 sleep 2
226 touch /tmp/def
227
228 echo 't /tmp/abc -nt /tmp/def'
229 t /tmp/abc -nt /tmp/def
230 echo 't /tmp/abc -ot /tmp/def'
231 t /tmp/abc -ot /tmp/def
232 echo 't /tmp/def -nt /tmp/abc'
233 t /tmp/def -nt /tmp/abc
234 echo 't /tmp/def -ot /tmp/abc'
235 t /tmp/def -ot /tmp/abc
236
237 echo 't /tmp/abc -ef /tmp/def'
238 t /tmp/abc -ef /tmp/def
239 ln /tmp/abc /tmp/ghi
240 echo 't /tmp/abc -ef /tmp/ghi'
241 t /tmp/abc -ef /tmp/ghi
242
243 rm /tmp/abc /tmp/def /tmp/ghi
244
245 echo 't -r /dev/fd/0'
246 t -r /dev/fd/0
247 echo 't -w /dev/fd/1'
248 t -w /dev/fd/1
249 echo 't -w /dev/fd/2'
250 t -w /dev/fd/2
251
252 echo 't'
253 t
254 echo 'b'
255 b
256
257 echo 't 12 -eq 34'
258 t 12 -eq 34
259 echo 't ! 12 -eq 34'
260 t ! 12 -eq 34
261
262 echo 't -n abcd -o aaa'
263 t -n abcd -o aaa
264 echo 't -n abcd -o -z aaa'
265 t -n abcd -o -z aaa
266
267 echo 't -n abcd -a aaa'
268 t -n abcd -a aaa
269 echo 't -n abcd -a -z aaa'
270 t -n abcd -a -z aaa
271
272 set +o allexport
273 echo 't -o allexport'
274 t -o allexport
275 echo 't ! -o allexport'
276 t ! -o allexport
277
278 echo 't xx -a yy'
279 t xx -a yy
280 echo 't xx -o ""'
281 t xx -o ""
282 echo 't xx -a ""'
283 t xx -a ""
284
285 echo 't -X -a -X'
286 t -X -a -X
287 echo 't -X -o -X'
288 t -X -o -X
289 echo 't -X -o ""'
290 t -X -o ""
291 echo 't -X -a ""'
292 t -X -a ""
293 echo 't "" -a -X'
294 t "" -a -X
295 echo 't "" -o -X'
296 t "" -o -X
297 echo 't "" -a ""'
298 t "" -a ""
299 echo 't "" -o ""'
300 t "" -o ""
301 echo 't true -o -X'
302 t true -o -X
303 echo 't true -a -X'
304 t true -a -X
305
306 echo 't ( -E )'
307 t \( -E \)
308 echo 't ( "" )'
309 t \( "" \)
310
311 z=42
312
313 echo 't ! -z "$z"'
314 t ! -z "$z"
315
316 echo 't ! -n "$z"'
317 t ! -n "$z"
318
319 zero=
320 echo 't "$zero"'
321 t "$zero"
322 echo 't ! "$zero"'
323 t ! "$zero"
324 echo 'b "$zero"'
325 b "$zero"
326 echo 'b ! "$zero"'
327 b ! "$zero"
328
329 touch /tmp/test.group
330 chgrp ${GROUPS[0]} /tmp/test.group
331 echo 't -G /tmp/test.group'
332 t -G /tmp/test.group
333 rm /tmp/test.group
334
335 case "${THIS_SH}" in
336 /*)     SHNAME=${THIS_SH} ;;
337 *)      SHNAME=${PWD}/${THIS_SH} ;;
338 esac
339
340 if ln -s ${SHNAME} /tmp/test.symlink 2>/dev/null; then
341         chgrp ${GROUPS[0]} /tmp/test.symlink
342         echo 't -h /tmp/test.symlink'
343         t -h /tmp/test.symlink
344         # some systems don't let you remove this
345         rm -f /tmp/test.symlink 2>/dev/null
346 else
347         echo 't -h /tmp/test.symlink'
348         echo 0
349 fi
350
351 # arithmetic constant errors
352 echo "t 4+3 -eq 7"
353 t 4+3 -eq 7
354 echo "b 4-5 -eq 7"
355 b 4+3 -eq 7
356
357 echo "t 9 -eq 4+5"
358 t 9 -eq 4+5
359 echo "b 9 -eq 4+5"
360 b 9 -eq 4+5
361
362 A=7
363 echo "t A -eq 7"
364 t A -eq 7
365 echo "b A -eq 7"
366 b A -eq 7
367
368 B=9
369 echo "t 9 -eq B"
370 t 9 -eq B
371 echo "b 9 -eq B"
372 b 9 -eq B
373
374 # badly formed expressions
375 echo 't ( 1 = 2'
376 t \( 1 = 2
377 echo 'b ( 1 = 2'
378 b \( 1 = 2
379
380 # more errors
381 t a b
382 t a b c
383 t -A v
384 # too many arguments -- argument expected is also reasonable
385 t 4 -eq 4 -a 2 -ne 5 -a 4 -ne
386 # too many arguments
387 t 4 -eq 4 -a 3 4
388
389 [
390 echo $?
391
392 t \( \)