test: implement shared check() macro
This commit is contained in:
parent
100d5ebbe4
commit
056b2d72c4
9
test/shared/test-util.c
Normal file
9
test/shared/test-util.c
Normal file
@ -0,0 +1,9 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "test-util.h"
|
||||
|
||||
void check_fail(const char* message) {
|
||||
puts(message);
|
||||
abort();
|
||||
}
|
||||
29
test/shared/test-util.h
Normal file
29
test/shared/test-util.h
Normal file
@ -0,0 +1,29 @@
|
||||
#ifndef TEST_UTIL_H_
|
||||
#define TEST_UTIL_H_
|
||||
|
||||
#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("Check failed:\n" \
|
||||
" test: " #expression "\n" \
|
||||
" file: " __FILE__ "\n" \
|
||||
" line: " __check_to_string(__LINE__) "\n"), \
|
||||
0))
|
||||
|
||||
#endif /* TEST_UTIL_H_ */
|
||||
Loading…
x
Reference in New Issue
Block a user