git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: Michael J Gruber <git@grubix.eu>
Cc: git@vger.kernel.org
Subject: Re: [BUG/WIP PATCH] unit-tests: use clean test environment
Date: Fri, 28 Feb 2025 11:50:42 +0100	[thread overview]
Message-ID: <Z8GVAjwZWOM7c2fR@pks.im> (raw)
In-Reply-To: <e3be6705d103ccbc165d0fd3b9b7c818d14001e9.1740516033.git.git@grubix.eu>

On Tue, Feb 25, 2025 at 09:48:47PM +0100, Michael J Gruber wrote:
> So far, unit-tests are run in the user's environment, in particular with
> the user's git config which can influence test runs.
> 
> Set up the same clean test environment which we use for the other tests.
> ---
> Hi there,
> 
> I finally got around to checking whether the last test in t-trailer fails
> for me: one of the trailers is present in my git config, messing up the
> test assumption. The reasons is a systematic problem in the way we run
> unit-tests.
> 
> The attached patch is more POC than WIP - it makes t-trailer work again
> for me, at least.
> 
> unittest-lib.sh is a trimmed down version of test-lib.sh, and I'm sure
> it can be trimmed down even more, maybe to the extent of being included
> in run-test.sh.
> 
> Also, I'm not sute the Makefile change catches all invocations of
> unit-tests. (It certainly does not cover direct invocations, of course.)

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.

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.

But other than that I don't think we rely on any other infrastructure
exposed via environment variables, to the best of my knowledge. So it
shouldn't be that much logic, which may make it an option to implement
this in "t/unit-tests/unit-test.c" directly.

We still have a couple of other unit tests that have a different entry
point than the clar-based tests. But Seyi has been converting most of
them already, and I wouldn't worry about the remaining ones. So only
doing it for the clar-based tests should be good enough for our case as
we can assume that the other tests will go away sooner rather than
later.

Thanks!

Patrick

  reply	other threads:[~2025-02-28 10:50 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 [this message]
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
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=Z8GVAjwZWOM7c2fR@pks.im \
    --to=ps@pks.im \
    --cc=git@grubix.eu \
    --cc=git@vger.kernel.org \
    /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).