git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Phillip Wood <phillip.wood123@gmail.com>
To: "René Scharfe" <l.s.r@web.de>, "Git List" <git@vger.kernel.org>
Cc: Patrick Steinhardt <ps@pks.im>,
	Phillip Wood <phillip.wood@dunelm.org.uk>
Subject: Re: [PATCH] t-strvec: use test_msg()
Date: Fri, 5 Jul 2024 10:44:40 +0100	[thread overview]
Message-ID: <3add9624-4f3a-4f70-bc15-2357920dbc9f@gmail.com> (raw)
In-Reply-To: <35b0ba6b-d485-44f2-a19f-3ce816f8b435@web.de>

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

  parent reply	other threads:[~2024-07-05  9:44 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-04 18:04 [PATCH] t-strvec: use test_msg() René Scharfe
2024-07-04 18:31 ` Eric Sunshine
2024-07-05  9:44 ` Phillip Wood [this message]
2024-07-05 17:03 ` [PATCH v2] " René Scharfe
2024-07-09 11:32   ` Jeff King
2024-07-14 10:17     ` René Scharfe
2024-07-16  1:43       ` Jeff King
2024-07-16 16:43         ` René Scharfe
2024-07-14 17:06   ` [PATCH v2 2/1] t-strvec: improve check_strvec() output René Scharfe
2024-07-15 14:44     ` Junio C Hamano
2024-07-14 17:06   ` [PATCH v2 3/1] t-strvec: tighten .alloc check in check_strvec René Scharfe
2024-07-15 14:43     ` Junio C Hamano
2024-07-15 16:47       ` René Scharfe
2024-07-15 17:27         ` Junio C Hamano
2024-07-14 10:17 ` [PATCH v3] t-strvec: improve check_strvec() output René Scharfe
2024-07-14 17:06   ` René Scharfe
2024-07-16  4:37   ` Jeff King
2024-07-16 15:20     ` Junio C Hamano
2024-07-16 16:14       ` [PATCH] t-strvec: fix type mismatch in check_strvec René Scharfe
2024-07-16 16:33         ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3add9624-4f3a-4f70-bc15-2357920dbc9f@gmail.com \
    --to=phillip.wood123@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=l.s.r@web.de \
    --cc=phillip.wood@dunelm.org.uk \
    --cc=ps@pks.im \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).