From: Junio C Hamano <gitster@pobox.com>
To: "Štěpán Němec" <stepnem@smrk.net>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] test-lib: make sure TEST_DIRECTORY has no trailing slash
Date: Wed, 04 Oct 2023 10:15:30 -0700 [thread overview]
Message-ID: <xmqqttr6pavh.fsf@gitster.g> (raw)
In-Reply-To: <20231004190140+0200.740775-stepnem@smrk.net> ("Štěpán Němec"'s message of "Wed, 04 Oct 2023 19:01:40 +0200")
Š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.
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). As long as it is not overdone,
it is a good practice to consider possibilities of similar problems
triggered by the same root cause, which we may not have got bitten
by yet, and preventing it from happening with the same fix.
Thanks.
next prev parent reply other threads:[~2023-10-04 17:15 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-03 8:23 [PATCH] test-lib: make sure TEST_DIRECTORY has no trailing slash Štěpán Němec
2023-10-03 21:21 ` Junio C Hamano
2023-10-03 21:57 ` Junio C Hamano
2023-10-04 9:34 ` Štěpán Němec
2023-10-04 16:19 ` Junio C Hamano
2023-10-04 17:01 ` Štěpán Němec
2023-10-04 17:15 ` Junio C Hamano [this message]
2023-10-04 17:40 ` Štěpán Němec
2023-10-04 18:24 ` 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=xmqqttr6pavh.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=stepnem@smrk.net \
/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).