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
284887Schin# test shell builtin commands
294887SchinCommand=${0##*/}
304887Schininteger Errors=0
314887Schinbuiltin getconf
324887Schin: ${foo=bar} || err_exit ": failed"
334887Schin[[ $foo = bar ]] || err_exit ": side effects failed"
344887Schinset -- - foobar
354887Schin[[ $# = 2 && $1 = - && $2 = foobar ]] || err_exit "set -- - foobar failed"
364887Schinset -- -x foobar
374887Schin[[ $# = 2 && $1 = -x && $2 = foobar ]] || err_exit "set -- -x foobar failed"
384887Schingetopts :x: foo || err_exit "getopts :x: returns false"
394887Schin[[ $foo = x && $OPTARG = foobar ]] || err_exit "getopts :x: failed"
404887SchinOPTIND=1
414887Schingetopts :r:s var -r
424887Schinif	[[ $var != : || $OPTARG != r ]]
434887Schinthen	err_exit "'getopts :r:s var -r' not working"
444887Schinfi
454887SchinOPTIND=1
46*8462SApril.Chin@Sun.COMgetopts :d#u OPT -d 16177
47*8462SApril.Chin@Sun.COMif	[[ $OPT != d || $OPTARG != 16177 ]]
48*8462SApril.Chin@Sun.COMthen	err_exit "'getopts :d#u OPT=d OPTARG=16177' failed -- OPT=$OPT OPTARG=$OPTARG"
494887Schinfi
504887SchinOPTIND=1
514887Schinwhile getopts 'ab' option -a -b
524887Schindo	[[ $OPTIND == $((OPTIND)) ]] || err_exit "OPTIND optimization bug"
534887Schindone
544887Schin
554887SchinUSAGE=$'[-][S:server?Operate on the specified \asubservice\a:]:[subservice:=pmserver]
564887Schin    {
574887Schin        [p:pmserver]
584887Schin        [r:repserver]
594887Schin        [11:notifyd]
604887Schin    }'
614887Schinset pmser p rep r notifyd -11
624887Schinwhile	(( $# > 1 ))
634887Schindo	OPTIND=1
644887Schin	getopts "$USAGE" OPT -S $1
654887Schin	[[ $OPT == S && $OPTARG == $2 ]] || err_exit "OPT=$OPT OPTARG=$OPTARG -- expected OPT=S OPTARG=$2"
664887Schin	shift 2
674887Schindone
684887Schin
694887Schinfalse ${foo=bar} &&  err_exit "false failed"
704887Schinread <<!
714887Schinhello world
724887Schin!
734887Schin[[ $REPLY = 'hello world' ]] || err_exit "read builtin failed"
744887Schinprint x:y | IFS=: read a b
754887Schinif	[[ $a != x ]]
764887Schinthen	err_exit "IFS=: read ... not working"
774887Schinfi
784887Schinread <<!
794887Schinhello \
804887Schinworld
814887Schin!
824887Schin[[ $REPLY = 'hello world' ]] || err_exit "read continuation failed"
834887Schinread -d x <<!
844887Schinhello worldxfoobar
854887Schin!
864887Schin[[ $REPLY = 'hello world' ]] || err_exit "read builtin failed"
874887Schinread <<\!
884887Schinhello \
894887Schin	world \
904887Schin
914887Schin!
924887Schin[[ $REPLY == 'hello 	world' ]] || err_exit "read continuation2 failed"
934887Schinprint "one\ntwo" | { read line
944887Schin	print $line | /bin/cat > /dev/null
954887Schin	read line
964887Schin}
974887Schinread <<\!
984887Schin\
994887Schina\
1004887Schin\
1014887Schin\
1024887Schinb
1034887Schin!
1044887Schinif	[[ $REPLY != ab ]]
1054887Schinthen	err_exit "read multiple continuation failed"
1064887Schinfi
1074887Schinif	[[ $line != two ]]
1084887Schinthen	err_exit "read from pipeline failed"
1094887Schinfi
1104887Schinline=two
1114887Schinread line < /dev/null
1124887Schinif	[[ $line != "" ]]
1134887Schinthen	err_exit "read from /dev/null failed"
1144887Schinfi
1154887Schinif	[[ $(print -R -) != - ]]
1164887Schinthen	err_exit "print -R not working correctly"
1174887Schinfi
1184887Schinif	[[ $(print -- -) != - ]]
1194887Schinthen	err_exit "print -- not working correctly"
1204887Schinfi
1214887Schinprint -f "hello%nbar\n" size > /dev/null
1224887Schinif	((	size != 5 ))
1234887Schinthen	err_exit "%n format of printf not working"
1244887Schinfi
1254887Schinprint -n -u2 2>&1-
1264887Schin[[ -w /dev/fd/1 ]] || err_exit "2<&1- with built-ins has side effects"
1274887Schinx=$0
1284887Schinif	[[ $(eval 'print $0') != $x ]]
1294887Schinthen	err_exit '$0 not correct for eval'
1304887Schinfi
131*8462SApril.Chin@Sun.COM$SHELL -c 'read x <<< hello' 2> /dev/null || err_exit 'syntax <<< not recognized'
132*8462SApril.Chin@Sun.COM($SHELL -c 'read x[1] <<< hello') 2> /dev/null || err_exit 'read x[1] not working'
1334887Schinunset x
1344887Schinreadonly x
1354887Schinset -- $(readonly)
1364887Schinif      [[ " $@ " != *" x "* ]]
1374887Schinthen    err_exit 'unset readonly variables are not displayed'
1384887Schinfi
1394887Schinif	[[ $(	for i in foo bar
1404887Schin		do	print $i
1414887Schin			continue 10
1424887Schin		done
1434887Schin	    ) != $'foo\nbar' ]]
1444887Schinthen	err_exit 'continue breaks out of loop'
1454887Schinfi
1464887Schin(continue bad 2>/dev/null && err_exit 'continue bad should return an error')
1474887Schin(break bad 2>/dev/null && err_exit 'break bad should return an error')
1484887Schin(continue 0 2>/dev/null && err_exit 'continue 0 should return an error')
1494887Schin(break 0 2>/dev/null && err_exit 'break 0 should return an error')
1504887Schinbreakfun() { break;}
1514887Schincontinuefun() { continue;}
1524887Schinfor fun in break continue
1534887Schindo	if	[[ $(	for i in foo
1544887Schin			do	${fun}fun
1554887Schin				print $i
1564887Schin			done
1574887Schin		) != foo ]]
1584887Schin	then	err_exit "$fun call in ${fun}fun breaks out of for loop"
1594887Schin	fi
1604887Schindone
1614887Schinif	[[ $(print -f "%b" "\a\n\v\b\r\f\E\03\\oo") != $'\a\n\v\b\r\f\E\03\\oo' ]]
1624887Schinthen	err_exit 'print -f "%b" not working'
1634887Schinfi
164*8462SApril.Chin@Sun.COMif	[[ $(print -f "%P" "[^x].*b\$") != '*[!x]*b' ]]
1654887Schinthen	err_exit 'print -f "%P" not working'
1664887Schinfi
1674887Schinif	[[ $(abc: for i in foo bar;do print $i;break abc;done) != foo ]]
1684887Schinthen	err_exit 'break labels not working'
1694887Schinfi
1704887Schinif	[[ $(command -v if)	!= if ]]
1714887Schinthen	err_exit	'command -v not working'
1724887Schinfi
1734887Schinread -r var <<\!
1744887Schin
1754887Schin!
1764887Schinif	[[ $var != "" ]]
1774887Schinthen	err_exit "read -r of blank line not working"
1784887Schinfi
1794887Schinmkdir -p /tmp/ksh$$/a/b/c 2>/dev/null || err_exit  "mkdir -p failed"
1804887Schin$SHELL -c "cd /tmp/ksh$$/a/b; cd c" 2>/dev/null || err_exit "initial script relative cd fails"
1814887Schinrm -r /tmp/ksh$$ || err_exit "rm -r /tmp/ksh$$ failed"
1824887Schintrap 'print HUP' HUP
1834887Schinif	[[ $(trap) != "trap -- 'print HUP' HUP" ]]
1844887Schinthen	err_exit '$(trap) not working'
1854887Schinfi
1864887Schinif	[[ $(trap -p HUP) != 'print HUP' ]]
1874887Schinthen	err_exit '$(trap -p HUP) not working'
1884887Schinfi
189*8462SApril.Chin@Sun.COM[[ $($SHELL -c 'trap "print ok" SIGTERM; kill -s SIGTERM $$' 2> /dev/null) == ok ]] || err_exit 'SIGTERM not recognized'
190*8462SApril.Chin@Sun.COM[[ $($SHELL -c 'trap "print ok" sigterm; kill -s sigterm $$' 2> /dev/null) == ok ]] || err_exit 'SIGTERM not recognized'
191*8462SApril.Chin@Sun.COM[[ $($SHELL -c '( trap "" TERM);kill $$;print bad' == bad) ]] 2> /dev/null && err_exit 'trap ignored in subshell causes it to be ignored by parent'
1924887Schin${SHELL} -c 'kill -1 -$$' 2> /dev/null
1934887Schin[[ $(kill -l $?) == HUP ]] || err_exit 'kill -1 -pid not working'
1944887Schin${SHELL} -c 'kill -1 -$$' 2> /dev/null
1954887Schin[[ $(kill -l $?) == HUP ]] || err_exit 'kill -n1 -pid not working'
1964887Schin${SHELL} -c 'kill -s HUP -$$' 2> /dev/null
1974887Schin[[ $(kill -l $?) == HUP ]] || err_exit 'kill -HUP -pid not working'
1984887Schinn=123
1994887Schintypeset -A base
2004887Schinbase[o]=8#
2014887Schinbase[x]=16#
2024887Schinbase[X]=16#
2034887Schinfor i in d i o u x X
2044887Schindo	if	(( $(( ${base[$i]}$(printf "%$i" $n) )) != n  ))
2054887Schin	then	err_exit "printf %$i not working"
2064887Schin	fi
2074887Schindone
2084887Schinif	[[ $( trap 'print done' EXIT) != done ]]
2094887Schinthen	err_exit 'trap on EXIT not working'
2104887Schinfi
2114887Schinif	[[ $( trap 'print done' EXIT; trap - EXIT) == done ]]
2124887Schinthen	err_exit 'trap on EXIT not being cleared'
2134887Schinfi
2144887Schinif	[[ $(type test) != 'test is a shell builtin' ]]
2154887Schinthen	err_exit 'whence -v test not a builtin'
2164887Schinfi
2174887Schinbuiltin -d test
2184887Schinif	[[ $(type test) == *builtin* ]]
2194887Schinthen	err_exit 'whence -v test after builtin -d incorrect'
2204887Schinfi
2214887Schintypeset -Z3 percent=$(printf '%o\n' "'%'")
2224887Schinforrmat=\\${percent}s
2234887Schinif      [[ $(printf "$forrmat") != %s ]]
2244887Schinthen    err_exit "printf $forrmat not working"
2254887Schinfi
2264887Schinif	(( $(printf 'x\0y' | wc -c) != 3 ))
2274887Schinthen	err_exit 'printf \0 not working'
2284887Schinfi
2294887Schinif	[[ $(printf "%bx%s\n" 'f\to\cbar') != $'f\to' ]]
2304887Schinthen	err_exit 'printf %bx%s\n  not working'
2314887Schinfi
2324887Schinalpha=abcdefghijklmnop
2334887Schinif	[[ $(printf "%10.*s\n" 5 $alpha) != '     abcde' ]]
2344887Schinthen	err_exit 'printf %10.%s\n  not working'
2354887Schinfi
2364887Schinfloat x2=.0000625
2374887Schinif	[[ $(printf "%10.5E\n" x2) != 6.25000E-05 ]]
2384887Schinthen	err_exit 'printf "%10.5E" not normalizing correctly'
2394887Schinfi
2404887Schinx2=.000000001
2414887Schinif	[[ $(printf "%g\n" x2 2>/dev/null) != 1e-09 ]]
2424887Schinthen	err_exit 'printf "%g" not working correctly'
2434887Schinfi
2444887Schin#FIXME#($SHELL read -s foobar <<\!
2454887Schin#FIXME#testing
2464887Schin#FIXME#!
2474887Schin#FIXME#) 2> /dev/null || err_exit ksh read -s var fails
2484887Schinif	[[ $(printf +3 2>/dev/null) !=   +3 ]]
2494887Schinthen	err_exit 'printf is not processing formats beginning with + correctly'
2504887Schinfi
2514887Schinif	printf "%d %d\n" 123bad 78 >/dev/null 2>/dev/null
2524887Schinthen	err_exit "printf not exiting non-zero with conversion errors"
2534887Schinfi
2544887Schinif	[[ $(trap --version 2> /dev/null;print done) != done ]]
2554887Schinthen	err_exit 'trap builtin terminating after --version'
2564887Schinfi
2574887Schinif	[[ $(set --version 2> /dev/null;print done) != done ]]
2584887Schinthen	err_exit 'set builtin terminating after --veresion'
2594887Schinfi
2604887Schinunset -f foobar
2614887Schinfunction foobar
2624887Schin{
2634887Schin	print 'hello world'
2644887Schin}
2654887SchinOPTIND=1
2664887Schinif	[[ $(getopts  $'[+?X\ffoobar\fX]' v --man 2>&1) != *'Xhello world'X* ]]
2674887Schinthen	err_exit '\f...\f not working in getopts usage strings'
2684887Schinfi
2694887Schinif	[[	$(printf '%H\n' $'<>"& \'\tabc') != '&lt;&gt;&quot;&amp;&nbsp;&apos;&#9;abc' ]]
2704887Schinthen	err_exit 'printf %H not working'
2714887Schinfi
2724887Schinif	[[	$(printf '%R %R %R %R\n' 'a.b' '*.c' '^'  '!(*.*)') != '^a\.b$ \.c$ ^\^$ ^(.*\..*)!$' ]]
2734887Schinthen	err_exit 'printf %R not working'
2744887Schinfi
2754887Schinif	[[ $(printf '%..:c\n' abc) != a:b:c ]]
2764887Schinthen	err_exit	"printf '%..:c' not working"
2774887Schinfi
2784887Schinif	[[ $(printf '%..*c\n' : abc) != a:b:c ]]
2794887Schinthen	err_exit	"printf '%..*c' not working"
2804887Schinfi
2814887Schinif	[[ $(printf '%..:s\n' abc def ) != abc:def ]]
2824887Schinthen	err_exit	"printf '%..:s' not working"
2834887Schinfi
2844887Schinif	[[ $(printf '%..*s\n' : abc def) != abc:def ]]
2854887Schinthen	err_exit	"printf '%..*s' not working"
2864887Schinfi
2874887Schin[[ $(printf '%q\n') == '' ]] || err_exit 'printf "%q" with missing arguments'
2884887Schin# we won't get hit by the one second boundary twice, right?
2894887Schin[[ $(printf '%T\n' now) == "$(date)" ]] ||
2904887Schin[[ $(printf '%T\n' now) == "$(date)" ]] ||
2914887Schinerr_exit 'printf "%T" now'
2924887Schinbehead()
2934887Schin{
2944887Schin	read line
2954887Schin	left=$(cat)
2964887Schin}
2974887Schinprint $'line1\nline2' | behead
2984887Schinif	[[ $left != line2 ]]
2994887Schinthen	err_exit  "read reading ahead on a pipe"
3004887Schinfi
3014887Schinprint -n $'{ read -r line;print $line;}\nhello' > /tmp/ksh$$
3024887Schinchmod 755 /tmp/ksh$$
3034887Schintrap 'rm -rf /tmp/ksh$$' EXIT
3044887Schinif	[[ $($SHELL < /tmp/ksh$$) != hello ]]
3054887Schinthen	err_exit 'read of incomplete line not working correctly'
3064887Schinfi
3074887Schinset -f
3084887Schinset -- *
3094887Schinif      [[ $1 != '*' ]]
3104887Schinthen    err_exit 'set -f not working'
3114887Schinfi
3124887Schinunset pid1 pid2
3134887Schinfalse &
3144887Schinpid1=$!
3154887Schinpid2=$(
3164887Schin	wait $pid1
3174887Schin	(( $? == 127 )) || err_exit "job known to subshell"
3184887Schin	print $!
3194887Schin)
3204887Schinwait $pid1
3214887Schin(( $? == 1 )) || err_exit "wait not saving exit value"
3224887Schinwait $pid2
3234887Schin(( $? == 127 )) || err_exit "subshell job known to parent"
3244887Schinset --noglob
3254887Schinifs=$IFS
3264887SchinIFS=,
3274887Schinset -- $(getconf LIBPATH)
3284887SchinIFS=$ifs
3294887Schinenv=
3304887Schinfor v
3314887Schindo	IFS=:
3324887Schin	set -- $v
3334887Schin	IFS=$ifs
3344887Schin	eval [[ \$$2 ]] && env="$env $2=\"\$$2\""
3354887Schindone
3364887Schinset --glob
3374887Schinif	[[ $(foo=bar; eval foo=\$foo $env exec -c \$SHELL -c \'print \$foo\') != bar ]]
3384887Schinthen	err_exit '"name=value exec -c ..." not working'
3394887Schinfi
3404887Schin$SHELL -c 'OPTIND=-1000000; getopts a opt -a' 2> /dev/null
3414887Schin[[ $? == 1 ]] || err_exit 'getopts with negative OPTIND not working'
3424887Schingetopts 'n#num' opt  -n 3
3434887Schin[[ $OPTARG == 3 ]] || err_exit 'getopts with numerical arguments failed'
3444887Schinif	[[ $($SHELL -c $'printf \'%2$s %1$s\n\' world hello') != 'hello world' ]]
3454887Schinthen	err_exit 'printf %2$s %1$s not working'
3464887Schinfi
347*8462SApril.Chin@Sun.COMval=$(( 'C' ))
348*8462SApril.Chin@Sun.COMset -- \
349*8462SApril.Chin@Sun.COM	"'C"	$val	0	\
350*8462SApril.Chin@Sun.COM	"'C'"	$val	0	\
351*8462SApril.Chin@Sun.COM	'"C'	$val	0	\
352*8462SApril.Chin@Sun.COM	'"C"'	$val	0	\
353*8462SApril.Chin@Sun.COM	"'CX"	$val	1	\
354*8462SApril.Chin@Sun.COM	"'CX'"	$val	1	\
355*8462SApril.Chin@Sun.COM	"'C'X"	$val	1	\
356*8462SApril.Chin@Sun.COM	'"CX'	$val	1	\
357*8462SApril.Chin@Sun.COM	'"CX"'	$val	1	\
358*8462SApril.Chin@Sun.COM	'"C"X'	$val	1
359*8462SApril.Chin@Sun.COMwhile (( $# >= 3 ))
360*8462SApril.Chin@Sun.COMdo	arg=$1 val=$2 code=$3
361*8462SApril.Chin@Sun.COM	shift 3
362*8462SApril.Chin@Sun.COM	for fmt in '%d' '%g'
363*8462SApril.Chin@Sun.COM	do	out=$(printf "$fmt" "$arg" 2>/dev/null)
364*8462SApril.Chin@Sun.COM		err=$(printf "$fmt" "$arg" 2>&1 >/dev/null)
365*8462SApril.Chin@Sun.COM		printf "$fmt" "$arg" >/dev/null 2>&1
366*8462SApril.Chin@Sun.COM		ret=$?
367*8462SApril.Chin@Sun.COM		[[ $out == $val ]] || err_exit "printf $fmt $arg failed -- expected $val, got $out"
368*8462SApril.Chin@Sun.COM		if	(( $code ))
369*8462SApril.Chin@Sun.COM		then	[[ $err ]] || err_exit "printf $fmt $arg failed, error message expected"
370*8462SApril.Chin@Sun.COM		else	[[ $err ]] && err_exit "$err: printf $fmt $arg failed, error message not expected -- got '$err'"
371*8462SApril.Chin@Sun.COM		fi
372*8462SApril.Chin@Sun.COM		(( $ret == $code )) || err_exit "printf $fmt $arg failed -- expected exit code $code, got $ret"
373*8462SApril.Chin@Sun.COM	done
374*8462SApril.Chin@Sun.COMdone
3754887Schin((n=0))
3764887Schin((n++)); ARGC[$n]=1 ARGV[$n]=""
3774887Schin((n++)); ARGC[$n]=2 ARGV[$n]="-a"
3784887Schin((n++)); ARGC[$n]=4 ARGV[$n]="-a -v 2"
3794887Schin((n++)); ARGC[$n]=4 ARGV[$n]="-a -v 2 x"
3804887Schin((n++)); ARGC[$n]=4 ARGV[$n]="-a -v 2 x y"
3814887Schinfor ((i=1; i<=n; i++))
3824887Schindo	set -- ${ARGV[$i]}
3834887Schin	OPTIND=0
3844887Schin	while	getopts -a tst "av:" OPT
3854887Schin	do	:
3864887Schin	done
3874887Schin	if	[[ $OPTIND != ${ARGC[$i]} ]]
388*8462SApril.Chin@Sun.COM	then	err_exit "\$OPTIND after getopts loop incorrect -- expected ${ARGC[$i]}, got $OPTIND"
3894887Schin	fi
3904887Schindone
391*8462SApril.Chin@Sun.COMoptions=ab:c
392*8462SApril.Chin@Sun.COMoptarg=foo
393*8462SApril.Chin@Sun.COMset -- -a -b $optarg -c bar
394*8462SApril.Chin@Sun.COMwhile	getopts $options opt
395*8462SApril.Chin@Sun.COMdo	case $opt in
396*8462SApril.Chin@Sun.COM	a|c)	[[ $OPTARG ]] && err_exit "getopts $options \$OPTARG for flag $opt failed, expected \"\", got \"$OPTARG\"" ;;
397*8462SApril.Chin@Sun.COM	b)	[[ $OPTARG == $optarg ]] || err_exit "getopts $options \$OPTARG failed -- \"$optarg\" expected, got \"$OPTARG\"" ;;
398*8462SApril.Chin@Sun.COM	*)	err_exit "getopts $options failed -- got flag $opt" ;;
399*8462SApril.Chin@Sun.COM	esac
400*8462SApril.Chin@Sun.COMdone
4014887Schinfunction longline
4024887Schin{
4034887Schin	integer i
4044887Schin	for((i=0; i < $1; i++))
4054887Schin	do	print argument$i
4064887Schin	done
4074887Schin}
4084887Schin# test command -x option
4094887Schininteger sum=0 n=10000
4104887Schinif	! ${SHELL:-ksh} -c 'print $#' count $(longline $n) > /dev/null  2>&1
4114887Schinthen	for i in $(command command -x ${SHELL:-ksh} -c 'print $#;[[ $1 != argument0 ]]' count $(longline $n) 2> /dev/null)
4124887Schin	do	((sum += $i))
4134887Schin	done
4144887Schin	(( sum == n )) || err_exit "command -x processed only $sum arguments"
4154887Schin	command -p command -x ${SHELL:-ksh} -c 'print $#;[[ $1 == argument0 ]]' count $(longline $n) > /dev/null  2>&1
4164887Schin	[[ $? != 1 ]] && err_exit 'incorrect exit status for command -x'
4174887Schinfi
4184887Schin# test command -x option with extra arguments
4194887Schininteger sum=0 n=10000
4204887Schinif      ! ${SHELL:-ksh} -c 'print $#' count $(longline $n) > /dev/null  2>&1
4214887Schinthen    for i in $(command command -x ${SHELL:-ksh} -c 'print $#;[[ $1 != argument0 ]]' count $(longline $n) one two three) #2> /dev/null)
4224887Schin	do      ((sum += $i))
4234887Schin	done
4244887Schin	(( sum  > n )) || err_exit "command -x processed only $sum arguments"
4254887Schin	(( (sum-n)%3==0 )) || err_exit "command -x processed only $sum arguments"
4264887Schin	(( sum == n+3)) && err_exit "command -x processed only $sum arguments"
4274887Schin	command -p command -x ${SHELL:-ksh} -c 'print $#;[[ $1 == argument0 ]]' count $(longline $n) > /dev/null  2>&1
4284887Schin	[[ $? != 1 ]] && err_exit 'incorrect exit status for command -x'
4294887Schinfi
4304887Schin# test for debug trap
4314887Schin[[ $(typeset -i i=0
4324887Schin	trap 'print $i' DEBUG
4334887Schin	while (( i <2))
4344887Schin	do	(( i++))
4354887Schin	done) == $'0\n0\n1\n1\n2' ]]  || err_exit  "DEBUG trap not working"
4364887Schingetconf UNIVERSE - ucb
4374887Schin[[ $($SHELL -c 'echo -3') == -3 ]] || err_exit "echo -3 not working in ucb universe"
4384887Schintypeset -F3 start_x=SECONDS total_t delay=0.02
4394887Schintypeset reps=50 leeway=5
4404887Schinsleep $(( 2 * leeway * reps * delay )) |
4414887Schinfor (( i=0 ; i < reps ; i++ ))
4424887Schindo	read -N1 -t $delay
4434887Schindone
4444887Schin(( total_t = SECONDS - start_x ))
4454887Schinif	(( total_t > leeway * reps * delay ))
4464887Schinthen	err_exit "read -t in pipe taking $total_t secs - $(( reps * delay )) minimum - too long"
4474887Schinelif	(( total_t < reps * delay ))
4484887Schinthen	err_exit "read -t in pipe taking $total_t secs - $(( reps * delay )) minimum - too fast"
4494887Schinfi
450*8462SApril.Chin@Sun.COM$SHELL -c 'sleep $(printf "%a" .95)' 2> /dev/null || err_exit "sleep doesn't except %a format constants"
451*8462SApril.Chin@Sun.COM$SHELL -c 'test \( ! -e \)' 2> /dev/null ; [[ $? == 1 ]] || err_exit 'test \( ! -e \) not working'
452*8462SApril.Chin@Sun.COM[[ $(ulimit) == "$(ulimit -fS)" ]] || err_exit 'ulimit is not the same as ulimit -fS'
453*8462SApril.Chin@Sun.COMtmpfile=${TMP-/tmp}/ksh$$.2
454*8462SApril.Chin@Sun.COMtrap 'rm -f /tmp/ksh$$ "$tmpfile"' EXIT
455*8462SApril.Chin@Sun.COMprint $'\nprint -r -- "${.sh.file} ${LINENO} ${.sh.lineno}"' > $tmpfile
456*8462SApril.Chin@Sun.COM[[ $( . "$tmpfile") == "$tmpfile 2 1" ]] || err_exit 'dot command not working'
457*8462SApril.Chin@Sun.COMprint -r -- "'xxx" > $tmpfile
458*8462SApril.Chin@Sun.COM[[ $($SHELL -c ". $tmpfile"$'\n print ok' 2> /dev/null) == ok ]] || err_exit 'syntax error in dot command affects next command'
459*8462SApril.Chin@Sun.COM
460*8462SApril.Chin@Sun.COMfloat sec=$SECONDS del=4
461*8462SApril.Chin@Sun.COMexec 3>&2 2>/dev/null
462*8462SApril.Chin@Sun.COM$SHELL -c "( sleep 1; kill -ALRM \$\$ ) & sleep $del" 2> /dev/null
463*8462SApril.Chin@Sun.COMexitval=$?
464*8462SApril.Chin@Sun.COM(( sec = SECONDS - sec ))
465*8462SApril.Chin@Sun.COMexec 2>&3-
466*8462SApril.Chin@Sun.COM(( exitval )) && err_exit "sleep doesn't exit 0 with ALRM interupt"
467*8462SApril.Chin@Sun.COM(( sec > (del - 1) )) || err_exit "ALRM signal causes sleep to terminate prematurely -- expected 3 sec, got $sec"
468*8462SApril.Chin@Sun.COM
4694887Schinexit $((Errors))
470