summaryrefslogtreecommitdiff
path: root/usr/src/lib/libshell/common/tests/variables.sh
diff options
context:
space:
mode:
authorRoland Mainz <roland.mainz@nrubsig.org>2009-10-28 10:36:39 -0700
committerRoland Mainz <roland.mainz@nrubsig.org>2009-10-28 10:36:39 -0700
commit34f9b3eef6fdadbda0a846aa4d68691ac40eace5 (patch)
tree0b0fdfb35f8eb9324728de5a99e50e939aca650f /usr/src/lib/libshell/common/tests/variables.sh
parent14969419acb89bb74e6c95fa472119b710224440 (diff)
downloadillumos-gate-34f9b3eef6fdadbda0a846aa4d68691ac40eace5.tar.gz
Portions contributed by Olga Kryzhanovska <olga.kryzhanovska@gmail.com>
PSARC/2009/063 ksh93 update 2 PSARC/2009/248 ksh93 update to 2009-03-10 PSARC/2009/249 more ksh93 command conversions 6888396 libast sources should not include localedef.h 6605478 ksh93 profile shell option does not work 6631006 ksh93 hangs in situations that ksh handles okay 6661487 logname reports nothing after running the script command 6705126 first call to read doesn't honor new setting of HISTFILE 6764665 *libpp* Array overrun in libpp 6765756 *libast* Array overruns in libast 6769332 Recursive function+command substitutions terminate shell after 257 iterations 6777491 *ksh93* lacks arithmetric function iszero() 6778077 *ksh93* does not understand "THAW" as a signal for use with trap 6789247 [ku1] libast/ksh93 1-digit hexfloat base conversion rounds incorrectly 6791838 *ksh93* unset of a variable which is not set should return 0 6793714 RFE: Update /usr/bin/comm to AT&T AST "comm" 6793719 RFE: Update /usr/bin/cut to AT&T AST "cut" 6793721 RFE: Update /usr/bin/paste to AT&T AST "paste" 6793722 RFE: Update /usr/bin/cmp to AT&T AST "cmp" 6793726 RFE: Update /usr/bin/uniq to AT&T AST "uniq" 6793735 RFE: Update /usr/bin/wc to AT&T AST "wc" 6793744 RFE: Add /usr/share/doc/ksh/ for ksh93 documentation 6793747 RFE: Provide "print" builtin as /usr/bin/print for external applications 6793763 RFE: Update /usr/bin/ksh93 to ast-ksh.2009-05-05 6794952 RFE: Enable "globstar" mode in /etc/ksh.kshrc (= interactive ksh93 shells) 6805792 [ku1] Moving local compound var into array does not work 6805794 [ku1] printf returns "invalid character constant" for $ printf "%d\n" "'<euro>" 6805795 [ku1] ksh93 does not differ between -0 and +0 6805797 [ku1]Can't append to nodes of an array of compound vars if addressing them via nameref 6805799 Indexed compound variable arrays do not work... 6805800 [ku1] Declaring associative compound array does not work 6805813 RFE: Update /usr/bin/join to AT&T AST "join". 6805819 RFE: Update /usr/bin/tee to AT&T AST "tee". 6809663 shlint missing ending newline on errors 6811916 ksh93 repeatedly segfaults when "tee" builtin is interrupted via <ctrl-c> in interactive mode 6821113 SUNWosdem package issues 6828644 RFE: Update /usr/bin/logname to AT&T AST "logname". 6828692 RFE: Update /usr/bin/cksum to AT&T AST "cksum". 6834184 ksh93 gets SIGSEGV if HISTFILE is changed in place. 6834207 ksh93 gets SIGSEGV on interactive function definition with HISTSIZE unset 6835835 ksh93 "cat" builtin does not handle "-n" correctly 6841442 Need exception list for OS/Net trees managed via Subversion 6848486 "echo ${test}" with test undefined crashes the shell 6850672 ksh93 (VISUAL=vi) crashes with memory fault while scrolling through history 6855875 typeset -X x ; print $x # does not print sufficient digits to restore value 6857344 /usr/bin/hash core dump with invalid arguments 6866676 Need test suite module to test the kernel support for compiled shell scripts 6881017 Subshell doesn't exit, holds pipe open preventing callers from exiting 6884409 fts functions in libast library can result in segv with deep dir trees (similar to CERT VU#590371)
Diffstat (limited to 'usr/src/lib/libshell/common/tests/variables.sh')
-rw-r--r--usr/src/lib/libshell/common/tests/variables.sh119
1 files changed, 72 insertions, 47 deletions
diff --git a/usr/src/lib/libshell/common/tests/variables.sh b/usr/src/lib/libshell/common/tests/variables.sh
index 1808d2fbcf..f174a9a2bf 100644
--- a/usr/src/lib/libshell/common/tests/variables.sh
+++ b/usr/src/lib/libshell/common/tests/variables.sh
@@ -1,7 +1,7 @@
########################################################################
# #
# This software is part of the ast package #
-# Copyright (c) 1982-2008 AT&T Intellectual Property #
+# Copyright (c) 1982-2009 AT&T Intellectual Property #
# and is licensed under the #
# Common Public License, Version 1.0 #
# by AT&T Intellectual Property #
@@ -28,11 +28,14 @@ alias err_exit='err_exit $LINENO'
Command=${0##*/}
integer Errors=0
+tmp=$(mktemp -dt) || { err_exit mktemp -dt failed; exit 1; }
+trap "cd /; rm -rf $tmp" EXIT
+
[[ ${.sh.version} == "$KSH_VERSION" ]] || err_exit '.sh.version != KSH_VERSION'
unset ss
-[[ ${@ss} ]] && err_exit '${@ss} should be empty string when ss is unset'
-[[ ${!ss} == ss ]] || err_exit '${!ss} should be ss when ss is unset'
-[[ ${#ss} == 0 ]] || err_exit '${#ss} should be 0 when ss is unset'
+[[ ${@ss} ]] && err_exit '${@ss} should be empty string when ss is unset'
+[[ ${!ss} == ss ]] || err_exit '${!ss} should be ss when ss is unset'
+[[ ${#ss} == 0 ]] || err_exit '${#ss} should be 0 when ss is unset'
# RANDOM
if (( RANDOM==RANDOM || $RANDOM==$RANDOM ))
then err_exit RANDOM variable not working
@@ -57,17 +60,19 @@ fi
#fi
# PWD
if [[ ! $PWD -ef . ]]
-then err_exit PWD variable not working
+then err_exit PWD variable failed, not equivalent to .
fi
# PPID
-if [[ $($SHELL -c 'print $PPID') != $$ ]]
-then err_exit PPID variable not working
+exp=$$
+got=${ $SHELL -c 'print $PPID'; }
+if [[ ${ $SHELL -c 'print $PPID'; } != $$ ]]
+then err_exit "PPID variable failed -- expected '$exp', got '$got'"
fi
# OLDPWD
old=$PWD
cd /
if [[ $OLDPWD != $old ]]
-then err_exit OLDPWD variable not working
+then err_exit "OLDPWD variable failed -- expected '$old', got '$OLDPWD'"
fi
cd $old || err_exit cd failed
# REPLY
@@ -90,7 +95,7 @@ LINENO=save+10
IFS=:
x=a::b::c
if [[ $x != a::b::c ]]
-then err_exit "Word splitting on constants"
+then err_exit "word splitting on constants"
fi
set -- $x
if [[ $# != 5 ]]
@@ -171,7 +176,7 @@ unset -n foo
foo=junk
function foo.get
{
- .sh.value=stuff
+ .sh.value=stuff
unset -f foo.get
}
if [[ $foo != stuff ]]
@@ -209,22 +214,19 @@ done
kill $!
unset x
CDPATH=/
-x=$(cd tmp)
-if [[ $x != /tmp ]]
+x=$(cd ${tmp#/})
+if [[ $x != $tmp ]]
then err_exit 'CDPATH does not display new directory'
fi
-mkdir /tmp/ksh$$
CDPATH=/:
-x=$(cd /tmp;cd ksh$$)
+x=$(cd ${tmp%/*}; cd ${tmp##*/})
if [[ $x ]]
then err_exit 'CDPATH displays new directory when not used'
fi
-x=$(cd tmp/ksh$$)
-if [[ $x != /tmp/ksh$$ ]]
-then err_exit "CDPATH tmp/ksh$$ does not display new directory"
+x=$(cd ${tmp#/})
+if [[ $x != $tmp ]]
+then err_exit "CDPATH ${tmp#/} does not display new directory"
fi
-cd /
-rm -rf /tmp/ksh$$
TMOUT=100
(TMOUT=20)
if (( TMOUT !=100 ))
@@ -411,15 +413,15 @@ done
unset IFS
if [[ $( (print ${12345:?}) 2>&1) != *12345* ]]
-then err_exit 'Incorrect error message with ${12345?}'
+then err_exit 'incorrect error message with ${12345?}'
fi
unset foobar
if [[ $( (print ${foobar:?}) 2>&1) != *foobar* ]]
-then err_exit 'Incorrect error message with ${foobar?}'
+then err_exit 'incorrect error message with ${foobar?}'
fi
unset bar
if [[ $( (print ${bar:?bam}) 2>&1) != *bar*bam* ]]
-then err_exit 'Incorrect error message with ${foobar?}'
+then err_exit 'incorrect error message with ${foobar?}'
fi
{ $SHELL -c '
function foo
@@ -427,14 +429,13 @@ function foo
typeset SECONDS=0
sleep 1.5
print $SECONDS
-
+
}
x=$(foo)
-(( x >1 && x < 2 ))
+(( x >1 && x < 2 ))
'
} 2> /dev/null || err_exit 'SECONDS not working in function'
-trap 'rm -f /tmp/script$$ /tmp/out$$' EXIT
-cat > /tmp/script$$ <<-\!
+cat > $tmp/script <<-\!
posixfun()
{
unset x
@@ -451,12 +452,12 @@ cat > /tmp/script$$ <<-\!
else print -r -- "${.sh.file}"
fi
!
-chmod +x /tmp/script$$
-. /tmp/script$$ 1
-[[ $file == /tmp/script$$ ]] || err_exit ".sh.file not working for dot scripts"
-[[ $($SHELL /tmp/script$$) == /tmp/script$$ ]] || err_exit ".sh.file not working for scripts"
-[[ $(posixfun .sh.file) == /tmp/script$$ ]] || err_exit ".sh.file not working for posix functions"
-[[ $(fun .sh.file) == /tmp/script$$ ]] || err_exit ".sh.file not working for functions"
+chmod +x $tmp/script
+. $tmp/script 1
+[[ $file == $tmp/script ]] || err_exit ".sh.file not working for dot scripts"
+[[ $($SHELL $tmp/script) == $tmp/script ]] || err_exit ".sh.file not working for scripts"
+[[ $(posixfun .sh.file) == $tmp/script ]] || err_exit ".sh.file not working for posix functions"
+[[ $(fun .sh.file) == $tmp/script ]] || err_exit ".sh.file not working for functions"
[[ $(posixfun .sh.fun) == posixfun ]] || err_exit ".sh.fun not working for posix functions"
[[ $(fun .sh.fun) == fun ]] || err_exit ".sh.fun not working for functions"
[[ $(posixfun .sh.subshell) == 1 ]] || err_exit ".sh.subshell not working for posix functions"
@@ -483,22 +484,22 @@ function dave.unset
unset dave
[[ $(typeset +f) == *dave.* ]] && err_exit 'unset discipline not removed'
-print 'print ${VAR}' > /tmp/script$$
+print 'print ${VAR}' > $tmp/script
unset VAR
-VAR=new /tmp/script$$ > /tmp/out$$
-got=$(</tmp/out$$)
+VAR=new $tmp/script > $tmp/out
+got=$(<$tmp/out)
[[ $got == new ]] || err_exit "previously unset environment variable not passed to script, expected 'new', got '$got'"
[[ ! $VAR ]] || err_exit "previously unset environment variable set after script, expected '', got '$VAR'"
unset VAR
VAR=old
-VAR=new /tmp/script$$ > /tmp/out$$
-got=$(</tmp/out$$)
+VAR=new $tmp/script > $tmp/out
+got=$(<$tmp/out)
[[ $got == new ]] || err_exit "environment variable covering local variable not passed to script, expected 'new', got '$got'"
[[ $VAR == old ]] || err_exit "previously set local variable changed after script, expected 'old', got '$VAR'"
unset VAR
export VAR=old
-VAR=new /tmp/script$$ > /tmp/out$$
-got=$(</tmp/out$$)
+VAR=new $tmp/script > $tmp/out
+got=$(<$tmp/out)
[[ $got == new ]] || err_exit "environment variable covering environment variable not passed to script, expected 'new', got '$got'"
[[ $VAR == old ]] || err_exit "previously set environment variable changed after script, expected 'old', got '$VAR'"
@@ -511,7 +512,7 @@ got=$(</tmp/out$$)
}
dave=foo; dave+=bar
[[ $dave == barfoo ]] || exit 2
-) 2> /dev/null
+) 2> /dev/null
case $? in
0) ;;
1) err_exit 'append discipline not implemented';;
@@ -522,8 +523,8 @@ esac
function .sh.foobar.get
{
.sh.value=world
- }
-} 2> /dev/null || err_exit "Can't add get discipline to .sh.foobar"
+ }
+} 2> /dev/null || err_exit "cannot add get discipline to .sh.foobar"
[[ ${.sh.foobar} == world ]] || err_exit 'get discipline for .sh.foobar not working'
x='a|b'
IFS='|'
@@ -557,12 +558,12 @@ function foo.set
;;
esac
}
-foo[barrier_hit]=no
+foo[barrier_hit]=no
foo[bar]=1
(( foo[bar] == 1 )) || err_exit 'foo[bar] should be 1'
[[ ${foo[barrier_hit]} == no ]] || err_exit 'foo[barrier_hit] should be no'
[[ ${foo[barrier_not_hit]} == yes ]] || err_exit 'foo[barrier_not_hit] should be yes'
-foo[barrier_hit]=no
+foo[barrier_hit]=no
foo[bar]=2
(( foo[bar] == 5 )) || err_exit 'foo[bar] should be 5'
[[ ${foo[barrier_hit]} == yes ]] || err_exit 'foo[barrier_hit] should be yes'
@@ -576,8 +577,10 @@ function x.set
}
x[0]=0 x[1]=1 x[2]=2 x[3]=3
[[ ${x[@]} == '12 8 5 3' ]] || err_exit 'set discipline for indexed array not working correctly'
+float seconds
((SECONDS=3*4))
-(( SECONDS < 12 || SECONDS > 12.1 )) && err_exit "SECONDS is $SECONDS and should be close to 12"
+seconds=SECONDS
+(( seconds < 12 || seconds > 12.1 )) && err_exit "SECONDS is $seconds and should be close to 12"
unset a
function a.set
{
@@ -611,15 +614,37 @@ do nameref r=$v
else err_exit "unset $v; : \$$v failed"
fi
done
+
+x=x
for v in LC_ALL LC_CTYPE LC_MESSAGES LC_COLLATE LC_NUMERIC
do nameref r=$v
unset $v
[[ $r ]] && err_exit "unset $v failed -- expected '', got '$r'"
d=$($SHELL -c "$v=$x" 2>&1)
[[ $d ]] || err_exit "$v=$x failed -- expected locale diagnostic"
- ( r=$x; [[ ! $r ]] ) 2>/dev/null || err_exit "$v=$x failed -- expected ''"
- ( r=C; r=$x; [[ $r == C ]] ) 2>/dev/null || err_exit "$v=C; $v=$x failed -- expected 'C'"
+ { g=$( r=$x; print -- $r ); } 2>/dev/null
+ [[ $g == '' ]] || err_exit "$v=$x failed -- expected '', got '$g'"
+ { g=$( r=C; r=$x; print -- $r ); } 2>/dev/null
+ [[ $g == 'C' ]] || err_exit "$v=C; $v=$x failed -- expected 'C', got '$g'"
done
PATH=$path
+cd $tmp
+
+print print -n zzz > zzz
+chmod +x zzz
+exp='aaazzz'
+got=$($SHELL -c 'unset SHLVL; print -n aaa; ./zzz' 2>&1) >/dev/null 2>&1
+[[ $got == "$exp" ]] || err_exit "unset SHLVL causes script failure -- expected '$exp', got '$got'"
+
+mkdir glean
+for cmd in date ok
+do exp="$cmd ok"
+ rm -f $cmd
+ print print $exp > glean/$cmd
+ chmod +x glean/$cmd
+ got=$(CDPATH=:.. $SHELL -c "PATH=:/bin:/usr/bin; date > /dev/null; cd glean && ./$cmd" 2>&1)
+ [[ $got == "$exp" ]] || err_exit "cd with CDPATH after PATH change failed -- expected '$exp', got '$got'"
+done
+
exit $((Errors))