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

Re: [BUG/WIP PATCH] unit-tests: use clean test environment

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 28, 2025, 14:15 UTC
Message-ID
<xmqqseny40kx.fsf@gitster.g>
In-Reply-To
<Z8GVAjwZWOM7c2fR@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
> This to me is the biggest issue with the chosen approach. It would be
> great if we could find a way to sanitize the environment in the unit
> test executable directly instead of forcing users to run the unit tests
> via the provided script.

True. What the end-to-end tests do is to have a central place (in test-lib.sh if I recall correctly) to ensure a sane environment and have everybody run that before their own code. In theory we should be able to do the same in C (otherwise we wouldn't rewriting things done in scripts to the language ;-)).

Show 8 quoted lines
> I suspect that most environment variables shouldn't matter (for now), so
> overall the duplication may be acceptable:
>
>   - We need to unset a couple of variables, but we can probably reuse
>     logic `git rev-parse --local-env-vars`.
>
>   - We need to ask Git to not read the configuration, which we can do by
>     setting a couple of envvars. This should be manageable.

"Provide a controlled environment where Git pretends this is the $HOME and that is the $AUTHOR_NAME and so on" is much more preferrable than "Tell it not to read", no?

Thanks.
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 3 of 10 in “unit-tests: use clean test environment”
  1. unit-tests: use clean test environmentMichael J Gruber, Feb 25, 2025
  2. Patrick SteinhardtFeb 28, 2025
  3. Junio C HamanoFeb 28, 2025
  4. Patrick SteinhardtMar 3, 2025
  5. Michael J GruberMar 3, 2025
  6. Junio C HamanoMar 3, 2025
  7. Jeff KingMar 4, 2025
  8. Patrick SteinhardtMar 4, 2025
  9. Jeff KingMar 4, 2025
  10. Junio C HamanoMar 4, 2025

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.