Skip to contentSkip to conversation

t/t4113-apply-ending.sh: Modernize a test script

PATCH In review Shuqi Liang 5 participants 49 messages Jan 31, 2023 – Feb 15, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 t/t4113-apply-ending.sh: Modernize a test script

I cleaned up some old style in test script.

for example :

* old style:

    test_expect_success \
        'title' \
        'body line 1 &&
        body line 2'

should become:

test_expect_success 'title' '
body line 1 &&
body line 2
'

---
Hi,I'm Shuqi Liang.a junior student majors in Computer Science at University of Western Ontario.

This patch is the microproject I try to getting involved with the Git project.

I have read 'MyFirstContribution.txt', 'Hacking Git' and the book 《pro git》 ,and I know more about objects, references, packfile format, etc. Over the coming period, I will delve into the source code and gain a deeper understanding and try to contribute more meaningful patch to the community.

 t/t4113-apply-ending.sh | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
t/t4113-apply-ending.sh +9 -7
index 66fa51591e..aa57895b22 100755
@@ -24,13 +24,14 @@ echo 'a' >file
 echo 'b' >>file
 echo 'c' >>file
 
-test_expect_success setup \
-    'git update-index --add file'
-
+test_expect_success setup '
+    git update-index --add file
+'
 # test
 
-test_expect_success 'apply at the end' \
-    'test_must_fail git apply --index test-patch'
+test_expect_success 'apply at the end' '
+    test_must_fail git apply --index test-patch
+'
 
 cat >test-patch <<\EOF
 diff a/file b/file
@@ -47,7 +48,8 @@ b
 c'
 git update-index file
 
-test_expect_success 'apply at the beginning' \
-	'test_must_fail git apply --index test-patch'
+test_expect_success 'apply at the beginning' '
+    test_must_fail git apply --index test-patch
+'
 
 test_done
Signature · 1 line
2.39.0
#1 lore raw

Hi Shuqi Liang,

Quoted 1 line

Subject: [GSoC][PATCH] t/t4113-apply-ending.sh: Modernize a test script

For patches that change a single test, the subject line can include just the "t" and the number. The part after the colon should start with a lowercase letter. Something like

t4113: modernize test style

Quoted 2 lines · Shuqi Liang

I cleaned up some old style in test script.

Commit message should start with description of the existing problem in present tense, something like:

Test scripts in file t4113-apply-ending.sh are written in old style, where the test_expect_success command and test title are written on separate lines ...

Then changes should be described using imperative mood, as if you are giving commands to the codebase. See section "[[describe-changes]]" in "Documentation/SubmittingPatches" for details.

You can also find examples of existing commit messages for similar changes:

    $ git log --no-merges --grep='modernize' -- t
Quoted 20 lines

for example :

* old style:

     test_expect_success \
         'title' \
         'body line 1 &&
         body line 2'

should become:

test_expect_success 'title' '
body line 1 &&
body line 2
'

Quoted 4 lines

---
Hi,I'm Shuqi Liang.a junior student majors in Computer Science at University of Western Ontario.

Welcome!

t/t4113-apply-ending.sh echo 'a' >file · line 25

Quoted 10 lines
  t/t4113-apply-ending.sh | 16 +++++++++-------
  1 file changed, 9 insertions(+), 7 deletions(-)
t/t4113-apply-ending.sh +0 -0
index 66fa51591e..aa57895b22 100755
@@ -24,13 +24,14 @@ echo 'a' >file
  echo 'b' >>file
  echo 'c' >>file

A "modern" test could also do such preparation for test files as part of its "setup" step. This could its own patch in the same series, separate from style changes.

In case of t4113, files "test-patch" and "file" are created twice. The second creation of the files could be either its own step 'setup for apply at the beginning', or incorporated into the step 'apply at the beginning'.

Section "Recommended style" in t/README also has some notes about how heredocs should be indented.

t/t4113-apply-ending.sh echo 'a' >file · line 29

Quoted 7 lines
t/t4113-apply-ending.sh +3 -3
-test_expect_success setup \
-    'git update-index --add file'
-
+test_expect_success setup '
+    git update-index --add file
+'

While changing the quoting around test tiles and commands, the indentation with spaces could also be changed to TABs.

t/t4113-apply-ending.sh echo 'a' >file · line 29

Quoted 1 line
t/t4113-apply-ending.sh +0 -0
  # test

If the setup code on top level of the file is moved into test steps, this comment and the "# setup" comment at line 11 will become unnecessary.

Quoted 10 lines
t/t4113-apply-ending.sh +3 -2
-test_expect_success 'apply at the end' \
-    'test_must_fail git apply --index test-patch'
+test_expect_success 'apply at the end' '
+    test_must_fail git apply --index test-patch
+'
 
  cat >test-patch <<\EOF
  diff a/file b/file

t/t4113-apply-ending.sh b · line 55

Quoted 10 lines
t/t4113-apply-ending.sh +3 -2
@@ -47,7 +48,8 @@ b
  c'
  git update-index file
 
-test_expect_success 'apply at the beginning' \
-	'test_must_fail git apply --index test-patch'
+test_expect_success 'apply at the beginning' '
+    test_must_fail git apply --index test-patch
+'
 
  test_done

Thanks.

#2 lore raw

Hi Andrei,

Andrei Rybak <[email protected]> On 31/01/2023 21:21:

Quoted 6 lines

For patches that change a single test, the subject line can include just the "t" and the number. The part after the colon should start with a lowercase letter. Something like

t4113: modernize test style

Thanks, this tip is really helpful. I will change it.

Quoted 7 lines

Commit message should start with description of the existing problem in present tense, something like:

Test scripts in file t4113-apply-ending.sh are written in old style, where the test_expect_success command and test title are written on separate lines ...

Quoted 9 lines

Then changes should be described using imperative mood, as if you are giving commands to the codebase. See section "[[describe-changes]]" in "Documentation/SubmittingPatches" for details.

You can also find examples of existing commit messages for similar changes:

     $ git log --no-merges --grep='modernize' -- t

Thanks,that is cool! I tried it and I saw a lot of examples and their descriptions were very clear and I learned a lot

Quoted 4 lines

In case of t4113, files "test-patch" and "file" are created twice. The second creation of the files could be either its own step 'setup for apply at the beginning', or incorporated into the step 'apply at the beginning'.

yeah,once before the first instance of test-patch and then again before the second instance of test-patch.
I will move the second creation of the files to its own step in setup for apply at the beginning.'

Quoted 2 lines

Section "Recommended style" in t/README also has some notes about how heredocs should be indented.

Sure, I did not realize this.I will use "<<-" instead of "<<".

Quoted 2 lines

While changing the quoting around test tiles and commands, the indentation with spaces could also be changed to TABs.

will do.

Quoted 3 lines

If the setup code on top level of the file is moved into test steps, this comment and the "# setup" comment at line 11 will become unnecessary.

Thanks. It's easy to miss.The purpose of these tags is to distinguish the setup and test parts of the script,
but if the file creation has been moved to a separate step, then these tags are no longer needed.

Thanks for the reply and it is really helpful!

--
Thanks,
Shuqi

#3 lore raw

v2 cover t4113: modernize test style

In reply to Shuqi Liang

Modernize the test script t4113.

Comparing to v1:

1.Test scripts in file in this script are written in old style,
where the test_expect_success command and test title are written on separate lines.Change the old style '\' to new style "'".
for example :
-test_expect_success setup \
- 'git update-index --add file'
-
+test_expect_success setup '
+ git update-index --add file
+'

2.Files "test-patch" and "file" are created twice. put the second creation of the files to its own step 'setup for apply at the beginning'

3.This script still use the old style "<<". Change "<<-" instead of "<<"
for exmaple:
- cat >test-patch <<\EOF
+ cat >test-patch <<-\EOF

4.The test bodies in this script are written in old style .which indented with space, but not TAB.replace indentation spaces with tabs. for example :

test_expect_success setup '
- git update-index --add file
+ git update-index --add file
'

Shuqi Liang (4):
t/t4113-apply-ending.sh: Modernize a test script
Test scripts in file t4113-apply-ending.sh, files "test-patch" and
"file" are created twice.
use "<<-" instead of "<<"
t4113-apply-ending.sh used 4-column indent with space,fix it in use
tabs for indentation.

 t/t4113-apply-ending.sh | 51 +++++++++++++++++++++--------------------
 1 file changed, 26 insertions(+), 25 deletions(-)

Range-diff against v1:

