Skip to content

Commit c6f35e5

Browse files
rscharfegitster
authored andcommitted
t-strvec: use test_msg()
check_strvec_loc() checks each strvec item by looping through them and comparing them with expected values. If a check fails then we'd like to know which item is affected. It reports that information by building a strbuf and delivering its contents using a failing assertion, e.g. if there are fewer items in the strvec than expected: # check "vec->nr > nr" failed at t/unit-tests/t-strvec.c:19 # left: 1 # right: 1 # check "strvec index 1" failed at t/unit-tests/t-strvec.c:71 Note that the index variable is "nr" and thus the interesting value is reported twice in that example (in lines three and four). Stop printing the index explicitly for checks that already report it. The message for the same condition as above becomes: # check "vec->nr > nr" failed at t/unit-tests/t-strvec.c:19 # left: 1 # right: 1 For the string comparison, whose error message doesn't include the index, report it using the simpler and more appropriate test_msg() instead. Report the index using its actual variable name and format the line like the preceding ones. The message for an unexpected string value becomes: # check "!strcmp(vec->v[nr], str)" failed at t/unit-tests/t-strvec.c:24 # left: "foo" # right: "bar" # nr: 0 Reported-by: Phillip Wood <[email protected]> Signed-off-by: René Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 06e570c commit c6f35e5

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

t/unit-tests/t-strvec.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ static void check_strvec_loc(const char *loc, struct strvec *vec, ...)
1717
break;
1818

1919
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);
20+
!check_uint(vec->alloc, >, nr)) {
21+
va_end(ap);
22+
return;
23+
}
24+
if (!check_str(vec->v[nr], str)) {
25+
test_msg(" nr: %"PRIuMAX, (uintmax_t)nr);
2626
va_end(ap);
2727
return;
2828
}

0 commit comments

Comments
 (0)