#!/bin/sh
#
#ident	"$Id: runtests,v 1.1 2005/10/25 22:38:34 jmoyer Exp $"
#
# Master runtests script.
#
#
# runtests [ -a|-b|-e|-p|-n|-v ]
#  
# -a|-b|-e|-p|-n|-v       This argument is optional. The default is read
#                         from the initialization file, 'tests.init'. The
#                         variable, TESTS contains this argument.
#                         This argument selects which tests to run:
#                           -a    run all tests
#                           -b    run the basic tests
#                           -e    run the executable map test
#                           -p    run the parser checking test
#                           -n    run the /net tests
#			    -v    run the version and protocol checking tests
#

Program=`basename $0`
LOG=/tmp/runtests.summary.$$

trap "rm -f ${LOG}; exit 1" 2 9

InitFile="../src/tests.init"

if [ $# -ne 0 ]; then
	TESTS=$1
else
	if [ -f $InitFile ]; then
		echo "$Program: using test defaults in $InitFile"
		. $InitFile
	else	
		echo "usage: $Program [-a|-b|-e|-p|-n|-s|-v ] "
		exit 1
	fi
fi

if [ x$TESTS = x ]; then
	echo "$Program: TESTS environment variable not specified"
	echo "          you may also set it as argument to this test"
	exit 1
fi

case $TESTS in
	-a)	dirs="parser parser-n test1 test2 test3 test4 test5 badnames trailing_space net net1 vers_check proto_check"  ;;
	-b)	dirs="parser test1 test2 test3 test4 test5 badnames trailing_space vers_check proto_check"	;;
	-e)	dirs="test2"	;;
	-p)	dirs="parser parser-n"	;;
	-n)	dirs="net net1"	;;
	-v)	dirs="vers_check proto_check"  ;;
	*)	echo "usage: $Program [-a|-b|-e|-p|-n|-s|-v ] "
                exit 1	;;
esac

for dir in $dirs
do
	NLINES=`echo ${dir} | sed 's/./-/g'`
	echo
	echo
	echo "    ----------------------${NLINES}----------------------"
	echo "    --------------- Executing ${dir} -----------------"
	echo
	if file ${dir} | grep "perl" > /dev/null; then
		perl ${dir}
	else
		sh ${dir}
	fi
	if [ $? -ne 0 ]; then
		echo $dir FAILED.
		echo $dir - FAILED. >> ${LOG}
	else
		echo $dir - PASSED. >> ${LOG}
	fi
done

echo
echo "All tests completed"
echo ""
echo "Test Summary:"
cat ${LOG}
rm ${LOG}

exit 0
