diff options
author | Alfred E. Heggestad <aeh@db.org> | 2015-10-10 21:17:00 +0200 |
---|---|---|
committer | Alfred E. Heggestad <aeh@db.org> | 2015-10-10 21:17:00 +0200 |
commit | 399dc2bc0c07fbe904742a1f109142be70ab4a56 (patch) | |
tree | e6a75601521ffb78cd6680be6590c3372a463dbd /test/main.c | |
parent | df805d411841359d52f553fe2cf38447399fceaa (diff) |
test: run all testcases from an array of tests
Diffstat (limited to 'test/main.c')
-rw-r--r-- | test/main.c | 55 |
1 files changed, 35 insertions, 20 deletions
diff --git a/test/main.c b/test/main.c index d39adfe..29e8460 100644 --- a/test/main.c +++ b/test/main.c @@ -8,29 +8,43 @@ #include "test.h" -static int run_tests(void) -{ - int err; +typedef int (test_exec_h)(void); - err = test_cmd(); - if (err) - return err; +struct test { + test_exec_h *exec; + const char *name; +}; - err = test_ua_alloc(); - if (err) - return err; +#define TEST(a) {a, #a} - err = test_uag_find_param(); - if (err) - return err; +static const struct test tests[] = { + TEST(test_cmd), + TEST(test_ua_alloc), + TEST(test_uag_find_param), + TEST(test_ua_register), + TEST(test_cplusplus), +}; - err = test_ua_register(); - if (err) - return err; - err = test_cplusplus(); - if (err) - return err; +static int run_tests(bool verbose) +{ + size_t i; + int err; + + for (i=0; i<ARRAY_SIZE(tests); i++) { + + if (verbose) { + re_printf("test %u -- %s\n", + i, tests[i].name); + } + + err = tests[i].exec(); + if (err) { + warning("%s: test failed (%m)\n", + tests[i].name, err); + return err; + } + } return 0; } @@ -60,7 +74,7 @@ int main(void) if (err) goto out; - err = run_tests(); + err = run_tests(false); if (err) goto out; @@ -71,7 +85,8 @@ int main(void) goto out; #endif - re_printf("\x1b[32mOK. selftest passed successfully\x1b[;m\n"); + re_printf("\x1b[32mOK. %zu tests passed successfully\x1b[;m\n", + ARRAY_SIZE(tests)); out: if (err) { |