-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added 'expect' assertion alternative
- Loading branch information
Showing
3 changed files
with
76 additions
and
6 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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <assert.h> | ||
|
||
typedef enum error_mode { | ||
DEFAULT_E, | ||
ABORT_E, | ||
ASSERT_E, | ||
} error_mode_e; | ||
|
||
error_mode_e mode = DEFAULT_E; | ||
FILE * error_log; | ||
|
||
#define NO_ACTION (void)(0) | ||
|
||
#ifdef ERROR_LOG_FILE_PATH | ||
|
||
#define expect(assertion, error_action, ...) \ | ||
{ \ | ||
if (assertion) { \ | ||
assert(error_log = fopen(ERROR_LOG_FILE_PATH, "a")); \ | ||
fprintf(error_log, __VA_ARGS__); \ | ||
fprintf(error_log, "\n"); \ | ||
fclose(error_log) \ | ||
switch (mode) { \ | ||
case ABORT_E : { abort(); } \ | ||
case ASSERT_E : { assert(assertion); } \ | ||
default : { error_action; } \ | ||
} \ | ||
} \ | ||
} | ||
|
||
#else | ||
|
||
#define expect(assertion, error_action, ...) \ | ||
{ \ | ||
if (assertion) { \ | ||
fprintf(error_log ? error_log : stderr, __VA_ARGS__); \ | ||
fprintf(error_log ? error_log : stderr, "\n"); \ | ||
switch (mode) { \ | ||
case ABORT_E : { abort(); } \ | ||
case ASSERT_E : { assert(assertion); } \ | ||
default : { error_action; } \ | ||
} \ | ||
} \ | ||
} | ||
|
||
#endif /* ERROR_LOG_FILE_PATH */ |
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
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