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