-
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.
- Loading branch information
Showing
6 changed files
with
70 additions
and
73 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,48 +1,51 @@ | ||
#ifndef INSTANCE_EXPECT_H | ||
#define INSTANCE_EXPECT_H | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <assert.h> | ||
|
||
typedef enum error_mode { | ||
DEFAULT_E, | ||
ABORT_E, | ||
ASSERT_E, | ||
typedef enum error_mode_type { | ||
DEFAULT_E, ABORT_E, ASSERT_E, | ||
} error_mode_e; | ||
|
||
error_mode_e mode = DEFAULT_E; | ||
FILE * error_log; | ||
static error_mode_e error_mode = DEFAULT_E; | ||
static FILE * error_log = NULL; | ||
|
||
#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; } \ | ||
} \ | ||
} \ | ||
#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 (error_mode) { \ | ||
case ABORT_E : { error_action; abort(); } \ | ||
case ASSERT_E : { error_action; assert(0 && 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; } \ | ||
} \ | ||
} \ | ||
#define expect(assertion, error_action, ...) \ | ||
{ \ | ||
if (!(assertion)) { \ | ||
fprintf(error_log ? error_log : stderr, __VA_ARGS__); \ | ||
fprintf(error_log ? error_log : stderr, "\n"); \ | ||
switch (error_mode) { \ | ||
case ABORT_E : { error_action; abort(); } \ | ||
case ASSERT_E : { error_action; assert(0 && assertion); } \ | ||
default : { error_action; } \ | ||
} \ | ||
} \ | ||
} | ||
|
||
#endif /* ERROR_LOG_FILE_PATH */ | ||
#endif /* ERROR_LOG_FILE_PATH */ | ||
|
||
#endif /* INSTANCE_EXPECT_H */ |
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
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
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