From: Alexander Strasser <hidden> Date: 2016-06-15 22:54:14
Hi,
during my recent bug hunting expedition I had the honor to modify
t/t4012-diff-binary.sh . After submitting my previous patch set it
quickly became clear that this file does not adhere to currently
practiced style of Git tests.
It took me some time to get back to this but here finally comes a
patch set to modernize t4012. While this patch set did not confront
me with great conceptual problems it still is a bit problematic and
depends to some point on personal preferences. That is part of the
reason why I tried to make as small and focused commits as possible.
(Other part is I find it easier to review/manage my changes for myself
with a finer commit granularity). The patches can still be squashed
together after review if this is preferred.
Also thanks again to Zbigniew who pointed out most of the addressed
issues.
Alexander Strasser (6):
t4012: Use different style for quoting
t4012: Unquote git command fragment in test title
t4012: Actually quote the sed script
t4012: Break up pipe into serial redirections
t4012: Re-indent test snippets
t4012: Make --shortstat more robust
t/t4012-diff-binary.sh | 92 +++++++++++++++++++++++++++-----------------------
1 file changed, 49 insertions(+), 43 deletions(-)
--
1.7.10.2.552.gaa3bb87
From: Johannes Sixt <hidden> Date: 2016-06-15 22:54:14
From: Johannes Sixt <redacted>
For some reason, 'echo X | dd bs=1k seek=1' creates a file with 2050 bytes
on Windows instead of the expected 1026 bytes, so that a test fails. Since
the actual contents of the file are irrelevant as long as there is at
least one zero byte so that the diff machinery recognizes it as binary,
use printf to generate it.
Signed-off-by: Johannes Sixt <redacted>
---
While the focus is on t4012, maybe you can add this patch to the series.
t/t4012-diff-binary.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
From: Alexander Strasser <hidden> Date: 2016-06-15 22:54:15
Hi,
Johannes Sixt wrote:
From: Johannes Sixt <redacted>
For some reason, 'echo X | dd bs=1k seek=1' creates a file with 2050 bytes
on Windows instead of the expected 1026 bytes, so that a test fails. Since
the actual contents of the file are irrelevant as long as there is at
least one zero byte so that the diff machinery recognizes it as binary,
use printf to generate it.
Signed-off-by: Johannes Sixt <redacted>
---
While the focus is on t4012, maybe you can add this patch to the series.
Your patch looks good to me and works here. If I hear no
objections I will include it as number 7 when resending this
series.
Alexander
From: Alexander Strasser <hidden> Date: 2016-06-15 22:54:16
Hi,
here goes the reroll. I corrected the spelling errors pointed out
by Zbigniew and appended another patch for replacing the if-else
"Did the command fail?" constructs with test_must_fail.
I based this series on the as/t4012-style-updates branch pushed by
Junio. So his fixes are included too.
Alexander Strasser (7):
t4012: modernize style for quoting
t4012: Unquote git command fragment in test title
t4012: Actually quote the sed script
t4012: Break up pipe into serial redirections
t4012: Make --shortstat test more robust
t4012: Re-indent test snippets
t4012: Use test_must_fail instead of if-else
Johannes Sixt (1):
t4012: use 'printf' instead of 'dd' to generate a binary file
t/t4012-diff-binary.sh | 94 +++++++++++++++++++++++---------------------------
1 file changed, 44 insertions(+), 50 deletions(-)
--
1.7.10.2.552.gaa3bb87
From: Alexander Strasser <hidden> Date: 2016-06-15 22:54:16
This quoting style is used by all newly added test code.
Signed-off-by: Alexander Strasser <redacted>
Signed-off-by: Junio C Hamano <redacted>
---
t/t4012-diff-binary.sh | 35 ++++++++++++++++++++---------------
1 file changed, 20 insertions(+), 15 deletions(-)
@@ -62,8 +63,8 @@ test_expect_success 'apply --numstat understands diff --binary format' '# apply needs to be able to skip the binary material correctly# in order to report the line number of a corrupt patch.-test_expect_success'apply detecting corrupt patch correctly'\-'git diff | sed -e 's/-CIT/xCIT/'>broken&&+test_expect_success'apply detecting corrupt patch correctly''+gitdiff|sed-e's/-CIT/xCIT/'>broken&&ifgitapply--stat--summarybroken2>detectedthenechounhappy-shouldhavedetectedanerror
From: Alexander Strasser <hidden> Date: 2016-06-15 22:54:16
The nested quoting is not needed in this cases, thus the previous
version did work just fine. Nevertheless the usage is misleading,
so just achieve nested quoting by using double quotes instead. Lower
the probability of breakage in the future and make the code easier
to read.
NOTE: Just dropping the single quotes around the sed arguments would
have also been possible.
Signed-off-by: Alexander Strasser <redacted>
Signed-off-by: Junio C Hamano <redacted>
---
t/t4012-diff-binary.sh | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
@@ -64,7 +64,7 @@ test_expect_success 'apply --numstat understands diff --binary format' '# apply needs to be able to skip the binary material correctly# in order to report the line number of a corrupt patch. test_expect_success'apply detecting corrupt patch correctly''-gitdiff|sed-e's/-CIT/xCIT/'>broken&&+gitdiff|sed-e"s/-CIT/xCIT/">broken&&ifgitapply--stat--summarybroken2>detectedthenechounhappy-shouldhavedetectedanerror
From: Alexander Strasser <hidden> Date: 2016-06-15 22:54:16
Do not hide possible git errors by masking its process
exit status.
Signed-off-by: Alexander Strasser <redacted>
Signed-off-by: Junio C Hamano <redacted>
---
t/t4012-diff-binary.sh | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
@@ -64,7 +64,8 @@ test_expect_success 'apply --numstat understands diff --binary format' '# apply needs to be able to skip the binary material correctly# in order to report the line number of a corrupt patch. test_expect_success'apply detecting corrupt patch correctly''-gitdiff|sed-e"s/-CIT/xCIT/">broken&&+gitdiff>output&&+sed-e"s/-CIT/xCIT/"<output>broken&&ifgitapply--stat--summarybroken2>detectedthenechounhappy-shouldhavedetectedanerror
From: Alexander Strasser <hidden> Date: 2016-06-15 22:54:16
The --shortstat test depends on the same scenario as the --stat
test. Use the part of the same expected result for the --stat test
to avoid duplicating it manually.
Signed-off-by: Alexander Strasser <redacted>
Signed-off-by: Junio C Hamano <redacted>
---
t/t4012-diff-binary.sh | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
From: Alexander Strasser <hidden> Date: 2016-06-15 22:54:16
Most one-level indents were 1 HT (horizontal tab) followed by 1 SP.
Remove the SP.
Signed-off-by: Alexander Strasser <redacted>
Signed-off-by: Junio C Hamano <redacted>
---
t/t4012-diff-binary.sh | 68 +++++++++++++++++++++++++-------------------------
1 file changed, 34 insertions(+), 34 deletions(-)
@@ -64,52 +64,52 @@ test_expect_success 'apply --numstat understands diff --binary format' '# apply needs to be able to skip the binary material correctly# in order to report the line number of a corrupt patch. test_expect_success'apply detecting corrupt patch correctly''-gitdiff>output&&-sed-e"s/-CIT/xCIT/"<output>broken&&-ifgitapply--stat--summarybroken2>detected-then+gitdiff>output&&+sed-e"s/-CIT/xCIT/"<output>broken&&+ifgitapply--stat--summarybroken2>detected+thenechounhappy-shouldhavedetectedanerror(exit1)-else+elseechohappy-fi&&-detected=`catdetected`&&-detected=`expr"$detected":"fatal.*at line \\([0-9]*\\)\$"`&&-detected=`sed-ne"${detected}p"broken`&&-test"$detected"=xCIT+fi&&+detected=`catdetected`&&+detected=`expr"$detected":"fatal.*at line \\([0-9]*\\)\$"`&&+detected=`sed-ne"${detected}p"broken`&&+test"$detected"=xCIT' test_expect_success'apply detecting corrupt patch correctly''-gitdiff--binary|sed-e"s/-CIT/xCIT/">broken&&-ifgitapply--stat--summarybroken2>detected-then+gitdiff--binary|sed-e"s/-CIT/xCIT/">broken&&+ifgitapply--stat--summarybroken2>detected+thenechounhappy-shouldhavedetectedanerror(exit1)-else+elseechohappy-fi&&-detected=`catdetected`&&-detected=`expr"$detected":"fatal.*at line \\([0-9]*\\)\$"`&&-detected=`sed-ne"${detected}p"broken`&&-test"$detected"=xCIT+fi&&+detected=`catdetected`&&+detected=`expr"$detected":"fatal.*at line \\([0-9]*\\)\$"`&&+detected=`sed-ne"${detected}p"broken`&&+test"$detected"=xCIT' test_expect_success'initial commit''git commit -a -m initial'# Try removal (b), modification (d), and creation (e). test_expect_success'diff-index with --binary''-echoAIT>a&&mvbe&&echoCIT>c&&cate>d&&-gitupdate-index--add--removeabcde&&-tree0=`gitwrite-tree`&&-gitdiff--cached--binary>current&&-gitapply--stat--summarycurrent+echoAIT>a&&mvbe&&echoCIT>c&&cate>d&&+gitupdate-index--add--removeabcde&&+tree0=`gitwrite-tree`&&+gitdiff--cached--binary>current&&+gitapply--stat--summarycurrent' test_expect_success'apply binary patch''-gitreset--hard&&-gitapply--binary--index<current&&-tree1=`gitwrite-tree`&&-test"$tree1"="$tree0"+gitreset--hard&&+gitapply--binary--index<current&&+tree1=`gitwrite-tree`&&+test"$tree1"="$tree0"' test_expect_success'diff --no-index with binary creation''
From: Alexander Strasser <hidden> Date: 2016-06-15 22:54:16
From: Johannes Sixt <redacted>
For some reason, 'echo X | dd bs=1k seek=1' creates a file with 2050 bytes
on Windows instead of the expected 1026 bytes, so that a test fails. Since
the actual contents of the file are irrelevant as long as there is at
least one zero byte so that the diff machinery recognizes it as binary,
use printf to generate it.
Signed-off-by: Johannes Sixt <redacted>
Signed-off-by: Junio C Hamano <redacted>
Signed-off-by: Alexander Strasser <redacted>
---
t/t4012-diff-binary.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
From: Alexander Strasser <hidden> Date: 2016-06-15 22:54:16
Make the code less bulky and easier to read. Also do not overlook
failures like e.g. git failing because of unexpected signals.
Signed-off-by: Alexander Strasser <redacted>
---
t/t4012-diff-binary.sh | 16 ++--------------
1 file changed, 2 insertions(+), 14 deletions(-)
From: Alexander Strasser <hidden> Date: 2016-06-15 22:54:16
The command fragments are quoted nowhere else in title texts of
this file, thus make this one consistent with all other titles.
Signed-off-by: Alexander Strasser <redacted>
Signed-off-by: Junio C Hamano <redacted>
---
t/t4012-diff-binary.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)