clar: iterate errors in report_all / report_errors Instead of trying to have a clever iterator pattern that increments the error number, just iterate over errors in the report errors or report all functions as it's easier to reason about in this fashion.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
diff --git a/tests/clar.c b/tests/clar.c
index 025f2f3..27d35e1 100644
--- a/tests/clar.c
+++ b/tests/clar.c
@@ -217,32 +217,28 @@ void cl_trace_register(cl_trace_cb *cb, void *payload)
/* Core test functions */
static void
-clar_report(int *i, struct clar_error *error)
-{
- while (error != NULL) {
- clar_print_error((*i)++, _clar.last_report, error);
- error = error->next;
- }
-}
-
-static void
-clar_report_errors(struct clar_error *error)
+clar_report_errors(struct clar_report *report)
{
+ struct clar_error *error;
int i = 1;
- clar_report(&i, error);
+
+ for (error = report->errors; error; error = error->next)
+ clar_print_error(i++, _clar.last_report, error);
}
static void
clar_report_all(void)
{
- int i = 1;
struct clar_report *report;
+ struct clar_error *error;
+ int i = 1;
+
+ for (report = _clar.reports; report; report = report->next) {
+ if (report->status != CL_TEST_FAILURE)
+ continue;
- report = _clar.reports;
- while (report != NULL) {
- if (report->status == CL_TEST_FAILURE)
- clar_report(&i, report->errors);
- report = report->next;
+ for (error = report->errors; error; error = error->next)
+ clar_print_error(i++, report, error);
}
}
@@ -285,7 +281,7 @@ clar_run_test(
_clar.local_cleanup_payload = NULL;
if (_clar.report_errors_only) {
- clar_report_errors(_clar.last_report->errors);
+ clar_report_errors(_clar.last_report);
} else {
clar_print_ontest(test->name, _clar.tests_ran, _clar.last_report->status);
}
@@ -576,7 +572,7 @@ static void abort_test(void)
if (!_clar.trampoline_enabled) {
clar_print_onabort(
"Fatal error: a cleanup method raised an exception.");
- clar_report_errors(_clar.last_report->errors);
+ clar_report_errors(_clar.last_report);
exit(-1);
}