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
|
# Tests corresponding to the texinfo node `Conditional Expressions'
%prep
umask 077
mkdir cond.tmp
cd cond.tmp
typeset -gi isnfs
[[ "$(find . -prune -fstype nfs 2>/dev/null)" == "." ]] && isnfs=1
if (( isnfs )) &&
(cd -q ${TMPPREFIX:h} >/dev/null 2>&1 &&
[[ "$(find . -prune -fstype nfs 2>/dev/null)" != "." ]]); then
filetmpprefix=${TMPPREFIX}-$$-
isnfs=0
else
filetmpprefix=
fi
newnewnew=${filetmpprefix}newnewnew
unmodified=${filetmpprefix}unmodified
zlnfs=${filetmpprefix}zlnfs
touch $unmodified
touch zerolength
chgrp $EGID zerolength
touch $zlnfs
chgrp $EGID $zlnfs
print 'Garbuglio' >nonzerolength
mkdir modish
chgrp $EGID modish
chmod 7710 modish # g+xs,u+s,+t
chmod g+s modish # two lines combined work around chmod bugs
touch unmodish
chmod 000 unmodish
print 'MZ' > cmd.exe
chmod +x cmd.exe
%test
[[ -a zerolength && ! -a nonexistent ]]
0:-a cond
# Find a block special file system. This is a little tricky.
block=$(find /dev(|ices)/ -type b -print)
if [[ -n $block ]]; then
[[ -b $block[(f)1] && ! -b zerolength ]]
else
print -u$ZTST_fd 'Warning: Not testing [[ -b blockdevice ]] (no devices found)'
[[ ! -b zerolength ]]
fi
0D:-b cond
# Use hardcoded /dev/tty because globbing inside /dev fails on Cygwin
char=/dev/tty
[[ -c $char && ! -c $zerolength ]]
0:-c cond
[[ -d . && ! -d zerolength ]]
0:-d cond
[[ -e zerolength && ! -e nonexistent ]]
0:-e cond
if [[ -n $block ]]; then
[[ -f zerolength && ! -f cond && ! -f $char && ! -f $block[(f)1] && ! -f . ]]
else
print -u$ZTST_fd 'Warning: Not testing [[ -f blockdevice ]] (no devices found)'
[[ -f zerolength && ! -f cond && ! -f $char && ! -f . ]]
fi
0:-f cond
[[ -g modish && ! -g zerolength ]]
0:-g cond
ln -s zerolength link
[[ -h link && ! -h zerolength ]]
0:-h cond
[[ -k modish && ! -k zerolength ]]
0:-k cond
foo=foo
bar=
[[ -n $foo && ! -n $bar && ! -n '' ]]
0:-n cond
[[ -o rcs && ! -o norcs && -o noerrexit && ! -o errexit ]]
0:-o cond
if ! grep '#define HAVE_FIFOS' $ZTST_testdir/../config.h; then
print -u$ZTST_fd 'Warning: Not testing [[ -p pipe ]] (FIFOs not supported)'
[[ ! -p zerolength ]]
else
if whence mkfifo && mkfifo pipe || mknod pipe p; then
[[ -p pipe && ! -p zerolength ]]
else
print -u$ZTST_fd 'Warning: Not testing [[ -p pipe ]] (cannot create FIFO)'
[[ ! -p zerolength ]]
fi
fi
0dD:-p cond
if (( EUID == 0 )); then
print -u$ZTST_fd 'Warning: Not testing [[ ! -r file ]] (root reads anything)'
[[ -r zerolength && -r unmodish ]]
elif [[ $OSTYPE = cygwin ]]; then
print -u$ZTST_fd 'Warning: Not testing [[ ! -r file ]]
(all files created by user may be readable)'
[[ -r zerolength ]]
else
[[ -r zerolength && ! -r unmodish ]]
fi
0:-r cond
[[ -s nonzerolength && ! -s zerolength ]]
0:-s cond
# no simple way of guaranteeing test for -t
[[ -u modish && ! -u zerolength ]]
0:-u cond
[[ -x cmd.exe && ! -x zerolength ]]
0:-x cond
[[ -z $bar && -z '' && ! -z $foo ]]
0:-z cond
[[ -L link && ! -L zerolength ]]
0:-L cond
# hard to guarantee a file not owned by current uid
[[ -O zerolength ]]
0:-O cond
[[ -G zerolength ]]
0:-G cond
# can't be bothered with -S
print -u $ZTST_fd 'This test takes two seconds...'
sleep 2
cat $unmodified
touch $newnewnew
if [[ $OSTYPE == "cygwin" ]]; then
ZTST_skip="[[ -N file ]] not supported on Cygwin"
elif (( isnfs )); then
ZTST_skip="[[ -N file ]] not supported with NFS"
elif { df -k -- ${$({mount || /sbin/mount} | awk '/noatime/ {print $1,$3}'):-""} | tr -s ' ' | fgrep "$(df -k . | tail -1 | tr -s ' ')" } >&/dev/null; then
ZTST_skip="[[ -N file ]] not supported with noatime file system"
else
[[ -N $newnewnew && ! -N $unmodified ]]
fi
0:-N cond
F:This test can fail on NFS-mounted filesystems as the access and
F:modification times are not updated separately. The test will fail
F:on HFS+ (Apple Mac OS X default) filesystems because access times
F:are not recorded. Also, Linux ext3 filesystems may be mounted
F:with the noatime option which does not update access times.
F:Failures in these cases do not indicate a problem in the shell.
[[ $newnewnew -nt $zlnfs && ! ($unmodified -nt $zlnfs) ]]
0:-nt cond
[[ $zlnfs -ot $newnewnew && ! ($zlnfs -ot $unmodified) ]]
0:-ot cond
[[ link -ef zerolength && ! (link -ef nonzerolength) ]]
0:-ef cond
[[ foo = foo && foo != bar && foo == foo && foo != '' ]]
0:=, == and != conds
[[ bar < foo && foo > bar ]]
0:< and > conds
[[ $(( 3 + 4 )) -eq 0x07 && $(( 5 * 2 )) -ne 0x10 ]]
0:-eq and -ne conds
[[ 3 -lt 04 && 05 -gt 2 ]]
0:-lt and -gt conds
[[ 3 -le 3 && ! (4 -le 3) ]]
0:-le cond
[[ 3 -ge 3 && ! (3 -ge 4) ]]
0:-ge cond
[[ 1 -lt 2 || 2 -lt 2 && 3 -gt 4 ]]
0:|| and && in conds
if ! grep '#define PATH_DEV_FD' $ZTST_testdir/../config.h; then
print -u$ZTST_fd "Warning: not testing [[ -e /dev/fd/0 ]] (/dev/fd not supported)"
true
else
[[ -e /dev/fd/0 ]]
fi
0dD:/dev/fd support in conds handled by access
if ! grep '#define PATH_DEV_FD' $ZTST_testdir/../config.h; then
print -u$ZTST_fd "Warning: not testing [[ -O /dev/fd/0 ]] (/dev/fd not supported)"
true
else
[[ -O /dev/fd/0 ]]
fi
0dD:/dev/fd support in conds handled by stat
[[ ( -z foo && -z foo ) || -z foo ]]
1:complex conds with skipping
[ '' != bar -a '' = '' ]
0:strings with `[' builtin
[ `echo 0` -lt `echo 1` ]
0:substitution in `[' builtin
[ -n foo scrimble ]
1:argument checking for [ builtin
?(eval):[:1: too many arguments
test -n foo scramble
1:argument checking for test builtin
?(eval):test:1: too many arguments
[ -n foo scrimble scromble ]
1:argument checking for [ builtin
?(eval):[:1: too many arguments
test -n foo scramble scrumble
1:argument checking for test builtin
?(eval):test:1: too many arguments
[ -n foo -a -n bar scrimble ]
1:argument checking for [ builtin
?(eval):[:1: too many arguments
test -n foo -a -z "" scramble
1:argument checking for test builtin
?(eval):test:1: too many arguments
fn() {
# careful: first file must exist to trigger bug
[[ -e $unmodified ]] || print Where\'s my file\?
[[ $unmodified -nt NonExistentFile ]]
print status = $?
}
fn
0:-nt shouldn't abort on non-existent files
>status = 1
# core dumps on failure
if zmodload zsh/regex 2>/dev/null; then
echo >regex_test.sh 'if [[ $# = 1 ]]; then
if [[ $1 =~ /?[^/]+:[0-9]+:$ ]]; then
:
fi
fi
exit 0'
$ZTST_testdir/../Src/zsh -f ./regex_test.sh
fi
0:regex tests shouldn't crash
if zmodload zsh/regex 2>/dev/null; then
( # subshell in case coredump test failed
string="this has stuff in it"
bad_regex=0
if [[ $string =~ "h([a-z]*) s([a-z]*) " ]]; then
if [[ "$MATCH $MBEGIN $MEND" != "has stuff 6 15" ]]; then
print -r "regex variables MATCH MBEGIN MEND:
'$MATCH $MBEGIN $MEND'
should be:
'has stuff 6 15'"
bad_regex=1
else
results=("as 7 8" "tuff 11 14")
for i in 1 2; do
if [[ "$match[$i] $mbegin[$i] $mend[$i]" != $results[i] ]]; then
print -r "regex variables match[$i] mbegin[$i] mend[$i]:
'$match[$i] $mbegin[$i] $mend[$i]'
should be
'$results[$i]'"
bad_regex=1
break
fi
done
fi
(( bad_regex )) || print OK
else
print -r "regex failed to match '$string'"
fi
)
else
# if it didn't load, tough, but not a test error
ZTST_skip="regexp library not found."
fi
0:MATCH, MBEGIN, MEND, match, mbegin, mend
>OK
if zmodload zsh/regex 2>/dev/null; then
( # subshell because regex module may dump core, see above
if [[ a =~ a && b == b ]]; then
print OK
else
print "regex =~ inverted following test"
fi
)
else
# not a test error
ZTST_skip="regexp library not found."
fi
0:regex infix operator should not invert following conditions
>OK
[[ -fail badly ]]
2:Error message for unknown prefix condition
?(eval):1: unknown condition: -fail
[[ really -fail badly ]]
2:Error message for unknown infix condition
?(eval):1: unknown condition: -fail
crashme() {
if [[ $1 =~ ^http:* ]]
then
url=${1#*=}
fi
}
which crashme
0:Regression test for examining code with regular expression match
>crashme () {
> if [[ $1 =~ ^http:* ]]
> then
> url=${1#*=}
> fi
>}
weirdies=(
'! -a !'
'! -o !'
'! -a'
'! -o'
'! -a ! -a !'
'! = !'
'! !'
'= -a o'
'! = -a o')
for w in $weirdies; do
eval test $w
print $?
done
0:test compatability weirdness: treat ! as a string sometimes
>0
>0
>1
>0
>0
>0
>1
>0
>1
foo=''
[[ $foo ]] || print foo is empty
foo=full
[[ $foo ]] && print foo is full
0:bash compatibility with single [[ ... ]] argument
>foo is empty
>foo is full
test -z \( || print Not zero 1
test -z \< || print Not zero 2
test -n \( && print Not zero 3
test -n \) && print Not zero 4
[ -n \> ] && print Not zero 5
[ -n \! ] && print Not zero 6
0:test with two arguments and a token
>Not zero 1
>Not zero 2
>Not zero 3
>Not zero 4
>Not zero 5
>Not zero 6
[ '(' = ')' ] || print OK 1
[ '((' = '))' ] || print OK 2
[ '(' = '(' ] && print OK 3
[ '(' non-empty-string ')' ] && echo OK 4
[ '(' '' ')' ] || echo OK 5
0:yet more old-fashioned test fix ups: prefer comparison to parentheses
>OK 1
>OK 2
>OK 3
>OK 4
>OK 5
%clean
# This works around a bug in rm -f in some versions of Cygwin
chmod 644 unmodish
for tmpfile in $newnewnew $unmodified $zlnfs; do
[[ -f $tmpfile ]] && rm -f $tmpfile
done
|