Repository navigation
Expand file tree
/
Copy pathtest_help.h
More file actions
64 lines (51 loc) · 1.84 KB
/
Copy pathtest_help.h
File metadata and controls
64 lines (51 loc) · 1.84 KB
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
/* A very simple test framework for valkey. See unit/README.md for more information on usage.
*
* Example:
*
* int test_example(int argc, char *argv[], int flags) {
* TEST_ASSERT_MESSAGE("Check if 1 == 1", 1==1);
* TEST_ASSERT(5 == 5);
* return 0;
* }
*/
#ifndef __TESTHELP_H
#define __TESTHELP_H
#include <stdlib.h>
#include <stdio.h>
/* The flags are the following:
* --accurate: Runs tests with more iterations.
* --large-memory: Enables tests that consume more than 100mb.
* --single: A flag to indicate a specific test file was executed.
* --valgrind: Runs tests with valgrind. */
#define UNIT_TEST_ACCURATE (1 << 0)
#define UNIT_TEST_LARGE_MEMORY (1 << 1)
#define UNIT_TEST_SINGLE (1 << 2)
#define UNIT_TEST_VALGRIND (1 << 3)
#define KRED "\33[31m"
#define KGRN "\33[32m"
#define KBLUE "\33[34m"
#define KRESET "\33[0m"
#define TEST_PRINT_ERROR(descr) printf("[" KRED "%s - %s:%d" KRESET "] %s\n", __func__, __FILE__, __LINE__, descr)
#define TEST_PRINT_INFO(descr, ...) \
printf("[" KBLUE "%s - %s:%d" KRESET "] " descr "\n", __func__, __FILE__, __LINE__, __VA_ARGS__)
#define TEST_ASSERT_MESSAGE(descr, _c) \
do { \
if (!(_c)) { \
TEST_PRINT_ERROR(descr); \
return 1; \
} \
} while (0)
#define TEST_ASSERT(_c) TEST_ASSERT_MESSAGE("Failed assertion: " #_c, _c)
#define TEST_EXPECT_MESSAGE(descr, _c) \
do { \
if (!(_c)) { \
TEST_PRINT_ERROR(descr); \
failed_expects++; \
} \
} while (0)
#define TEST_EXPECT(_c) TEST_EXPECT_MESSAGE("Failed expect: " #_c, _c)
#ifndef UNUSED
#define UNUSED(x) (void)(x)
#endif
extern int failed_expects;
#endif