Debug macros for the minunit framework.
More...
#include <stdio.h>
#include <errno.h>
#include <string.h>
Go to the source code of this file.
|
#define | debug(M, ...) |
|
#define | clean_errno() (errno == 0 ? "None" : strerror(errno)) |
|
#define | log_err(M, ...) |
|
#define | log_warn(M, ...) |
|
#define | log_info(M, ...) |
|
#define | check(A, M, ...) |
|
#define | sentinel(M, ...) { log_err(M, ##__VA_ARGS__); errno=0; goto error; } |
|
#define | check_mem(A) check((A), "Out of memory."); |
|
#define | check_debug(A, M, ...) |
|
Debug macros for the minunit framework.
- Author
- Zed Shaw
These debug macros come from Zed Shaw's book Learn C The Hard Way, and are used for the testing framework of GenSVM.
- See also
- minunit.h
Definition in file dbg.h.
◆ check
#define check |
( |
|
A, |
|
|
|
M, |
|
|
|
... |
|
) |
| |
Value:if(!(A)) {
log_err(M, ##__VA_ARGS__); errno=0; \
goto error; }
Check a condition an log an error with the given message if it fails
Definition at line 59 of file dbg.h.
◆ check_debug
#define check_debug |
( |
|
A, |
|
|
|
M, |
|
|
|
... |
|
) |
| |
Value:if (!(A)) {
debug(M, ##__VA_ARGS__); errno=0; \
goto error; }
Check a condition and log to debug if it fails, and reset errno
Definition at line 75 of file dbg.h.
◆ check_mem
#define check_mem |
( |
|
A | ) |
check((A), "Out of memory."); |
Check a memory allocation
Definition at line 70 of file dbg.h.
◆ clean_errno
#define clean_errno |
( |
| ) |
(errno == 0 ? "None" : strerror(errno)) |
Return a clean string of the current errno
Definition at line 36 of file dbg.h.
◆ debug
Value:fprintf(stderr, "DEBUG %s:%d: " M "\n", __FILE__, \
__LINE__, ##__VA_ARGS__)
Print debug info to stderr
Definition at line 29 of file dbg.h.
◆ log_err
#define log_err |
( |
|
M, |
|
|
|
... |
|
) |
| |
Value:fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " M "\n", \
Log an error to stderr
Definition at line 41 of file dbg.h.
◆ log_info
#define log_info |
( |
|
M, |
|
|
|
... |
|
) |
| |
Value:fprintf(stderr, "[INFO] (%s:%d) " M "\n", \
__FILE__, __LINE__, ##__VA_ARGS__)
Log info to stderr
Definition at line 53 of file dbg.h.
◆ log_warn
#define log_warn |
( |
|
M, |
|
|
|
... |
|
) |
| |
Value:fprintf(stderr, "[WARN] (%s:%d: errno: %s) " M "\n", \
Log a warning to stderr
Definition at line 47 of file dbg.h.
◆ sentinel
#define sentinel |
( |
|
M, |
|
|
|
... |
|
) |
| { log_err(M, ##__VA_ARGS__); errno=0; goto error; } |
Log an error with the given message and reset errno
Definition at line 65 of file dbg.h.