From c30917f6bb3a78a001d2928730d6b701da69bf5c Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Wed, 2 Feb 2005 17:02:16 +0000 Subject: Test -nt and FOO=BAR BAR=FOO echo bugs --- ChangeLog | 3 + Test/A06assign.ztst | 279 ++++++++++++++++++++++++++++++++++++++++++++++++++++ Test/C02cond.ztst | 210 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 492 insertions(+) create mode 100644 Test/A06assign.ztst create mode 100644 Test/C02cond.ztst diff --git a/ChangeLog b/ChangeLog index a397e2748..f97369ed5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2005-02-02 Peter Stephenson + * 2077: Test/A06assign.ztst, Test/C02cond.ztst: tests for + users/8422 and 20774. + * unposted: README, Config/version.mk, Etc/FAQ.yo: update version number to 4.2.4. diff --git a/Test/A06assign.ztst b/Test/A06assign.ztst new file mode 100644 index 000000000..bbed909c5 --- /dev/null +++ b/Test/A06assign.ztst @@ -0,0 +1,279 @@ +# Tests of parameter assignments + +%test + + typeset -A assoc + assoc=(one 1 two 2 odd) +1:assign to association with odd no. of values +?(eval):2: bad set of key/value pairs for associative array + +# tests of var+=scalar + + s+=foo + echo $s +0:append scalar to unset scalar +>foo + + s=foo + s+=bar + echo $s +0:append to scalar +>foobar + + set -- a b c + 2+=end + echo $2 +0:append to positional parameter +>bend + + a=(first second) + a+=last + print -l $a +0:add scalar to array +>first +>second +>last + + setopt ksharrays + a=(first second) + a+=last + print -l $a + unsetopt ksharrays +0:add scalar to array with ksharrays set +>firstlast + + a=(1 2) + a[@]+=3 + print -l $a +0:add scalar to array with alternate syntax +>1 +>2 +>3 + + integer i=10 + i+=20 + (( i == 30 )) +0:add to integer + + float f=3.4 + f+=2.3 + printf "%g\n" f +0:add to float +>5.7 + + typeset -A hash + hash=(one 1) + h+=string + [[ $h[@] == string ]] +0:add scalar to association + +# tests of var+=(array) + + unset a + a+=(1 2 3) + print -l $a +0:add array to unset parameter +>1 +>2 +>3 + + a=(a) + a+=(b) + print -l $a +0:add array to existing array +>a +>b + + s=foo + s+=(bar) + print -l $s +0:add array to scalar +>foo +>bar + + integer i=1 + i+=(2 3) + print -l $i +0:add array to integer +>1 +>2 +>3 + + float f=2.5 + f+=(3.5 4.5) + printf '%g\n' $f +0:add array to float +>2.5 +>3.5 +>4.5 + + typeset -A h + h+=(a 1 b 2) + print -l $h +0:add to empty association +>1 +>2 + + typeset -A h + h=(a 1) + h+=(b 2 c 3) + print -l $h +0:add to association +>1 +>2 +>3 + +# tests of var[range]+=scalar + + s=sting + s[2]+=art + echo $s +0:insert scalar inside another +>starting + + s=inert + s[-4]+=s + echo $s +0:insert scalar inside another with negative index +>insert + + s=append + s[2,6]+=age + echo $s +0:append scalar to scalar using a range +>appendage + + s=123456789 + s[3,-5]+=X + echo $s +0:insert scalar inside another, specifying a slice +>12345X6789 + + a=(a b c) + a[2]+=oo + echo $a +0:append to array element +>a boo c + + a=(a b c d) + a[-2]+=ool + echo $a +0:append to array element with negative index +>a b cool d + + a=(a b c d) + a[2,-1]+=oom + echo $a +0:append to array element, specifying a slice +>a b c doom + + setopt ksharrays + a=(a b c d) + a[0]+=0 + echo $a + unsetopt ksharrays +0:append to array element with ksharrays set +>a0 + + typeset -A h + h=(one foo) + h[one]+=bar + echo $h +0:append to association element +>foobar + + typeset -A h + h[foo]+=bar + echo ${(kv)h} +0:append to non-existent association element +>foo bar + + typeset -A h + h=(one a two b three c four d) + h[(I)*o*]+=append +1:attempt to append to slice of association +?(eval):3: h: attempt to set slice of associative array + + integer i=123 + i[2]+=6 +1:attempt to add to indexed integer variable +?(eval):2: attempt to add to slice of a numeric variable + + float f=1234.5 + f[2,4]+=3 +1:attempt to add to slice of float variable +?(eval):2: attempt to add to slice of a numeric variable + + unset u + u[3]+=third + echo $u[1]:$u[3] +0:append to unset variable with index +>:third + +# tests of var[range]+=(array) + + a=(1 2 3) + a[2]+=(a b) + echo $a +0:insert array inside another +>1 2 a b 3 + + a=(a b c) + a[-1]+=(d) + echo $a +0:append to array using negative index +>a b c d + + a=(1 2 3 4) + a[-1,-3]+=(x) + echo $a +0:insert array using negative range +>1 2 x 3 4 + + s=string + s[2]+=(a b) +1:attempt to insert array into string +?(eval):2: s: attempt to assign array value to non-array + + integer i=365 + i[2]+=(1 2) +1:attempt to insert array into string +?(eval):2: i: attempt to assign array value to non-array + + typeset -A h + h=(a 1) + h[a]+=(b 2) +1:attempt to append array to hash element +?(eval):3: h: attempt to set slice of associative array + + unset u + u[-34,-2]+=(a z) + echo $u +0:add array to indexed unset variable +>a z + + repeat 10 PATH=. echo hello +0:saving and restoring of exported special parameters +>hello +>hello +>hello +>hello +>hello +>hello +>hello +>hello +>hello +>hello + + repeat 10 FOO=BAR BAR=FOO echo $FOO $BAR +0:save and restore multiple variables around builtin +> +> +> +> +> +> +> +> +> +> diff --git a/Test/C02cond.ztst b/Test/C02cond.ztst new file mode 100644 index 000000000..3104a8680 --- /dev/null +++ b/Test/C02cond.ztst @@ -0,0 +1,210 @@ +# 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 -u8 '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 -u8 '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 -u8 '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 -u8 'Warning: Not testing [[ -p pipe ]] (cannot create FIFO)' + [[ ! -p zerolength ]] + fi + fi +0dD:-p cond + + if (( EUID == 0 )); then + print -u8 '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 + + sleep 1 + cat unmodified + touch newnewnew + if [[ $OSTYPE == "cygwin" ]]; then + print -u8 "Warning: not testing [[ -N file ]] (not supported on Cygwin)" + 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. This does 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 -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 + + 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 + + [[ ( -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 + + 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 + +%clean + # This works around a bug in rm -f in some versions of Cygwin + chmod 644 unmodish -- cgit 1.4.1