aboutsummaryrefslogtreecommitdiff
path: root/tests/test.c
blob: a1a382c377c394c72a9c6f333a7f0d0de4b956fa (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <stdio.h>

#include "coord_tests.h"
#include "fst_tests.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;
}

static bool
module_in_args(char *module, int argc, char *argv[])
{
	for (int i = 0; i < argc; i++)
		if (!strcmp(module, argv[i]))
			return true;
	return false;
}

int main(int argc, char *argv[]) {
	/* TODO: init should be in testsuites */
	init_env();
	init_trans();
	/**************************************/

	TestModule fst   = { .name = "fst",   .suites = fst_suites };
	TestModule coord = { .name = "coord", .suites = coord_suites };
	TestModule *modules[999] = {
		&fst,
		&coord,
		NULL
	};


	bool all = argc == 1 || module_in_args("all", argc, argv);
	int count = 0;
	for (int i = 0; modules[i] != NULL; i++) {
		if (all || module_in_args(modules[i]->name, argc, argv)) {
			for (int j = 0; modules[i]->suites[j] != NULL; j++) {
				if (!run_suite(modules[i]->suites[j])) {
					return 1;
				} else {
					count++;
				}
			}
		}
	}

	printf("All tests passed (%d test suites).\n", count);
	return 0;
}

Generated with cgit - Back to sebastiano.tronto.net