1:  d7d52f1f79 = 1:  d7d52f1f79 t/t4113-apply-ending.sh: Modernize a test script
-:  ---------- > 2:  d9e5a54e32 Test scripts in file t4113-apply-ending.sh, files "test-patch" and "file" are created twice.
-:  ---------- > 3:  01a5c3285e use "<<-" instead of "<<"
-:  ---------- > 4:  cf2b2ca5a0 t4113-apply-ending.sh used 4-column indent with space,fix it in use tabs for indentation.
Signature · 1 line
2.39.0
#4 lore raw

PATCH v2 1/4 t4113: replace backslash with single quote

Change the old style '\' to new style "'"

---
 t/t4113-apply-ending.sh | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
t/t4113-apply-ending.sh +9 -7
index 66fa51591e..aa57895b22 100755
@@ -24,13 +24,14 @@ echo 'a' >file
 echo 'b' >>file
 echo 'c' >>file
 
-test_expect_success setup \
-    'git update-index --add file'
-
+test_expect_success setup '
+    git update-index --add file
+'
 # test
 
-test_expect_success 'apply at the end' \
-    'test_must_fail git apply --index test-patch'
+test_expect_success 'apply at the end' '
+    test_must_fail git apply --index test-patch
+'
 
 cat >test-patch <<\EOF
 diff a/file b/file
@@ -47,7 +48,8 @@ b
 c'
 git update-index file
 
-test_expect_success 'apply at the beginning' \
-	'test_must_fail git apply --index test-patch'
+test_expect_success 'apply at the beginning' '
+    test_must_fail git apply --index test-patch
+'
 
 test_done
Signature · 1 line
2.39.0
#5 lore raw

Re: [PATCH v2 1/4]t4113: replace backslash with single quote

Shuqi Liang <[email protected]> writes:

The example Andrei gave you, i.e.

Test scripts in file t4113-apply-ending.sh are written in old style, where the test_expect_success command and test title are written on separate lines ...

was quite readable, but this

Quoted 1 line

Change the old style '\' to new style "'"

is almost impossible to understand without knowing that this wanted to say what Andrei gave in a different way. The title is worse. It's not replacing a backslash with a single quote, which would result in

    -test_expect_success setup \
    +test_expect_success setup '
        'git update-index --add file'

and obviously that is not what you did (or wanted to do).

Quoted 4 lines
---
 t/t4113-apply-ending.sh | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

The patch text looks OK.

#6 lore raw

Re: [PATCH v2 1/4]t4113: replace backslash with single quote

Hi Junio,

Quoted 10 lines · Junio C Hamano

is almost impossible to understand without knowing that this wanted to say what Andrei gave in a different way. The title is worse. It's not replacing a backslash with a single quote, which would result in

    -test_expect_success setup \
    +test_expect_success setup '
        'git update-index --add file'

and obviously that is not what you did (or wanted to do).

Thanks, I will modify it to make it clear about my motivation and the real changes to my patch.

#7 lore raw

PATCH v2 2/4 t4113:put second creation in own step

In reply to Shuqi Liang

files "test-patch" and "file" are created twice.put the second creation of the files to its own step'setup for apply at the beginning'.

Make the second creation of the files its own step 'setup for apply at the beginning'.

---
 t/t4113-apply-ending.sh | 33 ++++++++++++++++-----------------
 1 file changed, 16 insertions(+), 17 deletions(-)
t/t4113-apply-ending.sh +16 -17
index aa57895b22..d84f632bc3 100755
@@ -8,8 +8,6 @@ test_description='git apply trying to add an ending line.
 '
 . ./test-lib.sh
 
-# setup
-
 cat >test-patch <<\EOF
 diff --git a/file b/file
 --- a/file
@@ -27,26 +25,27 @@ echo 'c' >>file
 test_expect_success setup '
     git update-index --add file
 '
-# test
 
 test_expect_success 'apply at the end' '
     test_must_fail git apply --index test-patch
 '
 
-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_expect_success 'setup for 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_expect_success 'apply at the beginning' '
     test_must_fail git apply --index test-patch
Signature · 1 line
2.39.0
#8 lore raw

PATCH v2 3/4 t4113: use "<<-" instead of "<<"

In reply to Shuqi Liang

use "<<-" instead of "<<"

---
 t/t4113-apply-ending.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
t/t4113-apply-ending.sh +2 -2
index d84f632bc3..d5b15e97d3 100755
@@ -8,7 +8,7 @@ test_description='git apply trying to add an ending line.
 '
 . ./test-lib.sh
 
-cat >test-patch <<\EOF
+cat >test-patch <<-\EOF
 diff --git a/file b/file
 --- a/file
 +++ b/file
@@ -31,7 +31,7 @@ test_expect_success 'apply at the end' '
 '
 
 test_expect_success 'setup for apply at the beginning' '
-	cat >test-patch <<\EOF
+	cat >test-patch <<-\EOF
 	diff a/file b/file
 	--- a/file
 	+++ b/file
Signature · 1 line
2.39.0
#9 lore raw

Re: [PATCH v2 3/4] t4113: use "<<-" instead of "<<"

Quoted 1 line · Shuqi Liang

use "<<-" instead of "<<"

You forgot to explain "Why?". What you did, anybody can see in the patch text. Why you did so is what you are expected to explain in your proposed log message.

t/t4113-apply-ending.sh test_description='git apply trying to add an ending line. · line 14

Quoted 5 lines
t/t4113-apply-ending.sh +1 -1
-cat >test-patch <<\EOF
+cat >test-patch <<-\EOF
 diff --git a/file b/file
 --- a/file
 +++ b/file

There is no need to do this, as the body of the here-doc is not indented/prefixed with HT at all.

t/t4113-apply-ending.sh test_expect_success 'apply at the end' ' · line 37

Quoted 9 lines
t/t4113-apply-ending.sh +1 -1
@@ -31,7 +31,7 @@ test_expect_success 'apply at the end' '
 '
 
 test_expect_success 'setup for apply at the beginning' '
-	cat >test-patch <<\EOF
+	cat >test-patch <<-\EOF
 	diff a/file b/file
 	--- a/file
 	+++ b/file

This is necessary but that is only because [PATCH v2 2/4] broke it. In general, we frown upon a series where a bug is introduced in an earlier step, with another patch fixing that bug.

Let's not introduce such a bug that we need to fix later from the beginning instead.

Thanks.

#10 lore raw

Re: [PATCH v2 3/4] t4113: use "<<-" instead of "<<"

Quoted 3 lines · Junio C Hamano

You forgot to explain "Why?". What you did, anybody can see in the patch text. Why you did so is what you are expected to explain in your proposed log message.

Thanks. I did make a lot of mistakes in writing a good commit message. I will modify it.

Quoted 8 lines

t/t4113-apply-ending.sh test_description='git apply trying to add an ending line. · line 14

Quoted 5 lines
t/t4113-apply-ending.sh +1 -1
-cat >test-patch <<\EOF
+cat >test-patch <<-\EOF
 diff --git a/file b/file
 --- a/file
 +++ b/file

There is no need to do this, as the body of the here-doc is not indented/prefixed with HT at all.

yeah, I did not notice that , According to t/README says, Indent the body of here-document, and use "<<-" instead of "<<"
to strip leading TABs used for indentation. But here do not have the leading TABS in front of it.

Quoted 14 lines

t/t4113-apply-ending.sh test_expect_success 'apply at the end' ' · line 37

Quoted 9 lines
t/t4113-apply-ending.sh +1 -1
@@ -31,7 +31,7 @@ test_expect_success 'apply at the end' '
 '
 
 test_expect_success 'setup for apply at the beginning' '
-     cat >test-patch <<\EOF
+     cat >test-patch <<-\EOF
      diff a/file b/file
      --- a/file
      +++ b/file

This is necessary but that is only because [PATCH v2 2/4] broke it. In general, we frown upon a series where a bug is introduced in an earlier step, with another patch fixing that bug.

Quoted 2 lines

Let's not introduce such a bug that we need to fix later from the beginning instead.

Thanks, I will introduce the new bug caused by the current patch in the beginning.

--------
Thanks,
shuqi

#11 lore raw

PATCH v2 4/4 t4113: indent with tabs

In reply to Shuqi Liang

t4113-apply-ending.sh used 4-column indent with
space,fix it in use tabs for indentation.

---
 t/t4113-apply-ending.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
t/t4113-apply-ending.sh +3 -3
index d5b15e97d3..9e28c72355 100755
@@ -23,11 +23,11 @@ echo 'b' >>file
 echo 'c' >>file
 
 test_expect_success setup '
-    git update-index --add file
+	git update-index --add file
 '
 
 test_expect_success 'apply at the end' '
-    test_must_fail git apply --index test-patch
+	test_must_fail git apply --index test-patch
 '
 
 test_expect_success 'setup for apply at the beginning' '
