45 lines
1.4 KiB
C
45 lines
1.4 KiB
C
#ifndef TEST_UTIL_H_
|
|
#define TEST_UTIL_H_
|
|
|
|
#include <assert.h>
|
|
|
|
#ifdef __clang__
|
|
#pragma clang diagnostic ignored "-Wbad-function-cast"
|
|
#pragma clang diagnostic ignored "-Wcast-qual"
|
|
#pragma clang diagnostic ignored "-Wformat-non-iso"
|
|
#endif
|
|
|
|
#ifdef _MSC_VER
|
|
#define no_return __declspec(noreturn)
|
|
#else /* GCC/clang */
|
|
#define no_return __attribute__((noreturn))
|
|
#endif
|
|
|
|
#ifdef _MSC_VER
|
|
#define no_inline __declspec(noinline)
|
|
#else /* GCC/clang */
|
|
#define no_inline __attribute__((noinline))
|
|
#endif
|
|
|
|
void no_inline no_return check_fail(const char* message);
|
|
|
|
#define _check_to_string_helper(v) #v
|
|
#define _check_to_string(v) _check_to_string_helper(v)
|
|
|
|
#define check(expression) \
|
|
(void) ((!!(expression)) || \
|
|
(check_fail("\n" \
|
|
"Check failed:\n" \
|
|
" test: " #expression "\n" \
|
|
" file: " __FILE__ "\n" \
|
|
" line: " _check_to_string(__LINE__) "\n"), \
|
|
0))
|
|
|
|
/* Polyfill `static_assert` for some versions of clang and gcc. */
|
|
#if (defined(__clang__) || defined(__GNUC__)) && !defined(static_assert)
|
|
#define static_assert(condition, message) typedef __attribute__( \
|
|
(__unused__)) int __static_assert_##__LINE__[(condition) ? 1 : -1]
|
|
#endif
|
|
|
|
#endif /* TEST_UTIL_H_ */
|