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

Re: [PATCH v4 3/3] t4113: put executable lines to test_expect_success

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Feb 8, 2023, 07:44 UTC
Message-ID
<230208.865ycc1tqc.gmgdl@evledraar.gmail.com>
In-Reply-To
<CAMO4yUEcweeGZDCBm-y51TQ0fgze_geKr95RXBpEEpH4AyYJuQ@mail.gmail.com>
On Wed, Feb 08 2023, Shuqi Liang wrote:
Show 58 quoted lines
> On Tue, Feb 7, 2023 at 3:12 AM Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:
>
>> But this is almost certainly that you're trying to insert leading
>> whitespace into a line that's in a <<-EOF here-doc, the "-" part of that
>> means that your leading whitespace is being stripped.
>>
>> A typical idiom for that is have a marker for the start of line, and
>> strip the whitespace with "sed". See this for existing examples:
>>
>>         git grep 'sed.*\^.*>.*EOF'
>
>
> I try to use Z as the marker in front of 'a' and 'b' and use sed -e
> "s/Z/ /g" in order to replace Z with white space but it still can not
> pass the test.
>
> Then I realize even if I don't add tab in front of the line but with
> space in front of 'a' and 'b' like the original test script. It still
> says it can't read "b" and "c” :
>
> test_expect_success 'apply at the beginning' '
> cat >test-patch<<\EOF &&
> diff a/file b/file
> --- a/file
> +++ b/file
> @@ -1,2 +1,3 @@
> +a
>  b
>  c
> EOF
>
> echo >file 'a
> b
> c'&&
> git update-index file&&
> test_must_fail git apply --index test-patch
> '
> Maybe the error is not caused by whitespace?
>
> Then I try to change:
>
> echo >file 'a
> b
> c'
>
> To:
> echo >file "a
> b
> c"
>
> Then everything passes the test. I think double quotes allow for
> variable substitution and command substitution, while single quotes
> preserve the literal value of all characters within the quotes. In
> this case, the string contains no variables or commands, so either
> type of quote would work. Is there something wrong with my idea? Is it
> good to modify code like that?
>
> Looking forward to your reply!

I'm not sure because you're just posting snippets, if you have problems in the future it would be best to post the full diff to "master" that you're having issues with, e.g. an RFC per Documentation/SubmittingPatches.

But I think this is because the test itself is using '-quotes, so you need to use '\'' if you want to single quote, and " for double quotes, and \" if the test were in double quotes.

But the issues you're having here aren't with Git, but the very basics of POSIX shell syntax.

I think it would be good for you to read some basic documentation on POSIX shells, their syntax, common POSIX commands etc. Your local "man sh" is probably a good place to start, but there's also books, online tutorials etc.

In this case the syntax you're trying to get working is something we usually try to avoid in either case, i.e. even if it involves an external process we usually do:

	cat >out <<-\EOF
	a
        b
	c
	EOF
Rather than:
	echo "a
        b
	c" >out
If you are using "echo" I saw another change of yours had e.g.:
	echo x >f &&
	echo y >>f &&
	echo z >>f

It's better to e.g. (assuming use of "echo", or other built-ins or commands):

	{
		echo x &&
		echo y &&
		echo z
	} >f
Previous: Shuqi LiangNext: Shuqi Liang
Message 31 of 49 in “t/t4113-apply-ending.sh: Modernize a test script”
  1. Shuqi LiangJan 31, 2023
  2. Andrei RybakFeb 1, 2023
  3. cheska franFeb 2, 2023
  4. 0/4 t4113: modernize test styleShuqi Liang, Feb 2, 2023
  5. 1/4 t4113: replace backslash with single quoteShuqi Liang, Feb 2, 2023
  6. Junio C HamanoFeb 2, 2023
  7. Shuqi LiangFeb 5, 2023
  8. 2/4 t4113:put second creation in own stepShuqi Liang, Feb 2, 2023
  9. 3/4 t4113: use "<<-" instead of "<<"Shuqi Liang, Feb 2, 2023
  10. Junio C HamanoFeb 2, 2023
  11. Shuqi LiangFeb 5, 2023
  12. 4/4 t4113: indent with tabsShuqi Liang, Feb 2, 2023
  13. Junio C HamanoFeb 2, 2023
  14. Shuqi LiangFeb 5, 2023
  15. 0/3 modernize styleShuqi Liang, Feb 5, 2023
  16. 1/3 t4113: modernize a test scriptShuqi Liang, Feb 5, 2023
  17. 2/3 t4113: put executable lines to test_expect_successShuqi Liang, Feb 5, 2023
  18. 3/3 t4113: indent with spaceShuqi Liang, Feb 5, 2023
  19. Eric SunshineFeb 5, 2023
  20. Shuqi LiangFeb 6, 2023
  21. 0/3 t4113: modernize styleShuqi Liang, Feb 6, 2023
  22. 1/3 t4113: modernize test scriptShuqi Liang, Feb 6, 2023
  23. 2/3 t4113: indent with tabShuqi Liang, Feb 6, 2023
  24. 3/3 t4113: put executable lines to test_expect_successShuqi Liang, Feb 6, 2023
  25. Ævar Arnfjörð BjarmasonFeb 6, 2023
  26. Junio C HamanoFeb 6, 2023
  27. Shuqi LiangFeb 6, 2023
  28. Ævar Arnfjörð BjarmasonFeb 7, 2023
  29. Shuqi LiangFeb 7, 2023
  30. Shuqi LiangFeb 8, 2023
  31. Ævar Arnfjörð BjarmasonFeb 8, 2023
  32. Shuqi LiangFeb 10, 2023
  33. Eric SunshineFeb 15, 2023
  34. Eric SunshineFeb 15, 2023
  35. Shuqi LiangFeb 14, 2023
  36. Junio C HamanoFeb 14, 2023
  37. 0/3 t4113: modernize styleShuqi Liang, Feb 9, 2023
  38. 1/3 t4113: modernize test scriptShuqi Liang, Feb 9, 2023
  39. 2/3 t4113: indent with tabShuqi Liang, Feb 9, 2023
  40. Eric SunshineFeb 15, 2023
  41. Shuqi LiangFeb 15, 2023
  42. 3/3 t4113: put executable lines to test_expect_successShuqi Liang, Feb 9, 2023
  43. Eric SunshineFeb 15, 2023
  44. Shuqi LiangFeb 15, 2023
  45. 0/3 t4113: modernize styleShuqi Liang, Feb 15, 2023
  46. 0/3 t4113: modernize styleShuqi Liang, Feb 15, 2023
  47. 1/3 t4113: modernize test scriptShuqi Liang, Feb 15, 2023
  48. 2/3 t4113: indent with tabShuqi Liang, Feb 15, 2023
  49. 3/3 t4113: put executable lines to test_expect_successShuqi Liang, Feb 15, 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.