aboutsummaryrefslogtreecommitdiffstats
path: root/t/unit-tests
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2024-07-31 13:34:15 -0700
committerJunio C Hamano <gitster@pobox.com>2024-07-31 13:34:15 -0700
commit6a52f307af0e53aac2fcab8f995f69789472c334 (patch)
tree82a8674eebdaf27f78d78a00302e80d8223f300d /t/unit-tests
parent39bf06adf96da25b87c9aa7d35a32ef3683eb4a4 (diff)
parent78687168bcaeabd3bdcaa1849dc9dc7d3a6f02db (diff)
downloadgit-6a52f307af0e53aac2fcab8f995f69789472c334.tar.gz
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()
Diffstat (limited to 't/unit-tests')
-rw-r--r--t/unit-tests/t-strvec.c47
1 files changed, 15 insertions, 32 deletions
diff --git a/t/unit-tests/t-strvec.c b/t/unit-tests/t-strvec.c
index d4615ab06d..fa1a041469 100644
--- a/t/unit-tests/t-strvec.c
+++ b/t/unit-tests/t-strvec.c
@@ -3,38 +3,21 @@
#include "strvec.h"
#define check_strvec(vec, ...) \
- check_strvec_loc(TEST_LOCATION(), vec, __VA_ARGS__)
-LAST_ARG_MUST_BE_NULL
-static void check_strvec_loc(const char *loc, struct strvec *vec, ...)
-{
- va_list ap;
- size_t nr = 0;
-
- va_start(ap, vec);
- while (1) {
- const char *str = va_arg(ap, const char *);
- if (!str)
- break;
-
- if (!check_uint(vec->nr, >, nr) ||
- !check_uint(vec->alloc, >, nr) ||
- !check_str(vec->v[nr], str)) {
- struct strbuf msg = STRBUF_INIT;
- strbuf_addf(&msg, "strvec index %"PRIuMAX, (uintmax_t) nr);
- test_assert(loc, msg.buf, 0);
- strbuf_release(&msg);
- va_end(ap);
- return;
- }
-
- nr++;
- }
- va_end(ap);
-
- check_uint(vec->nr, ==, nr);
- check_uint(vec->alloc, >=, nr);
- check_pointer_eq(vec->v[nr], NULL);
-}
+ do { \
+ const char *expect[] = { __VA_ARGS__ }; \
+ if (check_uint(ARRAY_SIZE(expect), >, 0) && \
+ check_pointer_eq(expect[ARRAY_SIZE(expect) - 1], NULL) && \
+ check_uint((vec)->nr, ==, ARRAY_SIZE(expect) - 1) && \
+ check_uint((vec)->nr, <=, (vec)->alloc)) { \
+ for (size_t i = 0; i < ARRAY_SIZE(expect); i++) { \
+ if (!check_str((vec)->v[i], expect[i])) { \
+ test_msg(" i: %"PRIuMAX, \
+ (uintmax_t)i); \
+ break; \
+ } \
+ } \
+ } \
+ } while (0)
static void t_static_init(void)
{