32#define TEST_MAIN_CTOR push_error_context()
33#define TEST_MAIN_DTOR pop_error_context(ehflag_normaltidy)
44#define test_bail(reason) \
46 printf("Bail out! %s\n", (reason)); \
50#define test_xstringify(str) \
52#define test_stringify(str) \
63#define test_alloc(ptr) \
64 test_alloc((ptr), "cannot allocate memory for " #ptr " in " __FILE__ ":" test_stringify(__LINE__))
66#define test_try(jmp) \
67 push_error_context_jump(&(jmp), DPKG_NULL, "test try"); \
72 pop_error_context(ehflag_normaltidy);
74static inline const char *
75test_get_envdir(
const char *envvar)
77 const char *envdir = getenv(envvar);
78 return envdir ? envdir :
".";
81#define test_get_srcdir() \
82 test_get_envdir("srcdir")
83#define test_get_builddir() \
84 test_get_envdir("builddir")
87test_data_file(
const char *filename)
94 test_bail(
"cannot allocate data filename");
102 const char *verbose = getenv(
"TEST_VERBOSE");
103 return verbose !=
DPKG_NULL && strcmp(verbose,
"1") == 0;
106#ifndef TEST_OMIT_VARIABLES
107static int test_id = 1;
108static int test_skip_code;
109static const char *test_skip_prefix;
110static const char *test_skip_reason;
113#define test_plan(n) \
114 printf("1..%d\n", n);
116#define test_skip_all(reason) \
118 printf("1..0 # SKIP %s\n", (reason)); \
121#define test_skip(reason) \
122 printf("ok %d # SKIP %s\n", test_id++, (reason))
123#define test_skip_block(cond) \
124 for (test_skip_prefix = " # SKIP ", \
125 test_skip_reason = cond ? #cond : DPKG_NULL, \
126 test_skip_code = 1; \
128 test_skip_prefix = test_skip_reason = DPKG_NULL, \
131#define test_todo(a, reason, desc) \
133 test_skip_prefix = " # TODO "; \
134 test_skip_reason = reason; \
135 test_case(a, "%s", desc); \
136 test_skip_prefix = test_skip_reason = DPKG_NULL; \
138#define test_todo_block(reason) \
139 for (test_skip_prefix = " # TODO ", test_skip_reason = reason; \
141 test_skip_prefix = test_skip_reason = DPKG_NULL)
143#define test_case(a, fmt, ...) \
144 printf("%sok %d - " fmt "%s%s\n", \
145 test_skip_code || (a) ? "" : "not ", \
146 test_id++, __VA_ARGS__, \
147 test_skip_reason ? test_skip_prefix : "", \
148 test_skip_reason ? test_skip_reason : "")
150#define test_pass(a) \
151 test_case((a), "pass %s", #a)
152#define test_fail(a) \
153 test_case(!(a), "fail %s", #a)
154#define test_str(a, op, b) \
155 test_case(strcmp((a), (b)) op 0, "strcmp '%s' %s '%s'", a, #op, b)
156#define test_mem(a, op, b, size) \
157 test_case(memcmp((a), (b), (size)) op 0, "memcmp %p %s %p", a, #op, b)
160#define test_warn(e) \
162 test_pass((e).type == DPKG_MSG_WARN); \
163 dpkg_error_destroy(&(e)); \
165#define test_error(e) \
167 test_pass((e).type == DPKG_MSG_ERROR); \
168 dpkg_error_destroy(&(e)); \
175#define TEST_ENTRY(name) \
176static void name(void); \
178main(int argc, char **argv) \
180 setvbuf(stdout, DPKG_NULL, _IOLBF, 0); \
#define test_alloc(ptr)
Definition test.h:63
#define test_get_srcdir()
Definition test.h:81
#define test_bail(reason)
Definition test.h:44
#define DPKG_BEGIN_DECLS
Definition macros.h:164
#define DPKG_NULL
A null pointer constant that works on C or C++.
Definition macros.h:180
#define DPKG_END_DECLS
Definition macros.h:165