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

From: Junio C Hamano <[email-masked]>
Date: Fri, 28 Feb 2025 06:15:42 -0800

Patrick Steinhardt <[email-masked]> 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 ;-)).

> 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.