Subject: Re: [PATCH v2] t: run tests from a normalized working directory

From: Junio C Hamano <[email-masked]>
Date: Thu, 29 May 2025 22:04:24 -0700

Torsten Bögershausen <[email-masked]> writes:

> On Wed, May 28, 2025 at 04:17:37PM -0400, Mark Mentovai wrote:
>
> The problem is well described, thanks for that.
> However, different words and terms are used for the same thing:
>   "normalized working directory" (which is easy to confuse
>     with normalized working tree where CRLF-LF conversion had been
>     done and clean filters applied.
>   "pathname canonicalization"
>   "canonical absolute path"
>   "normalized path"
> ... and that is done in "strbuf_realpath()"
>
> May be the word normalized can be replaced here ?
> Starting with the head line, how about this:
> t: run tests from an absolute path
>
> And later in the text:
> use "absolute path" instead of "normalized path" ?

Thanks for a careful reading.  When I read the log message for the
first time, it did not bother me too much that it said canonicalize
and normalize interchangeably, and the two verbs still do not bother
me terribly.  I agree with you that clearly describing what the
canonicalization rules do (i.e. fully resolving symbolic links to
make the path absolute) very good idea, but I think the last
sentence of the first paragraph does a good job at it already.

Can you offer a rewrite along the lines you suggest so that we can
compare?  I personally felt that what Mark gave us, albeit a bit on
the more verbose and repetitive side, were written clearly enough.

Thanks.

>> Some tests make git perform actions that produce observable pathnames,
>> and have expectations on those paths. Tests run with $HOME set to a
>> $TRASH_DIRECTORY, and with their working directory the same
>> $TRASH_DIRECTORY, although these paths are logically identical, they do
>> not observe the same pathname canonicalization rules and thus might not
>> be represented by strings that compare equal. In particular, no pathname
>> normalization is applied to $TRASH_DIRECTORY or $HOME, while tests
>> change their working directory with `cd -P`, which normalizes the
>> working directory's path by fully resolving symbolic links.
>>
>> t7900's macOS maintenance tests (which are not limited to running on
>> macOS) have an expectation on a path that `git maintenance` forms by
>> using abspath.c strbuf_realpath() to resolve a canonical absolute path
>> based on $HOME. When t7900 runs from a working directory that contains
>> symbolic links in its pathname, $HOME will also contain symbolic links,
>> which `git maintenance` resolves but the test's expectation does not,
>> causing a test failure.
>> 
>> Align $TRASH_DIRECTORY and $HOME with the normalized path as used for
>> the working directory by resetting them to match the working directory
>> after it's established by `cd -P`. With all paths in agreement and
>> symbolic links resolved, pathname expectations can be set and met based
>> on string comparison without regard to external environmental factors
>> such as the presence of symbolic links in a path.
>> 
>> Suggested-by: Junio C Hamano <[email-masked]>
>> Signed-off-by: Mark Mentovai <[email-masked]>
>> ---
>>  t/test-lib.sh | 2 ++
>>  1 file changed, 2 insertions(+)
>> 
>> diff --git a/t/test-lib.sh b/t/test-lib.sh
>> index af722d383d9b..92d0db13d742 100644
>> --- a/t/test-lib.sh
>> +++ b/t/test-lib.sh
>> @@ -1577,6 +1577,8 @@ fi
>>  # Use -P to resolve symlinks in our working directory so that the cwd
>>  # in subprocesses like git equals our $PWD (for pathname comparisons).
>>  cd -P "$TRASH_DIRECTORY" || BAIL_OUT "cannot cd -P to \"$TRASH_DIRECTORY\""
>> +TRASH_DIRECTORY=$(pwd)
>> +HOME="$TRASH_DIRECTORY"
>>  
>>  start_test_output "$0"
>>  
>>