Files
libakerror/tests/err_swallow.c
Andrew Kesterson 4ae1decde2
All checks were successful
libakerror CI Build / cmake_build (push) Successful in 2m44s
libakerror CI Build / mutation_test (push) Successful in 7m46s
Expand error status test coverage
- Added explicit status validation across error handling tests.
- Added lifecycle and slot-leak checks to older tests.
- Improved unhandled-error propagation coverage.
- Added repository guidance and a test runner script.
- Verified all 23 CTest tests pass.

Co-Authored by Codex GPT 5.4
2026-07-29 17:12:52 -04:00

49 lines
1.4 KiB
C

#include "akerror.h"
#include "err_capture.h"
/*
* FINISH(ctx, false) closes an ATTEMPT block without propagating: an unhandled
* error is dropped (not returned, not passed to the unhandled handler) and the
* context is released back to the pool. Because we use FINISH (not
* FINISH_NORETURN) the process must continue normally and exit 0.
*/
static int wrong_handler_fired = 0;
static int swallowed_status = 0;
akerr_ErrorContext *boom(void)
{
PREPARE_ERROR(e);
FAIL_RETURN(e, AKERR_VALUE, "unhandled but swallowed");
}
/* FINISH(e, false) belongs in a context-returning function. On the swallow
* path e is released to NULL, so this returns NULL to its caller. */
akerr_ErrorContext *swallow_it(void)
{
PREPARE_ERROR(e);
ATTEMPT {
CATCH(e, boom());
} CLEANUP {
swallowed_status = (e != NULL) ? e->status : 0;
} PROCESS(e) {
} HANDLE(e, AKERR_KEY) {
wrong_handler_fired = 1; /* does not match AKERR_VALUE */
} FINISH(e, false);
return e; /* NULL: released even though unhandled */
}
int main(void)
{
akerr_capture_install();
akerr_ErrorContext *res = swallow_it();
AKERR_CHECK(wrong_handler_fired == 0);
AKERR_CHECK(swallowed_status == AKERR_VALUE);
AKERR_CHECK(res == NULL); /* released even though unhandled */
AKERR_CHECK(akerr_slots_in_use() == 0);
fprintf(stderr, "err_swallow ok\n");
return 0;
}