#!/bin/bash uname=`uname` if [ "$uname" = "Darwin" ]; then date="gdate" readlink="greadlink" wc="gwc" sed="gsed" else date="date" readlink="readlink" wc="wc" sed="sed" fi start=$($date +%s.%N) absdir=$($readlink -f $(dirname $0)) pass="\033[32mPASSED\033[0m" fail="\033[31mFAILED\033[0m" tests=0 passes=0 num=`ls $absdir | grep .\*.c | $wc -L` num=$((num-2)) fmt=`echo "%-$num""s"` for i in $(ls $absdir | grep .\*.c | sort); do answer=`$absdir/../mycc < $absdir/$i | tail -n 1` # exp_ans=`grep --color=none "##answer" $absdir/$i | $sed 's/[^0-9]\+\([0-9]\+\).\+/\1/g'` exp_ans=`grep --color=none "##answer" $absdir/$i | $sed 's/\/\* ##answer:\s\+\([^\*]\+\)\b\s*\*\//\1/g'` printf $fmt "${i%.*}" echo -n " ... " if [ "$answer" == "$exp_ans" ]; then echo -e "$pass" passes=$((passes+1)) else echo -e "$fail expected $exp_ans got $answer" fi tests=$((tests+1)) done end=$($date +%s.%N) runtime=$(python -c "print(${end} - ${start})") echo -e "\n$passes/$tests passed in $runtime""s" exit $((tests-passes))