From d17e67d08d6e73dbf0daeae5049f92a38c2d8bb6 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Sat, 8 Sep 2018 18:54:21 +0100 Subject: [PATCH] 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. --- tests/clar.c | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/tests/clar.c b/tests/clar.c index 025f2f3ec..27d35e1c7 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; - report = _clar.reports; - while (report != NULL) { - if (report->status == CL_TEST_FAILURE) - clar_report(&i, report->errors); - report = report->next; + for (report = _clar.reports; report; report = report->next) { + if (report->status != CL_TEST_FAILURE) + continue; + + 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); }