@@ -48,7 +48,7 @@ test_expect_success 'setup for apply at the beginning' '
 '
 
 test_expect_success 'apply at the beginning' '
-    test_must_fail git apply --index test-patch
+	test_must_fail git apply --index test-patch
 '
 
 test_done
Signature · 1 line
2.39.0
#12 lore raw

Re: [PATCH v2 4/4] t4113: indent with tabs

Quoted 2 lines · Shuqi Liang

t4113-apply-ending.sh used 4-column indent with
space,fix it in use tabs for indentation.

Good, but end the sentence with a full-top with a space after it, and start the next sentence with a capital letter.

Quoted 10 lines
---
 t/t4113-apply-ending.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
t/t4113-apply-ending.sh +0 -0
index d5b15e97d3..9e28c72355 100755

t/t4113-apply-ending.sh echo 'b' >>file · line 27

Quoted 6 lines
t/t4113-apply-ending.sh +1 -1
@@ -23,11 +23,11 @@ echo 'b' >>file
 echo 'c' >>file
 
 test_expect_success setup '
-    git update-index --add file
+	git update-index --add file
 '

This is not wrong per se, but the modern style is to avoid having any executable lines outside test_expect_foo. I'd expect that the resulting script begins more like the attached. [PATCH 4/4] stops the conversion in the middle, which leaves funny taste in our mouth.

Thanks.

t/t4113-apply-ending.sh +14 -18
index 66fa51591e..9746f45898 100755
@@ -8,24 +8,20 @@ test_description='git apply trying to add an ending line.
 '
 . ./test-lib.sh
 
-# setup
-
-cat >test-patch <<\EOF
-diff --git a/file b/file
---- a/file
-+++ b/file
-@@ -1,2 +1,3 @@
- a
- b
-+c
-EOF
-
-echo 'a' >file
-echo 'b' >>file
-echo 'c' >>file
-
-test_expect_success setup \
-    'git update-index --add file'
+test_expect_success setup '
+	cat >test-patch <<-\EOF
+	diff --git a/file b/file
+	--- a/file
+	+++ b/file
+	@@ -1,2 +1,3 @@
+	 a
+	 b
+	+c
+	EOF
+
+	test_write_lines a b c >file
+	git update-index --add file
+'
 
 # test
 
#13 lore raw

Re: [PATCH v2 4/4] t4113: indent with tabs

Quoted 2 lines · Junio C Hamano

Good, but end the sentence with a full-top with a space after it, and start the next sentence with a capital letter.

Sure, think I need to change it to " ...space. Fix..". I will pay more attention to my English written style.

Quoted 4 lines

This is not wrong per se, but the modern style is to avoid having any executable lines outside test_expect_foo. I'd expect that the resulting script begins more like the attached. [PATCH 4/4] stops the conversion in the middle, which leaves funny taste in our mouth.

Thanks, Will avoid having any executable lines outside test_expect_foo.

Overall, thanks for the reply and it is really helpful!
--------------------------------
Shuqi

#14 lore raw

v3 cover modernize style

In reply to Shuqi Liang

different between V2:

1.change the commit massage in t4113: Modernize test script and t4113: indent with space.

2. Put the executable lines inside the test_expect_success.Mention the new style problem cause by this change,which is change the "<<" to "<<-" to strip leading TABs used for indentation.

Shuqi Liang (3):
t/t4113-apply-ending.sh: Modernize test script
t4113: put executable lines to test_expect_success
t4113: indent with space

 t/t4113-apply-ending.sh | 79 ++++++++++++++++++++---------------------
 1 file changed, 38 insertions(+), 41 deletions(-)

Range-diff against v2:
1: d7d52f1f79 ! 1: 3d40bcce13 t/t4113-apply-ending.sh: Modernize a test script
@@ Metadata
Author: Shuqi Liang <[email protected]>

## Commit message ##
- t/t4113-apply-ending.sh: Modernize a test script
+ t/t4113-apply-ending.sh: Modernize test script

+ Test scripts in file in this script are written in old style,
+ where the test_expect_success command and test title are written on
+ separate lines. Change the old style to modern style.
+
+ for example :
+ -test_expect_success setup \
+ - 'git update-index --add file'
+ -
+ +test_expect_success setup '
+ + git update-index --add file
+ +'

## t/t4113-apply-ending.sh ##
2: d9e5a54e32 ! 2: 5c55b208a8 Test scripts in file t4113-apply-ending.sh, files "test-patch" and "file" are created twice.

    @@ Metadata
     Author: Shuqi Liang <[email protected]>
     
      ## Commit message ##
    -    Test scripts in file t4113-apply-ending.sh, files
    -    "test-patch" and "file" are created twice.
    +    t4113: put executable lines to test_expect_success
     
    -    Make the second creation of the files its own step
    -    'setup for apply at the beginning'.
    +    This script is written in old style,where there are
    +    some executable lines outside test_expect_success. Put the executable
    +    lines inside the test_expect_success.
    +
    +    As t/README says,use "<<-" instead of "<<"
    +    to strip leading TABs used for indentation. change the "<<" to "<<-"
    +
    +    for example:
    +    -cat >test-patch <<\EOF
    +    -diff a/file b/file
    +
    +     test_expect_success 'apply at the beginning' '
    +    +       cat >test-patch <<-\EOF
    +    +       diff a/file b/file
    +    +       --- a/file
     
         Signed-off-by: Shuqi Liang <[email protected]>
     
    @@ t/t4113-apply-ending.sh: test_description='git apply trying to add an ending lin
      
     -# setup
     -
    - cat >test-patch <<\EOF
    - diff --git a/file b/file
    - --- a/file
    -@@ t/t4113-apply-ending.sh: echo 'c' >>file
    +-cat >test-patch <<\EOF
    +-diff --git a/file b/file
    +---- a/file
    +-+++ b/file
    +-@@ -1,2 +1,3 @@
    +- a
    +- b
    +-+c
    +-EOF
    +-
    +-echo 'a' >file
    +-echo 'b' >>file
    +-echo 'c' >>file
    +-
      test_expect_success setup '
    ++	cat >test-patch <<-\EOF
    ++	diff --git a/file b/file
    ++	--- a/file
    ++	+++ b/file
    ++	@@ -1,2 +1,3 @@
    ++	a
    ++	b
    ++	+c
    ++	EOF
    ++
    ++	echo 'a' >file
    ++	echo 'b' >>file
    ++	echo 'c' >>file
          git update-index --add file
      '
     -# test
    @@ -1,2 +1,3 @@
     -b
     -c'
     -git update-index file
    -+test_expect_success 'setup for apply at the beginning' '
    -+	cat >test-patch <<\EOF
    +-
    + test_expect_success 'apply at the beginning' '
    ++	cat >test-patch <<-\EOF
     +	diff a/file b/file
     +	--- a/file
     +	+++ b/file
    @@ -1,2 +1,3 @@
     +	b
     +	c'
     +	git update-index file
    -+'
    - 
    - test_expect_success 'apply at the beginning' '
          test_must_fail git apply --index test-patch
    + '
    + 
3:  01a5c3285e < -:  ---------- use "<<-" instead of "<<"
4:  cf2b2ca5a0 < -:  ---------- t4113-apply-ending.sh used 4-column indent with space,fix it in use tabs for indentation.
-:  ---------- > 3:  02b661279f t4113: indent with space
Signature · 1 line
2.39.0
#15 lore raw

PATCH v3 1/3 t4113: modernize a test script

Test scripts in file in this script are written in old style, where the test_expect_success command and test title are written on separate lines. Change the old style to modern style.

for example :
-test_expect_success setup \
- 'git update-index --add file'
-
+test_expect_success setup '
+ git update-index --add file
+'

---
 t/t4113-apply-ending.sh | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
t/t4113-apply-ending.sh +9 -7
index 66fa51591e..aa57895b22 100755
@@ -24,13 +24,14 @@ echo 'a' >file
 echo 'b' >>file
 echo 'c' >>file
 
-test_expect_success setup \
-    'git update-index --add file'
-
+test_expect_success setup '
+    git update-index --add file
+'
 # test
 
-test_expect_success 'apply at the end' \
-    'test_must_fail git apply --index test-patch'
+test_expect_success 'apply at the end' '
+    test_must_fail git apply --index test-patch
+'
 
 cat >test-patch <<\EOF
 diff a/file b/file
@@ -47,7 +48,8 @@ b
 c'
 git update-index file
 
-test_expect_success 'apply at the beginning' \
-	'test_must_fail git apply --index test-patch'
+test_expect_success 'apply at the beginning' '
+    test_must_fail git apply --index test-patch
+'
 
 test_done
