aboutsummaryrefslogtreecommitdiff
path: root/include/tests/tests.h
blob: 8c89fccd7c669a8bb7be4a02e1f18d5f5478af45 (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
#ifndef TESTS_H
#define TESTS_H
#include <stdio.h>
#include <stdlib.h>

#ifndef NOCOLOR
#define TBLD "\033[1m"
#define TRED "\033[31m"
#define TGRN "\033[32m"
#define TBLU "\033[34m"
#define TRST "\033[0m"
#else
#define TBLD ""
#define TRED ""
#define TGRN ""
#define TBLU ""
#define TRST ""
#endif

#define RUN_TEST(test_func) \
	printf("%s:\t", #test_func); \
	fflush(stdout); \
	test_func(); \
	printf(TGRN "OK!\n" TRST)

#define INIT_TESTS() \
	printf(TBLD "running %s tests\n" TRST, __FILE__)

#define FAIL_TEST(reason) \
	printf(TBLD TRED "FAIL!\n" TRST); \
	printf("%s:%d: %s: ", __FILE__, __LINE__, __func__); \
	printf(reason); \
	abort()

#define asserteq(a, b) \
	if (a != b) { \
		FAIL_TEST("assertion " TBLD TBLU #a " == " #b TRST " failed\n"); \
	}

#define assertneq(a, b) \
	if (a == b) { \
		FAIL_TEST("assertion " TBLD TBLU #a " != " #b TRST " failed\n"); \
	}

#endif