shtests revision 34f9b3eef6fdadbda0a846aa4d68691ac40eace5
0N/A# This program runs ksh regression tests
1879N/A# shtests [ name=value ... ] [ --all | --compile ] [ --time ] [ a.sh b.sh ... ]
0N/A
0N/Atimesensitive='*@(options|sigchld|subshell).sh'
0N/A
0N/Aunset DISPLAY ENV FIGNORE HISTFILE
0N/ALANG=C
0N/ALC_ALL=C
0N/Acompile=1
0N/Ascript=1
0N/Atime=1
0N/Avmdebug=a
0N/Awhile :
0N/Ado case $1 in
0N/A -a|--a*)compile=2
0N/A script=2
0N/A ;;
0N/A -c|--c*)compile=2
1472N/A script=
1472N/A ;;
1472N/A -s|--s*)compile=
0N/A script=2
0N/A ;;
0N/A -t|--not*)time=
1879N/A ;;
1879N/A -v|--nov*)vmdebug=
1879N/A ;;
1879N/A -*) echo $0: $1: invalid option >&2
1879N/A exit 2
0N/A ;;
0N/A *=*) n=${1%%=*}
0N/A v=${1#*=}
304N/A eval $n=\'$v\'
304N/A export $n
304N/A ;;
0N/A *) break
304N/A ;;
304N/A esac
304N/A shift
0N/Adone
0N/Aif [[ ! $vmdebug ]]
304N/Athen unset VMDEBUG
304N/Aelif [[ $VMDEBUG ]]
304N/Athen vmdebug=$VMDEBUG
0N/Aelse export VMDEBUG=$vmdebug
0N/Afi
0N/A[[ $VMDEBUG ]] || timesensitive=.
0N/Aexport LANG LC_ALL PATH PWD SHELL
0N/APWD=`pwd`
304N/ASHELL=${SHELL-ksh}
304N/Acase $0 in
304N/A/*) d=`dirname $0`;;
304N/A*/*) d=$PWD/`dirname $0`;;
0N/A*) d=$PWD;;
304N/Aesac
0N/Acase $SHELL in
304N/A/*) ;;
304N/A*/*) SHELL=$d/$SHELL;;
304N/A*) SHELL=$(whence $SHELL);;
304N/Aesac
304N/APATH=/bin:/usr/bin
304N/Aif [[ -d /usr/ucb ]]
304N/Athen PATH=$PATH:/usr/ucb
304N/Afi
304N/APATH=$PATH:$d
304N/Aif [[ $INSTALLROOT && -r $INSTALLROOT/bin/.paths ]]
304N/Athen PATH=$INSTALLROOT/bin:$PATH
304N/Afi
304N/Aif [[ $compile ]]
304N/Athen SHCOMP=${SHCOMP:-shcomp}
304N/A if whence $SHCOMP > /dev/null
304N/A then tmp=$(mktemp -dt) || { echo mktemp -dt failed >&2; exit 1; }
304N/A trap "cd /; rm -rf $tmp" EXIT
304N/A elif [[ $compile != 1 ]]
304N/A then echo $0: --compile: $SHCOMP not found >&2
304N/A exit 1
0N/A else compile=
304N/A fi
304N/Afi
304N/Atypeset -A tests
304N/Afor i in ${*-*.sh}
304N/Ado t=$(grep -c err_exit $i)
304N/A if (( $t > 2 ))
304N/A then (( t = $t - 2 ))
304N/A fi
304N/A tests[$i]=$t
304N/A T=test
304N/A if (( $t != 1 ))
304N/A then T=${T}s
304N/A fi
304N/A E=error
304N/A if [[ $script ]]
304N/A then echo test $i begins ${time:+"at $(date +%Y-%m-%d+%H:%M:%S)"}
304N/A if [[ $i == $timesensitive ]]
304N/A then unset VMDEBUG
304N/A fi
304N/A if $SHELL $i
304N/A then echo test $i passed ${time:+"at $(date +%Y-%m-%d+%H:%M:%S)"} "[ $t $T 0 ${E}s ]"
304N/A else e=$?
304N/A if (( e > 256 ))
304N/A then e=1
304N/A E=signal
304N/A fi
304N/A if (( $e != 1 ))
304N/A then E=${E}s
304N/A fi
304N/A echo test $i failed ${time:+"at $(date +%Y-%m-%d+%H:%M:%S)"} with exit code $e "[ $t $T $e $E ]"
304N/A fi
0N/A if [[ $i == $timesensitive ]]
304N/A then export VMDEBUG=$vmdebug
304N/A fi
304N/A fi
304N/Adone
304N/Aif [[ $compile ]]
304N/Athen for i in ${*-*.sh}
304N/A do t=${tests[$i]}
304N/A T=test
304N/A if (( $t != 1 ))
304N/A then T=${T}s
304N/A fi
304N/A o=${i##*/}
304N/A o=shcomp-${o%.sh}.ksh
304N/A echo test $o begins ${time:+"at $(date +%Y-%m-%d+%H:%M:%S)"}
304N/A E=error
304N/A if $SHCOMP $i > $tmp/$o
304N/A then if [[ $i == $timesensitive ]]
304N/A then unset VMDEBUG
304N/A fi
304N/A if $SHELL $tmp/$o
304N/A then echo test $o passed ${time:+"at $(date +%Y-%m-%d+%H:%M:%S)"} "[ $t $T 0 ${E}s ]"
304N/A else e=$?
304N/A if (( e > 256 ))
304N/A then e=1
304N/A E=signal
304N/A fi
304N/A if (( $e != 1 ))
then E=${E}s
fi
echo test $o failed ${time:+"at $(date +%Y-%m-%d+%H:%M:%S)"} with exit code $e "[ $t $T $e $E ]"
fi
if [[ $i == $timesensitive ]]
then export VMDEBUG=$vmdebug
fi
else e=$?
t=1
T=test
echo test $o failed to compile ${time:+"at $(date +%Y-%m-%d+%H:%M:%S)"} with exit code $e "[ $t $T 1 $E ]"
fi
done
fi