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