Make error-status assertions authoritative
Replace standalone message assertions with a helper that checks the returned akerr status first, then validates message content only as secondary context. Drop ambiguous memcpy message checks where both NULL guards use the same format string.
This commit is contained in:
@@ -18,6 +18,8 @@
|
||||
* AKSL_CHECK_STATUS() run an akerror-returning expression, assert on the
|
||||
* status it came back with, and release the context
|
||||
* so the error pool does not leak.
|
||||
* AKSL_CHECK_STATUS_MSG_CONTAINS()
|
||||
* assert status first, then message content.
|
||||
* AKSL_CHECK_OK() assert a call returned no error context at all.
|
||||
* aksl_last_status/... the status, message and function name of the most
|
||||
* recent context taken by AKSL_CHECK_STATUS.
|
||||
@@ -200,9 +202,42 @@ static int __attribute__((unused)) aksl_take(akerr_ErrorContext *e)
|
||||
#define AKSL_CHECK_NOT_CONTAINS(needle) \
|
||||
AKSL_CHECK(strstr(aksl_capture_buf, (needle)) == NULL)
|
||||
|
||||
/* Assert on the message of the context most recently taken. */
|
||||
#define AKSL_CHECK_MSG_CONTAINS(needle) \
|
||||
AKSL_CHECK(strstr(aksl_last_message, (needle)) != NULL)
|
||||
/*
|
||||
* Message checks are secondary: the returned akerr status is the contract. Keep
|
||||
* the status and message assertions coupled so tests cannot pass on text alone.
|
||||
*/
|
||||
#define AKSL_CHECK_STATUS_MSG_CONTAINS(__expr, __expected, __needle) \
|
||||
do { \
|
||||
int __st = aksl_take(__expr); \
|
||||
if ( __st != (__expected) ) { \
|
||||
fprintf(stderr, \
|
||||
" CHECK FAILED: %s\n" \
|
||||
" got %d (%s) \"%s\"\n" \
|
||||
" expected %d (%s)\n" \
|
||||
" at %s:%d\n", \
|
||||
#__expr, \
|
||||
__st, akerr_name_for_status(__st, NULL), \
|
||||
aksl_last_message, \
|
||||
(__expected), \
|
||||
akerr_name_for_status((__expected), NULL), \
|
||||
__FILE__, __LINE__); \
|
||||
return 1; \
|
||||
} \
|
||||
if ( strstr(aksl_last_message, (__needle)) == NULL ) { \
|
||||
fprintf(stderr, \
|
||||
" CHECK FAILED: message from %s\n" \
|
||||
" got \"%s\"\n" \
|
||||
" expected substring \"%s\"\n" \
|
||||
" status %d (%s)\n" \
|
||||
" at %s:%d\n", \
|
||||
#__expr, \
|
||||
aksl_last_message, \
|
||||
(__needle), \
|
||||
__st, akerr_name_for_status(__st, NULL), \
|
||||
__FILE__, __LINE__); \
|
||||
return 1; \
|
||||
} \
|
||||
} while ( 0 )
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* Test driver */
|
||||
|
||||
Reference in New Issue
Block a user