summaryrefslogtreecommitdiff
path: root/tests/test.sh
blob: e6e8fe56c6117ded9d92bff8a96e7a7fa23ae150 (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/bash

tests='bf
control_flow
defer
sizeof
new
arr
arr2
arr3
foreign
params
nms
varargs
printf
use
misc'

STARTPWD=$(pwd)
cd $(pwd)/$(dirname $0)
TOC=../toc
CFLAGS="-g -Wno-parentheses-equality"
echo $$

compile_c() {
	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 -Wno-format-security"
	elif [ "$CC" = "tcc" ]; then
		EXTRA_FLAGS="-w"
	fi
	$CC $CFLAGS $EXTRA_FLAGS -Werror -o a.out out.c || exit 1
}

failed=false

do_tests() {
	echo "----$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
		if [ "$1" = "sizeof" ]; then
			if [ "$CC" = "tcc" ]; then
				continue # some versions of tcc don't have _Alignof
			fi
		fi
		printf "Running test $1 with C compiler $CC... "
		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
}
for x in $tests; do
	do_tests "$x"
done

rm got a.out out.c