Signature · 1 line
2.39.0
#16 lore raw

PATCH v3 2/3 t4113: put executable lines to test_expect_success

In reply to Shuqi Liang

This script is written in old style,where there are
some executable lines outside test_expect_success. Put the executable lines inside the test_expect_success.

As t/README says,use "<<-" instead of "<<"
to strip leading TABs used for indentation. Change the "<<" to "<<-"

for example:
-cat >test-patch <<\EOF
-diff a/file b/file

test_expect_success 'apply at the beginning' '
+ cat >test-patch <<-\EOF
+ diff a/file b/file
+ --- a/file

---
 t/t4113-apply-ending.sh | 59 +++++++++++++++++++----------------------
 1 file changed, 27 insertions(+), 32 deletions(-)
t/t4113-apply-ending.sh +27 -32
index aa57895b22..e0a52a12c4 100755
@@ -8,47 +8,42 @@ test_description='git apply trying to add an ending line.
 '
 . ./test-lib.sh
 
-# setup
-
-cat >test-patch <<\EOF
-diff --git a/file b/file
---- a/file
-+++ b/file
-@@ -1,2 +1,3 @@
- a
- b
-+c
-EOF
-
-echo 'a' >file
-echo 'b' >>file
-echo 'c' >>file
-
 test_expect_success setup '
+	cat >test-patch <<-\EOF
+	diff --git a/file b/file
+	--- a/file
+	+++ b/file
+	@@ -1,2 +1,3 @@
+	a
+	b
+	+c
+	EOF
+
+	echo 'a' >file
+	echo 'b' >>file
+	echo 'c' >>file
     git update-index --add file
 '
-# test
 
 test_expect_success 'apply at the end' '
     test_must_fail git apply --index test-patch
 '
 
-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_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
 '
 
Signature · 1 line
2.39.0
#17 lore raw

PATCH v3 3/3 t4113: indent with space

In reply to Shuqi Liang

As Documentation/CodingGuidelines says, the shell scripts are to use tabs for indentation, but this script
uses 4-column indent with space. Fix it in use tabs for indentation.

---
 t/t4113-apply-ending.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
t/t4113-apply-ending.sh +3 -3
index e0a52a12c4..ab5ecaab7f 100755
@@ -22,11 +22,11 @@ test_expect_success setup '
 	echo 'a' >file
 	echo 'b' >>file
 	echo 'c' >>file
-    git update-index --add file
+	git update-index --add file
 '
 
 test_expect_success 'apply at the end' '
-    test_must_fail git apply --index test-patch
+	test_must_fail git apply --index test-patch
 '
 
 test_expect_success 'apply at the beginning' '
@@ -44,7 +44,7 @@ test_expect_success 'apply at the beginning' '
 	b
 	c'
 	git update-index file
-    test_must_fail git apply --index test-patch
+	test_must_fail git apply --index test-patch
 '
 
 test_done
Signature · 1 line
2.39.0
#18 lore raw

Re: [PATCH v3 3/3] t4113: indent with space

Quoted 1 line · Shuqi Liang

t4113: indent with space

This probably ought to say "indent with tab" since that's what this patch is doing.

Quoted 3 lines

As Documentation/CodingGuidelines says, the shell scripts are to use tabs for indentation, but this script
uses 4-column indent with space. Fix it in use tabs for indentation.

s/in use/to use/

t/t4113-apply-ending.sh test_expect_success setup ' · line 26

Quoted 13 lines

---

t/t4113-apply-ending.sh +1 -1
index e0a52a12c4..ab5ecaab7f 100755
@@ -22,11 +22,11 @@ test_expect_success setup '
        echo 'a' >file
        echo 'b' >>file
        echo 'c' >>file
-    git update-index --add file
+       git update-index --add file
 '

As a GSoC microproject, v3 is probably "good enough", so there may not be a compelling reason to re-roll.

If you do find a reason to re-roll, though, I might suggest swapping patches 2 and 3 since the current organization leaves a mix of tab and space indentation in the tests, which makes reviewers do extra work since they have to look ahead in the patch series to see if you fix the inconsistent indentation in a later patch.

#19 lore raw

Re: [PATCH v3 3/3] t4113: indent with space

Hi, Eric

Quoted 2 lines · Eric Sunshine

This probably ought to say "indent with tab" since that's what this patch is doing.

Thanks ,I will fix it .

Quoted 5 lines

If you do find a reason to re-roll, though, I might suggest swapping patches 2 and 3 since the current organization leaves a mix of tab and space indentation in the tests, which makes reviewers do extra work since they have to look ahead in the patch series to see if you fix the inconsistent indentation in a later patch.

Yeah ,I didn‘t realize that .Thanks for reply! I will send the V4 soon.
----------
Thanks,
Shuqi

#20 lore raw

v4 cover t4113: modernize style

In reply to Shuqi Liang

Slightly different from V3:

1.Swap patches 2 and 3 because in patch [v3 2/3] leaves a mix of tab and space indentation in the tests

2.Change the commit message in patch [v3 3/3] to indent with tab.

Shuqi Liang (3):
t4113: modernize test script
t4113: indent with tab
t4113: put executable lines to test_expect_success

 t/t4113-apply-ending.sh | 79 ++++++++++++++++++++---------------------
 1 file changed, 38 insertions(+), 41 deletions(-)

base-commit: c48035d29b4e524aed3a32f0403676f0d9128863

Signature · 1 line
2.39.0
#21 lore raw

PATCH v4 1/3 t4113: modernize test script

Test scripts in file in this script are written in old style, where the test_expect_success command and test title are written on separate lines. Change the old style to modern style.

for example :
-test_expect_success setup \
- 'git update-index --add file'
-
+test_expect_success setup '
+ git update-index --add file
+'

---
 t/t4113-apply-ending.sh | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
t/t4113-apply-ending.sh +9 -7
index 66fa51591e..aa57895b22 100755
@@ -24,13 +24,14 @@ echo 'a' >file
 echo 'b' >>file
 echo 'c' >>file
 
-test_expect_success setup \
-    'git update-index --add file'
-
+test_expect_success setup '
+    git update-index --add file
+'
 # test
 
-test_expect_success 'apply at the end' \
-    'test_must_fail git apply --index test-patch'
+test_expect_success 'apply at the end' '
+    test_must_fail git apply --index test-patch
+'
 
 cat >test-patch <<\EOF
 diff a/file b/file
@@ -47,7 +48,8 @@ b
 c'
 git update-index file
 
-test_expect_success 'apply at the beginning' \
-	'test_must_fail git apply --index test-patch'
+test_expect_success 'apply at the beginning' '
+    test_must_fail git apply --index test-patch
+'
 
 test_done
Signature · 1 line
2.39.0
#22 lore raw

PATCH v4 2/3 t4113: indent with tab

In reply to Shuqi Liang

As Documentation/CodingGuidelines says, the shell scripts are to use tabs for indentation, but this script
uses 4-column indent with space. Fix it in use tabs for indentation.

---
 t/t4113-apply-ending.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
t/t4113-apply-ending.sh +3 -3
index aa57895b22..5ee177e8eb 100755
@@ -25,12 +25,12 @@ echo 'b' >>file
 echo 'c' >>file
 
 test_expect_success setup '
-    git update-index --add file
+	git update-index --add file
 '
 # test
 
 test_expect_success 'apply at the end' '
-    test_must_fail git apply --index test-patch
+	test_must_fail git apply --index test-patch
 '
 
 cat >test-patch <<\EOF
@@ -49,7 +49,7 @@ c'
 git update-index file
 
 test_expect_success 'apply at the beginning' '
-    test_must_fail git apply --index test-patch
+	test_must_fail git apply --index test-patch
 '
 
 test_done
Signature · 1 line
2.39.0
#23 lore raw

PATCH v4 3/3 t4113: put executable lines to test_expect_success

In reply to Shuqi Liang

This script is written in old style,where there are
some executable lines outside test_expect_success. Put the executable lines inside the test_expect_success.

As t/README says,use "<<-" instead of "<<"
to strip leading TABs used for indentation. Change the "<<" to "<<-"

for example:
-cat >test-patch <<\EOF
-diff a/file b/file

test_expect_success 'apply at the beginning' '

+       cat >test-patch <<-\EOF
+       diff a/file b/file
+       --- a/file
---
 t/t4113-apply-ending.sh | 59 +++++++++++++++++++----------------------
 1 file changed, 27 insertions(+), 32 deletions(-)
t/t4113-apply-ending.sh +27 -32
index 5ee177e8eb..ab5ecaab7f 100755
@@ -8,47 +8,42 @@ test_description='git apply trying to add an ending line.
 '
 . ./test-lib.sh
 
