1
0
mirror of git://git.code.sf.net/p/zsh/code synced 2024-11-15 13:34:18 +01:00
zsh/Test/C02cond.ztst
Peter Stephenson e21bd541a2 24600: yet another typo
24602: fix test when not run
2008-02-26 20:50:11 +00:00

253 lines
5.9 KiB
Plaintext

# Tests corresponding to the texinfo node `Conditional Expressions'
%prep
umask 077
mkdir cond.tmp
cd cond.tmp
touch unmodified
touch zerolength
chgrp $EGID zerolength
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 ]]
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
print -u$ZTST_fd "Warning: not testing [[ -N file ]] (not supported on Cygwin)"
true
elif [[ "$(find . -prune -fstype nfs 2>/dev/null)" == "." ]]; then
print -u$ZTST_fd "Warning: not testing [[ -N file ]] (not supported with NFS)"
true
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 zerolength && ! (unmodified -nt zerolength) ]]
0:-nt cond
[[ zerolength -ot newnewnew && ! (zerolength -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 -i 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
%clean
# This works around a bug in rm -f in some versions of Cygwin
chmod 644 unmodish