git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [GSoC][PATCH] t/: migrate helper/test-example-decorate to the unit testing framework

From
Christian Couder <christian.couder@gmail.com>
Date
May 30, 2024, 06:55 UTC
Message-ID
<CAP8UFD1YVyZj-uGfGXp6UxMfj3kZC5XXNed-5s-jj=ROx4URnA@mail.gmail.com>
In-Reply-To
<xmqq8qzsuwh1.fsf@gitster.g>
On Wed, May 29, 2024 at 11:41 PM Junio C Hamano <gitster@pobox.com> wrote:
> Ghanshyam Thakkar <shyamthakkar001@gmail.com> writes:
Show 29 quoted lines
> > +     TEST(t_add(&vars),
> > +          "Add 2 objects, one with a non-NULL decoration and one with a NULL decoration.");
> > +     TEST(t_readd(&vars),
> > +          "When re-adding an already existing object, the old decoration is returned.");
> > +     TEST(t_lookup(&vars),
> > +          "Lookup returns the added declarations, or NULL if the object was never added.");
> > +     TEST(t_loop(&vars), "The user can also loop through all entries.");
>
> These tests as a whole look like a faithful copy of the original
> done by cmd__example_decorate().
>
> I do not understand the criteria used to split them into the four
> separate helper functions.  It is not like they can be reused or
> reordered---for example, t_readd() must be done after t_add() has
> been done.
>
> What benefit are you trying to get out of these split?  IOW, what
> are we gaining by having four separate helper functions, instead of
> testing all of these same things in a single helper function t_all
> with something like
>
>         TEST(t_all(&vars), "Do all decorate tests.");
>
> in cmd_main()?  If there is a concrete benefit of having larger
> number of smaller tests, would it make the result even better if we
> split t_add() further into t_add_one() that adds one with deco_a and
> t_add_two() that adds two with NULL?  The other helpers can of
> course be further split into individual pieces the same way.  What
> ere the criteria used to decide where to stop and use these four?

The original code has some kind of "sections" (or paragraphs) separated using comments like:

      /*
       * Add 2 objects, one with a non-NULL decoration and one with a NULL
       * decoration.
       */
or:
      /*
       * When re-adding an already existing object, the old decoration is
       * returned.
       */

I think it makes sense to separate the code using functions matching these "sections" and to reuse each comment in the TEST() macro that calls the corresponding function. If this patch is rerolled for some reason, I think it would be a good idea to mention this in the commit message though.

Previous: Junio C HamanoNext: Ghanshyam Thakkar
Message 3 of 8 in “t/: migrate helper/test-example-decorate to the unit testing framework”
  1. Ghanshyam ThakkarMay 28, 2024
  2. Junio C HamanoMay 29, 2024
  3. Christian CouderMay 30, 2024
  4. Ghanshyam ThakkarMay 30, 2024
  5. Junio C HamanoMay 30, 2024
  6. Ghanshyam ThakkarJun 3, 2024
  7. Josh SteadmonJun 3, 2024
  8. Ghanshyam ThakkarJun 3, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.