Re: [PATCH v4 8/8] [Newcomer] t7004: Use single quotes instead of double quotes
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Aug 6, 2024, 16:35 UTC
- Message-ID
- <xmqqo765vcbu.fsf@gitster.g>
- In-Reply-To
- <CAPig+cSzq+6bua=T7w0M-+7+2zbzfD6ihXLkWfondZ8NbqUG4A@mail.gmail.com>
Eric Sunshine <sunshine@sunshineco.com> writes:
Show 11 quoted lines
> As a practical example, consider a test with a body like this: > > echo nothing >nothing && > git add nothing && > git commit -m nothing && > hash=$(git rev-parse HEAD) && > ... > > If this body is inside a double-quoted string, then `$(git rev-parse > HEAD)` will be evaluated and its value assigned to `hash` _before_ > test_expect_success() is called,
I know it is just your finger slipping, but the variable "hash" is not assigned to before test_expect_success is called even with the body inside dq.
What happens is that the value of HEAD is expanded in the string that will be evaled by test_expect_success so the 4th line in the above becomes "hash=3469a23659d8197190d2765cf9f31dec5ab602fa &&"; as the resulting string is then eval'ed by test_expect_success, the end result is as you descirbed, i.e., ...
> thus also before the `git commit` > command inside the test body (which is almost certainly not what the > author intended).
... $hash does not get the name of the commit object resulting from the "git commit" command before it.
Show 21 quoted lines
>> - " >> - test_expect_success "Doing 'git tag --list-like $option <commit> <pattern> is permitted" " >> + ' >> + test_expect_success 'Doing "git tag --list-like $option <commit> <pattern> is permitted' ' > > ... changing the double-quotes to single-quotes for the test _titles_ > in these instances is actively wrong. In this case, we _want_ > interpolation of `$option` to happen in the title string so that the > output looks like this: > > ok 167 - mixing incompatible modes with --contains is forbidden > ok 169 - mixing incompatible modes with --with is forbidden > ok 171 - mixing incompatible modes with --no-contains is forbidden > > By changing the title to use single-quotes, you suppress interpolation > of `$option`, with the result that the displayed titles become rather > useless: > > ok 167 - mixing incompatible modes with $option is forbidden > ok 169 - mixing incompatible modes with $option is forbidden > ok 171 - mixing incompatible modes with $option is forbidden
Yes, these has to be done carefully, both for titles and bodies.
Thanks.