blob: df50afbd05eae0b7e46dec8595dea06458a49dd3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
#ifndef LILY_TEST_H
#define LILY_TEST_H
#include <stddef.h>
/* gives a string like 'some/filename:xxx' */
#define STR_IMP(x) #x
#define STR(x) STR_IMP(x)
/* define SOURCE_PATH_SIZE to strip away the
leading parts of the full compilation path */
#ifndef SOURCE_PATH_SIZE
#define LILY_LOCATION "" __FILE__ ":" STR(__LINE__)
#else
#define LILY_LOCATION (("" __FILE__ ":" STR(__LINE__)) + SOURCE_PATH_SIZE)
#endif
struct lily_test_result_t {
int error;
const char *message;
const char *location;
void *data;
};
typedef struct lily_test_result_t lily_test;
#define LILY_SUCCESS (struct lily_test_result_t){ 0, NULL, NULL, NULL }
// assertions
#define LILY_NO_ERROR 0
#define LILY_NULL_DATA 1
#define LILY_INT_DATA 2
#define LILY_STRING_DATA 3
#define lily_assert_msg(statement, code, message, data) do { \
if(!(statement)) { \
return (struct lily_test_result_t){ \
(code), (message), LILY_LOCATION, (data) \
}; \
} \
} while(0)
#define lily_assert_equal(a, b) \
lily_assert_msg(a == b, LILY_NULL_DATA, #a " is not equal to " #b, NULL)
#endif
|