Skip to content

Commit d17e67d

Browse files
committed
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 parent e595eeb commit d17e67d

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

tests/clar.c

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -217,32 +217,28 @@ void cl_trace_register(cl_trace_cb *cb, void *payload)
217217

218218
/* Core test functions */
219219
static void
220-
clar_report(int *i, struct clar_error *error)
221-
{
222-
while (error != NULL) {
223-
clar_print_error((*i)++, _clar.last_report, error);
224-
error = error->next;
225-
}
226-
}
227-
228-
static void
229-
clar_report_errors(struct clar_error *error)
220+
clar_report_errors(struct clar_report *report)
230221
{
222+
struct clar_error *error;
231223
int i = 1;
232-
clar_report(&i, error);
224+
225+
for (error = report->errors; error; error = error->next)
226+
clar_print_error(i++, _clar.last_report, error);
233227
}
234228

235229
static void
236230
clar_report_all(void)
237231
{
238-
int i = 1;
239232
struct clar_report *report;
233+
struct clar_error *error;
234+
int i = 1;
235+
236+
for (report = _clar.reports; report; report = report->next) {
237+
if (report->status != CL_TEST_FAILURE)
238+
continue;
240239

241-
report = _clar.reports;
242-
while (report != NULL) {
243-
if (report->status == CL_TEST_FAILURE)
244-
clar_report(&i, report->errors);
245-
report = report->next;
240+
for (error = report->errors; error; error = error->next)
241+
clar_print_error(i++, report, error);
246242
}
247243
}
248244

@@ -285,7 +281,7 @@ clar_run_test(
285281
_clar.local_cleanup_payload = NULL;
286282

287283
if (_clar.report_errors_only) {
288-
clar_report_errors(_clar.last_report->errors);
284+
clar_report_errors(_clar.last_report);
289285
} else {
290286
clar_print_ontest(test->name, _clar.tests_ran, _clar.last_report->status);
291287
}
@@ -576,7 +572,7 @@ static void abort_test(void)
576572
if (!_clar.trampoline_enabled) {
577573
clar_print_onabort(
578574
"Fatal error: a cleanup method raised an exception.");
579-
clar_report_errors(_clar.last_report->errors);
575+
clar_report_errors(_clar.last_report);
580576
exit(-1);
581577
}
582578

0 commit comments

Comments
 (0)