Message ID | 35b0ba6b-d485-44f2-a19f-3ce816f8b435@web.de (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | t-strvec: use test_msg() | expand |
On Thu, Jul 4, 2024 at 2:04 PM René Scharfe <l.s.r@web.de> wrote: > check_strvec_loc() checks each the strvec item by looping through them s/each the/each/ > 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. > > Here's an example in which there are less items in the strvec than s/less/fewer/ > expected; the index of the missing item is reported in the last line: > > # 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 it is also reported in the third line, i.e. the variable > "nr" contains that index. > > 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 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 <phillip.wood@dunelm.org.uk> > --- Missing sign-off.
Hi René Thanks for working on this, this looks good modulo Eric's suggestions Best Wishes Phillip On 04/07/2024 19:04, René Scharfe wrote: > check_strvec_loc() checks each the 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. > > Here's an example in which there are less items in the strvec than > expected; the index of the missing item is reported in the last line: > > # 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 it is also reported in the third line, i.e. the variable > "nr" contains that index. > > 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 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 <phillip.wood@dunelm.org.uk> > --- > t/unit-tests/t-strvec.c | 12 ++++++------ > 1 file changed, 6 insertions(+), 6 deletions(-) > > diff --git a/t/unit-tests/t-strvec.c b/t/unit-tests/t-strvec.c > index d4615ab06d..236203af61 100644 > --- a/t/unit-tests/t-strvec.c > +++ b/t/unit-tests/t-strvec.c > @@ -17,12 +17,12 @@ static void check_strvec_loc(const char *loc, struct strvec *vec, ...) > 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); > + !check_uint(vec->alloc, >, nr)) { > + va_end(ap); > + return; > + } > + if (!check_str(vec->v[nr], str)) { > + test_msg(" nr: %"PRIuMAX, (uintmax_t)nr); > va_end(ap); > return; > } > -- > 2.45.2
diff --git a/t/unit-tests/t-strvec.c b/t/unit-tests/t-strvec.c index d4615ab06d..236203af61 100644 --- a/t/unit-tests/t-strvec.c +++ b/t/unit-tests/t-strvec.c @@ -17,12 +17,12 @@ static void check_strvec_loc(const char *loc, struct strvec *vec, ...) 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); + !check_uint(vec->alloc, >, nr)) { + va_end(ap); + return; + } + if (!check_str(vec->v[nr], str)) { + test_msg(" nr: %"PRIuMAX, (uintmax_t)nr); va_end(ap); return; }