Files
libakerror/tests/err_ignore.c

40 lines
1.1 KiB
C
Raw Normal View History

#include "akerror.h"
#include "err_capture.h"
2026-08-04 10:44:46 -04:00
#include <string.h>
2026-08-04 10:44:46 -04:00
/* IGNORE snapshots and logs an error, releases its pool slot, then continues. */
akerr_ErrorContext *boom(void)
{
PREPARE_ERROR(e);
FAIL_RETURN(e, AKERR_VALUE, "this error is ignored on purpose");
}
int main(void)
{
akerr_capture_install();
int reached_after_ignore = 0;
PREPARE_ERROR(e);
(void)e;
2026-08-03 12:55:42 -04:00
/* More failures than the pool has slots must remain safe: a leaking
2026-08-04 10:44:46 -04:00
* IGNORE used to exhaust the pool and terminate the process here. The
* copied snapshot must also survive the slot being reused on the next
* iteration. */
2026-08-03 12:55:42 -04:00
for ( int i = 0; i < AKERR_MAX_ARRAY_ERROR + 1; i++ ) {
IGNORE(boom());
2026-08-04 10:44:46 -04:00
AKERR_CHECK(__akerr_last_ignored.status == AKERR_VALUE);
AKERR_CHECK(strcmp(__akerr_last_ignored.message,
"this error is ignored on purpose") == 0);
2026-08-03 12:55:42 -04:00
AKERR_CHECK(akerr_slots_in_use() == 0);
}
reached_after_ignore = 1;
AKERR_CHECK(reached_after_ignore == 1);
AKERR_CHECK_CONTAINS("IGNORED ERROR");
AKERR_CHECK_CONTAINS("this error is ignored on purpose");
fprintf(stderr, "err_ignore ok\n");
return 0;
}