Newer
Older
Import / research / TestSuite / tests / bin / testcheck
#!/bin/bash


function usage
{
    echo
    echo "Usage $0 FileName.Ext"
    echo
    echo "Where FileName is the name of the program to check, eg:"
    echo
    echo "      MirrorString, CheckSumData or RotateData"
    echo
    echo "And where Ext is the type of program which is one of:"
    echo
    echo "      .c, .cpp, .py, .pl or .sh"
    echo
    exit 0
}


[ "$1" == "" ] && usage
ext=${1#*.}
base=${1%.*}
# echo "Checking Filename $base, Extension $ext"


echo -n "Program to check: "
if [ -e tests/$base/description ]
then
    cat tests/$base/description
else
    echo "Invalid"
    usage
fi


echo -n "Programming Language: "
case $ext in
    "c" )
        echo "C"
        gcc ${base}.c tests/$base/harness.c -o /tmp/$base || exit 0
        execute=/tmp/$base
        ;;
    "cpp" )
        echo "C++"
        gcc ${base}.cpp tests/$base/harness.cpp -o /tmp/$base || exit 0
        execute=/tmp/$base
        ;;
    "py" )
        echo "Python"
        execute=python tests/$base/harness.py
        ;;
    "pl" )
        echo "Perl"
        execute=perl tests/$base/harness.pl
        ;;
    "sh" )
        echo "Shell script"
        execute=bash tests/$base/harness.sh
        ;;
    * )
        echo "Invalid"
        usage
esac


cat tests/$base/tests | while read line
do
    $execute $line > /dev/null 2>&1
    if [ "$?" = "1" ]
    then
        echo pass
    else
        echo fail
    fi
done