~ubuntu-branches/ubuntu/trusty/bash/trusty-security

« back to all changes in this revision

Viewing changes to tests/test.tests

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2014-03-03 22:52:05 UTC
  • mfrom: (1.3.5) (2.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20140303225205-87ltrt5kspeq0g1b
Tags: 4.3-1ubuntu1
* Merge with Debian; remaining changes:
  - skel.bashrc:
    - Run lesspipe.
    - Enable ls aliases.
    - Set options in ll alias to -alF.
    - Define an alert alias.
    - Enabled colored grep aliases.
  - etc.bash.bashrc:
    - Add sudo hint.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 < /dev/tty
 
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
touch /tmp/test.socket
 
165
echo 't -S /tmp/test.socket'
 
166
t -S /tmp/test.socket   # false
 
167
rm -f /tmp/test.socket
 
168
 
 
169
touch /tmp/test.newer
 
170
echo 't -N /tmp/test.newer'
 
171
t -N /tmp/test.newer
 
172
rm -f /tmp/test.newer
 
173
 
 
174
echo 't "hello" = "hello"'
 
175
t "hello" = "hello"
 
176
echo 't "hello" = "goodbye"'
 
177
t "hello" = "goodbye"
 
178
 
 
179
echo 't "hello" == "hello"'
 
180
t "hello" == "hello"
 
181
echo 't "hello" == "goodbye"'
 
182
t "hello" == "goodbye"
 
183
 
 
184
echo 't "hello" != "hello"'
 
185
t "hello" != "hello"
 
186
echo 't "hello" != "goodbye"'
 
187
t "hello" != "goodbye"
 
188
 
 
189
echo 't "hello" < "goodbye"'
 
190
t "hello" \< "goodbye"
 
191
echo 't "hello" > "goodbye"'
 
192
t "hello" \> "goodbye"
 
193
 
 
194
echo 't ! "hello" > "goodbye"'
 
195
t "! hello" \> "goodbye"
 
196
 
 
197
echo 't 200 -eq 200'
 
198
t 200 -eq 200
 
199
echo 't 34 -eq 222'
 
200
t 34 -eq 222
 
201
echo 't -32 -eq 32'
 
202
t -32 -eq 32
 
203
 
 
204
echo 't 200 -ne 200'
 
205
t 200 -ne 200
 
206
echo 't 34 -ne 222'
 
207
t 34 -ne 222
 
208
 
 
209
echo 't 200 -gt 200'
 
210
t 200 -gt 200
 
211
echo 't 340 -gt 222'
 
212
t 340 -gt 222
 
213
 
 
214
echo 't 200 -ge 200'
 
215
t 200 -ge 200
 
216
echo 't 34 -ge 222'
 
217
t 34 -ge 222
 
218
 
 
219
echo 't 200 -lt 200'
 
220
t 200 -lt 200
 
221
echo 't 34 -lt 222'
 
222
t 34 -lt 222
 
223
 
 
224
echo 't 200 -le 200'
 
225
t 200 -le 200
 
226
echo 't 340 -le 222'
 
227
t 340 -le 222
 
228
 
 
229
echo 't 700 -le 1000 -a -n "1" -a "20" = "20"'
 
230
t 700 -le 1000 -a -n "1" -a "20" = "20"
 
231
echo 't ! \( 700 -le 1000 -a -n "1" -a "20" = "20" \)'
 
232
t ! \( 700 -le 1000 -a -n "1" -a "20" = "20" \)
 
233
 
 
234
touch /tmp/abc
 
235
sleep 2
 
236
touch /tmp/def
 
237
 
 
238
echo 't /tmp/abc -nt /tmp/def'
 
239
t /tmp/abc -nt /tmp/def
 
240
echo 't /tmp/abc -ot /tmp/def'
 
241
t /tmp/abc -ot /tmp/def
 
242
echo 't /tmp/def -nt /tmp/abc'
 
243
t /tmp/def -nt /tmp/abc
 
244
echo 't /tmp/def -ot /tmp/abc'
 
245
t /tmp/def -ot /tmp/abc
 
246
 
 
247
echo 't /tmp/abc -ef /tmp/def'
 
248
t /tmp/abc -ef /tmp/def
 
249
ln /tmp/abc /tmp/ghi
 
250
echo 't /tmp/abc -ef /tmp/ghi'
 
251
t /tmp/abc -ef /tmp/ghi
 
252
 
 
253
rm /tmp/abc /tmp/def /tmp/ghi
 
254
 
 
255
echo 't -r /dev/fd/0'
 
256
t -r /dev/fd/0
 
257
echo 't -w /dev/fd/1'
 
258
t -w /dev/fd/1
 
259
echo 't -w /dev/fd/2'
 
260
t -w /dev/fd/2
 
261
 
 
262
echo 't -r /dev/stdin'
 
263
t -r /dev/stdin
 
264
echo 't -w /dev/stdout'
 
265
t -w /dev/stdout
 
266
echo 't -w /dev/stderr'
 
267
t -w /dev/stderr
 
268
 
 
269
echo 't'
 
270
t
 
271
echo 'b'
 
272
b
 
273
 
 
274
echo 't 12 -eq 34'
 
275
t 12 -eq 34
 
276
echo 't ! 12 -eq 34'
 
277
t ! 12 -eq 34
 
278
 
 
279
echo 't -n abcd -o aaa'
 
280
t -n abcd -o aaa
 
281
echo 't -n abcd -o -z aaa'
 
282
t -n abcd -o -z aaa
 
283
 
 
284
echo 't -n abcd -a aaa'
 
285
t -n abcd -a aaa
 
286
echo 't -n abcd -a -z aaa'
 
287
t -n abcd -a -z aaa
 
288
 
 
289
# test set or unset shell options
 
290
set +o allexport
 
291
echo 't -o allexport'
 
292
t -o allexport
 
293
echo 't ! -o allexport'
 
294
t ! -o allexport
 
295
 
 
296
#test set or unset shell variables
 
297
unset unset
 
298
echo 't -v unset'
 
299
t -v unset
 
300
set=
 
301
echo 't -v set'
 
302
t -v set
 
303
set=set
 
304
echo 't -v set'
 
305
t -v set
 
306
 
 
307
echo 't xx -a yy'
 
308
t xx -a yy
 
309
echo 't xx -o ""'
 
310
t xx -o ""
 
311
echo 't xx -a ""'
 
312
t xx -a ""
 
313
 
 
314
echo 't -X -a -X'
 
315
t -X -a -X
 
316
echo 't -X -o -X'
 
317
t -X -o -X
 
318
echo 't -X -o ""'
 
319
t -X -o ""
 
320
echo 't -X -a ""'
 
321
t -X -a ""
 
322
echo 't "" -a -X'
 
323
t "" -a -X
 
324
echo 't "" -o -X'
 
325
t "" -o -X
 
326
echo 't "" -a ""'
 
327
t "" -a ""
 
328
echo 't "" -o ""'
 
329
t "" -o ""
 
330
echo 't true -o -X'
 
331
t true -o -X
 
332
echo 't true -a -X'
 
333
t true -a -X
 
334
 
 
335
echo 't ( -E )'
 
336
t \( -E \)
 
337
echo 't ( "" )'
 
338
t \( "" \)
 
339
 
 
340
z=42
 
341
 
 
342
echo 't ! -z "$z"'
 
343
t ! -z "$z"
 
344
 
 
345
echo 't ! -n "$z"'
 
346
t ! -n "$z"
 
347
 
 
348
zero=
 
349
echo 't "$zero"'
 
350
t "$zero"
 
351
echo 't ! "$zero"'
 
352
t ! "$zero"
 
353
echo 'b "$zero"'
 
354
b "$zero"
 
355
echo 'b ! "$zero"'
 
356
b ! "$zero"
 
357
 
 
358
touch /tmp/test.group
 
359
chgrp ${GROUPS[0]} /tmp/test.group
 
360
echo 't -G /tmp/test.group'
 
361
t -G /tmp/test.group
 
362
rm /tmp/test.group
 
363
 
 
364
case "${THIS_SH}" in
 
365
/*)     SHNAME=${THIS_SH} ;;
 
366
*)      SHNAME=${PWD}/${THIS_SH} ;;
 
367
esac
 
368
 
 
369
if ln -s ${SHNAME} /tmp/test.symlink 2>/dev/null; then
 
370
        chgrp ${GROUPS[0]} /tmp/test.symlink 2>/dev/null
 
371
        echo 't -h /tmp/test.symlink'
 
372
        t -h /tmp/test.symlink
 
373
        # some systems don't let you remove this
 
374
        rm -f /tmp/test.symlink 2>/dev/null
 
375
else
 
376
        echo 't -h /tmp/test.symlink'
 
377
        echo 0
 
378
fi
 
379
 
 
380
# arithmetic constant errors
 
381
echo "t 4+3 -eq 7"
 
382
t 4+3 -eq 7
 
383
echo "b 4-5 -eq 7"
 
384
b 4+3 -eq 7
 
385
 
 
386
echo "t 9 -eq 4+5"
 
387
t 9 -eq 4+5
 
388
echo "b 9 -eq 4+5"
 
389
b 9 -eq 4+5
 
390
 
 
391
A=7
 
392
echo "t A -eq 7"
 
393
t A -eq 7
 
394
echo "b A -eq 7"
 
395
b A -eq 7
 
396
 
 
397
B=9
 
398
echo "t 9 -eq B"
 
399
t 9 -eq B
 
400
echo "b 9 -eq B"
 
401
b 9 -eq B
 
402
 
 
403
# badly formed expressions
 
404
echo 't ( 1 = 2'
 
405
t \( 1 = 2
 
406
echo 'b ( 1 = 2'
 
407
b \( 1 = 2
 
408
 
 
409
# more errors
 
410
t a b
 
411
t a b c
 
412
t -A v
 
413
# too many arguments -- argument expected is also reasonable
 
414
t 4 -eq 4 -a 2 -ne 5 -a 4 -ne
 
415
# too many arguments
 
416
t 4 -eq 4 -a 3 4
 
417
 
 
418
[
 
419
echo $?
 
420
 
 
421
t \( \)
 
422
 
 
423
# non-numeric arguments to `test -t' should return failure -- fix in 2.05
 
424
echo 't -t a'
 
425
t -t a
 
426
echo 't -t addsds'
 
427
t -t addsds
 
428
echo 't -t 42'
 
429
t -t 42
 
430
echo 't -t /dev/tty'
 
431
t -t /dev/tty
 
432
echo 't -t /dev/tty4'
 
433
t -t /dev/tty4
 
434
echo 't -t /dev/tty4444444...'
 
435
t -t /dev/tty4444444...
 
436
 
 
437
# fixed in bash-4.0-beta
 
438
t -t ' '