From 86bacdb2bd67597be06fc12a693cd04de1068046 Mon Sep 17 00:00:00 2001 From: Alessio Chiapperini Date: Tue, 23 Jul 2024 16:52:40 +0200 Subject: [PATCH] Add function for printing the list of tests --- src/harness.c | 29 +++++++++++++++++++++++++++++ src/harness.h | 7 +++++++ src/harness_demo.c | 3 +++ 3 files changed, 39 insertions(+) diff --git a/src/harness.c b/src/harness.c index 4b89f6a..eda8da2 100644 --- a/src/harness.c +++ b/src/harness.c @@ -95,6 +95,35 @@ harness_add_suite(char *test_suite, struct harness_test *tests) { return (res); } +void +harness_list_tests(char *test_suite) +{ + int s; + + if (test_suite != NULL) { + for (s = 0; s < cfg->nsuites; s++) { + if (!strcmp(test_suites[s].suite_name, test_suite)) { + break; + } + } + (void)fprintf(stdout, "%s\n", test_suite); + + for (int t = 0; t < test_suites[s].ntests; t++) { + (void)fprintf(stdout, " %s\n", + test_suites[s].tests[t].test_name); + } + } else { + for (s = 0; s < cfg->nsuites; s++) { + (void)fprintf(stdout, "%s\n", + test_suites[s].suite_name); + for (int t = 0; t < test_suites[s].ntests; t++) { + (void)fprintf(stdout, " %s\n", + test_suites[s].tests[t].test_name); + } + } + } +} + int harness_run(void *user_data) { diff --git a/src/harness.h b/src/harness.h index ef8940c..e5b3260 100644 --- a/src/harness.h +++ b/src/harness.h @@ -269,6 +269,13 @@ int harness_add_test(char *test_suite, char *test_name, test_function *test, int harness_add_suite(char *test_suite, struct harness_test *tests); /** + * Print the tests belonging to @p test_suite. If NULL is passed, all the tests + * will be printed + * @param[in] test_suite From which testsuite to print the test names + */ +void harness_list_tests(char *test_suite); + +/** * Run the entire test harness * @param[in] user_data pointer to any user specified data to use inside the * runner diff --git a/src/harness_demo.c b/src/harness_demo.c index c86de48..f13e9c1 100644 --- a/src/harness_demo.c +++ b/src/harness_demo.c @@ -307,6 +307,9 @@ main(int argc, char *argv[]) harness_add_test("example_suite", "test_pass", test_pass, NULL, NULL, NULL); + + harness_list_tests(NULL); + ret = harness_run(NULL); harness_destroy(&cfg); -- 2.11.4.GIT