mbox series

[0/6] unit-tests: add and use TEST_RUN to simplify tests

Message ID 85b6b8a9-ee5f-42ab-bcbc-49976b30ef33@web.de (mailing list archive)
Headers show
Series unit-tests: add and use TEST_RUN to simplify tests | expand

Message

René Scharfe June 29, 2024, 3:33 p.m. UTC
The macro TEST only allows defining a test that consists of a single
expression.  This requires wrapping tests made up of one or more
statements in a function, which is a small, but avoidable hurdle.  This
series provides a new macro, TEST_RUN, that provides a way to define
tests without requiring to declare a function.

  t0080: move expected output to a file
  unit-tests: add TEST_RUN
  t-ctype: use TEST_RUN
  t-reftable-basics: use TEST_RUN
  t-strvec: use TEST_RUN
  t-strbuf: use TEST_RUN

 t/helper/test-example-tap.c      |  33 +++
 t/t0080-unit-test-output.sh      |  48 +----
 t/t0080/expect                   |  76 +++++++
 t/unit-tests/t-ctype.c           |   4 +-
 t/unit-tests/t-reftable-basics.c | 228 +++++++++-----------
 t/unit-tests/t-strbuf.c          |  79 +++----
 t/unit-tests/t-strvec.c          | 356 ++++++++++++++-----------------
 t/unit-tests/test-lib.c          |  42 +++-
 t/unit-tests/test-lib.h          |   8 +
 9 files changed, 462 insertions(+), 412 deletions(-)
 create mode 100644 t/t0080/expect

--
2.45.2

Comments

Josh Steadmon July 1, 2024, 7:59 p.m. UTC | #1
On 2024.06.29 17:33, René Scharfe wrote:
> The macro TEST only allows defining a test that consists of a single
> expression.  This requires wrapping tests made up of one or more
> statements in a function, which is a small, but avoidable hurdle.  This
> series provides a new macro, TEST_RUN, that provides a way to define
> tests without requiring to declare a function.
> 
>   t0080: move expected output to a file
>   unit-tests: add TEST_RUN
>   t-ctype: use TEST_RUN
>   t-reftable-basics: use TEST_RUN
>   t-strvec: use TEST_RUN
>   t-strbuf: use TEST_RUN
> 
>  t/helper/test-example-tap.c      |  33 +++
>  t/t0080-unit-test-output.sh      |  48 +----
>  t/t0080/expect                   |  76 +++++++
>  t/unit-tests/t-ctype.c           |   4 +-
>  t/unit-tests/t-reftable-basics.c | 228 +++++++++-----------
>  t/unit-tests/t-strbuf.c          |  79 +++----
>  t/unit-tests/t-strvec.c          | 356 ++++++++++++++-----------------
>  t/unit-tests/test-lib.c          |  42 +++-
>  t/unit-tests/test-lib.h          |   8 +
>  9 files changed, 462 insertions(+), 412 deletions(-)
>  create mode 100644 t/t0080/expect
> 
> --
> 2.45.2

One small nitpick on patch #3 and a question on #6, but basically this
series looks good to me. I'll be away from email for the rest of the
week, so I'll go ahead and sign off:

Reviewed-by: Josh Steadmon <steadmon@google.com>
Junio C Hamano July 10, 2024, 10:13 p.m. UTC | #2
René Scharfe <l.s.r@web.de> writes:

> The macro TEST only allows defining a test that consists of a single
> expression.  This requires wrapping tests made up of one or more
> statements in a function, which is a small, but avoidable hurdle.  This
> series provides a new macro, TEST_RUN, that provides a way to define
> tests without requiring to declare a function.
>
>   t0080: move expected output to a file
>   unit-tests: add TEST_RUN
>   t-ctype: use TEST_RUN
>   t-reftable-basics: use TEST_RUN
>   t-strvec: use TEST_RUN
>   t-strbuf: use TEST_RUN
>
>  t/helper/test-example-tap.c      |  33 +++
>  t/t0080-unit-test-output.sh      |  48 +----
>  t/t0080/expect                   |  76 +++++++
>  t/unit-tests/t-ctype.c           |   4 +-
>  t/unit-tests/t-reftable-basics.c | 228 +++++++++-----------
>  t/unit-tests/t-strbuf.c          |  79 +++----
>  t/unit-tests/t-strvec.c          | 356 ++++++++++++++-----------------
>  t/unit-tests/test-lib.c          |  42 +++-
>  t/unit-tests/test-lib.h          |   8 +
>  9 files changed, 462 insertions(+), 412 deletions(-)
>  create mode 100644 t/t0080/expect

