1*4887Schin######################################################################## 2*4887Schin# # 3*4887Schin# This software is part of the ast package # 4*4887Schin# Copyright (c) 1982-2007 AT&T Knowledge Ventures # 5*4887Schin# and is licensed under the # 6*4887Schin# Common Public License, Version 1.0 # 7*4887Schin# by AT&T Knowledge Ventures # 8*4887Schin# # 9*4887Schin# A copy of the License is available at # 10*4887Schin# http://www.opensource.org/licenses/cpl1.0.txt # 11*4887Schin# (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) # 12*4887Schin# # 13*4887Schin# Information and Software Systems Research # 14*4887Schin# AT&T Research # 15*4887Schin# Florham Park NJ # 16*4887Schin# # 17*4887Schin# David Korn <dgk@research.att.com> # 18*4887Schin# # 19*4887Schin######################################################################## 20*4887Schinfunction err_exit 21*4887Schin{ 22*4887Schin print -u2 -n "\t" 23*4887Schin print -u2 -r ${Command}[$1]: "${@:2}" 24*4887Schin let Errors+=1 25*4887Schin} 26*4887Schinalias err_exit='err_exit $LINENO' 27*4887Schin 28*4887SchinCommand=${0##*/} 29*4887Schininteger Errors=0 30*4887Schinr=readonly u=Uppercase l=Lowercase i=22 i8=10 L=abc L5=def uL5=abcdef xi=20 31*4887Schinx=export t=tagged H=hostname LZ5=026 RZ5=026 Z5=123 lR5=ABcdef R5=def n=l 32*4887Schinfor option in u l i i8 L L5 LZ5 RZ5 Z5 r x H t R5 uL5 lR5 xi n 33*4887Schindo typeset -$option $option 34*4887Schindone 35*4887Schin(r=newval) 2> /dev/null && err_exit readonly attribute fails 36*4887Schini=i+5 37*4887Schinif ((i != 27)) 38*4887Schinthen err_exit integer attributes fails 39*4887Schinfi 40*4887Schinif [[ $i8 != 8#12 ]] 41*4887Schinthen err_exit integer base 8 fails 42*4887Schinfi 43*4887Schinif [[ $u != UPPERCASE ]] 44*4887Schinthen err_exit uppercase fails 45*4887Schinfi 46*4887Schinif [[ $l != lowercase ]] 47*4887Schinthen err_exit lowercase fails 48*4887Schinfi 49*4887Schinif [[ $n != lowercase ]] 50*4887Schinthen err_exit reference variables fail 51*4887Schinfi 52*4887Schinif [[ t=tagged != $(typeset -t) ]] 53*4887Schinthen err_exit tagged fails 54*4887Schinfi 55*4887Schinif [[ t != $(typeset +t) ]] 56*4887Schinthen err_exit tagged fails 57*4887Schinfi 58*4887Schinif [[ $Z5 != 00123 ]] 59*4887Schinthen err_exit zerofill fails 60*4887Schinfi 61*4887Schinif [[ $RZ5 != 00026 ]] 62*4887Schinthen err_exit right zerofill fails 63*4887Schinfi 64*4887SchinL=12345 65*4887Schinif [[ $L != 123 ]] 66*4887Schinthen err_exit leftjust fails 67*4887Schinfi 68*4887Schinif [[ $L5 != "def " ]] 69*4887Schinthen err_exit leftjust fails 70*4887Schinfi 71*4887Schinif [[ $uL5 != ABCDE ]] 72*4887Schinthen err_exit leftjust uppercase fails 73*4887Schinfi 74*4887Schinif [[ $lR5 != bcdef ]] 75*4887Schinthen err_exit rightjust fails 76*4887Schinfi 77*4887Schinif [[ $R5 != " def" ]] 78*4887Schinthen err_exit rightjust fails 79*4887Schinfi 80*4887Schinif [[ $($SHELL -c 'echo $x') != export ]] 81*4887Schinthen err_exit export fails 82*4887Schinfi 83*4887Schinif [[ $($SHELL -c 'xi=xi+4;echo $xi') != 24 ]] 84*4887Schinthen err_exit export attributes fails 85*4887Schinfi 86*4887Schinx=$(foo=abc $SHELL <<! 87*4887Schin foo=bar 88*4887Schin $SHELL -c 'print \$foo' 89*4887Schin! 90*4887Schin) 91*4887Schinif [[ $x != bar ]] 92*4887Schinthen err_exit 'environment variables require re-export' 93*4887Schinfi 94*4887Schin(typeset + ) > /dev/null 2>&1 || err_exit 'typeset + not working' 95*4887Schin(typeset -L-5 buf="A" 2>/dev/null) 96*4887Schinif [[ $? == 0 ]] 97*4887Schinthen err_exit 'typeset allows negative field for left/right adjust' 98*4887Schinfi 99*4887Schina=b 100*4887Schinreadonly $a=foo 101*4887Schinif [[ $b != foo ]] 102*4887Schinthen err_exit 'readonly $a=b not working' 103*4887Schinfi 104*4887Schinif [[ $(export | grep '^PATH=') != PATH=* ]] 105*4887Schinthen err_exit 'export not working' 106*4887Schinfi 107*4887Schinpicture=( 108*4887Schin bitmap=/fruit 109*4887Schin size=(typeset -E x=2.5) 110*4887Schin) 111*4887Schinstring="$(print $picture)" 112*4887Schinif [[ "${string}" != *'size=( typeset -E'* ]] 113*4887Schinthen err_exit 'print of compound exponential variable not working' 114*4887Schinfi 115*4887Schinsz=(typeset -E y=2.2) 116*4887Schinstring="$(print $sz)" 117*4887Schinif [[ "${sz}" == *'typeset -E -F'* ]] 118*4887Schinthen err_exit 'print of exponential shows both -E and -F attributes' 119*4887Schinfi 120*4887Schinprint 'typeset -i m=48/4+1;print -- $m' > /tmp/ksh$$ 121*4887Schinchmod +x /tmp/ksh$$ 122*4887Schintypeset -Z2 m 123*4887Schinif [[ $(/tmp/ksh$$) != 13 ]] 124*4887Schinthen err_exit 'attributes not cleared for script execution' 125*4887Schinfi 126*4887Schintypeset -Z LAST=00 127*4887Schinunset -f foo 128*4887Schinfunction foo 129*4887Schin{ 130*4887Schin if [[ $1 ]] 131*4887Schin then LAST=$1 132*4887Schin else ((LAST++)) 133*4887Schin fi 134*4887Schin} 135*4887Schinfoo 1 136*4887Schinif (( ${#LAST} != 2 )) 137*4887Schinthen err_exit 'LAST!=2' 138*4887Schinfi 139*4887Schinfoo 140*4887Schinif (( ${#LAST} != 2 )) 141*4887Schinthen err_exit 'LAST!=2' 142*4887Schinfi 143*4887Schinrm -rf /tmp/ksh$$ 144*4887Schinset -a 145*4887Schinunset foo 146*4887Schinfoo=bar 147*4887Schinif [[ $(export | grep ^foo=) != 'foo=bar' ]] 148*4887Schinthen err_exit 'all export not working' 149*4887Schinfi 150*4887Schinunset foo 151*4887Schinread foo <<! 152*4887Schinbar 153*4887Schin! 154*4887Schinif [[ $(export | grep ^foo=) != 'foo=bar' ]] 155*4887Schinthen err_exit 'all export not working with read' 156*4887Schinfi 157*4887Schinif [[ $(typeset | grep PS2) == PS2 ]] 158*4887Schinthen err_exit 'typeset without arguments outputs names without attributes' 159*4887Schinfi 160*4887Schinunset a z q x 161*4887Schinw1=hello 162*4887Schinw2=world 163*4887Schint1="$w1 $w2" 164*4887Schinif (( 'a' == 97 )) 165*4887Schinthen b1=aGVsbG8gd29ybGQ= 166*4887Schin b2=aGVsbG8gd29ybGRoZWxsbyB3b3JsZA== 167*4887Schinelse b1=iIWTk5ZAppaZk4Q= 168*4887Schin b2=iIWTk5ZAppaZk4SIhZOTlkCmlpmThA== 169*4887Schinfi 170*4887Schinz=$b1 171*4887Schintypeset -b x=$b1 172*4887Schin[[ $x == "$z" ]] || print -u2 'binary variable not expanding correctly' 173*4887Schin[[ $(printf "%B" x) == $t1 ]] || err_exit 'typeset -b not working' 174*4887Schintypeset -b -Z5 a=$b1 175*4887Schin[[ $(printf "%B" a) == $w1 ]] || err_exit 'typeset -b -Z5 not working' 176*4887Schintypeset -b q=$x$x 177*4887Schin[[ $q == $b2 ]] || err_exit 'typeset -b not working with concatination' 178*4887Schin[[ $(printf "%B" q) == $t1$t1 ]] || err_exit 'typeset -b concatination not working' 179*4887Schinx+=$b1 180*4887Schin[[ $x == $b2 ]] || err_exit 'typeset -b not working with append' 181*4887Schin[[ $(printf "%B" x) == $t1$t1 ]] || err_exit 'typeset -b append not working' 182*4887Schintypeset -b -Z20 z=$b1 183*4887Schin(( $(printf "%B" z | wc -c) == 20 )) || err_exit 'typeset -b -Z20 not storing 20 bytes' 184*4887Schin{ 185*4887Schin typeset -b v1 v2 186*4887Schin read -N11 v1 187*4887Schin read -N22 v2 188*4887Schin} << ! 189*4887Schinhello worldhello worldhello world 190*4887Schin! 191*4887Schin[[ $v1 == "$b1" ]] || err_exit "v1=$v1 should be $b1" 192*4887Schin[[ $v2 == "$x" ]] || err_exit "v1=$v2 should be $x" 193*4887Schin[[ $(env '!=1' $SHELL -c 'echo ok' 2>/dev/null) == ok ]] || err_exit 'malformed environment terminates shell' 194*4887Schinunset var 195*4887Schintypeset -b var 196*4887Schinprintf '12%Z34' | read -r -N 5 var 197*4887Schin[[ $var == MTIAMzQ= ]] || err_exit 'binary files with zeros not working' 198*4887Schinunset var 199*4887Schinif command typeset -usi var=0xfffff 2> /dev/null 200*4887Schinthen (( $var == 0xffff )) || err_exit 'unsigned short integers not working' 201*4887Schinelse err_exit 'typeset -usi cannot be used for unsigned short' 202*4887Schinfi 203*4887Schin[[ $($SHELL -c 'unset foo;typeset -Z2 foo; print ${foo:-3}' 2> /dev/null) == 3 ]] || err_exit '${foo:-3} not 3 when typeset -Z2 field undefined' 204*4887Schin[[ $($SHELL -c 'unset foo;typeset -Z2 foo; print ${foo:=3}' 2> /dev/null) == 03 ]] || err_exit '${foo:=-3} not 3 when typeset -Z2 foo undefined' 205*4887Schinunset foo bar 206*4887Schinunset -f fun 207*4887Schinfunction fun 208*4887Schin{ 209*4887Schin export foo=hello 210*4887Schin typeset -x bar=world 211*4887Schin [[ $foo == hello ]] || err_exit 'export scoping problem in function' 212*4887Schin} 213*4887Schinfun 214*4887Schin[[ $(export | grep foo) == 'foo=hello' ]] || err_exit 'export not working in functions' 215*4887Schin[[ $(export | grep bar) ]] && err_exit 'typeset -x not local' 216*4887Schinexit $((Errors)) 217