git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christian Couder <christian.couder@gmail.com>
To: Ghanshyam Thakkar <shyamthakkar001@gmail.com>
Cc: Junio C Hamano <gitster@pobox.com>,
	git@vger.kernel.org,  Christian Couder <chriscool@tuxfamily.org>,
	Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Subject: Re: [GSoC][PATCH] t/: migrate helper/test-oidtree.c to unit-tests/t-oidtree.c
Date: Fri, 7 Jun 2024 10:31:29 +0200	[thread overview]
Message-ID: <CAP8UFD0r+YYxAvN2Ej1mGa2Kt5M2dQgQEGLraB3iQ30cPWuA6Q@mail.gmail.com> (raw)
In-Reply-To: <dohbd64jxuahelut63esztozdozqrhx5rgv5m4t3wt5gz6v6kv@6q2aivlcvxcq>

On Fri, Jun 7, 2024 at 1:35 AM Ghanshyam Thakkar
<shyamthakkar001@gmail.com> wrote:

> > Come to think of it, how is your check_each_cb() ensuring that it is
> > only called once with "123" when queried with "12300"?  If the
> > callback is made with "123" 100 times with the single query with
> > "12300", would it even notice?  I would imagine that the original
> > would (simply because it dumps each and every callback to a file to
> > be compared with the golden copy).
>
> That's true! I did not think of that. What do you think about something
> like this then? I will clean it up to send in v2.
>
> ---
>
> struct cb_data {
>         int *i;
>         struct strvec *expected_hexes;
> };

It might be better to use a more meaningful name for the struct, like
perhaps 'expected_hex_iter'. Also I think 'i' could be just 'size_t i'
instead of 'int *i', and 'expected_hexes' could be just 'hexes'.

> static enum cb_next check_each_cb(const struct object_id *oid, void *data)
> {
>         struct cb_data *cb_data = data;

Maybe: `struct expected_hex_iter *hex_iter = data;`

>         struct object_id expected;
>
>         if(!check_int(*cb_data->i, <, cb_data->hexes->nr)) {

A space character is missing between 'if' and '('. And by the way you
use 'hexes' instead of 'expected_hexes' here.

>                 test_msg("error: extraneous callback. found oid: %s", oid_to_hex(oid));
>                 return CB_BREAK;
>         }
>
>         if (!check_int(get_oid_arbitrary_hex(cb_data->expected_hexes->v[*cb_data->i], &expected), ==, 0))
>                 return CB_BREAK;
>         if (!check(oideq(oid, &expected)))
>                 test_msg("expected: %s\n       got: %s",
>                          hash_to_hex(expected.hash), hash_to_hex(oid->hash));
>
>         *cb_data->i += 1;
>         return CB_CONTINUE;
> }
>
> static void check_each(struct oidtree *ot, char *query, ...)
> {
>         struct object_id oid;
>         struct strvec hexes = STRVEC_INIT;
>         struct cb_data cb_data;
>         const char *arg;
>         int i = 0;
>
>         va_list expected;
>         va_start(expected, query);
>
>         while ((arg = va_arg(expected, const char *)))
>                 strvec_push(&hexes, arg);
>
>         cb_data.i = &i;
>         cb_data.expected_hexes = &hexes;

Can't we just have something like:

        struct expected_hex_iter hex_iter = { .i = 0, .hexes = &hexes };

above when 'hex_iter' is declared?

>         if (!check_int(get_oid_arbitrary_hex(query, &oid), ==, 0))
>                 return;
>         oidtree_each(ot, &oid, strlen(query), check_each_cb, &cb_data);
>
>         if (!check_int(*cb_data.i, ==, cb_data.expected_hexes->nr))
>                 test_msg("error: could not find some oids");
> }

Thanks.

  reply	other threads:[~2024-06-07  8:31 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-05 13:43 [GSoC][PATCH] t/: migrate helper/test-oidtree.c to unit-tests/t-oidtree.c Ghanshyam Thakkar
2024-06-06 21:54 ` Junio C Hamano
2024-06-06 23:35   ` Ghanshyam Thakkar
2024-06-07  8:31     ` Christian Couder [this message]
2024-06-07  8:36       ` Christian Couder
2024-06-07  8:41         ` Christian Couder
2024-06-07 16:37     ` Junio C Hamano
2024-06-08 16:57 ` [GSoC][PATCH v2] " Ghanshyam Thakkar
2024-06-10 16:40   ` Junio C Hamano
2024-06-10 20:52     ` Ghanshyam Thakkar
2024-06-10 21:06       ` Junio C Hamano
2024-06-10 22:01         ` Ghanshyam Thakkar
2024-06-10 23:20           ` Junio C Hamano
2024-06-10 23:36             ` Ghanshyam Thakkar

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=CAP8UFD0r+YYxAvN2Ej1mGa2Kt5M2dQgQEGLraB3iQ30cPWuA6Q@mail.gmail.com \
    --to=christian.couder@gmail.com \
    --cc=chriscool@tuxfamily.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=kaartic.sivaraam@gmail.com \
    --cc=shyamthakkar001@gmail.com \
    /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).