From: Patrick Steinhardt <ps@pks.im>
To: Jeff King <peff@peff.net>
Cc: Junio C Hamano <gitster@pobox.com>,
Michael J Gruber <git@grubix.eu>,
git@vger.kernel.org
Subject: Re: [BUG/WIP PATCH] unit-tests: use clean test environment
Date: Tue, 4 Mar 2025 08:39:50 +0100 [thread overview]
Message-ID: <Z8auRqylLYuwalAA@pks.im> (raw)
In-Reply-To: <20250304073010.GC1283943@coredump.intra.peff.net>
On Tue, Mar 04, 2025 at 02:30:10AM -0500, Jeff King wrote:
> On Mon, Mar 03, 2025 at 06:07:29AM -0800, Junio C Hamano wrote:
>
> > Patrick Steinhardt <ps@pks.im> writes:
> >
> > > Maybe. I guess for unit tests it's a lot less clear cut as most of the
> > > tests won't depend on such a controlled environment. So sanitizing the
> > > environment would be a good enough first step for me, and if we see
> > > demand for making specific information available to lots of tests we
> > > could still start to expose those at a later point.
> >
> > Fair enough.
> >
> > To put it another way, if you write a test and if it gets affected
> > by externalities, perhaps you are testing a function that is at too
> > high a level that is not a suitable target for unit tested?
>
> I think one problem with this approach is that breakage is likely going
> to depend on the user's environment. So something that works just fine
> for you, the test author, may introduce a hidden dependency that breaks
> for somebody else much later.
>
> Some examples, assuming we just suppress reading Git config:
>
> - Without an explicit ident, we fall back to constructing one from
> system info. So if a unit test ever creates a commit, it will work
> fine for most people, but not for somebody with a blank GECOS field
> in /etc/passwd. (We do look at that field for reflogs, which current
> unit tests already do, but we are more forgiving there since we
> don't pass IDENT_STRICT).
>
> - Other programs we call (e.g., imagine gpg or ssh for commit signing
> or verification) may read their own config based on $HOME,
> $XDG_CONFIG_HOME, etc. I don't know if Patrick was including that in
> "sanitizing the environment" or not.
Oh, yes. I didn't mean to say we shouldn't sanitize at all, I rather
meant to say we should sanitize to values that simply cause us to do a
no-op in the relevant parts. That means we'd:
- Unset a bunch of environment variables where we know that they
impact Git.
- Set config-related environment variables to read configuration
from "/dev/null".
This is in contrast to the more involved fix here, which would be to
populate a temporary home directory with gitconfig files and whatnot.
Patrick
next prev parent reply other threads:[~2025-03-04 7:39 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-25 20:48 [BUG/WIP PATCH] unit-tests: use clean test environment Michael J Gruber
2025-02-28 10:50 ` Patrick Steinhardt
2025-02-28 14:15 ` Junio C Hamano
2025-03-03 10:33 ` Patrick Steinhardt
2025-03-03 10:49 ` Michael J Gruber
2025-03-03 14:07 ` Junio C Hamano
2025-03-04 7:30 ` Jeff King
2025-03-04 7:39 ` Patrick Steinhardt [this message]
2025-03-04 8:33 ` Jeff King
2025-03-04 15:54 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Z8auRqylLYuwalAA@pks.im \
--to=ps@pks.im \
--cc=git@grubix.eu \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).