diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2018-09-08 18:54:21 +0100 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2018-09-08 19:47:25 +0100 |
commit | d17e67d08d6e73dbf0daeae5049f92a38c2d8bb6 (patch) | |
tree | 1c6a22bdecd5e4bdfe907f95751a741071621aa0 | |
parent | e595eeb5ab88142b97798ed65e651de6560515e9 (diff) | |
download | libgit2-d17e67d08d6e73dbf0daeae5049f92a38c2d8bb6.tar.gz |
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.
-rw-r--r-- | tests/clar.c | 34 |
1 files 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; + + 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); } |