Re: [PATCH v2 2/6] unit-tests: add for_test
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jul 22, 2024, 20:41 UTC
- Message-ID
- <xmqqwmld9n2b.fsf@gitster.g>
- In-Reply-To
- <be282096-49af-4d83-b5f7-8b4f1b447edb@web.de>
René Scharfe <l.s.r@web.de> writes:
Show 7 quoted lines
>>> And the issue won't be caught. >> >> You are right. Making an empty body somehow catchable by the >> compiler would be a vast improvement. > > That would be nice, but I have no idea how to do that without compiler > changes.
Me neither. I was trying to nerd-snipe Kyle into coming up with a solution ;-)
Show 7 quoted lines
> In the meantime the existing runtime checks will catch both > the empty test in the first line and the out-of-test check in the second > one and report them like this: > > # BUG: test has no checks at t/helper/test-example-tap.c:75 > not ok 1 - for_test passing test > Assertion failed: (ctx.running), function test_assert, file test-lib.c, line 267.
Nice improvement, I would say.
Show 19 quoted lines
> diff --git a/t/unit-tests/test-lib.c b/t/unit-tests/test-lib.c
> index 3c513ce59a..9977c81739 100644
> --- a/t/unit-tests/test-lib.c
> +++ b/t/unit-tests/test-lib.c
> @@ -264,7 +264,11 @@ static void test_todo(void)
>
> int test_assert(const char *location, const char *check, int ok)
> {
> - assert(ctx.running);
> + if (!ctx.running) {
> + test_msg("BUG: check outside of test at %s",
> + make_relative(location));
> + return 0;
> + }
>
> if (ctx.result == RESULT_SKIP) {
> test_msg("skipping check '%s' at %s", check,
> --
> 2.45.2