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

Re: [PATCH 2/2] test-lib-functions: use BUG() in 'test_must_fail'

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 14, 2026, 21:11 UTC
Message-ID
<xmqqv7dt8cyj.fsf@gitster.g>
In-Reply-To
<ad6pEbnSKzUOkS2k@szeder.dev>
SZEDER Gábor <szeder.dev@gmail.com> writes:
Show 19 quoted lines
> On Sun, Feb 21, 2021 at 04:58:23PM -0500, Jeff King wrote:
>> On Sun, Feb 21, 2021 at 08:25:12PM +0100, SZEDER Gábor wrote:
>> 
>> > In many test helper functions we verify that they were invoked with
>> > sensible parameters, and call BUG() to abort the test script when the
>> > parameters are buggy.  6a67c75948 (test-lib-functions: restrict
>> > test_must_fail usage, 2020-07-07) added such a parameter verification
>> > to 'test_must_fail', but it didn't report the error with BUG(), like
>> > we usually do.
>> 
>> OK. I do not care all that much between BUG() and not-BUG here, since we
>> are unlikely to have a test where test_must_fail returning 0 yields
>> success. I guess the most interesting outcome is that we would notice a
>> bug in a test_expect_failure block.
>
> If I had managed to send a new version of this patch series in the
> last 5 years :), then this would have caught the issue noted in:
>
>   https://public-inbox.org/git/ad6hovxCkwMTG11U@szeder.dev/

I was wondering if we should remove "test_might_fail". Its use case is rather limited to very narrow cases, like

 * we want to kill something but it may have exited on its own
 * we want "git config --unset" but the variable may or may not be set
 * we want "git foo --abort" just in case we are in the middle of
   "git foo"

all of which is clearer with "|| :", and more importantly, the thing whose "failure" is protected against the test framework declaring a test failure is *not* what we are testing (these "config --unset" are not about testing "git config", in other words).

So the extra ability test_must_fail and test_might_fail have that they can detect uncontrolled death with non-zero exit status (aka "crash") is not very interesting---it is more like "As we are running a git command here, it would be better to catch than not catch a segfault here as well", i.e., a nice to have item.

Previous: SZEDER GáborNext: Jeff King
Message 8 of 13 in “tests: don't mess with fd 7 of test helper functions”
  1. 1/2 tests: don't mess with fd 7 of test helper functionsSZEDER Gábor, Feb 21, 2021
  2. 2/2 test-lib-functions: use BUG() in 'test_must_fail'SZEDER Gábor, Feb 21, 2021
  3. Jeff KingFeb 21, 2021
  4. Jeff KingFeb 22, 2021
  5. Jeff KingFeb 22, 2021
  6. Junio C HamanoFeb 22, 2021
  7. SZEDER GáborApr 14, 2026
  8. Junio C HamanoApr 14, 2026
  9. Jeff KingApr 14, 2026
  10. Junio C HamanoApr 15, 2026
  11. Jeff KingApr 14, 2026
  12. Jeff KingFeb 21, 2021
  13. Junio C HamanoFeb 22, 2021

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.