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

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
Previous: Junio C HamanoNext: Junio C Hamano
Message 8 of 9 in “test-lib: make sure TEST_DIRECTORY has no trailing slash”
  1. test-lib: make sure TEST_DIRECTORY has no trailing slashŠtěpán Němec, Oct 3, 2023
  2. Junio C HamanoOct 3, 2023
  3. Junio C HamanoOct 3, 2023
  4. Štěpán NěmecOct 4, 2023
  5. Junio C HamanoOct 4, 2023
  6. Štěpán NěmecOct 4, 2023
  7. Junio C HamanoOct 4, 2023
  8. Štěpán NěmecOct 4, 2023
  9. Junio C HamanoOct 4, 2023

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.