aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/fst_tests.c10
-rw-r--r--tests/fst_tests.h2
-rw-r--r--tests/test.c43
-rw-r--r--tests/test.h7
-rw-r--r--tests/test_common.h34
5 files changed, 73 insertions, 23 deletions
diff --git a/tests/fst_tests.c b/tests/fst_tests.c
index 684a479..dfaab39 100644
--- a/tests/fst_tests.c
+++ b/tests/fst_tests.c
@@ -3,9 +3,7 @@
3static bool testmethod_fst_is_consistent(void *); 3static bool testmethod_fst_is_consistent(void *);
4static bool testmethod_cube_to_fst_to_cube(void *); 4static bool testmethod_cube_to_fst_to_cube(void *);
5static bool testmethod_fst_move(void *); 5static bool testmethod_fst_move(void *);
6static bool testmethod_fst_inverse(void *); 6static bool testmethod_fst_inverse(void *); static bool check_equal_and_log(Cube *, Cube *);
7
8static bool check_equal_and_log(Cube *, Cube *);
9static void void_to_cube(void *, Cube *); 7static void void_to_cube(void *, Cube *);
10 8
11char *algs[] = { 9char *algs[] = {
@@ -66,6 +64,12 @@ TestSuite fst_post_init_suite = {
66 .teardown = NULL, 64 .teardown = NULL,
67}; 65};
68 66
67TestSuite *fst_testsuites[] = {
68 &fst_pre_init_suite,
69 &fst_post_init_suite,
70 NULL
71};
72
69static bool 73static bool
70check_equal_and_log(Cube *c, Cube *d) 74check_equal_and_log(Cube *c, Cube *d)
71{ 75{
diff --git a/tests/fst_tests.h b/tests/fst_tests.h
index 3a7496e..324028e 100644
--- a/tests/fst_tests.h
+++ b/tests/fst_tests.h
@@ -14,4 +14,6 @@ extern Test test_fst_inverse;
14extern TestSuite fst_pre_init_suite; 14extern TestSuite fst_pre_init_suite;
15extern TestSuite fst_post_init_suite; 15extern TestSuite fst_post_init_suite;
16 16
17extern TestSuite *fst_testsuites[];
18
17#endif 19#endif
diff --git a/tests/test.c b/tests/test.c
index 2055c78..cc14456 100644
--- a/tests/test.c
+++ b/tests/test.c
@@ -1,4 +1,6 @@
1#include "test.h" 1#include <stdio.h>
2
3#include "fst_tests.h"
2 4
3static bool run_test(Test *); 5static bool run_test(Test *);
4static bool run_suite(TestSuite *); 6static bool run_suite(TestSuite *);
@@ -36,15 +38,42 @@ run_suite(TestSuite *suite)
36 return true; 38 return true;
37} 39}
38 40
39int main() { 41static bool
42module_in_args(char *module, int argc, char *argv[])
43{
44 for (int i = 0; i < argc; i++)
45 if (!strcmp(module, argv[i]))
46 return true;
47 return false;
48}
49
50int main(int argc, char *argv[]) {
51 /* TODO: init should be in testsuites */
40 init_env(); 52 init_env();
41 init_trans(); 53 init_trans();
54 /**************************************/
42 55
43 if (!run_suite(&fst_pre_init_suite)) 56 TestModule fst = { .name = "fst", .suites = fst_testsuites };
44 return 1; 57 TestModule *modules[999] = {
45 if (!run_suite(&fst_post_init_suite)) 58 &fst,
46 return 1; 59 NULL
60 };
61
62
63 bool all = argc == 1 || module_in_args("all", argc, argv);
64 int count = 0;
65 for (int i = 0; modules[i] != NULL; i++) {
66 if (all || module_in_args(modules[i]->name, argc, argv)) {
67 for (int j = 0; modules[i]->suites[j] != NULL; j++) {
68 if (!run_suite(modules[i]->suites[j])) {
69 return 1;
70 } else {
71 count++;
72 }
73 }
74 }
75 }
47 76
48 printf("All tests passed.\n"); 77 printf("All tests passed (%d test suites).\n", count);
49 return 0; 78 return 0;
50} 79}
diff --git a/tests/test.h b/tests/test.h
deleted file mode 100644
index ac30cdb..0000000
--- a/tests/test.h
+++ /dev/null
@@ -1,7 +0,0 @@
1#ifndef TEST_H
2#define TEST_H
3
4#include <stdio.h>
5#include "fst_tests.h"
6
7#endif
diff --git a/tests/test_common.h b/tests/test_common.h
index ea35ecd..03511ef 100644
--- a/tests/test_common.h
+++ b/tests/test_common.h
@@ -1,19 +1,41 @@
1#ifndef TEST_COMMON_H 1#ifndef TEST_COMMON_H
2#define TEST_COMMON_H 2#define TEST_COMMON_H
3 3
4/*
5 * Common utilities for testing.
6 * A VoidMethod can be used as a setup or teardown method for testing, see
7 * the TestSuite struct. A TestMethod takes a void pointer (usually cast
8 * to some data to be used for testing, but can also be ignored) and returns
9 * a bool: true for pass, false for fail.
10 * A Test consists of a name (string), a TestMethod and an array of void
11 * pointers that describe the test cases. Each element of this array is
12 * passed to the test method sequentially, and the test session stops on
13 * the first failure.
14 * A test suite is just a list of tests with a setup and a teardown method.
15 * The setup method is run once and for all before the first test, and the
16 * teardown is run at the end of the testsuite.
17 * Finally, a TestModule roughly corresponds to a test file. This type is
18 * only used in test.c to collect multiple test modules.
19 */
20
4typedef void (*VoidMethod)(void); 21typedef void (*VoidMethod)(void);
5typedef bool (*TestMethod)(void *); 22typedef bool (*TestMethod)(void *);
6 23
7typedef struct { 24typedef struct {
8 char * name; 25 char * name;
9 TestMethod t; 26 TestMethod t;
10 void ** cases; 27 void ** cases;
11} Test; 28} Test;
12 29
13typedef struct { 30typedef struct {
14 VoidMethod setup; 31 VoidMethod setup;
15 Test ** tests; 32 Test ** tests;
16 VoidMethod teardown; 33 VoidMethod teardown;
17} TestSuite; 34} TestSuite;
18 35
36typedef struct {
37 char * name;
38 TestSuite ** suites;
39} TestModule;
40
19#endif 41#endif

Generated with cgit - Back to sebastiano.tronto.net