Skip to content

Commit 6a52f30

Browse files
committed
Merge branch 'rs/t-strvec-use-test-msg'
Unit test clean-up. * rs/t-strvec-use-test-msg: t-strvec: fix type mismatch in check_strvec t-strvec: improve check_strvec() output t-strvec: use test_msg()
2 parents 39bf06a + 7868716 commit 6a52f30

File tree

1 file changed

+15
-32
lines changed

1 file changed

+15
-32
lines changed

t/unit-tests/t-strvec.c

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,21 @@
33
#include "strvec.h"
44

55
#define check_strvec(vec, ...) \
6-
check_strvec_loc(TEST_LOCATION(), vec, __VA_ARGS__)
7-
LAST_ARG_MUST_BE_NULL
8-
static void check_strvec_loc(const char *loc, struct strvec *vec, ...)
9-
{
10-
va_list ap;
11-
size_t nr = 0;
12-
13-
va_start(ap, vec);
14-
while (1) {
15-
const char *str = va_arg(ap, const char *);
16-
if (!str)
17-
break;
18-
19-
if (!check_uint(vec->nr, >, nr) ||
20-
!check_uint(vec->alloc, >, nr) ||
21-
!check_str(vec->v[nr], str)) {
22-
struct strbuf msg = STRBUF_INIT;
23-
strbuf_addf(&msg, "strvec index %"PRIuMAX, (uintmax_t) nr);
24-
test_assert(loc, msg.buf, 0);
25-
strbuf_release(&msg);
26-
va_end(ap);
27-
return;
28-
}
29-
30-
nr++;
31-
}
32-
va_end(ap);
33-
34-
check_uint(vec->nr, ==, nr);
35-
check_uint(vec->alloc, >=, nr);
36-
check_pointer_eq(vec->v[nr], NULL);
37-
}
6+
do { \
7+
const char *expect[] = { __VA_ARGS__ }; \
8+
if (check_uint(ARRAY_SIZE(expect), >, 0) && \
9+
check_pointer_eq(expect[ARRAY_SIZE(expect) - 1], NULL) && \
10+
check_uint((vec)->nr, ==, ARRAY_SIZE(expect) - 1) && \
11+
check_uint((vec)->nr, <=, (vec)->alloc)) { \
12+
for (size_t i = 0; i < ARRAY_SIZE(expect); i++) { \
13+
if (!check_str((vec)->v[i], expect[i])) { \
14+
test_msg(" i: %"PRIuMAX, \
15+
(uintmax_t)i); \
16+
break; \
17+
} \
18+
} \
19+
} \
20+
} while (0)
3821

3922
static void t_static_init(void)
4023
{

0 commit comments

Comments
 (0)