14887Schin######################################################################## 24887Schin# # 34887Schin# This software is part of the ast package # 4*10898Sroland.mainz@nrubsig.org# Copyright (c) 1982-2009 AT&T Intellectual Property # 54887Schin# and is licensed under the # 64887Schin# Common Public License, Version 1.0 # 78462SApril.Chin@Sun.COM# by AT&T Intellectual Property # 84887Schin# # 94887Schin# A copy of the License is available at # 104887Schin# http://www.opensource.org/licenses/cpl1.0.txt # 114887Schin# (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) # 124887Schin# # 134887Schin# Information and Software Systems Research # 144887Schin# AT&T Research # 154887Schin# Florham Park NJ # 164887Schin# # 174887Schin# David Korn <dgk@research.att.com> # 184887Schin# # 194887Schin######################################################################## 204887Schinfunction err_exit 214887Schin{ 224887Schin print -u2 -n "\t" 234887Schin print -u2 -r ${Command}[$1]: "${@:2}" 244887Schin let Errors+=1 254887Schin} 264887Schinalias err_exit='err_exit $LINENO' 274887Schin 284887SchinCommand=${0##*/} 294887Schininteger Errors=0 30*10898Sroland.mainz@nrubsig.org 31*10898Sroland.mainz@nrubsig.orgtmp=$(mktemp -dt) || { err_exit mktemp -dt failed; exit 1; } 32*10898Sroland.mainz@nrubsig.orgtrap "cd /; rm -rf $tmp" EXIT 33*10898Sroland.mainz@nrubsig.org 344887Schinr=readonly u=Uppercase l=Lowercase i=22 i8=10 L=abc L5=def uL5=abcdef xi=20 354887Schinx=export t=tagged H=hostname LZ5=026 RZ5=026 Z5=123 lR5=ABcdef R5=def n=l 364887Schinfor option in u l i i8 L L5 LZ5 RZ5 Z5 r x H t R5 uL5 lR5 xi n 374887Schindo typeset -$option $option 384887Schindone 394887Schin(r=newval) 2> /dev/null && err_exit readonly attribute fails 404887Schini=i+5 414887Schinif ((i != 27)) 424887Schinthen err_exit integer attributes fails 434887Schinfi 444887Schinif [[ $i8 != 8#12 ]] 454887Schinthen err_exit integer base 8 fails 464887Schinfi 474887Schinif [[ $u != UPPERCASE ]] 484887Schinthen err_exit uppercase fails 494887Schinfi 504887Schinif [[ $l != lowercase ]] 514887Schinthen err_exit lowercase fails 524887Schinfi 534887Schinif [[ $n != lowercase ]] 544887Schinthen err_exit reference variables fail 554887Schinfi 564887Schinif [[ t=tagged != $(typeset -t) ]] 574887Schinthen err_exit tagged fails 584887Schinfi 594887Schinif [[ t != $(typeset +t) ]] 604887Schinthen err_exit tagged fails 614887Schinfi 624887Schinif [[ $Z5 != 00123 ]] 634887Schinthen err_exit zerofill fails 644887Schinfi 654887Schinif [[ $RZ5 != 00026 ]] 664887Schinthen err_exit right zerofill fails 674887Schinfi 684887SchinL=12345 694887Schinif [[ $L != 123 ]] 704887Schinthen err_exit leftjust fails 714887Schinfi 724887Schinif [[ $L5 != "def " ]] 734887Schinthen err_exit leftjust fails 744887Schinfi 754887Schinif [[ $uL5 != ABCDE ]] 764887Schinthen err_exit leftjust uppercase fails 774887Schinfi 784887Schinif [[ $lR5 != bcdef ]] 794887Schinthen err_exit rightjust fails 804887Schinfi 814887Schinif [[ $R5 != " def" ]] 824887Schinthen err_exit rightjust fails 834887Schinfi 844887Schinif [[ $($SHELL -c 'echo $x') != export ]] 854887Schinthen err_exit export fails 864887Schinfi 874887Schinif [[ $($SHELL -c 'xi=xi+4;echo $xi') != 24 ]] 884887Schinthen err_exit export attributes fails 894887Schinfi 904887Schinx=$(foo=abc $SHELL <<! 914887Schin foo=bar 924887Schin $SHELL -c 'print \$foo' 934887Schin! 944887Schin) 954887Schinif [[ $x != bar ]] 964887Schinthen err_exit 'environment variables require re-export' 974887Schinfi 984887Schin(typeset + ) > /dev/null 2>&1 || err_exit 'typeset + not working' 994887Schin(typeset -L-5 buf="A" 2>/dev/null) 1004887Schinif [[ $? == 0 ]] 1014887Schinthen err_exit 'typeset allows negative field for left/right adjust' 1024887Schinfi 1034887Schina=b 1044887Schinreadonly $a=foo 1054887Schinif [[ $b != foo ]] 1064887Schinthen err_exit 'readonly $a=b not working' 1074887Schinfi 1084887Schinif [[ $(export | grep '^PATH=') != PATH=* ]] 1094887Schinthen err_exit 'export not working' 1104887Schinfi 1114887Schinpicture=( 1124887Schin bitmap=/fruit 1134887Schin size=(typeset -E x=2.5) 1144887Schin) 1154887Schinstring="$(print $picture)" 1164887Schinif [[ "${string}" != *'size=( typeset -E'* ]] 1174887Schinthen err_exit 'print of compound exponential variable not working' 1184887Schinfi 1194887Schinsz=(typeset -E y=2.2) 1204887Schinstring="$(print $sz)" 1214887Schinif [[ "${sz}" == *'typeset -E -F'* ]] 122*10898Sroland.mainz@nrubsig.orgthen err_exit 'print of exponential shows both -E and -F attributes' 1234887Schinfi 124*10898Sroland.mainz@nrubsig.orgprint 'typeset -i m=48/4+1;print -- $m' > $tmp/script 125*10898Sroland.mainz@nrubsig.orgchmod +x $tmp/script 1264887Schintypeset -Z2 m 127*10898Sroland.mainz@nrubsig.orgif [[ $($tmp/script) != 13 ]] 1284887Schinthen err_exit 'attributes not cleared for script execution' 1294887Schinfi 130*10898Sroland.mainz@nrubsig.orgprint 'print VAR=$VAR' > $tmp/script 1318462SApril.Chin@Sun.COMtypeset -L70 VAR=var 132*10898Sroland.mainz@nrubsig.org$tmp/script > $tmp/script.1 133*10898Sroland.mainz@nrubsig.org[[ $(< $tmp/script.1) == VAR= ]] || err_exit 'typeset -L should not be inherited' 1344887Schintypeset -Z LAST=00 1354887Schinunset -f foo 1364887Schinfunction foo 1374887Schin{ 1384887Schin if [[ $1 ]] 1394887Schin then LAST=$1 1404887Schin else ((LAST++)) 1414887Schin fi 1424887Schin} 1434887Schinfoo 1 1444887Schinif (( ${#LAST} != 2 )) 1454887Schinthen err_exit 'LAST!=2' 1464887Schinfi 1474887Schinfoo 1484887Schinif (( ${#LAST} != 2 )) 1494887Schinthen err_exit 'LAST!=2' 1504887Schinfi 1518462SApril.Chin@Sun.COM[[ $(set | grep LAST) == LAST=02 ]] || err_exit "LAST not correct in set list" 1524887Schinset -a 1534887Schinunset foo 1544887Schinfoo=bar 1554887Schinif [[ $(export | grep ^foo=) != 'foo=bar' ]] 1564887Schinthen err_exit 'all export not working' 1574887Schinfi 1584887Schinunset foo 1594887Schinread foo <<! 1604887Schinbar 1614887Schin! 1624887Schinif [[ $(export | grep ^foo=) != 'foo=bar' ]] 1634887Schinthen err_exit 'all export not working with read' 1644887Schinfi 1654887Schinif [[ $(typeset | grep PS2) == PS2 ]] 1664887Schinthen err_exit 'typeset without arguments outputs names without attributes' 1674887Schinfi 1684887Schinunset a z q x 1694887Schinw1=hello 1704887Schinw2=world 1714887Schint1="$w1 $w2" 1724887Schinif (( 'a' == 97 )) 1734887Schinthen b1=aGVsbG8gd29ybGQ= 1744887Schin b2=aGVsbG8gd29ybGRoZWxsbyB3b3JsZA== 1754887Schinelse b1=iIWTk5ZAppaZk4Q= 1764887Schin b2=iIWTk5ZAppaZk4SIhZOTlkCmlpmThA== 1774887Schinfi 1784887Schinz=$b1 1794887Schintypeset -b x=$b1 1804887Schin[[ $x == "$z" ]] || print -u2 'binary variable not expanding correctly' 1814887Schin[[ $(printf "%B" x) == $t1 ]] || err_exit 'typeset -b not working' 1824887Schintypeset -b -Z5 a=$b1 1834887Schin[[ $(printf "%B" a) == $w1 ]] || err_exit 'typeset -b -Z5 not working' 1844887Schintypeset -b q=$x$x 1854887Schin[[ $q == $b2 ]] || err_exit 'typeset -b not working with concatination' 1864887Schin[[ $(printf "%B" q) == $t1$t1 ]] || err_exit 'typeset -b concatination not working' 1874887Schinx+=$b1 1884887Schin[[ $x == $b2 ]] || err_exit 'typeset -b not working with append' 1894887Schin[[ $(printf "%B" x) == $t1$t1 ]] || err_exit 'typeset -b append not working' 1904887Schintypeset -b -Z20 z=$b1 1914887Schin(( $(printf "%B" z | wc -c) == 20 )) || err_exit 'typeset -b -Z20 not storing 20 bytes' 1924887Schin{ 1934887Schin typeset -b v1 v2 1944887Schin read -N11 v1 1954887Schin read -N22 v2 1964887Schin} << ! 1974887Schinhello worldhello worldhello world 1984887Schin! 1994887Schin[[ $v1 == "$b1" ]] || err_exit "v1=$v1 should be $b1" 2004887Schin[[ $v2 == "$x" ]] || err_exit "v1=$v2 should be $x" 201*10898Sroland.mainz@nrubsig.orgif env '!=1' >/dev/null 2>&1 202*10898Sroland.mainz@nrubsig.orgthen [[ $(env '!=1' $SHELL -c 'echo ok' 2>/dev/null) == ok ]] || err_exit 'malformed environment terminates shell' 203*10898Sroland.mainz@nrubsig.orgfi 2044887Schinunset var 2054887Schintypeset -b var 2064887Schinprintf '12%Z34' | read -r -N 5 var 2074887Schin[[ $var == MTIAMzQ= ]] || err_exit 'binary files with zeros not working' 2084887Schinunset var 2094887Schinif command typeset -usi var=0xfffff 2> /dev/null 2104887Schinthen (( $var == 0xffff )) || err_exit 'unsigned short integers not working' 2114887Schinelse err_exit 'typeset -usi cannot be used for unsigned short' 2124887Schinfi 2134887Schin[[ $($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' 2144887Schin[[ $($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' 2154887Schinunset foo bar 2164887Schinunset -f fun 2174887Schinfunction fun 2184887Schin{ 219*10898Sroland.mainz@nrubsig.org export foo=hello 2204887Schin typeset -x bar=world 2214887Schin [[ $foo == hello ]] || err_exit 'export scoping problem in function' 222*10898Sroland.mainz@nrubsig.org} 2234887Schinfun 2244887Schin[[ $(export | grep foo) == 'foo=hello' ]] || err_exit 'export not working in functions' 2254887Schin[[ $(export | grep bar) ]] && err_exit 'typeset -x not local' 2268462SApril.Chin@Sun.COM[[ $($SHELL -c 'typeset -r IFS=;print -r $(pwd)' 2> /dev/null) == "$(pwd)" ]] || err_exit 'readonly IFS causes command substitution to fail' 2278462SApril.Chin@Sun.COMfred[66]=88 2288462SApril.Chin@Sun.COM[[ $(typeset -pa) == *fred* ]] || err_exit 'typeset -pa not working' 2298462SApril.Chin@Sun.COMunset x y z 2308462SApril.Chin@Sun.COMtypeset -LZ3 x=abcd y z=00abcd 2318462SApril.Chin@Sun.COMy=03 232*10898Sroland.mainz@nrubsig.org[[ $y == "3 " ]] || err_exit '-LZ3 not working for value 03' 233*10898Sroland.mainz@nrubsig.org[[ $x == "abc" ]] || err_exit '-LZ3 not working for value abcd' 234*10898Sroland.mainz@nrubsig.org[[ $x == "abc" ]] || err_exit '-LZ3 not working for value 00abcd' 2358462SApril.Chin@Sun.COMunset x z 2368462SApril.Chin@Sun.COMset +a 2378462SApril.Chin@Sun.COM[[ $(typeset -p z) ]] && err_exit "typeset -p for z undefined failed" 2388462SApril.Chin@Sun.COMunset z 2398462SApril.Chin@Sun.COMx='typeset -i z=45' 2408462SApril.Chin@Sun.COMeval "$x" 2418462SApril.Chin@Sun.COM[[ $(typeset -p z) == "$x" ]] || err_exit "typeset -p for '$x' failed" 2428462SApril.Chin@Sun.COM[[ $(typeset +p z) == "${x%=*}" ]] || err_exit "typeset +p for '$x' failed" 2438462SApril.Chin@Sun.COMunset z 2448462SApril.Chin@Sun.COMx='typeset -a z=(a b c)' 2458462SApril.Chin@Sun.COMeval "$x" 2468462SApril.Chin@Sun.COM[[ $(typeset -p z) == "$x" ]] || err_exit "typeset -p for '$x' failed" 2478462SApril.Chin@Sun.COM[[ $(typeset +p z) == "${x%=*}" ]] || err_exit "typeset +p for '$x' failed" 2488462SApril.Chin@Sun.COMunset z 2498462SApril.Chin@Sun.COMx='typeset -C z=( 2508462SApril.Chin@Sun.COM foo=bar 2518462SApril.Chin@Sun.COM xxx=bam 2528462SApril.Chin@Sun.COM)' 2538462SApril.Chin@Sun.COMeval "$x" 2548462SApril.Chin@Sun.COMx=${x//$'\t'} 2558462SApril.Chin@Sun.COMx=${x//$'(\n'/'('} 2568462SApril.Chin@Sun.COMx=${x//$'\n'/';'} 2578462SApril.Chin@Sun.COM[[ $(typeset -p z) == "$x" ]] || err_exit "typeset -p for '$x' failed" 2588462SApril.Chin@Sun.COM[[ $(typeset +p z) == "${x%%=*}" ]] || err_exit "typeset +p for '$x' failed" 2598462SApril.Chin@Sun.COMunset z 2608462SApril.Chin@Sun.COMx='typeset -A z=([bar]=bam [xyz]=bar)' 2618462SApril.Chin@Sun.COMeval "$x" 2628462SApril.Chin@Sun.COM[[ $(typeset -p z) == "$x" ]] || err_exit "typeset -p for '$x' failed" 2638462SApril.Chin@Sun.COM[[ $(typeset +p z) == "${x%%=*}" ]] || err_exit "typeset +p for '$x' failed" 2648462SApril.Chin@Sun.COMunset z 2658462SApril.Chin@Sun.COMfoo=abc 2668462SApril.Chin@Sun.COMx='typeset -n z=foo' 2678462SApril.Chin@Sun.COMeval "$x" 2688462SApril.Chin@Sun.COM[[ $(typeset -p z) == "$x" ]] || err_exit "typeset -p for '$x' failed" 2698462SApril.Chin@Sun.COM[[ $(typeset +p z) == "${x%%=*}" ]] || err_exit "typeset +p for '$x' failed" 2708462SApril.Chin@Sun.COMtypeset +n z 2718462SApril.Chin@Sun.COMunset foo z 2728462SApril.Chin@Sun.COMtypeset -T Pt_t=( 2738462SApril.Chin@Sun.COM float x=1 y=2 2748462SApril.Chin@Sun.COM) 2758462SApril.Chin@Sun.COMPt_t z 2768462SApril.Chin@Sun.COMx=${z//$'\t'} 2778462SApril.Chin@Sun.COMx=${x//$'(\n'/'('} 2788462SApril.Chin@Sun.COMx=${x//$'\n'/';'} 2798462SApril.Chin@Sun.COM[[ $(typeset -p z) == "Pt_t z=$x" ]] || err_exit "typeset -p for type failed" 2808462SApril.Chin@Sun.COM[[ $(typeset +p z) == "Pt_t z" ]] || err_exit "typeset +p for type failed" 2818462SApril.Chin@Sun.COMunset z 2828462SApril.Chin@Sun.COMfunction foo 2838462SApril.Chin@Sun.COM{ 2848462SApril.Chin@Sun.COM typeset -p bar 2858462SApril.Chin@Sun.COM} 2868462SApril.Chin@Sun.COMbar=xxx 2878462SApril.Chin@Sun.COM[[ $(foo) == bar=xxx ]] || err_exit 'typeset -p not working inside a function' 288*10898Sroland.mainz@nrubsig.orgunset foo 289*10898Sroland.mainz@nrubsig.orgtypeset -L5 foo 290*10898Sroland.mainz@nrubsig.org[[ $(typeset -p foo) == 'typeset -L 5 foo' ]] || err_exit 'typeset -p not working for variables with attributes but without a value' 291*10898Sroland.mainz@nrubsig.org{ $SHELL <<- EOF 292*10898Sroland.mainz@nrubsig.org typeset -L3 foo=aaa 293*10898Sroland.mainz@nrubsig.org typeset -L6 foo=bbbbbb 294*10898Sroland.mainz@nrubsig.org [[ \$foo == bbbbbb ]] 295*10898Sroland.mainz@nrubsig.orgEOF 296*10898Sroland.mainz@nrubsig.org} || err_exit 'typeset -L should not preserve old attributes' 297*10898Sroland.mainz@nrubsig.org{ $SHELL <<- EOF 298*10898Sroland.mainz@nrubsig.org typeset -R3 foo=aaa 299*10898Sroland.mainz@nrubsig.org typeset -R6 foo=bbbbbb 300*10898Sroland.mainz@nrubsig.org [[ \$foo == bbbbbb ]] 301*10898Sroland.mainz@nrubsig.orgEOF 302*10898Sroland.mainz@nrubsig.org} 2> /dev/null || err_exit 'typeset -R should not preserve old attributes' 303*10898Sroland.mainz@nrubsig.org 304*10898Sroland.mainz@nrubsig.orgexpected='YWJjZGVmZ2hpag==' 305*10898Sroland.mainz@nrubsig.orgunset foo 306*10898Sroland.mainz@nrubsig.orgtypeset -b -Z10 foo 307*10898Sroland.mainz@nrubsig.orgread foo <<< 'abcdefghijklmnop' 308*10898Sroland.mainz@nrubsig.org[[ $foo == "$expected" ]] || err_exit 'read foo, where foo is "typeset -b -Z10" not working' 309*10898Sroland.mainz@nrubsig.orgunset foo 310*10898Sroland.mainz@nrubsig.orgtypeset -b -Z10 foo 311*10898Sroland.mainz@nrubsig.orgread -N10 foo <<< 'abcdefghijklmnop' 312*10898Sroland.mainz@nrubsig.org[[ $foo == "$expected" ]] || err_exit 'read -N10 foo, where foo is "typeset -b -Z10" not working' 313*10898Sroland.mainz@nrubsig.orgunset foo 314*10898Sroland.mainz@nrubsig.orgtypeset -b -A foo 315*10898Sroland.mainz@nrubsig.orgread -N10 foo[4] <<< 'abcdefghijklmnop' 316*10898Sroland.mainz@nrubsig.org[[ ${foo[4]} == "$expected" ]] || err_exit 'read -N10 foo, where foo is "typeset -b -A" foo not working' 317*10898Sroland.mainz@nrubsig.orgunset foo 318*10898Sroland.mainz@nrubsig.orgtypeset -b -a foo 319*10898Sroland.mainz@nrubsig.orgread -N10 foo[4] <<< 'abcdefghijklmnop' 320*10898Sroland.mainz@nrubsig.org[[ ${foo[4]} == "$expected" ]] || err_exit 'read -N10 foo, where foo is "typeset -b -a" foo not working' 321*10898Sroland.mainz@nrubsig.org[[ $(printf %B foo[4]) == abcdefghij ]] || err_exit 'printf %B for binary associative array element not working' 322*10898Sroland.mainz@nrubsig.org[[ $(printf %B foo[4]) == abcdefghij ]] || err_exit 'printf %B for binary indexed array element not working' 323*10898Sroland.mainz@nrubsig.orgunset foo 324*10898Sroland.mainz@nrubsig.org 325*10898Sroland.mainz@nrubsig.org$SHELL 2> /dev/null -c 'export foo=(bar=3)' && err_exit 'compound variables cannot be exported' 326*10898Sroland.mainz@nrubsig.org 3274887Schinexit $((Errors)) 328