summaryrefslogtreecommitdiff
path: root/tests/test.sh
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test.sh')
-rwxr-xr-xtests/test.sh28
1 files changed, 15 insertions, 13 deletions
diff --git a/tests/test.sh b/tests/test.sh
index 6d534d3..1d47dff 100755
--- a/tests/test.sh
+++ b/tests/test.sh
@@ -1,10 +1,11 @@
#!/bin/bash
-DIR=$(pwd)/$(dirname $0)
-TOC=$DIR/../toc
+STARTPWD=$(pwd)
+cd $(pwd)/$(dirname $0)
+TOC=../toc
CFLAGS="-g -Wno-parentheses-equality"
echo $$
-compile() {
+compile_c() {
EXTRA_FLAGS=""
if [ "$CC" = "gcc -O0 -g" ]; then
EXTRA_FLAGS="-Wno-builtin-declaration-mismatch"
@@ -13,24 +14,24 @@ compile() {
elif [ "$CC" = "tcc" ]; then
EXTRA_FLAGS="-w"
fi
- $CC $CFLAGS $EXTRA_FLAGS -o $DIR/$1/$1.bin $DIR/$1/$1.c || exit 1
+ $CC $CFLAGS $EXTRA_FLAGS -o a.out out.c || exit 1
}
do_tests() {
- cd "$DIR/$1"
- valgrind -q --exit-on-first-error=yes --error-exitcode=1 $TOC "$DIR/$1/$1.toc" -o "$DIR/$1/$1.c" >/dev/null || exit 1
+ valgrind -q --exit-on-first-error=yes --error-exitcode=1 $TOC "$1.toc" -o out.c || exit 1
for CC in "gcc -O0 -g" "tcc" "clang -O3 -s"; do
printf "Running test $1 with C compiler $CC... "
- compile "$1"
- ./test.sh || { printf "\x1b[91mfailed!\x1b[0m\n"; exit 1; }
- printf '\x1b[92mpassed!\x1b[0m\n'
+ compile_c "$1"
+ ./a.out > got
+ if diff "$1"_expected got; then
+ printf '\x1b[92mpassed!\x1b[0m\n'
+ else
+ printf '\x1b[91mfailed!\x1b[0m\n'
+ exit 1
+ fi
done
- cd $STARTPWD
-
}
-STARTPWD="$(pwd)"
-
do_tests bf
do_tests arr
do_tests arr2
@@ -38,3 +39,4 @@ do_tests arr3
do_tests foreign
do_tests params
do_tests nms
+rm got a.out out.c