-# setup
-
-cat >test-patch <<\EOF
-diff --git a/file b/file
---- a/file
-+++ b/file
-@@ -1,2 +1,3 @@
- a
- b
-+c
-EOF
-
-echo 'a' >file
-echo 'b' >>file
-echo 'c' >>file
-
 test_expect_success setup '
+	cat >test-patch <<-\EOF
+	diff --git a/file b/file
+	--- a/file
+	+++ b/file
+	@@ -1,2 +1,3 @@
+	a
+	b
+	+c
+	EOF
+
+	echo 'a' >file
+	echo 'b' >>file
+	echo 'c' >>file
 	git update-index --add file
 '
-# test
 
 test_expect_success 'apply at the end' '
 	test_must_fail git apply --index test-patch
 '
 
-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_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
 '
 
Signature · 1 line
2.39.0
#24 lore raw

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

On Mon, Feb 06 2023, Shuqi Liang wrote:

. ./test-lib.sh

Quoted 21 lines
t/t4113-apply-ending.sh +3 -16
-# setup
-
-cat >test-patch <<\EOF
-diff --git a/file b/file
---- a/file
-+++ b/file
-@@ -1,2 +1,3 @@
- a
- b
-+c
-EOF
-
-echo 'a' >file
-echo 'b' >>file
-echo 'c' >>file
-
 test_expect_success setup '
+	cat >test-patch <<-\EOF
+	diff --git a/file b/file
+	--- a/file

t/t4113-apply-ending.sh test_description='git apply trying to add an ending line. · line 24

Quoted 10 lines
t/t4113-apply-ending.sh +10 -0
+	+++ b/file
+	@@ -1,2 +1,3 @@
+	a
+	b
+	+c
+	EOF
+
+	echo 'a' >file
+	echo 'b' >>file
+	echo 'c' >>file

