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