Last active
May 19, 2019 18:35
-
-
Save atn34/7608446 to your computer and use it in GitHub Desktop.
run_tests.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
#RUNTIME is the path to the directory with the makefile/cubex_lib.h etc | |
#JARFILE is the path to your compiler | |
RUNTIME=../../../runtime | |
JARFILE=../../../x3c.jar | |
FLAGS= | |
FILES= | |
while (($#)) ; do | |
if echo $1 | grep -q '^-' ; then | |
FLAGS="$FLAGS $1" | |
else | |
FILES="$FILES $1" | |
fi | |
shift | |
done | |
if [ -z "$FILES" ] | |
then | |
INPUT_FILES="$(ls *.x3)" | |
else | |
INPUT_FILES="$FILES" | |
fi | |
FAILED_TESTS= | |
ALL_PASSED=TRUE | |
for F in $INPUT_FILES; do | |
in_file=$(echo "$F" | sed "s/\.x3$/\.in/") | |
out_file=$(echo "$F" | sed "s/\.x3$/\.out/") | |
PASSED=TRUE | |
REASON= | |
echo "generating C..." | |
RESULT=$(java -jar $JARFILE $FLAGS $F) | |
if [ "$?" != "0" ] ; then | |
echo "compiler crashed" | |
PASSED=FALSE | |
REASON="compiler crashed" | |
elif [ "$RESULT" = "reject" ] ; then | |
if [ "$(cat $out_file)" != "reject" ] ; then | |
PASSED=FALSE | |
REASON="compiler rejected input" | |
echo $RESULT | |
fi | |
else | |
echo "compiling C..." | |
mv out.c $RUNTIME/out.c | |
if ! make -C $RUNTIME > /dev/null 2> /dev/null ; then | |
echo "compiling C failed." | |
PASSED=FALSE | |
REASON="compiling C failed" | |
fi | |
if [ $PASSED = TRUE ] && ! cat $in_file | xargs $RUNTIME/a.out > /tmp/"$out_file".actual 2> /tmp/"$out_file".error ; then | |
PASSED=FALSE | |
REASON="$(cat /tmp/"$out_file".error)" | |
echo "$REASON" | |
fi | |
if [ $PASSED = TRUE ] && ! diff /tmp/"$out_file".actual $out_file ; then | |
PASSED=FALSE | |
REASON="diffs did not match" | |
fi | |
fi | |
if [ "$PASSED" != "TRUE" ] ; then | |
echo "[[41;30m Failed [m][91m $F [m" | |
ALL_PASSED=FALSE | |
FAILED_TESTS="$FAILED_TESTS""$F&$REASON\n" | |
else | |
echo "[[32m OK [m] $F" | |
fi | |
make -C $RUNTIME clean > /dev/null 2> /dev/null | |
done | |
if [ $ALL_PASSED = TRUE ]; then | |
echo "============================" | |
echo " All tests pass! " | |
echo "============================" | |
exit 0 | |
else | |
echo "============================" | |
echo " Failed tests: " | |
echo "============================" | |
echo -e $FAILED_TESTS | column -t -s'&' | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment