aboutsummaryrefslogtreecommitdiff
path: root/tests/test.c
blob: 2055c78ba71f63176bfe4d87844e1ae95aa213d2 (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
#include "test.h"

static bool run_test(Test *);
static bool run_suite(TestSuite *);

static bool
run_test(Test *test)
{
	int i;

	printf("Running test %s...", test->name);
	for (i = 0; test->cases[i] != NULL; i++) {
		if (!test->t(test->cases[i])) {
			printf("FAILED!\n");
			return false;
		}
	}

	printf("OK\n");
	return true;
}

static bool
run_suite(TestSuite *suite)
{
	int i;

	if (suite->setup != NULL)
		suite->setup();
	for (i = 0; suite->tests[i] != NULL; i++)
		if(!run_test(suite->tests[i]))
			return false;
	if (suite->teardown != NULL)
		suite->teardown();

	return true;
}

int main() {
	init_env();
	init_trans();

	if (!run_suite(&fst_pre_init_suite))
		return 1;
	if (!run_suite(&fst_post_init_suite))
		return 1;

	printf("All tests passed.\n");
	return 0;
}

Generated with cgit - Back to sebastiano.tronto.net