I have not read the rest here, but this immediately fails with a very large error from chain-lint by default, and even if you manually disable it (which I assume you're doing, or just not testing these at all before submission), you'll get:

	$ ./t4113-apply-ending.sh --no-chain-lint
	ok 1 - setup
	ok 2 - apply at the end
	ok 3 - apply at the beginning
	./t4113-apply-ending.sh: 44: b: not found
	./t4113-apply-ending.sh: 48: c
	        git update-index file
	        test_must_fail git apply --index test-patch
	: not found
	# passed all 3 test(s)
	1..3

Which shows that even with the &&-chaining fixed you have quoting issues here, you're trying to execute 'b' etc.

I didn't read the rest of this topic, but please test with chain-lint, see if there's any unexpected new output from the tests etc. before a v5 re-roll.

#25 lore raw

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

In reply to Shuqi Liang

t/t4113-apply-ending.sh test_description='git apply trying to add an ending line. · line 25

Quoted 13 lines · Shuqi Liang
t/t4113-apply-ending.sh +0 -13
-cat >test-patch <<\EOF
-diff --git a/file b/file
---- a/file
-+++ b/file
-@@ -1,2 +1,3 @@
- a
- b
-+c
-EOF
-
-echo 'a' >file
-echo 'b' >>file
-echo 'c' >>file

Have you run the resulting test?

t/t4113-apply-ending.sh test_description='git apply trying to add an ending line. · line 20

Quoted 10 lines

test_expect_success setup '

t/t4113-apply-ending.sh +9 -0
+	cat >test-patch <<-\EOF
+	diff --git a/file b/file
+	--- a/file
+	+++ b/file
+	@@ -1,2 +1,3 @@
+	a
+	b
+	+c
+	EOF

This creates a "test-patch" file with lines 'a' and 'b' that are common context lines without any whitespace before them, no? The original left the necessary single space in front of them (see the line removed above).

#26 lore raw

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

Quoted 1 line · Junio C Hamano

Have you run the resulting test?

My apologies for not testing after V1. That was a major oversight on my part. I'll make sure to thoroughly test before each submission to avoid any issues with the code in the future.

Quoted 4 lines

This creates a "test-patch" file with lines 'a' and 'b' that are common context lines without any whitespace before them, no? The original left the necessary single space in front of them (see the line removed above).

I try to change the code to(left the necessary single space in front of 'a' and 'b':

t/t4113-apply-ending.sh +4 -3
index ab5ecaab7f..ef61a3187c 100755
@@ -14,8 +14,8 @@ test_expect_success setup '
--- a/file
+++ b/file
@@ -1,2 +1,3 @@
- a
- b
+ a
+ b
+c

EOF

Here I only show one part ,but I fix two same issue in the V4 patch and it still can not pass the test .
It say :

Test Summary Report

-------------------

t4113-apply-ending.sh (Wstat: 256 Tests: 0 Failed: 0)

Non-zero exit status: 1

Parse errors: No plan found in TAP output

Files=1, Tests=0, 0 wallclock secs ( 0.01 usr 0.01 sys + 0.05 cusr 0.02 csys = 0.09 CPU)

Result: FAIL.

I'm stumped as to why it's still failing. I've tried searching for answers on StackOverflow, but I still can't figure it out.
----------------
Thanks,
Shuqi

#27 lore raw

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

Quoted 49 lines · Shuqi Liang
Quoted 1 line · Junio C Hamano

Have you run the resulting test?

My apologies for not testing after V1. That was a major oversight on my part. I'll make sure to thoroughly test before each submission to avoid any issues with the code in the future.

Quoted 4 lines

This creates a "test-patch" file with lines 'a' and 'b' that are common context lines without any whitespace before them, no? The original left the necessary single space in front of them (see the line removed above).

I try to change the code to(left the necessary single space in front of 'a' and 'b':

t/t4113-apply-ending.sh +0 -0
index ab5ecaab7f..ef61a3187c 100755
@@ -14,8 +14,8 @@ test_expect_success setup '
file +3 -2
@@ -1,2 +1,3 @@
- a
- b
+ a
+ b
+c

EOF

Here I only show one part ,but I fix two same issue in the V4 patch and it still can not pass the test .
It say :

Test Summary Report

-------------------

t4113-apply-ending.sh (Wstat: 256 Tests: 0 Failed: 0)

Non-zero exit status: 1

Parse errors: No plan found in TAP output

Files=1, Tests=0, 0 wallclock secs ( 0.01 usr 0.01 sys + 0.05 cusr 0.02 csys = 0.09 CPU)

Quoted 7 lines

Result: FAIL.

I'm stumped as to why it's still failing. I've tried searching for answers on StackOverflow, but I still can't figure it out.
----------------
Thanks,
Shuqi

The error doesn't tell us much, instead of "make prove" or "prove <name>" running e.g.:

	./t4113-apply-ending.sh -vixd

Gives you better output.

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'
#28 lore raw

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

Hi Ævar,

Quoted 6 lines · Ævar Arnfjörð Bjarmason

The error doesn't tell us much, instead of "make prove" or "prove <name>" running e.g.:

        ./t4113-apply-ending.sh -vixd

Gives you better output.

Thanks, this is really helpful.

Quoted 8 lines

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'

Thank you for the tip! I'll try to fix the problem as soon as possible.

---------
Thanks,
Shuqi

#29 lore raw

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

In reply to Ævar Arnfjörð Bjarmason

Hi Ævar,

Quoted 8 lines · Ævar Arnfjörð Bjarmason

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 &&

file +1 -0
diff 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!

------
Shuqi

#30 lore raw

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

Quoted 50 lines · Shuqi Liang
Quoted 8 lines · Ævar Arnfjörð Bjarmason

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

file +1 -0
@@ -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"

Quoted 8 lines

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
#31 lore raw

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

Hi Ævar ,

Sorry if I sent this email twice. I forget to CC [email protected].

Quoted 3 lines · Ævar Arnfjörð Bjarmason

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.

Yeah, posting snippets doesn't describe the problem very well. Thanks for the advice.

Quoted 5 lines

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.

Quoted 7 lines

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.

Thanks, will do . I'll try to avoid making mistakes on POSIX shells questions and really learn the basic POSIX shells syntax.

Quoted 22 lines

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
Quoted 8 lines

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

        {
                echo x &&
                echo y &&
                echo z
        } >f

Seen I pass the test s, I'v a submit V5 patch instead of RFC, Would you mind taking a look at this for me? Looking forward to reply.

-----------------------------
Thanks

Shuqi

Quoted 109 lines · Ævar Arnfjörð Bjarmason
Quoted 50 lines · Shuqi Liang
Quoted 8 lines · Ævar Arnfjörð Bjarmason

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

file +1 -0
@@ -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"

Quoted 8 lines

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
#32 lore raw

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

In reply to Ævar Arnfjörð Bjarmason
Quoted 10 lines · Ævar Arnfjörð Bjarmason

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
Quoted 5 lines

Rather than:

        echo "a
        b
        c" >out

The here-doc (<<-\EOF) form is definitely a good idea when the code is part of an indented test body, whereas the multi-line double-quoted string will be problematic since lines "b" and "c" will be indented with TAB, which is undesirable here.

Even better for such a simple case would be:

    test_write_lines a b c >out &&

In fact, Junio made this suggestion in the form of a code snipped much earlier in this thread.

Quoted 6 lines

If you are using "echo" I saw another change of yours had e.g.:

        echo x >f &&
        echo y >>f &&
        echo z >>f
Quoted 8 lines

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

        {
                echo x &&
                echo y &&
                echo z
        } >f

This is also an improvement, though test_write_lines would (again) be even better for such a simple case:

    test_write_lines x y z >f &&
#33 lore raw

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

In reply to Ævar Arnfjörð Bjarmason
Quoted 21 lines · Ævar Arnfjörð Bjarmason
Quoted 20 lines · Shuqi Liang
Quoted 4 lines · Junio C Hamano

This creates a "test-patch" file with lines 'a' and 'b' that are common context lines without any whitespace before them, no? The original left the necessary single space in front of them (see the line removed above).

I try to change the code to(left the necessary single space in front of 'a' and 'b':

t/t4113-apply-ending.sh +3 -2
@@ -1,2 +1,3 @@
- a
- b
+ a
+ b
+c

EOF

t4113-apply-ending.sh (Wstat: 256 Tests: 0 Failed: 0)
Result: FAIL.

Quoted 6 lines
Quoted 2 lines

I'm stumped as to why it's still failing. I've tried searching for answers on StackOverflow, but I still can't figure it out.

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.

Almost. The <<- operator actually only strips leading TABs; other whitespace following the TABs is left intact.

#34 lore raw

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

In reply to Junio C Hamano

Hi Junio,

I didn't see this change in " What's cooking in git.git". I'm not sure if the V5 patch is overlooked. I didn't receive any review after V5. Is there anything wrong in V5 that needs to be corrected?

Thanks,
Shuqi

#35 lore raw

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

Quoted 3 lines · Shuqi Liang

I didn't see this change in " What's cooking in git.git". I'm not sure if the V5 patch is overlooked. I didn't receive any review after V5. Is there anything wrong in V5 that needs to be corrected?

I dunno (yet). These days a day did not have enough time to be looking at all the patches on the list, and patches that are more about practice than fixing real bugs or adding real features tend to be placed on the back burner.

THanks for pinging.

#36 lore raw

v5 cover t4113: modernize style

In reply to Shuqi Liang

different with V4:
1.chain test assertions

For example:

-cat >test-patch <<\EOF
-diff --git a/file b/file

+ cat >test-patch <<-\EOF &&
+ diff --git a/file b/file

2.change the modern style with echo
echo x >file &&
echo y >>file &&
echo z >>file

  Change it to this stlye :
        {
        echo x &&
        echo y &&
        echo z
        } >file

3.In order to escape for executable lines inside the test_expect_success. Change ' in executable lines to '\'' in order to escape.

(V4 didn't test before sumbit so I show the difference between orgin t4113 )

Shuqi Liang (3):
t4113: modernize test script
t4113: indent with tab
t4113: put executable lines to test_expect_success

 t/t4113-apply-ending.sh | 81 ++++++++++++++++++++---------------------
 1 file changed, 40 insertions(+), 41 deletions(-)

base-commit: c48035d29b4e524aed3a32f0403676f0d9128863

Signature · 1 line
2.39.0
#37 lore raw

PATCH v5 1/3 t4113: modernize test script

Test scripts in file in this script are written in old style, where the test_expect_success command and test title are written on separate lines. Change the old style to modern style.

for example :
-test_expect_success setup \
- 'git update-index --add file'
-
+test_expect_success setup '
+ git update-index --add file
+'

---
 t/t4113-apply-ending.sh | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
t/t4113-apply-ending.sh +9 -9
index 66fa51591e..41526ca805 100755
@@ -24,14 +24,14 @@ echo 'a' >file
 echo 'b' >>file
 echo 'c' >>file
 
-test_expect_success setup \
-    'git update-index --add file'
-
+test_expect_success setup '
+    git update-index --add file
+'
 # test
 
-test_expect_success 'apply at the end' \
-    'test_must_fail git apply --index test-patch'
-
+test_expect_success 'apply at the end' '
+    test_must_fail git apply --index test-patch
+'
 cat >test-patch <<\EOF
 diff a/file b/file
 --- a/file
@@ -47,7 +47,7 @@ b
 c'
 git update-index file
 
-test_expect_success 'apply at the beginning' \
-	'test_must_fail git apply --index test-patch'
-
+test_expect_success 'apply at the beginning' '
+	test_must_fail git apply --index test-patch
+'
 test_done
Signature · 1 line
2.39.0
#38 lore raw

PATCH v5 2/3 t4113: indent with tab

In reply to Shuqi Liang

As Documentation/CodingGuidelines says, the shell scripts are to use tabs for indentation, but this script
uses 4-column indent with space. Fix it in use tabs for indentation.

---
 t/t4113-apply-ending.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
t/t4113-apply-ending.sh +2 -2
index 41526ca805..a470c9ce7b 100755
@@ -25,12 +25,12 @@ echo 'b' >>file
 echo 'c' >>file
 
 test_expect_success setup '
-    git update-index --add file
+	git update-index --add file
 '
 # test
 
 test_expect_success 'apply at the end' '
-    test_must_fail git apply --index test-patch
+	test_must_fail git apply --index test-patch
 '
 cat >test-patch <<\EOF
 diff a/file b/file
Signature · 1 line
2.39.0
#39 lore raw

Re: [PATCH v5 2/3] t4113: indent with tab

Quoted 3 lines · Shuqi Liang

As Documentation/CodingGuidelines says, the shell scripts are to use tabs for indentation, but this script
uses 4-column indent with space. Fix it in use tabs for indentation.

s/in use/to use/

Quoted 1 line

The patch itself looks fine.

#40 lore raw

Re: [PATCH v5 2/3] t4113: indent with tab

Hi, Eric

Quoted 1 line · Eric Sunshine

The patch itself looks fine.

Thank you for your recognition!

------
Thanks
Shuqi

#41 lore raw

PATCH v5 3/3 t4113: put executable lines to test_expect_success

In reply to Shuqi Liang

As t/README says, put all code inside test_expect_success and other assertions. This script is written in old style,where there are some executable lines outside test_expect_success. Put the executable lines inside the test_expect_success.

As t/README says,use "<<-" instead of "<<"
to strip leading TABs used for indentation. Change the "<<" to "<<-"

for example:
-cat >test-patch <<\EOF
-diff a/file b/file

test_expect_success 'apply at the beginning' '

+       cat >test-patch <<-\EOF
+       diff a/file b/file
+       --- a/file

As t/README says,chain test assertions.Chain this test assertions with &&.

For example:

-cat >test-patch <<\EOF
-diff --git a/file b/file

+ cat >test-patch <<-\EOF &&
+ diff --git a/file b/file

This script is written in old style,where there are something like

        echo x >file &&
        echo y >>file &&
        echo z >>file
  Change it to this stlye :
        {
        echo x &&
        echo y &&
        echo z
        } >file

In order to escape for executable lines inside the test_expect_success. Change ' in executable lines to '\'' in order to escape.

---
 t/t4113-apply-ending.sh | 61 ++++++++++++++++++++---------------------
 1 file changed, 30 insertions(+), 31 deletions(-)
t/t4113-apply-ending.sh +30 -31
index a470c9ce7b..c70429bd07 100755
@@ -8,46 +8,45 @@ test_description='git apply trying to add an ending line.
 '
 . ./test-lib.sh
 
-# setup
-
-cat >test-patch <<\EOF
-diff --git a/file b/file
---- a/file
-+++ b/file
-@@ -1,2 +1,3 @@
- a
- b
-+c
-EOF
-
-echo 'a' >file
-echo 'b' >>file
-echo 'c' >>file
-
 test_expect_success setup '
+	cat >test-patch <<-\EOF &&
+	diff --git a/file b/file
+	--- a/file
+	+++ b/file
+	@@ -1,2 +1,3 @@
+	 a
+	 b
+	+c
+	EOF
+
+	{
+	echo '\''a'\'' &&
+	echo '\''b'\'' &&
+	echo '\''c'\''
+	} >file &&
 	git update-index --add file
 '
-# test
 
 test_expect_success 'apply at the end' '
 	test_must_fail git apply --index test-patch
 '
-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_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
 '
+
 test_done
Signature · 1 line
2.39.0
#42 lore raw

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

Quoted 4 lines · Shuqi Liang

As t/README says, put all code inside test_expect_success and other assertions. This script is written in old style,where there are some executable lines outside test_expect_success. Put the executable lines inside the test_expect_success.

Although it's true that t/README explains why code should be placed inside tests, you can help readers out by simply explaining the reason here in the commit message. For instance, you might replace the above paragraph with:

Some old test scripts have setup code outside of tests. This is problematic since any failures of the setup code will go unnoticed. Therefore, move setup code into the tests themselves so that failures are properly flagged.

As for the rest of the commit message...

t/t4113-apply-ending.sh test_description='git apply trying to add an ending line. · line 37

Quoted 11 lines

As t/README says,use "<<-" instead of "<<"
to strip leading TABs used for indentation. Change the "<<" to "<<-"

for example:

t/t4113-apply-ending.sh +3 -2
-cat >test-patch <<\EOF
-diff a/file b/file
 
 test_expect_success 'apply at the beginning' '
+       cat >test-patch <<-\EOF
+       diff a/file b/file
+       --- a/file

Certain changes are considered obvious by reviewers, so you don't need to mention them explicitly in the commit message. This is one such change. Any reviewer who sees that you indented the here-doc body to match the indentation of the rest of the test body will understand why you changed << to <<- without the commit message having to explain it.

t/t4113-apply-ending.sh test_description='git apply trying to add an ending line.

Quoted 10 lines

As t/README says,chain test assertions.Chain this test assertions with &&.

For example:

t/t4113-apply-ending.sh +2 -2
-cat >test-patch <<\EOF
-diff --git a/file b/file
 
+ cat >test-patch <<-\EOF &&
+ diff --git a/file b/file

Same thing. Reviewers understand that all code inside a test body must have an intact &&-chain, so you needn't mention this in the commit message.

Quoted 6 lines

This script is written in old style,where there are something like

        echo x >file &&
        echo y >>file &&
        echo z >>file
Quoted 6 lines
  Change it to this stlye :
        {
        echo x &&
        echo y &&
        echo z
        } >file

This is similar. This is such a simple style change, and the code fragment itself is so tiny, that a reviewer can understand this change without the commit message spelling it out.

Quoted 2 lines

In order to escape for executable lines inside the test_expect_success. Change ' in executable lines to '\'' in order to escape.

Likewise.

Reviewers appreciate well-explained commit messages, but they also appreciate succinctness. Although it may not always be obvious how much to write in a commit message, you can assume that reviewers will understand obvious changes simply by reading the patch itself, thus you don't need to mention every little detail in the commit message. The important thing to mention in the commit message is the explanation of _why_ the change is being made, plus any changes which might not be obvious. In this case, all the changes are obvious, so, really, you can collapse this entire commit message to just the first paragraph.

t/t4113-apply-ending.sh test_description='git apply trying to add an ending line. · line 9

Quoted 6 lines

---

t/t4113-apply-ending.sh +0 -2
@@ -8,46 +8,45 @@ test_description='git apply trying to add an ending line.
-# setup
-

Good to see that you got rid of the now-unnecessary comment.

Quoted 14 lines
t/t4113-apply-ending.sh +0 -14
-cat >test-patch <<\EOF
-diff --git a/file b/file
---- a/file
-+++ b/file
-@@ -1,2 +1,3 @@
- a
- b
-+c
-EOF
-
-echo 'a' >file
-echo 'b' >>file
-echo 'c' >>file
-

t/t4113-apply-ending.sh test_description='git apply trying to add an ending line. · line 20

Quoted 10 lines
t/t4113-apply-ending.sh +9 -0
 test_expect_success setup '
+       cat >test-patch <<-\EOF &&
+       diff --git a/file b/file
+       --- a/file
+       +++ b/file
+       @@ -1,2 +1,3 @@
+        a
+        b
+       +c
+       EOF

Okay.

t/t4113-apply-ending.sh test_description='git apply trying to add an ending line. · line 26

Quoted 5 lines
t/t4113-apply-ending.sh +5 -0
+       {
+       echo '\''a'\'' &&
+       echo '\''b'\'' &&
+       echo '\''c'\''
+       } >file &&

A few comments:

This is unnecessarily confusing. Although this does work, it would be sufficient just to change the single-quotes to double-quotes, like this:

    {
    echo "a" &&
    echo "b" &&
    echo "c"
    } >file &&

Even simpler, you could drop the quotes altogether for such a simple case:

    {
    echo a &&
    echo b &&
    echo c
    } >file &&

However, as mentioned elsewhere in this thread, a really succinct way to do this, taking advantage of modern style would be to use test_write_lines(), so the five lines collapse to a single line:

    test_write_lines a b c >file &&
Quoted 19 lines
t/t4113-apply-ending.sh +3 -14
-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_expect_success 'apply at the beginning' '
+       cat >test-patch <<-\EOF &&
+       diff a/file b/file
+       --- a/file

t/t4113-apply-ending.sh test_description='git apply trying to add an ending line. · line 47

Quoted 10 lines
t/t4113-apply-ending.sh +10 -0
+       +++ b/file
+       @@ -1,2 +1,3 @@
+       +a
+        b
+        c
+       EOF
+
+       echo >file '\''a
+       b
+       c'\'' &&

Same comment about simply using double-quotes instead of single-quotes, however, this is also another really good place to use test_write_lines:

    test_write_lines a b c >file &&
#43 lore raw

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

Quoted 10 lines · Eric Sunshine

Although it's true that t/README explains why code should be placed inside tests, you can help readers out by simply explaining the reason here in the commit message. For instance, you might replace the above paragraph with:

Some old test scripts have setup code outside of tests. This is problematic since any failures of the setup code will go unnoticed. Therefore, move setup code into the tests themselves so that failures are properly flagged.

Thanks, that really makes the change more clear for the readers. I learn a lot.

Quoted 10 lines

Reviewers appreciate well-explained commit messages, but they also appreciate succinctness. Although it may not always be obvious how much to write in a commit message, you can assume that reviewers will understand obvious changes simply by reading the patch itself, thus you don't need to mention every little detail in the commit message. The important thing to mention in the commit message is the explanation of _why_ the change is being made, plus any changes which might not be obvious. In this case, all the changes are obvious, so, really, you can collapse this entire commit message to just the first paragraph.

Yeah, the commit looks very wordy. I'll make it more succinct.

Quoted 7 lines
    test_write_lines a b c >file &&

Same comment about simply using double quotes instead of single-quotes, however, this is also another really good place to use test_write_lines:

    test_write_lines a b c >file &&

Thanks for the tips!

(Sorry for sending the V6 to you twice I send it by accident .)

-------------------------
Thanks
Shuqi

#44 lore raw

v6 cover t4113: modernize style

In reply to Shuqi Liang

different with 5 :

1.change the commit message to be more succinct.

2.
use

test_write_lines a b c >file &&

instead of :

{
    echo a &&
    echo b &&
    echo c
} >file &&

Shuqi Liang (3):
t4113: modernize test script
t4113: indent with tab
t4113: put executable lines to test_expect_success

 t/t4113-apply-ending.sh | 75 +++++++++++++++++++----------------------
 1 file changed, 34 insertions(+), 41 deletions(-)

Range-diff against v5:
1: 4d55e522a6 ! 1: cb29da5d42 t4113: modernize test script
@@ Commit message
where the test_expect_success command and test title are written on separate lines. Change the old style to modern style.

- for example :
- -test_expect_success setup \
- - 'git update-index --add file'
- -
- +test_expect_success setup '
- + git update-index --add file
- +'
-

## t/t4113-apply-ending.sh ##

2:  cb997bc422 = 2:  09efa23ba4 t4113: indent with tab
3:  726d2fcb47 ! 3:  0169cbd402 t4113: put executable lines to test_expect_success

@@ Commit message
t4113: put executable lines to test_expect_success

As t/README says, put all code inside test_expect_success and
- other assertions. This script is written in old style,where there are
- some executable lines outside test_expect_success. Put the executable
- lines inside the test_expect_success.
-
- As t/README says,use "<<-" instead of "<<"
- to strip leading TABs used for indentation. Change the "<<" to "<<-"
-
- for example:
- -cat >test-patch <<\EOF
- -diff a/file b/file
-
- test_expect_success 'apply at the beginning' '
- + cat >test-patch <<-\EOF
- + diff a/file b/file
- + --- a/file
-
- As t/README says,chain test assertions.Chain this test assertions
- with &&.
-
- For example:
-
- -cat >test-patch <<\EOF
- -diff --git a/file b/file
-
- + cat >test-patch <<-\EOF &&
- + diff --git a/file b/file
-
- This script is written in old style,where there are something like
-
- echo x >file &&
- echo y >>file &&
- echo z >>file
-
- Change it to this stlye :
- {
- echo x &&
- echo y &&
- echo z
- } >file
-
- In order to escape for executable lines inside the test_expect_success.
- Change ' in executable lines to '\'' in order to escape.
+ other assertions. This old test scripts have setup code
+ outside of tests. This is problematic since any failures of the
+ setup code will go unnoticed. Therefore, move setup code into the tests
+ themselves so that failures are properly flagged. t/README also says,
+ use "<<-" instead of "<<" to strip leading TABs used for indentation.
+ Fix it. We should chain test assertions(t/README). Therefore,Chain
+ this test assertions with &&. What's more,take advantage of modern
+ style. Use test_write_lines instead.

@@ -1,2 +1,3 @@
+ +c
+ EOF
+
-+ {
-+ echo '\''a'\'' &&
-+ echo '\''b'\'' &&
-+ echo '\''c'\''
-+ } >file &&
++ test_write_lines a b c >file &&
git update-index --add file
'
-# test
@@ -1,2 +1,3 @@
+ c
+ EOF
+
-+ echo >file '\''a
-+ b
-+ c'\'' &&
++ test_write_lines a b c >file &&
+ git update-index file &&
test_must_fail git apply --index test-patch
'

Signature · 1 line
2.39.0
#45 lore raw

v6 cover t4113: modernize style

In reply to Shuqi Liang

different with 5 :

1.change the commit message to be more succinct.

2.
use

test_write_lines a b c >file &&

instead of :

{
    echo a &&
    echo b &&
    echo c
} >file &&

Shuqi Liang (3):
t4113: modernize test script
t4113: indent with tab
t4113: put executable lines to test_expect_success

 t/t4113-apply-ending.sh | 75 +++++++++++++++++++----------------------
 1 file changed, 34 insertions(+), 41 deletions(-)

Range-diff against v5:
1: 4d55e522a6 ! 1: cb29da5d42 t4113: modernize test script
@@ Commit message
where the test_expect_success command and test title are written on separate lines. Change the old style to modern style.

- for example :
- -test_expect_success setup \
- - 'git update-index --add file'
- -
- +test_expect_success setup '
- + git update-index --add file
- +'
-

## t/t4113-apply-ending.sh ##

2:  cb997bc422 = 2:  09efa23ba4 t4113: indent with tab
3:  726d2fcb47 ! 3:  0169cbd402 t4113: put executable lines to test_expect_success

@@ Commit message
t4113: put executable lines to test_expect_success

As t/README says, put all code inside test_expect_success and
- other assertions. This script is written in old style,where there are
- some executable lines outside test_expect_success. Put the executable
- lines inside the test_expect_success.
-
- As t/README says,use "<<-" instead of "<<"
- to strip leading TABs used for indentation. Change the "<<" to "<<-"
-
- for example:
- -cat >test-patch <<\EOF
- -diff a/file b/file
-
- test_expect_success 'apply at the beginning' '
- + cat >test-patch <<-\EOF
- + diff a/file b/file
- + --- a/file
-
- As t/README says,chain test assertions.Chain this test assertions
- with &&.
-
- For example:
-
- -cat >test-patch <<\EOF
- -diff --git a/file b/file
-
- + cat >test-patch <<-\EOF &&
- + diff --git a/file b/file
-
- This script is written in old style,where there are something like
-
- echo x >file &&
- echo y >>file &&
- echo z >>file
-
- Change it to this stlye :
- {
- echo x &&
- echo y &&
- echo z
- } >file
-
- In order to escape for executable lines inside the test_expect_success.
- Change ' in executable lines to '\'' in order to escape.
+ other assertions. This old test scripts have setup code
+ outside of tests. This is problematic since any failures of the
+ setup code will go unnoticed. Therefore, move setup code into the tests
+ themselves so that failures are properly flagged. t/README also says,
+ use "<<-" instead of "<<" to strip leading TABs used for indentation.
+ Fix it. We should chain test assertions(t/README). Therefore,Chain
+ this test assertions with &&. What's more,take advantage of modern
+ style. Use test_write_lines instead.

@@ -1,2 +1,3 @@
+ +c
+ EOF
+
-+ {
-+ echo '\''a'\'' &&
-+ echo '\''b'\'' &&
-+ echo '\''c'\''
-+ } >file &&
++ test_write_lines a b c >file &&
git update-index --add file
'
-# test
@@ -1,2 +1,3 @@
+ c
+ EOF
+
-+ echo >file '\''a
-+ b
-+ c'\'' &&
++ test_write_lines a b c >file &&
+ git update-index file &&
test_must_fail git apply --index test-patch
'

Signature · 1 line
2.39.0
#46 lore raw

PATCH v6 1/3 t4113: modernize test script

Test scripts in file in this script are written in old style, where the test_expect_success command and test title are written on separate lines. Change the old style to modern style.

---
 t/t4113-apply-ending.sh | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
t/t4113-apply-ending.sh +9 -9
index 66fa51591e..41526ca805 100755
@@ -24,14 +24,14 @@ echo 'a' >file
 echo 'b' >>file
 echo 'c' >>file
 
-test_expect_success setup \
-    'git update-index --add file'
-
+test_expect_success setup '
+    git update-index --add file
+'
 # test
 
-test_expect_success 'apply at the end' \
-    'test_must_fail git apply --index test-patch'
-
+test_expect_success 'apply at the end' '
+    test_must_fail git apply --index test-patch
+'
 cat >test-patch <<\EOF
 diff a/file b/file
 --- a/file
@@ -47,7 +47,7 @@ b
 c'
 git update-index file
 
-test_expect_success 'apply at the beginning' \
-	'test_must_fail git apply --index test-patch'
-
+test_expect_success 'apply at the beginning' '
+	test_must_fail git apply --index test-patch
+'
 test_done
Signature · 1 line
2.39.0
#47 lore raw

PATCH v6 2/3 t4113: indent with tab

In reply to Shuqi Liang

As Documentation/CodingGuidelines says, the shell scripts are to use tabs for indentation, but this script
uses 4-column indent with space. Fix it in use tabs for indentation.

---
 t/t4113-apply-ending.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
t/t4113-apply-ending.sh +2 -2
index 41526ca805..a470c9ce7b 100755
@@ -25,12 +25,12 @@ echo 'b' >>file
 echo 'c' >>file
 
 test_expect_success setup '
-    git update-index --add file
+	git update-index --add file
 '
 # test
 
 test_expect_success 'apply at the end' '
-    test_must_fail git apply --index test-patch
+	test_must_fail git apply --index test-patch
 '
 cat >test-patch <<\EOF
 diff a/file b/file
Signature · 1 line
2.39.0
#48 lore raw

PATCH v6 3/3 t4113: put executable lines to test_expect_success

In reply to Shuqi Liang

As t/README says, put all code inside test_expect_success and other assertions. This old test scripts have setup code outside of tests. This is problematic since any failures of the setup code will go unnoticed. Therefore, move setup code into the tests themselves so that failures are properly flagged. t/README also says, use "<<-" instead of "<<" to strip leading TABs used for indentation. Fix it. We should chain test assertions(t/README). Therefore,Chain this test assertions with &&. What's more,take advantage of modern style. Use test_write_lines instead.

---
 t/t4113-apply-ending.sh | 55 ++++++++++++++++++-----------------------
 1 file changed, 24 insertions(+), 31 deletions(-)
t/t4113-apply-ending.sh +24 -31
index a470c9ce7b..56fc2f436b 100755
@@ -8,46 +8,39 @@ test_description='git apply trying to add an ending line.
 '
 . ./test-lib.sh
 
-# setup
-
-cat >test-patch <<\EOF
-diff --git a/file b/file
---- a/file
-+++ b/file
-@@ -1,2 +1,3 @@
- a
- b
-+c
-EOF
-
-echo 'a' >file
-echo 'b' >>file
-echo 'c' >>file
-
 test_expect_success setup '
+	cat >test-patch <<-\EOF &&
+	diff --git a/file b/file
+	--- a/file
+	+++ b/file
+	@@ -1,2 +1,3 @@
+	 a
+	 b
+	+c
+	EOF
+
+	test_write_lines a b c >file &&
 	git update-index --add file
 '
-# test
 
 test_expect_success 'apply at the end' '
 	test_must_fail git apply --index test-patch
 '
-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_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
+
+	test_write_lines a b c >file &&
+	git update-index file &&
 	test_must_fail git apply --index test-patch
 '
+
 test_done
Signature · 1 line
2.39.0