Re: [PATCH] test-lib: make sure TEST_DIRECTORY has no trailing slash
- From
Štěpán Němec <stepnem@smrk.net>
- Date
- Oct 4, 2023, 17:40 UTC
- Message-ID
- <20231004194046+0200.353534-stepnem@smrk.net>
- In-Reply-To
- <xmqqttr6pavh.fsf@gitster.g>
On Wed, 04 Oct 2023 10:15:30 -0700 Junio C. Hamano wrote:
Show 26 quoted lines
> Štěpán Němec <stepnem@smrk.net> writes:
>
>> Yes, this is even simpler and more obvious, although for some reason,
>> the subshell version works just as well, i.e., with just
>> TEST_DIRECTORY=$(cd . && pwd) (no cd in the parent) in test-lib.sh and
>>
>> cat <<EOF >./tslash.sh
>> #!/bin/sh
>> test_description='yada yada'
>>
>> . ./test-lib.sh
>>
>> test_expect_success 'check TEST_DIRECTORY for trailing slash' '
>> echo "$TEST_DIRECTORY" &&
>> test "$TEST_DIRECTORY" = "${TEST_DIRECTORY%/}"
>> '
>>
>> test_done
>> EOF
>
> If the only thing you checked was if TEST_DIRECTORY has or does not
> have a trailing slash, then it is totally understandable how and why
> the chdir inside subshell works. The value $(pwd) in the subshell
> returns, that is assigned to TEST_DIRECTORY, is canonicalized. But
> the outer shell still thinks $(pwd) is with trailing slash, and the
> above does not test it.Oh my, of course... thanks.
Show 5 quoted lines
>
> test_expect_success 'check $PWD for trailing slash' '
> echo "$PWD" &&
> test "$PWD" = "${PWD%/}"
> '> The primary reason why I said I was silly doing it in a subshell was > because I wanted to make sure that any test that refers to $PWD or > $(pwd) later in the code would not get upset the same way with > trailing slash after $PWD or $(pwd).
The $PWD inside the test is the trash directory, though, so that's not the problematic $PWD with a trailing slash any more, so I guess this problem can't really happen in a test that follows the '. ./test-lib.sh' (which does cd -P "$TRASH_DIRECTORY") convention?
-- Štěpán