1 # Tests corresponding to the texinfo node `Conditional Expressions'
14 chgrp $EGID zerolength
16 print 'Garbuglio' >nonzerolength
21 chmod 7710 modish # g+xs,u+s,+t
22 chmod g+s modish # two lines combined work around chmod bugs
31 [[ -a zerolength && ! -a nonexistent ]]
34 # Find a block special file system. This is a little tricky.
35 block=$(find /dev(|ices)/ -type b -print)
36 if [[ -n $block ]]; then
37 [[ -b $block[(f)1] && ! -b zerolength ]]
39 print -u$ZTST_fd 'Warning: Not testing [[ -b blockdevice ]] (no devices found)'
44 # Use hardcoded /dev/tty because globbing inside /dev fails on Cygwin
46 [[ -c $char && ! -c $zerolength ]]
49 [[ -d . && ! -d zerolength ]]
52 [[ -e zerolength && ! -e nonexistent ]]
55 if [[ -n $block ]]; then
56 [[ -f zerolength && ! -f cond && ! -f $char && ! -f $block[(f)1] && ! -f . ]]
58 print -u$ZTST_fd 'Warning: Not testing [[ -f blockdevice ]] (no devices found)'
59 [[ -f zerolength && ! -f cond && ! -f $char && ! -f . ]]
63 [[ -g modish && ! -g zerolength ]]
67 [[ -h link && ! -h zerolength ]]
70 [[ -k modish && ! -k zerolength ]]
75 [[ -n $foo && ! -n $bar && ! -n '' ]]
78 [[ -o rcs && ! -o norcs && -o noerrexit && ! -o errexit ]]
81 if ! grep '#define HAVE_FIFOS' $ZTST_testdir/../config.h; then
82 print -u$ZTST_fd 'Warning: Not testing [[ -p pipe ]] (FIFOs not supported)'
85 if whence mkfifo && mkfifo pipe || mknod pipe p; then
86 [[ -p pipe && ! -p zerolength ]]
88 print -u$ZTST_fd 'Warning: Not testing [[ -p pipe ]] (cannot create FIFO)'
94 if (( EUID == 0 )); then
95 print -u$ZTST_fd 'Warning: Not testing [[ ! -r file ]] (root reads anything)'
96 [[ -r zerolength && -r unmodish ]]
97 elif [[ $OSTYPE = cygwin ]]; then
98 print -u$ZTST_fd 'Warning: Not testing [[ ! -r file ]]
99 (all files created by user may be readable)'
102 [[ -r zerolength && ! -r unmodish ]]
106 [[ -s nonzerolength && ! -s zerolength ]]
109 # no simple way of guaranteeing test for -t
111 [[ -u modish && ! -u zerolength ]]
114 [[ -x cmd.exe && ! -x zerolength ]]
117 [[ -z $bar && -z '' && ! -z $foo ]]
120 [[ -L link && ! -L zerolength ]]
123 # hard to guarantee a file not owned by current uid
130 # can't be bothered with -S
132 print -u $ZTST_fd 'This test takes two seconds...'
136 if [[ $OSTYPE == "cygwin" ]]; then
137 print -u$ZTST_fd "Warning: not testing [[ -N file ]] (not supported on Cygwin)"
139 elif [[ "$(find . -prune -fstype nfs 2>/dev/null)" == "." ]]; then
140 print -u$ZTST_fd "Warning: not testing [[ -N file ]] (not supported with NFS)"
143 [[ -N newnewnew && ! -N unmodified ]]
146 F:This test can fail on NFS-mounted filesystems as the access and
147 F:modification times are not updated separately. The test will fail
148 F:on HFS+ (Apple Mac OS X default) filesystems because access times
149 F:are not recorded. Also, Linux ext3 filesystems may be mounted
150 F:with the noatime option which does not update access times.
151 F:Failures in these cases do not indicate a problem in the shell.
153 [[ newnewnew -nt zerolength && ! (unmodified -nt zerolength) ]]
156 [[ zerolength -ot newnewnew && ! (zerolength -ot unmodified) ]]
159 [[ link -ef zerolength && ! (link -ef nonzerolength) ]]
162 [[ foo = foo && foo != bar && foo == foo && foo != '' ]]
165 [[ bar < foo && foo > bar ]]
168 [[ $(( 3 + 4 )) -eq 0x07 && $(( 5 * 2 )) -ne 0x10 ]]
171 [[ 3 -lt 04 && 05 -gt 2 ]]
174 [[ 3 -le 3 && ! (4 -le 3) ]]
177 [[ 3 -ge 3 && ! (3 -ge 4) ]]
180 [[ 1 -lt 2 || 2 -lt 2 && 3 -gt 4 ]]
183 if ! grep '#define PATH_DEV_FD' $ZTST_testdir/../config.h; then
184 print -u$ZTST_fd "Warning: not testing [[ -e /dev/fd/0 ]] (/dev/fd not supported)"
189 0dD:/dev/fd support in conds handled by access
191 if ! grep '#define PATH_DEV_FD' $ZTST_testdir/../config.h; then
192 print -u$ZTST_fd "Warning: not testing [[ -O /dev/fd/0 ]] (/dev/fd not supported)"
197 0dD:/dev/fd support in conds handled by stat
199 [[ ( -z foo && -z foo ) || -z foo ]]
200 1:complex conds with skipping
202 [ '' != bar -a '' = '' ]
203 0:strings with `[' builtin
205 [ `echo 0` -lt `echo 1` ]
206 0:substitution in `[' builtin
209 1:argument checking for [ builtin
210 ?(eval):[:1: too many arguments
213 1:argument checking for test builtin
214 ?(eval):test:1: too many arguments
216 [ -n foo scrimble scromble ]
217 1:argument checking for [ builtin
218 ?(eval):[:1: too many arguments
220 test -n foo scramble scrumble
221 1:argument checking for test builtin
222 ?(eval):test:1: too many arguments
224 [ -n foo -a -n bar scrimble ]
225 1:argument checking for [ builtin
226 ?(eval):[:1: too many arguments
228 test -n foo -a -z "" scramble
229 1:argument checking for test builtin
230 ?(eval):test:1: too many arguments
233 # careful: first file must exist to trigger bug
234 [[ -e unmodified ]] || print Where\'s my file\?
235 [[ unmodified -nt NonExistentFile ]]
239 0:-nt shouldn't abort on non-existent files
242 # core dumps on failure
243 if zmodload -i zsh/regex 2>/dev/null; then
244 echo >regex_test.sh 'if [[ $# = 1 ]]; then
245 if [[ $1 =~ /?[^/]+:[0-9]+:$ ]]; then
250 $ZTST_testdir/../Src/zsh -f ./regex_test.sh
252 0:regex tests shouldn't crash
255 # This works around a bug in rm -f in some versions of Cygwin