From 1358bb496fb182d8047a039f09c3859364cea2b4 Mon Sep 17 00:00:00 2001 From: Alexander Strasser Date: Thu, 12 Jul 2012 00:12:03 +0200 Subject: t4012: modernize style for quoting This quoting style is used by all newly added test code. Signed-off-by: Alexander Strasser Signed-off-by: Junio C Hamano --- t/t4012-diff-binary.sh | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/t/t4012-diff-binary.sh b/t/t4012-diff-binary.sh index 6cebb3951b..2a8b68ef48 100755 --- a/t/t4012-diff-binary.sh +++ b/t/t4012-diff-binary.sh @@ -15,13 +15,14 @@ cat >expect.binary-numstat <<\EOF - - d EOF -test_expect_success 'prepare repository' \ - 'echo AIT >a && echo BIT >b && echo CIT >c && echo DIT >d && +test_expect_success 'prepare repository' ' + echo AIT >a && echo BIT >b && echo CIT >c && echo DIT >d && git update-index --add a b c d && echo git >a && cat "$TEST_DIRECTORY"/test-binary-1.png >b && echo git >c && - cat b b >d' + cat b b >d +' cat > expected <<\EOF a | 2 +- @@ -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' ' + git diff | sed -e 's/-CIT/xCIT/' >broken && if git apply --stat --summary broken 2>detected then echo unhappy - should have detected an error @@ -74,10 +75,11 @@ test_expect_success 'apply detecting corrupt patch correctly' \ detected=`cat detected` && detected=`expr "$detected" : "fatal.*at line \\([0-9]*\\)\$"` && detected=`sed -ne "${detected}p" broken` && - test "$detected" = xCIT' + test "$detected" = xCIT +' -test_expect_success 'apply detecting corrupt patch correctly' \ - 'git diff --binary | sed -e 's/-CIT/xCIT/' >broken && +test_expect_success 'apply detecting corrupt patch correctly' ' + git diff --binary | sed -e 's/-CIT/xCIT/' >broken && if git apply --stat --summary broken 2>detected then echo unhappy - should have detected an error @@ -88,23 +90,26 @@ test_expect_success 'apply detecting corrupt patch correctly' \ detected=`cat detected` && detected=`expr "$detected" : "fatal.*at line \\([0-9]*\\)\$"` && detected=`sed -ne "${detected}p" broken` && - test "$detected" = xCIT' + 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' \ - 'echo AIT >a && mv b e && echo CIT >c && cat e >d && +test_expect_success 'diff-index with --binary' ' + echo AIT >a && mv b e && echo CIT >c && cat e >d && git update-index --add --remove a b c d e && tree0=`git write-tree` && git diff --cached --binary >current && - git apply --stat --summary current' + git apply --stat --summary current +' -test_expect_success 'apply binary patch' \ - 'git reset --hard && +test_expect_success 'apply binary patch' ' + git reset --hard && git apply --binary --index binary && -- cgit v1.2.3 From bb84e67c82af3a6678f193159f56d2244c5529dc Mon Sep 17 00:00:00 2001 From: Alexander Strasser Date: Thu, 12 Jul 2012 00:12:21 +0200 Subject: t4012: Unquote git command fragment in test title 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 Signed-off-by: Junio C Hamano --- t/t4012-diff-binary.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/t4012-diff-binary.sh b/t/t4012-diff-binary.sh index 2a8b68ef48..3c542690cd 100755 --- a/t/t4012-diff-binary.sh +++ b/t/t4012-diff-binary.sh @@ -31,7 +31,7 @@ cat > expected <<\EOF d | Bin 4 files changed, 2 insertions(+), 2 deletions(-) EOF -test_expect_success '"apply --stat" output for binary file change' ' +test_expect_success 'apply --stat output for binary file change' ' git diff >diff && git apply --stat --summary current && test_i18ncmp expected current -- cgit v1.2.3 From 4a2b716e220f0f5369c386d7257b87399d424a3f Mon Sep 17 00:00:00 2001 From: Alexander Strasser Date: Mon, 16 Jul 2012 22:43:58 +0200 Subject: t4012: Actually quote the sed script 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 Signed-off-by: Junio C Hamano --- t/t4012-diff-binary.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/t/t4012-diff-binary.sh b/t/t4012-diff-binary.sh index 3c542690cd..60c2f6c36f 100755 --- a/t/t4012-diff-binary.sh +++ b/t/t4012-diff-binary.sh @@ -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' ' - git diff | sed -e 's/-CIT/xCIT/' >broken && + git diff | sed -e "s/-CIT/xCIT/" >broken && if git apply --stat --summary broken 2>detected then echo unhappy - should have detected an error @@ -79,7 +79,7 @@ test_expect_success 'apply detecting corrupt patch correctly' ' ' test_expect_success 'apply detecting corrupt patch correctly' ' - git diff --binary | sed -e 's/-CIT/xCIT/' >broken && + git diff --binary | sed -e "s/-CIT/xCIT/" >broken && if git apply --stat --summary broken 2>detected then echo unhappy - should have detected an error -- cgit v1.2.3 From 4220afd7238c94f33bde55cf3fd6c84275eebe9a Mon Sep 17 00:00:00 2001 From: Alexander Strasser Date: Mon, 16 Jul 2012 22:44:30 +0200 Subject: t4012: Break up pipe into serial redirections Do not hide possible git errors by masking its process exit status. Signed-off-by: Alexander Strasser Signed-off-by: Junio C Hamano --- t/t4012-diff-binary.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/t/t4012-diff-binary.sh b/t/t4012-diff-binary.sh index 60c2f6c36f..daf8234614 100755 --- a/t/t4012-diff-binary.sh +++ b/t/t4012-diff-binary.sh @@ -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' ' - git diff | sed -e "s/-CIT/xCIT/" >broken && + git diff >output && + sed -e "s/-CIT/xCIT/" broken && if git apply --stat --summary broken 2>detected then echo unhappy - should have detected an error -- cgit v1.2.3 From 216f25f65fe20a93d4c8264b335718a8888d007e Mon Sep 17 00:00:00 2001 From: Alexander Strasser Date: Mon, 16 Jul 2012 22:45:10 +0200 Subject: t4012: Make --shortstat test more robust 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 Signed-off-by: Junio C Hamano --- t/t4012-diff-binary.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/t/t4012-diff-binary.sh b/t/t4012-diff-binary.sh index daf8234614..4767761187 100755 --- a/t/t4012-diff-binary.sh +++ b/t/t4012-diff-binary.sh @@ -38,9 +38,9 @@ test_expect_success 'apply --stat output for binary file change' ' ' test_expect_success 'diff --shortstat output for binary file change' ' - echo " 4 files changed, 2 insertions(+), 2 deletions(-)" >expected && + tail -n 1 expected >expect && git diff --shortstat >current && - test_i18ncmp expected current + test_i18ncmp expect current ' test_expect_success 'diff --shortstat output for binary file change only' ' -- cgit v1.2.3 From 3e9cdf7fca90acd6efd380a2ed0d6801f33a46b7 Mon Sep 17 00:00:00 2001 From: Alexander Strasser Date: Mon, 16 Jul 2012 22:45:40 +0200 Subject: t4012: Re-indent test snippets Most one-level indents were 1 HT (horizontal tab) followed by 1 SP. Remove the SP. Signed-off-by: Alexander Strasser Signed-off-by: Junio C Hamano --- t/t4012-diff-binary.sh | 68 +++++++++++++++++++++++++------------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/t/t4012-diff-binary.sh b/t/t4012-diff-binary.sh index 4767761187..7b0e759c74 100755 --- a/t/t4012-diff-binary.sh +++ b/t/t4012-diff-binary.sh @@ -16,12 +16,12 @@ cat >expect.binary-numstat <<\EOF EOF test_expect_success 'prepare repository' ' - echo AIT >a && echo BIT >b && echo CIT >c && echo DIT >d && - git update-index --add a b c d && - echo git >a && - cat "$TEST_DIRECTORY"/test-binary-1.png >b && - echo git >c && - cat b b >d + echo AIT >a && echo BIT >b && echo CIT >c && echo DIT >d && + git update-index --add a b c d && + echo git >a && + cat "$TEST_DIRECTORY"/test-binary-1.png >b && + echo git >c && + cat b b >d ' cat > expected <<\EOF @@ -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' ' - git diff >output && - sed -e "s/-CIT/xCIT/" broken && - if git apply --stat --summary broken 2>detected - then + git diff >output && + sed -e "s/-CIT/xCIT/" broken && + if git apply --stat --summary broken 2>detected + then echo unhappy - should have detected an error (exit 1) - else + else echo happy - fi && - detected=`cat detected` && - detected=`expr "$detected" : "fatal.*at line \\([0-9]*\\)\$"` && - detected=`sed -ne "${detected}p" broken` && - test "$detected" = xCIT + fi && + detected=`cat detected` && + 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' ' - git diff --binary | sed -e "s/-CIT/xCIT/" >broken && - if git apply --stat --summary broken 2>detected - then + git diff --binary | sed -e "s/-CIT/xCIT/" >broken && + if git apply --stat --summary broken 2>detected + then echo unhappy - should have detected an error (exit 1) - else + else echo happy - fi && - detected=`cat detected` && - detected=`expr "$detected" : "fatal.*at line \\([0-9]*\\)\$"` && - detected=`sed -ne "${detected}p" broken` && - test "$detected" = xCIT + fi && + detected=`cat detected` && + 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' ' - echo AIT >a && mv b e && echo CIT >c && cat e >d && - git update-index --add --remove a b c d e && - tree0=`git write-tree` && - git diff --cached --binary >current && - git apply --stat --summary current + echo AIT >a && mv b e && echo CIT >c && cat e >d && + git update-index --add --remove a b c d e && + tree0=`git write-tree` && + git diff --cached --binary >current && + git apply --stat --summary current ' test_expect_success 'apply binary patch' ' - git reset --hard && - git apply --binary --index Date: Mon, 16 Jul 2012 22:46:56 +0200 Subject: t4012: use 'printf' instead of 'dd' to generate a binary file 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 Signed-off-by: Junio C Hamano Signed-off-by: Alexander Strasser Signed-off-by: Junio C Hamano --- t/t4012-diff-binary.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/t4012-diff-binary.sh b/t/t4012-diff-binary.sh index 7b0e759c74..077870e95d 100755 --- a/t/t4012-diff-binary.sh +++ b/t/t4012-diff-binary.sh @@ -131,7 +131,7 @@ cat >expect <binfile && git add binfile && i=0 && while test $i -lt 10000; do -- cgit v1.2.3 From c7c0a2503fef1c8746dd4ce074de51fd6b215aa5 Mon Sep 17 00:00:00 2001 From: Alexander Strasser Date: Mon, 16 Jul 2012 22:47:22 +0200 Subject: t4012: Use test_must_fail instead of if-else 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 Signed-off-by: Junio C Hamano --- t/t4012-diff-binary.sh | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/t/t4012-diff-binary.sh b/t/t4012-diff-binary.sh index 077870e95d..ec4deea192 100755 --- a/t/t4012-diff-binary.sh +++ b/t/t4012-diff-binary.sh @@ -66,13 +66,7 @@ test_expect_success 'apply --numstat understands diff --binary format' ' test_expect_success 'apply detecting corrupt patch correctly' ' git diff >output && sed -e "s/-CIT/xCIT/" broken && - if git apply --stat --summary broken 2>detected - then - echo unhappy - should have detected an error - (exit 1) - else - echo happy - fi && + test_must_fail git apply --stat --summary broken 2>detected && detected=`cat detected` && detected=`expr "$detected" : "fatal.*at line \\([0-9]*\\)\$"` && detected=`sed -ne "${detected}p" broken` && @@ -81,13 +75,7 @@ test_expect_success 'apply detecting corrupt patch correctly' ' test_expect_success 'apply detecting corrupt patch correctly' ' git diff --binary | sed -e "s/-CIT/xCIT/" >broken && - if git apply --stat --summary broken 2>detected - then - echo unhappy - should have detected an error - (exit 1) - else - echo happy - fi && + test_must_fail git apply --stat --summary broken 2>detected && detected=`cat detected` && detected=`expr "$detected" : "fatal.*at line \\([0-9]*\\)\$"` && detected=`sed -ne "${detected}p" broken` && -- cgit v1.2.3