Commit d17e67d0 by Edward Thomson

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.
parent e595eeb5
...@@ -217,32 +217,28 @@ void cl_trace_register(cl_trace_cb *cb, void *payload) ...@@ -217,32 +217,28 @@ void cl_trace_register(cl_trace_cb *cb, void *payload)
/* Core test functions */ /* Core test functions */
static void static void
clar_report(int *i, struct clar_error *error) clar_report_errors(struct clar_report *report)
{
while (error != NULL) {
clar_print_error((*i)++, _clar.last_report, error);
error = error->next;
}
}
static void
clar_report_errors(struct clar_error *error)
{ {
struct clar_error *error;
int i = 1; 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 static void
clar_report_all(void) clar_report_all(void)
{ {
int i = 1;
struct clar_report *report; 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; for (error = report->errors; error; error = error->next)
while (report != NULL) { clar_print_error(i++, report, error);
if (report->status == CL_TEST_FAILURE)
clar_report(&i, report->errors);
report = report->next;
} }
} }
...@@ -285,7 +281,7 @@ clar_run_test( ...@@ -285,7 +281,7 @@ clar_run_test(
_clar.local_cleanup_payload = NULL; _clar.local_cleanup_payload = NULL;
if (_clar.report_errors_only) { if (_clar.report_errors_only) {
clar_report_errors(_clar.last_report->errors); clar_report_errors(_clar.last_report);
} else { } else {
clar_print_ontest(test->name, _clar.tests_ran, _clar.last_report->status); clar_print_ontest(test->name, _clar.tests_ran, _clar.last_report->status);
} }
...@@ -576,7 +572,7 @@ static void abort_test(void) ...@@ -576,7 +572,7 @@ static void abort_test(void)
if (!_clar.trampoline_enabled) { if (!_clar.trampoline_enabled) {
clar_print_onabort( clar_print_onabort(
"Fatal error: a cleanup method raised an exception."); "Fatal error: a cleanup method raised an exception.");
clar_report_errors(_clar.last_report->errors); clar_report_errors(_clar.last_report);
exit(-1); exit(-1);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment