14887Schin########################################################################
24887Schin#                                                                      #
34887Schin#               This software is part of the ast package               #
4*8462SApril.Chin@Sun.COM#          Copyright (c) 1982-2008 AT&T Intellectual Property          #
54887Schin#                      and is licensed under the                       #
64887Schin#                  Common Public License, Version 1.0                  #
7*8462SApril.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
304887Schinr=readonly u=Uppercase l=Lowercase i=22 i8=10 L=abc L5=def uL5=abcdef xi=20
314887Schinx=export t=tagged H=hostname LZ5=026 RZ5=026 Z5=123 lR5=ABcdef R5=def n=l
324887Schinfor option in u l i i8 L L5 LZ5 RZ5 Z5 r x H t R5 uL5 lR5 xi n
334887Schindo	typeset -$option $option
344887Schindone
354887Schin(r=newval) 2> /dev/null && err_exit readonly attribute fails
364887Schini=i+5
374887Schinif	((i != 27))
384887Schinthen	err_exit integer attributes fails
394887Schinfi
404887Schinif	[[ $i8 != 8#12 ]]
414887Schinthen	err_exit integer base 8 fails
424887Schinfi
434887Schinif	[[ $u != UPPERCASE ]]
444887Schinthen	err_exit uppercase fails
454887Schinfi
464887Schinif	[[ $l != lowercase ]]
474887Schinthen	err_exit lowercase fails
484887Schinfi
494887Schinif	[[ $n != lowercase ]]
504887Schinthen	err_exit reference variables fail
514887Schinfi
524887Schinif	[[ t=tagged != $(typeset -t) ]]
534887Schinthen	err_exit tagged fails
544887Schinfi
554887Schinif	[[ t != $(typeset +t) ]]
564887Schinthen	err_exit tagged fails
574887Schinfi
584887Schinif	[[ $Z5 != 00123 ]]
594887Schinthen	err_exit zerofill fails
604887Schinfi
614887Schinif	[[ $RZ5 != 00026 ]]
624887Schinthen	err_exit right zerofill fails
634887Schinfi
644887SchinL=12345
654887Schinif	[[ $L != 123 ]]
664887Schinthen	err_exit leftjust fails
674887Schinfi
684887Schinif	[[ $L5 != "def  " ]]
694887Schinthen	err_exit leftjust fails
704887Schinfi
714887Schinif	[[ $uL5 != ABCDE ]]
724887Schinthen	err_exit leftjust uppercase fails
734887Schinfi
744887Schinif	[[ $lR5 != bcdef ]]
754887Schinthen	err_exit rightjust fails
764887Schinfi
774887Schinif	[[ $R5 != "  def" ]]
784887Schinthen	err_exit rightjust fails
794887Schinfi
804887Schinif	[[ $($SHELL -c 'echo $x') != export ]]
814887Schinthen	err_exit export fails
824887Schinfi
834887Schinif	[[ $($SHELL -c 'xi=xi+4;echo $xi') != 24 ]]
844887Schinthen	err_exit export attributes fails
854887Schinfi
864887Schinx=$(foo=abc $SHELL <<!
874887Schin	foo=bar
884887Schin	$SHELL -c  'print \$foo'
894887Schin!
904887Schin)
914887Schinif	[[ $x != bar ]]
924887Schinthen	err_exit 'environment variables require re-export'
934887Schinfi
944887Schin(typeset + ) > /dev/null 2>&1 || err_exit 'typeset + not working'
954887Schin(typeset -L-5 buf="A" 2>/dev/null)
964887Schinif [[ $? == 0 ]]
974887Schinthen	err_exit 'typeset allows negative field for left/right adjust'
984887Schinfi
994887Schina=b
1004887Schinreadonly $a=foo
1014887Schinif	[[ $b != foo ]]
1024887Schinthen	err_exit 'readonly $a=b not working'
1034887Schinfi
1044887Schinif	[[ $(export | grep '^PATH=') != PATH=* ]]
1054887Schinthen	err_exit 'export not working'
1064887Schinfi
1074887Schinpicture=(
1084887Schin	bitmap=/fruit
1094887Schin	size=(typeset -E x=2.5)
1104887Schin)
1114887Schinstring="$(print $picture)"
1124887Schinif [[ "${string}" != *'size=( typeset -E'* ]]
1134887Schinthen	err_exit 'print of compound exponential variable not working'
1144887Schinfi
1154887Schinsz=(typeset -E y=2.2)
1164887Schinstring="$(print $sz)"
1174887Schinif [[ "${sz}" == *'typeset -E -F'* ]]
1184887Schinthen 	err_exit 'print of exponential shows both -E and -F attributes'
1194887Schinfi
1204887Schinprint 'typeset -i m=48/4+1;print -- $m' > /tmp/ksh$$
1214887Schinchmod +x /tmp/ksh$$
1224887Schintypeset -Z2 m
1234887Schinif	[[ $(/tmp/ksh$$) != 13 ]]
1244887Schinthen	err_exit 'attributes not cleared for script execution'
1254887Schinfi
126*8462SApril.Chin@Sun.COMprint 'print VAR=$VAR' > /tmp/ksh$$
127*8462SApril.Chin@Sun.COMtypeset -L70 VAR=var
128*8462SApril.Chin@Sun.COM/tmp/ksh$$ > /tmp/ksh$$.1
129*8462SApril.Chin@Sun.COM[[ $(< /tmp/ksh$$.1) == VAR= ]] || err_exit 'typeset -L should not be inherited'
1304887Schintypeset -Z  LAST=00
1314887Schinunset -f foo
1324887Schinfunction foo
1334887Schin{
1344887Schin        if [[ $1 ]]
1354887Schin        then    LAST=$1
1364887Schin        else    ((LAST++))
1374887Schin        fi
1384887Schin}
1394887Schinfoo 1
1404887Schinif	(( ${#LAST} != 2 ))
1414887Schinthen	err_exit 'LAST!=2'
1424887Schinfi
1434887Schinfoo
1444887Schinif	(( ${#LAST} != 2 ))
1454887Schinthen	err_exit 'LAST!=2'
1464887Schinfi
147*8462SApril.Chin@Sun.COM[[ $(set | grep LAST) == LAST=02 ]] || err_exit "LAST not correct in set list"
148*8462SApril.Chin@Sun.COMrm -rf /tmp/ksh$$*
1494887Schinset -a
1504887Schinunset foo
1514887Schinfoo=bar
1524887Schinif	[[ $(export | grep ^foo=) != 'foo=bar' ]]
1534887Schinthen	err_exit 'all export not working'
1544887Schinfi
1554887Schinunset foo
1564887Schinread foo <<!
1574887Schinbar
1584887Schin!
1594887Schinif	[[ $(export | grep ^foo=) != 'foo=bar' ]]
1604887Schinthen	err_exit 'all export not working with read'
1614887Schinfi
1624887Schinif	[[ $(typeset | grep PS2) == PS2 ]]
1634887Schinthen	err_exit 'typeset without arguments outputs names without attributes'
1644887Schinfi
1654887Schinunset a z q x
1664887Schinw1=hello
1674887Schinw2=world
1684887Schint1="$w1 $w2"
1694887Schinif	(( 'a' == 97 ))
1704887Schinthen	b1=aGVsbG8gd29ybGQ=
1714887Schin	b2=aGVsbG8gd29ybGRoZWxsbyB3b3JsZA==
1724887Schinelse	b1=iIWTk5ZAppaZk4Q=
1734887Schin	b2=iIWTk5ZAppaZk4SIhZOTlkCmlpmThA==
1744887Schinfi
1754887Schinz=$b1
1764887Schintypeset -b x=$b1
1774887Schin[[ $x == "$z" ]] || print -u2 'binary variable not expanding correctly'
1784887Schin[[  $(printf "%B" x) == $t1 ]] || err_exit 'typeset -b not working'
1794887Schintypeset -b -Z5 a=$b1
1804887Schin[[  $(printf "%B" a) == $w1 ]] || err_exit 'typeset -b -Z5 not working'
1814887Schintypeset -b q=$x$x
1824887Schin[[ $q == $b2 ]] || err_exit 'typeset -b not working with concatination'
1834887Schin[[  $(printf "%B" q) == $t1$t1 ]] || err_exit 'typeset -b concatination not working'
1844887Schinx+=$b1
1854887Schin[[ $x == $b2 ]] || err_exit 'typeset -b not working with append'
1864887Schin[[  $(printf "%B" x) == $t1$t1 ]] || err_exit 'typeset -b append not working'
1874887Schintypeset -b -Z20 z=$b1
1884887Schin(( $(printf "%B" z | wc -c) == 20 )) || err_exit 'typeset -b -Z20 not storing 20 bytes'
1894887Schin{
1904887Schin	typeset -b v1 v2
1914887Schin	read -N11 v1
1924887Schin	read -N22 v2
1934887Schin} << !
1944887Schinhello worldhello worldhello world
1954887Schin!
1964887Schin[[ $v1 == "$b1" ]] || err_exit "v1=$v1 should be $b1"
1974887Schin[[ $v2 == "$x" ]] || err_exit "v1=$v2 should be $x"
198*8462SApril.Chin@Sun.COM[[ $(env - '!=1' $SHELL -c 'echo ok' 2>/dev/null) == ok ]] || err_exit 'malformed environment terminates shell'
1994887Schinunset var
2004887Schintypeset -b var
2014887Schinprintf '12%Z34' | read -r -N 5 var
2024887Schin[[ $var == MTIAMzQ= ]] || err_exit 'binary files with zeros not working'
2034887Schinunset var
2044887Schinif	command typeset -usi var=0xfffff 2> /dev/null
2054887Schinthen	(( $var == 0xffff )) || err_exit 'unsigned short integers not working'
2064887Schinelse	err_exit 'typeset -usi cannot be used for unsigned short'
2074887Schinfi
2084887Schin[[ $($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'
2094887Schin[[ $($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'
2104887Schinunset foo bar
2114887Schinunset -f fun
2124887Schinfunction fun
2134887Schin{
2144887Schin	export foo=hello
2154887Schin	typeset -x  bar=world
2164887Schin	[[ $foo == hello ]] || err_exit 'export scoping problem in function'
2174887Schin}
2184887Schinfun
2194887Schin[[ $(export | grep foo) == 'foo=hello' ]] || err_exit 'export not working in functions'
2204887Schin[[ $(export | grep bar) ]] && err_exit 'typeset -x not local'
221*8462SApril.Chin@Sun.COM[[ $($SHELL -c 'typeset -r IFS=;print -r $(pwd)' 2> /dev/null) == "$(pwd)" ]] || err_exit 'readonly IFS causes command substitution to fail'
222*8462SApril.Chin@Sun.COMfred[66]=88
223*8462SApril.Chin@Sun.COM[[ $(typeset -pa) == *fred* ]] || err_exit 'typeset -pa not working'
224*8462SApril.Chin@Sun.COMunset x y z
225*8462SApril.Chin@Sun.COMtypeset -LZ3 x=abcd y z=00abcd
226*8462SApril.Chin@Sun.COMy=03
227*8462SApril.Chin@Sun.COM[[ $y == "3  " ]] || err_exit '-LZ3 not working for value 03'
228*8462SApril.Chin@Sun.COM[[ $x == "abc" ]] || err_exit '-LZ3 not working for value abcd'
229*8462SApril.Chin@Sun.COM[[ $x == "abc" ]] || err_exit '-LZ3 not working for value 00abcd'
230*8462SApril.Chin@Sun.COMunset x z
231*8462SApril.Chin@Sun.COMset +a
232*8462SApril.Chin@Sun.COM[[ $(typeset -p z) ]] && err_exit "typeset -p for z undefined failed"
233*8462SApril.Chin@Sun.COMunset z
234*8462SApril.Chin@Sun.COMx='typeset -i z=45'
235*8462SApril.Chin@Sun.COMeval "$x"
236*8462SApril.Chin@Sun.COM[[ $(typeset -p z) == "$x" ]] || err_exit "typeset -p for '$x' failed"
237*8462SApril.Chin@Sun.COM[[ $(typeset +p z) == "${x%=*}" ]] || err_exit "typeset +p for '$x' failed"
238*8462SApril.Chin@Sun.COMunset z
239*8462SApril.Chin@Sun.COMx='typeset -a z=(a b c)'
240*8462SApril.Chin@Sun.COMeval "$x"
241*8462SApril.Chin@Sun.COM[[ $(typeset -p z) == "$x" ]] || err_exit "typeset -p for '$x' failed"
242*8462SApril.Chin@Sun.COM[[ $(typeset +p z) == "${x%=*}" ]] || err_exit "typeset +p for '$x' failed"
243*8462SApril.Chin@Sun.COMunset z
244*8462SApril.Chin@Sun.COMx='typeset -C z=(
245*8462SApril.Chin@Sun.COM	foo=bar
246*8462SApril.Chin@Sun.COM	xxx=bam
247*8462SApril.Chin@Sun.COM)'
248*8462SApril.Chin@Sun.COMeval "$x"
249*8462SApril.Chin@Sun.COMx=${x//$'\t'}
250*8462SApril.Chin@Sun.COMx=${x//$'(\n'/'('}
251*8462SApril.Chin@Sun.COMx=${x//$'\n'/';'}
252*8462SApril.Chin@Sun.COM[[ $(typeset -p z) == "$x" ]] || err_exit "typeset -p for '$x' failed"
253*8462SApril.Chin@Sun.COM[[ $(typeset +p z) == "${x%%=*}" ]] || err_exit "typeset +p for '$x' failed"
254*8462SApril.Chin@Sun.COMunset z
255*8462SApril.Chin@Sun.COMx='typeset -A z=([bar]=bam [xyz]=bar)'
256*8462SApril.Chin@Sun.COMeval "$x"
257*8462SApril.Chin@Sun.COM[[ $(typeset -p z) == "$x" ]] || err_exit "typeset -p for '$x' failed"
258*8462SApril.Chin@Sun.COM[[ $(typeset +p z) == "${x%%=*}" ]] || err_exit "typeset +p for '$x' failed"
259*8462SApril.Chin@Sun.COMunset z
260*8462SApril.Chin@Sun.COMfoo=abc
261*8462SApril.Chin@Sun.COMx='typeset -n z=foo'
262*8462SApril.Chin@Sun.COMeval "$x"
263*8462SApril.Chin@Sun.COM[[ $(typeset -p z) == "$x" ]] || err_exit "typeset -p for '$x' failed"
264*8462SApril.Chin@Sun.COM[[ $(typeset +p z) == "${x%%=*}" ]] || err_exit "typeset +p for '$x' failed"
265*8462SApril.Chin@Sun.COMtypeset +n z
266*8462SApril.Chin@Sun.COMunset foo z
267*8462SApril.Chin@Sun.COMtypeset -T Pt_t=(
268*8462SApril.Chin@Sun.COM	float x=1 y=2
269*8462SApril.Chin@Sun.COM)
270*8462SApril.Chin@Sun.COMPt_t z
271*8462SApril.Chin@Sun.COMx=${z//$'\t'}
272*8462SApril.Chin@Sun.COMx=${x//$'(\n'/'('}
273*8462SApril.Chin@Sun.COMx=${x//$'\n'/';'}
274*8462SApril.Chin@Sun.COM[[ $(typeset -p z) == "Pt_t z=$x" ]] || err_exit "typeset -p for type failed"
275*8462SApril.Chin@Sun.COM[[ $(typeset +p z) == "Pt_t z" ]] || err_exit "typeset +p for type failed"
276*8462SApril.Chin@Sun.COMunset z
277*8462SApril.Chin@Sun.COMfunction foo
278*8462SApril.Chin@Sun.COM{
279*8462SApril.Chin@Sun.COM	typeset -p bar
280*8462SApril.Chin@Sun.COM}
281*8462SApril.Chin@Sun.COMbar=xxx
282*8462SApril.Chin@Sun.COM[[ $(foo) == bar=xxx ]] || err_exit 'typeset -p not working inside a function'
2834887Schinexit	$((Errors))
284