aboutsummaryrefslogtreecommitdiff
path: root/tests/test.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test.c')
-rw-r--r--tests/test.c85
1 files changed, 0 insertions, 85 deletions
diff --git a/tests/test.c b/tests/test.c
deleted file mode 100644
index 8961de1..0000000
--- a/tests/test.c
+++ /dev/null
@@ -1,85 +0,0 @@
1#include <stdio.h>
2
3#include "alg_tests.h"
4#include "coord_tests.h"
5#include "fst_tests.h"
6
7static bool run_test(Test *);
8static bool run_suite(TestSuite *);
9
10static bool
11run_test(Test *test)
12{
13 int i;
14
15 printf("Running test %s...", test->name);
16 for (i = 0; test->cases[i] != NULL; i++) {
17 if (!test->t(test->cases[i])) {
18 printf("FAILED!\n");
19 return false;
20 }
21 }
22
23 printf("OK\n");
24 return true;
25}
26
27static bool
28run_suite(TestSuite *suite)
29{
30 int i;
31
32 if (suite->setup != NULL)
33 suite->setup();
34 for (i = 0; suite->tests[i] != NULL; i++)
35 if(!run_test(suite->tests[i]))
36 return false;
37 if (suite->teardown != NULL)
38 suite->teardown();
39
40 return true;
41}
42
43static bool
44module_in_args(char *module, int argc, char *argv[])
45{
46 for (int i = 0; i < argc; i++)
47 if (!strcmp(module, argv[i]))
48 return true;
49 return false;
50}
51
52int main(int argc, char *argv[]) {
53 /* TODO: init should be in testsuites */
54 init_env();
55 init_trans();
56 /**************************************/
57
58 TestModule alg = { .name = "alg", .suites = alg_suites };
59 TestModule fst = { .name = "fst", .suites = fst_suites };
60 TestModule coord = { .name = "coord", .suites = coord_suites };
61 TestModule *modules[999] = {
62 &alg,
63 &fst,
64 &coord,
65 NULL
66 };
67
68
69 bool all = argc == 1 || module_in_args("all", argc, argv);
70 int count = 0;
71 for (int i = 0; modules[i] != NULL; i++) {
72 if (all || module_in_args(modules[i]->name, argc, argv)) {
73 for (int j = 0; modules[i]->suites[j] != NULL; j++) {
74 if (!run_suite(modules[i]->suites[j])) {
75 return 1;
76 } else {
77 count++;
78 }
79 }
80 }
81 }
82
83 printf("All tests passed (%d test suites).\n", count);
84 return 0;
85}

Generated with cgit - Back to sebastiano.tronto.net