From aaeb153ce869567f4f88f083dba28445216714f6 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Sun, 22 Jan 2023 00:23:32 +0100 Subject: Started working on testing (broken for now) --- tests/test.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tests/test.c (limited to 'tests/test.c') 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 @@ +#include +#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; +} + +int main() { + 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; +} -- cgit v1.3