So, looking back the discussion list on

  https://lore.kernel.org/git/85b6b8a9-ee5f-42ab-bcbc-49976b30ef33@web.de/

any loose ends still need to be addressed?  I didn't spot any
myself, so I am willing to merge it to 'next' soonish, but please
stop me if there were something I missed.

Thanks.
Phillip Wood July 11, 2024, 10:05 a.m. UTC | #3
On 10/07/2024 23:13, Junio C Hamano wrote:
> René Scharfe <l.s.r@web.de> writes:
>
> So, looking back the discussion list on
> 
>    https://lore.kernel.org/git/85b6b8a9-ee5f-42ab-bcbc-49976b30ef33@web.de/
> 
> any loose ends still need to be addressed?  I didn't spot any
> myself, so I am willing to merge it to 'next' soonish, but please
> stop me if there were something I missed.

I thought René was planning a re-roll to avoid using xstrfmt() in Patch 
2 c.f <97390954-49bc-48c4-bab1-95be10717aca@web.de>. Also I'm not sure 
we've reached a conclusion on whether to include the "if" in the macro 
or require the user to write "if(TEST_RUN(...))". My impression is that 
there is a consensus building around having the macro include the "if" 
but we haven't decided what to call it c.f. 
<62d221cc-532a-4a6d-8e96-b5a246ddeb1b@web.de>

Best Wishes

Phillip
Junio C Hamano July 11, 2024, 3:12 p.m. UTC | #4
Phillip Wood <phillip.wood123@gmail.com> writes:

> On 10/07/2024 23:13, Junio C Hamano wrote:
>> René Scharfe <l.s.r@web.de> writes:
>>
>> So, looking back the discussion list on
>>    https://lore.kernel.org/git/85b6b8a9-ee5f-42ab-bcbc-49976b30ef33@web.de/
>> any loose ends still need to be addressed?  I didn't spot any
>> myself, so I am willing to merge it to 'next' soonish, but please
>> stop me if there were something I missed.
>
> I thought René was planning a re-roll to avoid using xstrfmt() in
> Patch 2 c.f <97390954-49bc-48c4-bab1-95be10717aca@web.de>. Also I'm
> not sure we've reached a conclusion on whether to include the "if" in
> the macro or require the user to write "if(TEST_RUN(...))". My
> impression is that there is a consensus building around having the
> macro include the "if" but we haven't decided what to call it
> c.f. <62d221cc-532a-4a6d-8e96-b5a246ddeb1b@web.de>
>
> Best Wishes

Thanks.  Very much appreciated.
René Scharfe July 14, 2024, 10:35 a.m. UTC | #5
Am 11.07.24 um 12:05 schrieb Phillip Wood:
> On 10/07/2024 23:13, Junio C Hamano wrote:
>> René Scharfe <l.s.r@web.de> writes:
>>
>> So, looking back the discussion list on
>>
>>    https://lore.kernel.org/git/85b6b8a9-ee5f-42ab-bcbc-49976b30ef33@web.de/
>>
>> any loose ends still need to be addressed?  I didn't spot any
>> myself, so I am willing to merge it to 'next' soonish, but please
>> stop me if there were something I missed.
>
> I thought René was planning a re-roll to avoid using xstrfmt() in
> Patch 2 c.f <97390954-49bc-48c4-bab1-95be10717aca@web.de>. Also I'm
> not sure we've reached a conclusion on whether to include the "if" in
> the macro or require the user to write "if(TEST_RUN(...))". My
> impression is that there is a consensus building around having the
> macro include the "if" but we haven't decided what to call it c.f.
> <62d221cc-532a-4a6d-8e96-b5a246ddeb1b@web.de>
Right, thanks, and I'm back now from a surprisingly exhausting business
trip.  Will send v3 soonish.

René