From 9ca41b21867393e9c52ff71abe67633f2344755a Mon Sep 17 00:00:00 2001 From: Jingbo Hou Date: Wed, 16 Sep 2026 10:33:35 +0800 Subject: [PATCH] Add test statistics and three-state conclusion to run_all_tests() Signed-off-by: Jingbo Hou --- tests/examples/test_framework.c | 21 +++++++++++++++++---- tests/examples/test_framework.h | 7 ++++++- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/tests/examples/test_framework.c b/tests/examples/test_framework.c index 0f9286c..7bfd510 100644 --- a/tests/examples/test_framework.c +++ b/tests/examples/test_framework.c @@ -166,6 +166,8 @@ int run_all_tests(test_entry_t *tests, int num_tests, int argc, char *argv[]) { printf("========================================\n"); int result = 0; + int num_skipped = 0; + int num_failed = 0; int *tc_results = (int *)calloc(num_tests, sizeof(int)); if (!tc_results) { fprintf(stderr, "Failed to allocate results array\n"); @@ -175,7 +177,12 @@ int run_all_tests(test_entry_t *tests, int num_tests, int argc, char *argv[]) { for (int i = 0; i < num_tests; i++) { printf("\n--- Running %s: %s ---\n", tests[i].name, tests[i].description); tc_results[i] = run_test_in_child(tests, num_tests, i); - if (tc_results[i] == TEST_FAIL) result = 1; + if (tc_results[i] == TEST_FAIL) { + result = 1; + num_failed++; + } else if (tc_results[i] == TEST_SKIP) { + num_skipped++; + } } printf("\n========================================\n"); @@ -186,14 +193,20 @@ int run_all_tests(test_entry_t *tests, int num_tests, int argc, char *argv[]) { : tc_results[i] == TEST_SKIP ? "SKIPPED" : "FAILED/CRASHED"); } + printf("\n%d passed, %d skipped, %d failed/crashed out of %d test(s)\n", + num_tests - num_skipped - num_failed, num_skipped, num_failed, + num_tests); printf("========================================\n"); free(tc_results); - if (result == 0) { - printf("\nAll tests passed.\n"); - } else { + if (result != 0) { printf("\nSome tests failed or crashed. Review output above.\n"); + } else if (num_skipped > 0) { + printf("\nAll executed tests passed, but %d test(s) skipped.\n", + num_skipped); + } else { + printf("\nAll tests passed.\n"); } return result; diff --git a/tests/examples/test_framework.h b/tests/examples/test_framework.h index e203beb..c6e4fed 100644 --- a/tests/examples/test_framework.h +++ b/tests/examples/test_framework.h @@ -126,11 +126,16 @@ typedef struct { * When called with "--child " (Windows child-process mode), runs only * the test at @p index and returns its result directly. * + * The summary includes per-test status and aggregate counts + * (passed / skipped / failed out of total). The final message distinguishes + * three outcomes: all passed, some skipped (no failures), or some failed. + * Skipped tests do not affect the return value. + * * @param tests Array of test entries. * @param num_tests Number of entries in @p tests. * @param argc Argument count from main(). * @param argv Argument vector from main(). - * @return 0 if all tests passed, non-zero if any failed. + * @return 0 if no test failed or crashed, non-zero otherwise. */ int run_all_tests(test_entry_t *tests, int num_tests, int argc, char *argv[]);