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
Ghanshyam Thakkar <shyamthakkar001@gmail.com>
Date
May 30, 2024, 08:39 UTC
Message-ID
<tubjmjeczh6iigem32ulffvt2ucpygbm4frsr3jsps5tv2i7v5@ly3wge23zn6f>
In-Reply-To
<CAP8UFD1YVyZj-uGfGXp6UxMfj3kZC5XXNed-5s-jj=ROx4URnA@mail.gmail.com>
On Thu, 30 May 2024, Christian Couder <christian.couder@gmail.com> wrote:
Show 26 quoted lines
> On Wed, May 29, 2024 at 11:41 PM Junio C Hamano <gitster@pobox.com> wrote:
> > Ghanshyam Thakkar <shyamthakkar001@gmail.com> writes:
> 
> > > +     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 addition to what Christian said, doing it all in one function would provide no context as is. i.e. when we do it in a single function,

*** unit-tests/bin/t-example-decorate *** # check "objects_noticed == 1" failed at t/unit-tests/t-example-decorate.c:46 # left: 2 # right: 1 # should have 2 objects not ok 1 - All decorate tests 1..1 make[1]: *** [Makefile:78: unit-tests/bin/t-example-decorate] Error 1

vs separated

*** unit-tests/bin/t-example-decorate *** ok 1 - Add 2 objects, one with a non-NULL decoration and one with a NULL decoration. ok 2 - When re-adding an already existing object, the old decoration is returned. ok 3 - Lookup returns the added declarations, or NULL if the object was never added. # check "objects_noticed == 1" failed at t/unit-tests/t-example-decorate.c:56 # left: 2 # right: 1 # should have 2 objects not ok 4 - The user can also loop through all entries. 1..4 make[1]: *** [Makefile:78: unit-tests/bin/t-example-decorate] Error 1

The latter provides much more context (we almost don't have to open t-example-decorate.c file itself in some cases to know what failed) than the former. Now, of course we can add more test_msg()s to the former to improve, but I feel that this approach of splitting them provides and improves the information provided on stdout _without_ adding any of my own test_msg()s. And I think that this is a good middleground between cluttering the stdout vs providing very little context while also remaining a faithful copy of the original.

Show 27 quoted lines
> > 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.
I agree about the commit message.
Thanks.
Previous: Christian CouderNext: Junio C Hamano
Message 4 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.