test.sh (887B)
1 #!/bin/sh 2 3 detectsan() { cc -fsanitize=$1 -dM -E -x c - </dev/null | grep "SANITIZE"; } 4 5 re="${TEST:-$@}" 6 7 CC="cc -DDEBUG -std=c99 -pedantic -Wall -Wextra -g3" 8 9 [ -n "$(detectsan address)" ] && CC="$CC -fsanitize=address" 10 [ -n "$(detectsan undefined)" ] && CC="$CC -fsanitize=undefined" 11 12 TESTBIN="test/run" 13 TESTOUT="test/last.out" 14 TESTERR="test/last.err" 15 CUBEOBJ="debugcube.o" 16 17 for t in test/*; do 18 if [ -n "$re" ] && [ -z "$(echo "$t" | grep "$re")" ]; then 19 continue 20 fi 21 if [ ! -d $t ]; then continue; fi 22 $CC -o $TESTBIN $t/*.c $CUBEOBJ || exit 1; 23 for cin in $t/*.in; do 24 c=$(echo "$cin" | sed 's/\.in//') 25 cout=$c.out 26 printf "$c: " 27 $TESTBIN < "$cin" > $TESTOUT 2> $TESTERR 28 if diff $cout $TESTOUT; then 29 printf "OK\n" 30 else 31 printf "Test failed! stderr:\n" 32 cat $TESTERR 33 exit 1 34 fi 35 done 36 done 37 38 echo "All tests passed!" 39 rm -rf $TESTBIN $TESTOUT $TESTERR $CUBEOBJ