- 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
49 lines
1.2 KiB
C
49 lines
1.2 KiB
C
#include "akerror.h"
|
|
#include "err_capture.h"
|
|
#include <errno.h>
|
|
|
|
/*
|
|
* The library imports system errno codes and their descriptions at build time
|
|
* (scripts/generrno.sh -> akerr_init_errno). Verify:
|
|
* - a system errno (EACCES) has a registered, non-empty name;
|
|
* - an out-of-range status returns the "Unknown Error" sentinel;
|
|
* - a system errno can be raised, propagated and handled like any AKERR_* code.
|
|
*/
|
|
|
|
static int handled = 0;
|
|
|
|
akerr_ErrorContext *boom(void)
|
|
{
|
|
PREPARE_ERROR(e);
|
|
FAIL_RETURN(e, EACCES, "permission denied");
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
akerr_capture_install();
|
|
akerr_init();
|
|
|
|
char *nm = akerr_name_for_status(EACCES, NULL);
|
|
AKERR_CHECK(nm != NULL);
|
|
AKERR_CHECK(nm[0] != '\0');
|
|
AKERR_CHECK(strcmp(nm, "Unknown Error") != 0);
|
|
|
|
AKERR_CHECK(strcmp(akerr_name_for_status(AKERR_MAX_ERR_VALUE + 5000, NULL),
|
|
"Unknown Error") == 0);
|
|
|
|
PREPARE_ERROR(e);
|
|
ATTEMPT {
|
|
CATCH(e, boom());
|
|
} CLEANUP {
|
|
} PROCESS(e) {
|
|
} HANDLE(e, EACCES) {
|
|
AKERR_CHECK_STATUS(e, EACCES);
|
|
handled = 1;
|
|
} FINISH_NORETURN(e);
|
|
|
|
AKERR_CHECK(handled == 1);
|
|
AKERR_CHECK(akerr_slots_in_use() == 0);
|
|
fprintf(stderr, "err_errno ok (EACCES name: \"%s\")\n", nm);
|
|
return 0;
|
|
}
|