da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin########################################################################
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# This software is part of the ast package #
3e14f97f673e8a630f076077de35afdd43dc1587Roger A. Faulkner# Copyright (c) 1982-2010 AT&T Intellectual Property #
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# and is licensed under the #
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# Common Public License, Version 1.0 #
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# by AT&T Intellectual Property #
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# A copy of the License is available at #
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) #
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# Information and Software Systems Research #
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# AT&T Research #
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# Florham Park NJ #
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# David Korn <dgk@research.att.com> #
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin########################################################################
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainztmp=$(mktemp -dt) || { err_exit mktemp -dt failed; exit 1; }
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz# test shell builtin commands
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin[[ $# = 2 && $1 = - && $2 = foobar ]] || err_exit "set -- - foobar failed"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin[[ $# = 2 && $1 = -x && $2 = foobar ]] || err_exit "set -- -x foobar failed"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin[[ $foo = x && $OPTARG = foobar ]] || err_exit "getopts :x: failed"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chingetopts :r:s var -r
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chingetopts :d#u OPT -d 16177
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinthen err_exit "'getopts :d#u OPT=d OPTARG=16177' failed -- OPT=$OPT OPTARG=$OPTARG"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chindo [[ $OPTIND == $((OPTIND)) ]] || err_exit "OPTIND optimization bug"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinUSAGE=$'[-][S:server?Operate on the specified \asubservice\a:]:[subservice:=pmserver]
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin [p:pmserver]
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin [r:repserver]
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin [11:notifyd]
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin [[ $OPT == S && $OPTARG == $2 ]] || err_exit "OPT=$OPT OPTARG=$OPTARG -- expected OPT=S OPTARG=$2"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin[[ $REPLY = 'hello world' ]] || err_exit "read builtin failed"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinprint x:y | IFS=: read a b
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinif [[ $a != x ]]
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin[[ $REPLY = 'hello world' ]] || err_exit "read continuation failed"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinread -d x <<!
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin[[ $REPLY = 'hello world' ]] || err_exit "read builtin failed"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin[[ $REPLY == 'hello world' ]] || err_exit "read continuation2 failed"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinif [[ $(print -R -) != - ]]
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinif [[ $(print -- -) != - ]]
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin[[ -w /dev/fd/1 ]] || err_exit "2<&1- with built-ins has side effects"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin$SHELL -c 'read x <<< hello' 2> /dev/null || err_exit 'syntax <<< not recognized'
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin($SHELL -c 'read x[1] <<< hello') 2> /dev/null || err_exit 'read x[1] not working'
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinset -- $(readonly)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinthen err_exit 'unset readonly variables are not displayed'
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinif [[ $( for i in foo bar
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin do print $i
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin continue 10
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin(continue bad 2>/dev/null && err_exit 'continue bad should return an error')
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin(break bad 2>/dev/null && err_exit 'break bad should return an error')
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin(continue 0 2>/dev/null && err_exit 'continue 0 should return an error')
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin(break 0 2>/dev/null && err_exit 'break 0 should return an error')
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chindo if [[ $( for i in foo
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin then err_exit "$fun call in ${fun}fun breaks out of for loop"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinif [[ $(print -f "%b" "\a\n\v\b\r\f\E\03\\oo") != $'\a\n\v\b\r\f\E\03\\oo' ]]
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinif [[ $(print -f "%P" "[^x].*b\$") != '*[!x]*b' ]]
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinif [[ $(abc: for i in foo bar;do print $i;break abc;done) != foo ]]
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinif [[ $(command -v if) != if ]]
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinread -r var <<\!
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainzmkdir -p $tmp/a/b/c 2>/dev/null || err_exit "mkdir -p failed"
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz$SHELL -c "cd $tmp/a/b; cd c" 2>/dev/null || err_exit "initial script relative cd fails"
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainzexp=$'trap -- \'print TERM\' TERM\ntrap -- \'cd /; rm -rf '$tmp$'\' EXIT'
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz[[ $got == $exp ]] || err_exit "\$(trap) failed -- expected \"$exp\", got \"$got\""
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz[[ $got == $exp ]] || err_exit "\$(trap -p TERM) failed -- expected \"$exp\", got \"$got\""
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin[[ $($SHELL -c 'trap "print ok" SIGTERM; kill -s SIGTERM $$' 2> /dev/null) == ok ]] || err_exit 'SIGTERM not recognized'
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin[[ $($SHELL -c 'trap "print ok" sigterm; kill -s sigterm $$' 2> /dev/null) == ok ]] || err_exit 'SIGTERM not recognized'
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin[[ $($SHELL -c '( trap "" TERM);kill $$;print bad' == bad) ]] 2> /dev/null && err_exit 'trap ignored in subshell causes it to be ignored by parent'
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz[[ $(kill -l $?) == HUP ]] || err_exit 'kill -1 -pid not working'
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz[[ $(kill -l $?) == HUP ]] || err_exit 'kill -n1 -pid not working'
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz[[ $(kill -l $?) == HUP ]] || err_exit 'kill -HUP -pid not working'
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinfor i in d i o u x X
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinif [[ $( trap 'print done' EXIT; trap - EXIT) == done ]]
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinbuiltin -d test
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinif [[ $(type test) == *builtin* ]]
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinthen err_exit 'whence -v test after builtin -d incorrect'
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinthen err_exit 'printf "%10.5E" not normalizing correctly'
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#FIXME#($SHELL read -s foobar <<\!
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#FIXME#testing
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#FIXME#) 2> /dev/null || err_exit ksh read -s var fails
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinthen err_exit 'printf is not processing formats beginning with + correctly'
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinthen err_exit "printf not exiting non-zero with conversion errors"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinif [[ $(trap --version 2> /dev/null;print done) != done ]]
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinthen err_exit 'trap builtin terminating after --version'
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinif [[ $(set --version 2> /dev/null;print done) != done ]]
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinthen err_exit 'set builtin terminating after --veresion'
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinif [[ $(getopts $'[+?X\ffoobar\fX]' v --man 2>&1) != *'Xhello world'X* ]]
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinthen err_exit '\f...\f not working in getopts usage strings'
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainzif [[ $(printf '%H\n' $'<>"& \'\tabc') != '<>"& '	abc' ]]
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainzif [[ $(printf '%R %R %R %R\n' 'a.b' '*.c' '^' '!(*.*)') != '^a\.b$ \.c$ ^\^$ ^(.*\..*)!$' ]]
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin[[ $(printf '%q\n') == '' ]] || err_exit 'printf "%q" with missing arguments'
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# we won't get hit by the one second boundary twice, right?
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainzif [[ $y != $exp ]]
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainzthen err_exit "read -n1 failed -- expected '$exp', got '$y'"
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainzprint -n $'{ read -r line;print $line;}\nhello' > $tmp/script
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinthen err_exit 'read of incomplete line not working correctly'
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin(( $? == 127 )) || err_exit "subshell job known to parent"
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainzfor v in ${v//,/ }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinif [[ $(foo=bar; eval foo=\$foo $env exec -c \$SHELL -c \'print \$foo\') != bar ]]
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin$SHELL -c 'OPTIND=-1000000; getopts a opt -a' 2> /dev/null
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin[[ $? == 1 ]] || err_exit 'getopts with negative OPTIND not working'
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin[[ $OPTARG == 3 ]] || err_exit 'getopts with numerical arguments failed'
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinif [[ $($SHELL -c $'printf \'%2$s %1$s\n\' world hello') != 'hello world' ]]
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz [[ $out == $val ]] || err_exit "printf $fmt $arg failed -- expected '$val', got '$out'"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin then [[ $err ]] || err_exit "printf $fmt $arg failed, error message expected"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin else [[ $err ]] && err_exit "$err: printf $fmt $arg failed, error message not expected -- got '$err'"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin (( $ret == $code )) || err_exit "printf $fmt $arg failed -- expected exit code $code, got $ret"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chindo set -- ${ARGV[$i]}
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin then err_exit "\$OPTIND after getopts loop incorrect -- expected ${ARGC[$i]}, got $OPTIND"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin a|c) [[ $OPTARG ]] && err_exit "getopts $options \$OPTARG for flag $opt failed, expected \"\", got \"$OPTARG\"" ;;
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin b) [[ $OPTARG == $optarg ]] || err_exit "getopts $options \$OPTARG failed -- \"$optarg\" expected, got \"$OPTARG\"" ;;
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin *) err_exit "getopts $options failed -- got flag $opt" ;;
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz{ read -N3 a; read -N1 b;} <<!
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz[[ $a == $exp ]] || err_exit "read -N3 here-document failed -- expected '$exp', got '$a'"
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz[[ $b == $exp ]] || err_exit "read -N1 here-document failed -- expected '$exp', got '$b'"
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz[[ $a == $exp ]] || err_exit "read -n3 here-document failed -- expected '$exp', got '$a'"
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#(print -n a;sleep 1; print -n bcde) | { read -N3 a; read -N1 b;}
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#[[ $a == $exp ]] || err_exit "read -N3 from pipe failed -- expected '$exp', got '$a'"
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#[[ $b == $exp ]] || err_exit "read -N1 from pipe failed -- expected '$exp', got '$b'"
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#(print -n a;sleep 1; print -n bcde) | read -n3 a
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#[[ $a == $exp ]] || err_exit "read -n3 from pipe failed -- expected '$exp', got '$a'"
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#if mkfifo $tmp/fifo 2> /dev/null
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#then (print -n a; sleep 1;print -n bcde) > $tmp/fifo &
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz# read -u5 -n3 -t2 a || err_exit 'read -n3 from fifo timedout'
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz# read -u5 -n1 -t2 b || err_exit 'read -n1 from fifo timedout'
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz# [[ $a == $exp ]] || err_exit "read -n3 from fifo failed -- expected '$exp', got '$a'"
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz# mkfifo $tmp/fifo 2> /dev/null
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz# (print -n a; sleep 1;print -n bcde) > $tmp/fifo &
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz# read -u5 -N3 -t2 a || err_exit 'read -N3 from fifo timed out'
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz# read -u5 -N1 -t2 b || err_exit 'read -N1 from fifo timedout'
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz# [[ $a == $exp ]] || err_exit "read -N3 from fifo failed -- expected '$exp', got '$a'"
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz# [[ $b == $exp ]] || err_exit "read -N1 from fifo failed -- expected '$exp', got '$b'"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# test command -x option
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinif ! ${SHELL:-ksh} -c 'print $#' count $(longline $n) > /dev/null 2>&1
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinthen for i in $(command command -x ${SHELL:-ksh} -c 'print $#;[[ $1 != argument0 ]]' count $(longline $n) 2> /dev/null)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin (( sum == n )) || err_exit "command -x processed only $sum arguments"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin command -p command -x ${SHELL:-ksh} -c 'print $#;[[ $1 == argument0 ]]' count $(longline $n) > /dev/null 2>&1
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin [[ $? != 1 ]] && err_exit 'incorrect exit status for command -x'
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# test command -x option with extra arguments
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinif ! ${SHELL:-ksh} -c 'print $#' count $(longline $n) > /dev/null 2>&1
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinthen for i in $(command command -x ${SHELL:-ksh} -c 'print $#;[[ $1 != argument0 ]]' count $(longline $n) one two three) #2> /dev/null)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin (( sum > n )) || err_exit "command -x processed only $sum arguments"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin (( (sum-n)%3==0 )) || err_exit "command -x processed only $sum arguments"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin (( sum == n+3)) && err_exit "command -x processed only $sum arguments"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin command -p command -x ${SHELL:-ksh} -c 'print $#;[[ $1 == argument0 ]]' count $(longline $n) > /dev/null 2>&1
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin [[ $? != 1 ]] && err_exit 'incorrect exit status for command -x'
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# test for debug trap
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin[[ $(typeset -i i=0
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin done) == $'0\n0\n1\n1\n2' ]] || err_exit "DEBUG trap not working"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin[[ $($SHELL -c 'echo -3') == -3 ]] || err_exit "echo -3 not working in ucb universe"
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#sleep $(( 2 * leeway * reps * delay )) |
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#for (( i=0 ; i < reps ; i++ ))
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#do read -N1 -t $delay
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#(( total_t = SECONDS - start_x ))
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#if (( total_t > leeway * reps * delay ))
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#then err_exit "read -t in pipe taking $total_t secs - $(( reps * delay )) minimum - too long"
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#elif (( total_t < reps * delay ))
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#then err_exit "read -t in pipe taking $total_t secs - $(( reps * delay )) minimum - too fast"
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#$SHELL -c 'sleep $(printf "%a" .95)' 2> /dev/null || err_exit "sleep doesn't except %a format constants"
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#$SHELL -c 'test \( ! -e \)' 2> /dev/null ; [[ $? == 1 ]] || err_exit 'test \( ! -e \) not working'
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin[[ $(ulimit) == "$(ulimit -fS)" ]] || err_exit 'ulimit is not the same as ulimit -fS'
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinprint $'\nprint -r -- "${.sh.file} ${LINENO} ${.sh.lineno}"' > $tmpfile
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin[[ $( . "$tmpfile") == "$tmpfile 2 1" ]] || err_exit 'dot command not working'
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin[[ $($SHELL -c ". $tmpfile"$'\n print ok' 2> /dev/null) == ok ]] || err_exit 'syntax error in dot command affects next command'
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#float sec=$SECONDS del=4
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#exec 3>&2 2>/dev/null
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#$SHELL -c "( sleep 1; kill -ALRM \$\$ ) & sleep $del" 2> /dev/null
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#(( sec = SECONDS - sec ))
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#(( exitval )) && err_exit "sleep doesn't exit 0 with ALRM interupt"
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#(( sec > (del - 1) )) || err_exit "ALRM signal causes sleep to terminate prematurely -- expected 3 sec, got $sec"
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainztypeset -r z=3
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainzdo ( unset $i) 2>/dev/null && err_exit "unset $i should fail"
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainzdo unset $i || print -u2 "err_exit unset $i should not fail"
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz[[ $($SHELL -c 'y=3; unset 123 y;print $?$y') == 1 ]] 2> /dev/null || err_exit 'y is not getting unset with unset 123 y'
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz[[ $($SHELL -c 'trap foo TERM; (trap;(trap) )') == 'trap -- foo TERM' ]] || err_exit 'traps not getting reset when subshell is last process'