cs240/sync/Lab4/task2/testall
2018-10-15 17:20:57 -04:00

90 lines
2.2 KiB
Bash
Executable File

#!/bin/bash
export LAB=lab4
#Check if they included string.h, and report error if so
if grep --quiet '\"string.h\"' mystring.c; then
echo "ERROR! the text \"string.h\" is present in your mystring.c file! Please remove all references to string.h, as you are not allowed to use any string.h functions in this assignment!"
exit 1
fi
(make clean; make) || exit 1
total=0
totalmax=0
rm -f total.txt *out total.txt
# Test driver
function runtest {
prog=$1
args=$2
testinput=$3
compout=$4
grade=$5
totalmax=`expr $totalmax + $grade`;
inputdescr=
if [ "$testinput" != "none" ]; then
inputdescr=" < $testinput"
fi
descr="$prog $args $inputdescr"
echo "======= $descr ==========="
#Run tested program
if [ $compout -eq 0 ]; then
./$prog $args < $testinput > $prog.out
if [ $? -eq 0 ]; then
cat $prog.out
echo Test passed...;
printf "%-36s: %-3d of %-3d\n" "$descr " $grade $grade >> total.txt
total=`expr $total + $grade`;
else
cat $prog.out
echo "*****Test Failed*****";
printf "%-36s: %-3d of %-3d\n" "$descr " 0 $grade >> total.txt
fi
else
./$prog $args < $testinput > $prog.out
./$prog.org $args < $testinput > $prog.org.out
diff $prog.out $prog.org.out > diff.out
if [ $? -eq 0 ]; then
cat $prog.out
echo Test passed...;
printf "%-36s: %-3d of %-3d\n" "$descr " $grade $grade >> total.txt
total=`expr $total + $grade`;
else
echo "*****Test Failed*****";
echo ------ Your Output ----------
cat $prog.out
echo ------ Expected Output ------
cat $prog.org.out
echo ------ Difference -----------
cat diff.out
echo -----------------------------
printf "%-36s: %-3d of %-3d\n" "$descr " 0 $grade >> total.txt
fi
fi
echo
}
# List of tests running
runtest test_mystring "test1" none 1 15
echo
echo
echo "-------------------------------------------------"
echo "CS240: $LAB. $USER "
echo "-------------------------------------------------"
cat total.txt
echo "-------------------------------------------------"
echo "CS240: $LAB. $USER" `date` " Total: " $total of $totalmax >> total.out
echo >> total.out
cat total.out
cat total.out >> .local.total.out