Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions tests/examples/test_framework.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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");
Expand All @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion tests/examples/test_framework.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,16 @@ typedef struct {
* When called with "--child <index>" (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[]);

Expand Down
Loading