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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
#ifndef TARANTOOL_TEST_H_INCLUDED
#define TARANTOOL_TEST_H_INCLUDED
/**
@brief example
@code
#include "test.h"
int main(void) {
plan(3); // count of test You planned to check
ok(1, "Test name 1");
is(4, 2 * 2, "2 * 2 == 4");
isnt(5, 2 * 2, "2 * 2 != 5);
return check_plan(); // print resume
}
@endcode
*/
/* private function, use ok(...) instead */
int _ok(int condition, const char *fmt, ...);
/**
@brief set and print plan
@param count
Before anything else, you need a testing plan. This basically declares
how many tests your program is going to run to protect against premature
failure.
*/
void plan(int count);
/**
@brief check if plan is reached and print report
*/
int check_plan(void);
#define ok(condition, fmt, args...) { \
int res = _ok(condition, fmt, ##args); \
if (!res) { \
fprintf(stderr, "# Failed test '"); \
fprintf(stderr, fmt, ##args); \
fprintf(stderr, "'\n"); \
fprintf(stderr, "# in %s at line %d\n", __FILE__, __LINE__); \
} \
res = res; \
}
#define is(a, b, fmt, args...) { \
int res = _ok((a) == (b), fmt, ##args); \
if (!res) { \
fprintf(stderr, "# Failed test '"); \
fprintf(stderr, fmt, ##args); \
fprintf(stderr, "'\n"); \
fprintf(stderr, "# in %s at line %d\n", __FILE__, __LINE__); \
} \
res = res; \
}
#define isnt(a, b, fmt, args...) { \
int res = _ok((a) != (b), fmt, ##args); \
if (!res) { \
fprintf(stderr, "# Failed test '"); \
fprintf(stderr, fmt, ##args); \
fprintf(stderr, "'\n"); \
fprintf(stderr, "# in %s at line %d\n", __FILE__, __LINE__); \
} \
res = res; \
}
#define fail(fmt, args...) \
ok(0, fmt, ##args)
#endif /* TARANTOOL_TEST_H_INCLUDED */
|