diff options
author | axtloss <axtlos@getcryst.al> | 2024-09-27 12:11:52 +0200 |
---|---|---|
committer | axtloss <axtlos@getcryst.al> | 2024-09-27 12:11:52 +0200 |
commit | 7aa261f8d57cb53cc334f6bf1920a6f8517ff054 (patch) | |
tree | f23a96feda17de737c71b45dc94e7e044410ad35 /tests/driver.c | |
parent | 27bb394bc0bf2ca66d06931bf1e73a3e20d5741a (diff) | |
download | extlib-7aa261f8d57cb53cc334f6bf1920a6f8517ff054.tar.gz extlib-7aa261f8d57cb53cc334f6bf1920a6f8517ff054.tar.bz2 |
Rework test suite to be more modular
Diffstat (limited to '')
-rw-r--r-- | tests/driver.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/driver.c b/tests/driver.c new file mode 100644 index 0000000..235d598 --- /dev/null +++ b/tests/driver.c @@ -0,0 +1,46 @@ +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <sys/types.h> +#define USE_SECURE_MEM +#include "../src/extlib.h" +#include "test_driver.h" + +const char* success = "\033[1;32m"; +const char* fail = " \033[1;31m"; +const char *reset = "\033[0m"; + +int tests_count; +struct test_t** registered_tests; + +int +test_runner (struct test_t *test, int n) +{ + printf ("Test Case %d: %s -- %s\n", n, test->test_name, test->test_desc); + int test_result = test->test_func(); + if (test_result == 0) + printf ("Test Case %d: %s -- %sSUCCESS%s\n\n", n, test->test_name, success, reset); + else + printf ("Test Case %d: %s -- %sFAIL %d%s\n\n", n, test->test_name, test_result, fail, reset); +} + +void +register_test (struct test_t *test) +{ + tests_count += 1; + registered_tests = reallocarray (registered_tests, sizeof (struct test_t), tests_count); + + registered_tests[tests_count-1] = test; +} + +int +main (int argc, char *argv[]) +{ + registered_tests = malloc (8); + tests_entrypoint(); + for (int i = 0; i < tests_count; i++) + { + test_runner(registered_tests[i], i+1); + } + return 0; +} |