Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding some assertion macros to improve error messaging
Example output: Wrong uint64 length: Expected 1 but was 3 (ion_binary_test.c:21) ion_binary_test over (null) Value COUNT: 1 FAILURES: 1
- Loading branch information
Showing
2 changed files
with
31 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,22 @@ | ||
#include <ion_debug.h> | ||
|
||
static inline iERR assert_equals_int(int expected, int actual) { | ||
return (expected == actual) ? IERR_OK : IERR_INVALID_ARG; | ||
static int ASSERT_BUFFER_SIZE = 1024; | ||
|
||
#define ASSERT_ERROR(message, file, line) fprintf(stderr, "%s (%s:%d)", (message), ion_helper_short_filename((file)), (line)) | ||
|
||
#define ASSERT_EQUALS_INT(expected, actual, message) _assert_equals_int((expected), (actual), (message), __FILE__, __LINE__) | ||
|
||
static inline iERR _assert_equals_int(int expected, int actual, char* message, char* file, int line) { | ||
if (expected == actual) { | ||
return IERR_OK; | ||
} else { | ||
char* buffer = calloc(ASSERT_BUFFER_SIZE, sizeof(char)); | ||
if (message != NULL) { | ||
snprintf(buffer, ASSERT_BUFFER_SIZE, "%s: Expected %i but was %i", message, expected, actual); | ||
} else { | ||
snprintf(buffer, ASSERT_BUFFER_SIZE, "Expected %i but was %i", message, expected, actual); | ||
} | ||
ASSERT_ERROR(buffer, file, line); | ||
return IERR_INVALID_ARG; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters