summaryrefslogtreecommitdiff
path: root/tests/test.sh
blob: ceb6cbe0320e68fb35a46a2be94cb0ec476a1955 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash
DIR=$(dirname $0)
TOC=$DIR/../toc
CFLAGS="-g -Wno-parentheses-equality"
echo $$

compile() {
	EXTRA_FLAGS=""
	if [ "$CC" = "gcc -O0 -g" ]; then
		EXTRA_FLAGS="-Wno-builtin-declaration-mismatch"
	elif [ "$CC" = "clang -O3 -s" ]; then
		EXTRA_FLAGS="-Wno-builtin-requires-header"
	fi
	$CC $CFLAGS $EXTRA_FLAGS -o $DIR/$1/$1.bin $DIR/$1/$1.c || exit 1
}

do_tests() {
	valgrind  -q --exit-on-first-error=yes --error-exitcode=1 $TOC "$DIR/$1/$1.toc" -o "$DIR/$1/$1.c" >/dev/null || exit 1
	for CC in "gcc -O0 -g" "tcc" "clang -O3 -s"; do
		printf "Running test $1 with C compiler $CC... "
		compile "$1"
		cd "$DIR/$1"
		./test.sh || { printf "\x1b[91mfailed!\x1b[0m\n"; exit 1; }
		printf '\x1b[92mpassed!\x1b[0m\n'
		cd $STARTPWD
	done
	
}

STARTPWD="$(pwd)"

do_tests bf
do_tests arr
do_tests arr2
do_tests foreign
do_tests params