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