12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- #ifndef _TEST_HELPERS
- #define _TEST_HELPERS
- #include <errno.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <unistd.h>
- #define ERROR_IF(func, status, condition) \
- do { \
- if (status condition) { \
- fprintf(stderr, "%s:%s:%d: '%s' failed: %s (%d)\n", \
- __FILE__, __func__, __LINE__, #func, strerror(errno), errno); \
- _exit(EXIT_FAILURE)
- } \
- } while(0)
- #define UNEXP_IF(func, status, condition) \
- do { \
- if (status condition) { \
- fprintf(stderr, "%s:%s:%d: '%s' returned a non-standard value: ", \
- __FILE__, __func__, __LINE__, #func); \
- fprintf(stderr, _Generic((status), \
- char *: "char*(%p) = \"%1$s\"", \
- void *: "void*(%p)", \
- default: "%i" \
- ), status)
- fprintf(stderr, "\n")
- _exit(EXIT_FAILURE)
- } \
- } while (0)
- #define exit(code) \
- do { \
- if (code != EXIT_SUCCESS) { \
- fprintf(stderr, "%s:%s:%d: Test failed with exit(%s)\n", \
- __FILE__, __func__, __LINE__, #code); \
- } \
- _exit(code)
- } while(0)
- #endif
|