aboutsummaryrefslogtreecommitdiff
path: root/tests/test.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test.c')
-rw-r--r--tests/test.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/test.c b/tests/test.c
new file mode 100644
index 0000000..c122db8
--- /dev/null
+++ b/tests/test.c
@@ -0,0 +1,48 @@
1#include <stdio.h>
2#include "fst_tests.h"
3
4static bool run_test(Test *);
5static bool run_suite(TestSuite *);
6
7static bool
8run_test(Test *test)
9{
10 int i;
11
12 printf("Running test %s...", test->name);
13 for (i = 0; test->cases[i] != NULL; i++) {
14 if (!test->t(test->cases[i])) {
15 printf("FAILED!\n");
16 return false;
17 }
18 }
19
20 printf("OK\n");
21 return true;
22}
23
24static bool
25run_suite(TestSuite *suite)
26{
27 int i;
28
29 if (suite->setup != NULL)
30 suite->setup();
31 for (i = 0; suite->tests[i] != NULL; i++)
32 if(!run_test(suite->tests[i]))
33 return false;
34 if (suite->teardown != NULL)
35 suite->teardown();
36
37 return true;
38}
39
40int main() {
41 if (!run_suite(&fst_pre_init_suite))
42 return 1;
43 if (!run_suite(&fst_post_init_suite))
44 return 1;
45
46 printf("All tests passed.\n");
47 return 0;
48}

Generated with cgit - Back to sebastiano.tronto.net