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

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

From
Michael J Gruber <git@grubix.eu>
Date
Mar 3, 2025, 10:49 UTC
Message-ID
<CAA19uiTBzjHCn598t7DA7aF2X52WCuuVo0n1tgG5f2GFSLJiBg@mail.gmail.com>
In-Reply-To
<Z8WFcaEtMCD5C0EN@pks.im>
Am Mo., 3. März 2025 um 11:33 Uhr schrieb Patrick Steinhardt <ps@pks.im>:
Show 21 quoted lines
>
> On Fri, Feb 28, 2025 at 06:15:42AM -0800, Junio C Hamano wrote:
> > Patrick Steinhardt <ps@pks.im> writes:
> > > 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?
>
> 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.

Since I haven't been following the list I don't know what the plan is regarding the different test sets/framework. But, unless they are meant to be completely separate or rewritten right away, I would say that both shell tests and C tests (whatever framework) should run in the same environment, and this should be a controlled environment in terms of git and other config files (which means set up a separate HOME) and the most relevant env vars (test-lib.sh tries to do that, too).

> Of course, if the author already wants to do both steps right now I
> won't complain :)

Nah, I had a hard time just reading the failing unit-test and figuring out how to deal with it - GIT_TEST_OPTIONS=`-i -v` does nothing for unit-tests, and I yet have to find documentation on them. I do understand why you want a solution in C, not a shell wrapper. (Though you have one right now ...)

I'd rather leave this to those "in the know", or "in the want" ;-)
Michael
Previous: Patrick SteinhardtNext: Junio C Hamano
Message 5 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.