Commit 39abfdc3 authored by Geoff Simmons's avatar Geoff Simmons

added more convenience macros to minunit.h

parent d2d5b4b2
......@@ -39,24 +39,46 @@
* understanding that it comes with NO WARRANTY."
*/
/* XXX: Format error message in mu_assert() */
#define mu_assert(msg, test) do { if (!(test)) return msg; } while (0)
#define mu_run_test(test) do { const char *msg = test(); tests_run++; \
if (msg) return msg; } while (0)
/* phk-ish mu_assert */
#define mu_assert_errno(c) \
do { \
if (!(c)) { \
sprintf(errmsg, "%s failed in %s at %s:%d: errno %d (%s)", \
#c, __func__, __FILE__, __LINE__, errno, strerror(errno)); \
mu_assert(errmsg, 0); \
} \
#define _massert(test, errmsg, msg, ...) \
do { \
if (!(test)) { \
sprintf((errmsg), (msg), __VA_ARGS__); \
return (errmsg); \
} \
} while(0)
#define _massert0(test, errmsg, msg) \
do { \
if (!(test)) { \
sprintf((errmsg), (msg)); \
return (errmsg); \
} \
} while(0)
/* These assume that a global static char* errmsg is declared and
has allocated space. */
#define VMASSERT(test, msg, ...) _massert((test),(errmsg),(msg),__VA_ARGS__)
#define MASSERT0(test, msg) _massert0((test),(errmsg),(msg))
/* This assumes #include <errno.h> and <string.h> */
#define MASSERT(c) \
VMASSERT((c), "%s failed in %s at %s:%d (errno %d: %s)", \
#c, __func__, __FILE__, __LINE__, errno, strerror(errno))
/* short for MU Assert Zero / Non-Zero */
#define MAZ(c) do { mu_assert_errno((c) == 0); } while(0)
#define MAN(c) do { mu_assert_errno((c) != 0); } while(0)
#define MAZ(c) MASSERT((c) == 0)
#define MAN(c) MASSERT((c) != 0)
#define MCHECK_OBJ(ptr, type_magic) MASSERT((ptr)->magic == type_magic)
#define MCHECK_OBJ_NOTNULL(ptr, type_magic) \
do { \
MAN(ptr); \
MCHECK_OBJ(ptr, type_magic); \
} while(0)
extern int tests_run;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment