2001-04-02 14:32:27 +02:00
|
|
|
# Tests corresponding to the texinfo node `Conditional Expressions'
|
|
|
|
|
|
|
|
%prep
|
|
|
|
|
|
|
|
umask 077
|
|
|
|
|
|
|
|
mkdir cond.tmp
|
|
|
|
|
|
|
|
cd cond.tmp
|
|
|
|
|
|
|
|
touch unmodified
|
|
|
|
|
|
|
|
touch zerolength
|
|
|
|
chgrp $EGID zerolength
|
2001-08-22 17:59:27 +02:00
|
|
|
|
2001-04-02 14:32:27 +02:00
|
|
|
print 'Garbuglio' >nonzerolength
|
|
|
|
|
|
|
|
mkdir modish
|
2001-06-09 20:14:58 +02:00
|
|
|
chgrp $EGID modish
|
2001-08-22 17:59:27 +02:00
|
|
|
|
2001-09-27 17:50:15 +02:00
|
|
|
chmod 7710 modish # g+xs,u+s,+t
|
2001-10-10 18:02:24 +02:00
|
|
|
chmod g+s modish # two lines combined work around chmod bugs
|
2001-04-02 14:32:27 +02:00
|
|
|
|
2001-05-24 05:06:24 +02:00
|
|
|
touch unmodish
|
|
|
|
chmod 000 unmodish
|
2001-05-30 12:56:42 +02:00
|
|
|
|
|
|
|
print 'MZ' > cmd.exe
|
|
|
|
chmod +x cmd.exe
|
2001-04-02 14:32:27 +02:00
|
|
|
%test
|
|
|
|
|
|
|
|
[[ -a zerolength && ! -a nonexistent ]]
|
|
|
|
0:-a cond
|
|
|
|
|
|
|
|
# Find a block special file system. This is a little tricky.
|
2001-05-28 18:33:54 +02:00
|
|
|
block=$(find /dev(|ices)/ -type b -print)
|
2001-05-26 10:41:01 +02:00
|
|
|
if [[ -n $block ]]; then
|
2001-05-26 03:51:28 +02:00
|
|
|
[[ -b $block[(f)1] && ! -b zerolength ]]
|
|
|
|
else
|
|
|
|
print -u8 'Warning: Not testing [[ -b blockdevice ]] (no devices found)'
|
|
|
|
[[ ! -b zerolength ]]
|
|
|
|
fi
|
|
|
|
0D:-b cond
|
2001-04-02 14:32:27 +02:00
|
|
|
|
2001-05-28 18:33:54 +02:00
|
|
|
# Use hardcoded /dev/tty because globbing inside /dev fails on Cygwin
|
|
|
|
char=/dev/tty
|
|
|
|
[[ -c $char && ! -c $zerolength ]]
|
2001-04-02 14:32:27 +02:00
|
|
|
0:-c cond
|
|
|
|
|
|
|
|
[[ -d . && ! -d zerolength ]]
|
|
|
|
0:-d cond
|
|
|
|
|
|
|
|
[[ -e zerolength && ! -e nonexistent ]]
|
|
|
|
0:-e cond
|
|
|
|
|
|
|
|
[[ -f zerolength && ! -f cond && ! -f $char && ! -f $block && ! -f . ]]
|
|
|
|
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
|
|
|
|
|
2001-05-28 18:33:54 +02:00
|
|
|
if ! grep '#define HAVE_FIFOS' $ZTST_testdir/../config.h; then
|
|
|
|
print -u8 'Warning: Not testing [[ -p pipe ]] (FIFOs not supported)'
|
|
|
|
[[ ! -p zerolength ]]
|
2001-04-02 14:32:27 +02:00
|
|
|
else
|
2001-05-28 18:33:54 +02:00
|
|
|
if whence mkfifo && mkfifo pipe || mknod pipe p; then
|
|
|
|
[[ -p pipe && ! -p zerolength ]]
|
|
|
|
else
|
|
|
|
print -u8 'Warning: Not testing [[ -p pipe ]] (cannot create FIFO)'
|
|
|
|
[[ ! -p zerolength ]]
|
|
|
|
fi
|
2001-04-02 14:32:27 +02:00
|
|
|
fi
|
2001-05-28 18:33:54 +02:00
|
|
|
0dD:-p cond
|
2001-04-02 14:32:27 +02:00
|
|
|
|
2001-08-22 17:59:27 +02:00
|
|
|
if (( EUID == 0 )); then
|
|
|
|
print -u8 'Warning: Not testing [[ ! -r file ]] (root reads anything)'
|
|
|
|
[[ -r zerolength && -r unmodish ]]
|
|
|
|
else
|
|
|
|
[[ -r zerolength && ! -r unmodish ]]
|
|
|
|
fi
|
2001-04-02 14:32:27 +02:00
|
|
|
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
|
|
|
|
|
2001-05-30 12:56:42 +02:00
|
|
|
[[ -x cmd.exe && ! -x zerolength ]]
|
2001-04-02 14:32:27 +02:00
|
|
|
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
|
|
|
|
|
|
|
|
sleep 1
|
|
|
|
cat unmodified
|
|
|
|
touch newnewnew
|
2001-05-30 12:56:42 +02:00
|
|
|
if [[ $OSTYPE == "cygwin" ]]; then
|
|
|
|
print -u8 "Warning: not testing [[ -N file ]] (not supported on Cygwin)"
|
|
|
|
true
|
|
|
|
else
|
|
|
|
[[ -N newnewnew && ! -N unmodified ]]
|
|
|
|
fi
|
2001-04-02 14:32:27 +02:00
|
|
|
0:-N cond
|
|
|
|
|
|
|
|
[[ 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
|
|
|
|
|
2001-05-30 12:56:42 +02:00
|
|
|
if ! grep '#define PATH_DEV_FD' $ZTST_testdir/../config.h; then
|
|
|
|
print -u8 "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
|
2001-04-02 14:32:27 +02:00
|
|
|
|
2001-05-30 12:56:42 +02:00
|
|
|
if ! grep '#define PATH_DEV_FD' $ZTST_testdir/../config.h; then
|
|
|
|
print -u8 "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
|
2001-04-02 14:32:27 +02:00
|
|
|
|
|
|
|
[[ ( -z foo && -z foo ) || -z foo ]]
|
|
|
|
1:complex conds with skipping
|
|
|
|
|
|
|
|
[ '' != bar -a '' = '' ]
|
|
|
|
0:strings with `[' builtin
|
|
|
|
|
|
|
|
[ `echo 0` -lt `echo 1` ]
|
|
|
|
0:substituion in `[' builtin
|
2001-05-24 05:06:24 +02:00
|
|
|
|
|
|
|
%clean
|
|
|
|
# This works around a bug in rm -f in some versions of Cygwin
|
|
|
|
chmod 644 unmodish
|