Skip to content

Instantly share code, notes, and snippets.

@bouk
Created November 21, 2012 19:52
Show Gist options
  • Save bouk/4127239 to your computer and use it in GitHub Desktop.
Save bouk/4127239 to your computer and use it in GitHub Desktop.
#!/bin/bash
if [ $# -lt 1 ]
then
echo "Needs program filename argument"
exit 1
fi
executable=`mktemp`
echo "Testing $1"
echo
if [ $# -lt 2 ]
then
testcases=1
else
testcases=$2
fi
if [ $# -lt 3 ]
then
extra=''
else
extra=$3
fi
echo "Compiling ..."
g++ -o $executable $1
if (( $? ))
then
echo "Compilation failed"
exit 1
else
chmod +x $executable
for ((i = 1; i <= $testcases; i++))
do
if ! [ -a "$extra$i.in" ]
then
echo "Testcase input $i does not exist"
exit 1
fi
tempresultfile=`mktemp`
$executable < "$extra$i.in" > $tempresultfile
diff --ignore-trailing-space $tempresultfile "$extra$i.out" >/dev/null
if (( $? ))
then
echo "Test $i failed"
sdiff $tempresultfile "$extra$i.out"
echo
else
echo "Test $i OK"
fi
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment