Skip to contentSkip to conversation

don't use test_must_fail with grep

PATCH Superseded Pranit Bauva 5 participants 21 messages Dec 31, 2016 – Jan 9, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 don't use test_must_fail with grep

test_must_fail should only be used for testing git commands. To test the failure of other commands use !.

---
 t/t3510-cherry-pick-sequence.sh  |  6 +++---
 t/t5504-fetch-receive-strict.sh  |  2 +-
 t/t5516-fetch-push.sh            |  2 +-
 t/t5601-clone.sh                 |  2 +-
 t/t6030-bisect-porcelain.sh      |  2 +-
 t/t7610-mergetool.sh             |  2 +-
 t/t9001-send-email.sh            |  2 +-
 t/t9117-git-svn-init-clone.sh    | 12 ++++++------
 t/t9813-git-p4-preserve-users.sh |  8 ++++----
 t/t9814-git-p4-rename.sh         |  6 +++---
 10 files changed, 22 insertions(+), 22 deletions(-)
t/t3510-cherry-pick-sequence.sh +3 -3
index 372307c21..0acf4b146 100755
@@ -385,7 +385,7 @@ test_expect_success '--continue respects opts' '
 	git cat-file commit HEAD~1 >picked_msg &&
 	git cat-file commit HEAD~2 >unrelatedpick_msg &&
 	git cat-file commit HEAD~3 >initial_msg &&
-	test_must_fail grep "cherry picked from" initial_msg &&
+	! grep "cherry picked from" initial_msg &&
 	grep "cherry picked from" unrelatedpick_msg &&
 	grep "cherry picked from" picked_msg &&
 	grep "cherry picked from" anotherpick_msg
@@ -426,9 +426,9 @@ test_expect_failure '--signoff is automatically propagated to resolved conflict'
 	git cat-file commit HEAD~1 >picked_msg &&
 	git cat-file commit HEAD~2 >unrelatedpick_msg &&
 	git cat-file commit HEAD~3 >initial_msg &&
-	test_must_fail grep "Signed-off-by:" initial_msg &&
+	! grep "Signed-off-by:" initial_msg &&
 	grep "Signed-off-by:" unrelatedpick_msg &&
-	test_must_fail grep "Signed-off-by:" picked_msg &&
+	! grep "Signed-off-by:" picked_msg &&
 	grep "Signed-off-by:" anotherpick_msg
 '
 
t/t5504-fetch-receive-strict.sh +1 -1
index 9b19cff72..49d3621a9 100755
@@ -152,7 +152,7 @@ test_expect_success 'push with receive.fsck.missingEmail=warn' '
 	git --git-dir=dst/.git config --add \
 		receive.fsck.badDate warn &&
 	git push --porcelain dst bogus >act 2>&1 &&
-	test_must_fail grep "missingEmail" act
+	! grep "missingEmail" act
 '
 
 test_expect_success \
t/t5516-fetch-push.sh +1 -1
index 26b2cafc4..0fc5a7c59 100755
@@ -1004,7 +1004,7 @@ test_expect_success 'push --porcelain' '
 test_expect_success 'push --porcelain bad url' '
 	mk_empty testrepo &&
 	test_must_fail git push >.git/bar --porcelain asdfasdfasd refs/heads/master:refs/remotes/origin/master &&
-	test_must_fail grep -q Done .git/bar
+	! grep -q Done .git/bar
 '
 
 test_expect_success 'push --porcelain rejected' '
t/t5601-clone.sh +1 -1
index a43339420..4241ea5b3 100755
@@ -151,7 +151,7 @@ test_expect_success 'clone --mirror does not repeat tags' '
 	git clone --mirror src mirror2 &&
 	(cd mirror2 &&
 	 git show-ref 2> clone.err > clone.out) &&
-	test_must_fail grep Duplicate mirror2/clone.err &&
+	! grep Duplicate mirror2/clone.err &&
 	grep some-tag mirror2/clone.out
 
 '
t/t6030-bisect-porcelain.sh +1 -1
index 5e5370feb..8c2c6eaef 100755
@@ -407,7 +407,7 @@ test_expect_success 'good merge base when good and bad are siblings' '
 	test_i18ngrep "merge base must be tested" my_bisect_log.txt &&
 	grep $HASH4 my_bisect_log.txt &&
 	git bisect good > my_bisect_log.txt &&
-	test_must_fail grep "merge base must be tested" my_bisect_log.txt &&
+	! grep "merge base must be tested" my_bisect_log.txt &&
 	grep $HASH6 my_bisect_log.txt &&
 	git bisect reset
 '
t/t7610-mergetool.sh +1 -1
index 63d36fb28..0fe7e58cf 100755
@@ -602,7 +602,7 @@ test_expect_success MKTEMP 'temporary filenames are used with mergetool.writeToT
 	test_config mergetool.myecho.trustExitCode true &&
 	test_must_fail git merge master &&
 	git mergetool --no-prompt --tool myecho -- both >actual &&
-	test_must_fail grep ^\./both_LOCAL_ actual >/dev/null &&
+	! grep ^\./both_LOCAL_ actual >/dev/null &&
 	grep /both_LOCAL_ actual >/dev/null &&
 	git reset --hard master >/dev/null 2>&1
 '
t/t9001-send-email.sh +1 -1
index 3dc4a3454..0f398dd16 100755
@@ -50,7 +50,7 @@ test_no_confirm () {
 		--smtp-server="$(pwd)/fake.sendmail" \
 		$@ \
 		$patches >stdout &&
-		test_must_fail grep "Send this email" stdout &&
+		! grep "Send this email" stdout &&
 		>no_confirm_okay
 }
 
t/t9117-git-svn-init-clone.sh +6 -6
index 69a675052..044f65e91 100755
@@ -55,7 +55,7 @@ test_expect_success 'clone to target directory with --stdlayout' '
 test_expect_success 'init without -s/-T/-b/-t does not warn' '
 	test ! -d trunk &&
 	git svn init "$svnrepo"/project/trunk trunk 2>warning &&
-	test_must_fail grep -q prefix warning &&
+	! grep -q prefix warning &&
 	rm -rf trunk &&
 	rm -f warning
 	'
@@ -63,7 +63,7 @@ test_expect_success 'init without -s/-T/-b/-t does not warn' '
 test_expect_success 'clone without -s/-T/-b/-t does not warn' '
 	test ! -d trunk &&
 	git svn clone "$svnrepo"/project/trunk 2>warning &&
-	test_must_fail grep -q prefix warning &&
+	! grep -q prefix warning &&
 	rm -rf trunk &&
 	rm -f warning
 	'
@@ -86,7 +86,7 @@ EOF
 test_expect_success 'init with -s/-T/-b/-t assumes --prefix=origin/' '
 	test ! -d project &&
 	git svn init -s "$svnrepo"/project project 2>warning &&
-	test_must_fail grep -q prefix warning &&
+	! grep -q prefix warning &&
 	test_svn_configured_prefix "origin/" &&
 	rm -rf project &&
 	rm -f warning
@@ -95,7 +95,7 @@ test_expect_success 'init with -s/-T/-b/-t assumes --prefix=origin/' '
 test_expect_success 'clone with -s/-T/-b/-t assumes --prefix=origin/' '
 	test ! -d project &&
 	git svn clone -s "$svnrepo"/project 2>warning &&
-	test_must_fail grep -q prefix warning &&
+	! grep -q prefix warning &&
 	test_svn_configured_prefix "origin/" &&
 	rm -rf project &&
 	rm -f warning
@@ -104,7 +104,7 @@ test_expect_success 'clone with -s/-T/-b/-t assumes --prefix=origin/' '
 test_expect_success 'init with -s/-T/-b/-t and --prefix "" still works' '
 	test ! -d project &&
 	git svn init -s "$svnrepo"/project project --prefix "" 2>warning &&
-	test_must_fail grep -q prefix warning &&
+	! grep -q prefix warning &&
 	test_svn_configured_prefix "" &&
 	rm -rf project &&
 	rm -f warning
@@ -113,7 +113,7 @@ test_expect_success 'init with -s/-T/-b/-t and --prefix "" still works' '
 test_expect_success 'clone with -s/-T/-b/-t and --prefix "" still works' '
 	test ! -d project &&
 	git svn clone -s "$svnrepo"/project --prefix "" 2>warning &&
-	test_must_fail grep -q prefix warning &&
+	! grep -q prefix warning &&
 	test_svn_configured_prefix "" &&
 	rm -rf project &&
 	rm -f warning
t/t9813-git-p4-preserve-users.sh +4 -4
index 0fe231280..2384535a7 100755
@@ -126,13 +126,13 @@ test_expect_success 'not preserving user with mixed authorship' '
 		grep "git author [email protected] does not match" &&
 
 		make_change_by_user usernamefile3 alice [email protected] &&
-		git p4 commit |\
-		test_must_fail grep "git author.*does not match" &&
+		! git p4 commit |\
+		grep "git author.*does not match" &&
 
 		git config git-p4.skipUserNameCheck true &&
 		make_change_by_user usernamefile3 Charlie [email protected] &&
-		git p4 commit |\
-		test_must_fail grep "git author.*does not match" &&
+		! git p4 commit |\
+		grep "git author.*does not match" &&
 
 		p4_check_commit_author usernamefile3 alice
 	)
t/t9814-git-p4-rename.sh +3 -3
index c89992cf9..e7e0268e9 100755
@@ -141,7 +141,7 @@ test_expect_success 'detect copies' '
 		git diff-tree -r -C HEAD &&
 		git p4 submit &&
 		p4 filelog //depot/file8 &&
-		p4 filelog //depot/file8 | test_must_fail grep -q "branch from" &&
+		! p4 filelog //depot/file8 | grep -q "branch from" &&
 
 		echo "file9" >>file2 &&
 		git commit -a -m "Differentiate file2" &&
@@ -154,7 +154,7 @@ test_expect_success 'detect copies' '
 		git config git-p4.detectCopies true &&
 		git p4 submit &&
 		p4 filelog //depot/file9 &&
-		p4 filelog //depot/file9 | test_must_fail grep -q "branch from" &&
+		! p4 filelog //depot/file9 | grep -q "branch from" &&
 
 		echo "file10" >>file2 &&
 		git commit -a -m "Differentiate file2" &&
@@ -202,7 +202,7 @@ test_expect_success 'detect copies' '
 		git config git-p4.detectCopies $(($level + 2)) &&
 		git p4 submit &&
 		p4 filelog //depot/file12 &&
-		p4 filelog //depot/file12 | test_must_fail grep -q "branch from" &&
+		! p4 filelog //depot/file12 | grep -q "branch from" &&
 
 		echo "file13" >>file2 &&
 		git commit -a -m "Differentiate file2" &&
Signature · 1 line
2.11.0
#1 lore raw
Quoted 184 lines · Pranit Bauva

test_must_fail should only be used for testing git commands. To test the failure of other commands use !.

---
 t/t3510-cherry-pick-sequence.sh  |  6 +++---
 t/t5504-fetch-receive-strict.sh  |  2 +-
 t/t5516-fetch-push.sh            |  2 +-
 t/t5601-clone.sh                 |  2 +-
 t/t6030-bisect-porcelain.sh      |  2 +-
 t/t7610-mergetool.sh             |  2 +-
 t/t9001-send-email.sh            |  2 +-
 t/t9117-git-svn-init-clone.sh    | 12 ++++++------
 t/t9813-git-p4-preserve-users.sh |  8 ++++----
 t/t9814-git-p4-rename.sh         |  6 +++---
 10 files changed, 22 insertions(+), 22 deletions(-)
t/t3510-cherry-pick-sequence.sh +3 -3
index 372307c21..0acf4b146 100755
@@ -385,7 +385,7 @@ test_expect_success '--continue respects opts' '
        git cat-file commit HEAD~1 >picked_msg &&
        git cat-file commit HEAD~2 >unrelatedpick_msg &&
        git cat-file commit HEAD~3 >initial_msg &&
-       test_must_fail grep "cherry picked from" initial_msg &&
+       ! grep "cherry picked from" initial_msg &&
        grep "cherry picked from" unrelatedpick_msg &&
        grep "cherry picked from" picked_msg &&
        grep "cherry picked from" anotherpick_msg
@@ -426,9 +426,9 @@ test_expect_failure '--signoff is automatically propagated to resolved conflict'
        git cat-file commit HEAD~1 >picked_msg &&
        git cat-file commit HEAD~2 >unrelatedpick_msg &&
        git cat-file commit HEAD~3 >initial_msg &&
-       test_must_fail grep "Signed-off-by:" initial_msg &&
+       ! grep "Signed-off-by:" initial_msg &&
        grep "Signed-off-by:" unrelatedpick_msg &&
-       test_must_fail grep "Signed-off-by:" picked_msg &&
+       ! grep "Signed-off-by:" picked_msg &&
        grep "Signed-off-by:" anotherpick_msg
 '
 
t/t5504-fetch-receive-strict.sh +1 -1
index 9b19cff72..49d3621a9 100755
@@ -152,7 +152,7 @@ test_expect_success 'push with receive.fsck.missingEmail=warn' '
        git --git-dir=dst/.git config --add \
                receive.fsck.badDate warn &&
        git push --porcelain dst bogus >act 2>&1 &&
-       test_must_fail grep "missingEmail" act
+       ! grep "missingEmail" act
 '
 
 test_expect_success \
t/t5516-fetch-push.sh +1 -1
index 26b2cafc4..0fc5a7c59 100755
@@ -1004,7 +1004,7 @@ test_expect_success 'push --porcelain' '
 test_expect_success 'push --porcelain bad url' '
        mk_empty testrepo &&
        test_must_fail git push >.git/bar --porcelain asdfasdfasd refs/heads/master:refs/remotes/origin/master &&
-       test_must_fail grep -q Done .git/bar
+       ! grep -q Done .git/bar
 '
 
 test_expect_success 'push --porcelain rejected' '
t/t5601-clone.sh +1 -1
index a43339420..4241ea5b3 100755
@@ -151,7 +151,7 @@ test_expect_success 'clone --mirror does not repeat tags' '
        git clone --mirror src mirror2 &&
        (cd mirror2 &&
         git show-ref 2> clone.err > clone.out) &&
-       test_must_fail grep Duplicate mirror2/clone.err &&
+       ! grep Duplicate mirror2/clone.err &&
        grep some-tag mirror2/clone.out
 
 '
t/t6030-bisect-porcelain.sh +1 -1
index 5e5370feb..8c2c6eaef 100755
@@ -407,7 +407,7 @@ test_expect_success 'good merge base when good and bad are siblings' '
        test_i18ngrep "merge base must be tested" my_bisect_log.txt &&
        grep $HASH4 my_bisect_log.txt &&
        git bisect good > my_bisect_log.txt &&
-       test_must_fail grep "merge base must be tested" my_bisect_log.txt &&
+       ! grep "merge base must be tested" my_bisect_log.txt &&
        grep $HASH6 my_bisect_log.txt &&
        git bisect reset
 '
t/t7610-mergetool.sh +1 -1
index 63d36fb28..0fe7e58cf 100755
@@ -602,7 +602,7 @@ test_expect_success MKTEMP 'temporary filenames are used with mergetool.writeToT
        test_config mergetool.myecho.trustExitCode true &&
        test_must_fail git merge master &&
        git mergetool --no-prompt --tool myecho -- both >actual &&
-       test_must_fail grep ^\./both_LOCAL_ actual >/dev/null &&
+       ! grep ^\./both_LOCAL_ actual >/dev/null &&
        grep /both_LOCAL_ actual >/dev/null &&
        git reset --hard master >/dev/null 2>&1
 '
t/t9001-send-email.sh +1 -1
index 3dc4a3454..0f398dd16 100755
@@ -50,7 +50,7 @@ test_no_confirm () {
                --smtp-server="$(pwd)/fake.sendmail" \
                $@ \
                $patches >stdout &&
-               test_must_fail grep "Send this email" stdout &&
+               ! grep "Send this email" stdout &&
                >no_confirm_okay
 }
 
t/t9117-git-svn-init-clone.sh +6 -6
index 69a675052..044f65e91 100755
@@ -55,7 +55,7 @@ test_expect_success 'clone to target directory with --stdlayout' '
 test_expect_success 'init without -s/-T/-b/-t does not warn' '
        test ! -d trunk &&
        git svn init "$svnrepo"/project/trunk trunk 2>warning &&
-       test_must_fail grep -q prefix warning &&
+       ! grep -q prefix warning &&
        rm -rf trunk &&
        rm -f warning
        '
@@ -63,7 +63,7 @@ test_expect_success 'init without -s/-T/-b/-t does not warn' '
 test_expect_success 'clone without -s/-T/-b/-t does not warn' '
        test ! -d trunk &&
        git svn clone "$svnrepo"/project/trunk 2>warning &&
-       test_must_fail grep -q prefix warning &&
+       ! grep -q prefix warning &&
        rm -rf trunk &&
        rm -f warning
        '
@@ -86,7 +86,7 @@ EOF
 test_expect_success 'init with -s/-T/-b/-t assumes --prefix=origin/' '
        test ! -d project &&
        git svn init -s "$svnrepo"/project project 2>warning &&
-       test_must_fail grep -q prefix warning &&
+       ! grep -q prefix warning &&
        test_svn_configured_prefix "origin/" &&
        rm -rf project &&
        rm -f warning
@@ -95,7 +95,7 @@ test_expect_success 'init with -s/-T/-b/-t assumes --prefix=origin/' '
 test_expect_success 'clone with -s/-T/-b/-t assumes --prefix=origin/' '
        test ! -d project &&
        git svn clone -s "$svnrepo"/project 2>warning &&
-       test_must_fail grep -q prefix warning &&
+       ! grep -q prefix warning &&
        test_svn_configured_prefix "origin/" &&
        rm -rf project &&
        rm -f warning
@@ -104,7 +104,7 @@ test_expect_success 'clone with -s/-T/-b/-t assumes --prefix=origin/' '
 test_expect_success 'init with -s/-T/-b/-t and --prefix "" still works' '
        test ! -d project &&
        git svn init -s "$svnrepo"/project project --prefix "" 2>warning &&
-       test_must_fail grep -q prefix warning &&
+       ! grep -q prefix warning &&
        test_svn_configured_prefix "" &&
        rm -rf project &&
        rm -f warning
@@ -113,7 +113,7 @@ test_expect_success 'init with -s/-T/-b/-t and --prefix "" still works' '
 test_expect_success 'clone with -s/-T/-b/-t and --prefix "" still works' '
        test ! -d project &&
        git svn clone -s "$svnrepo"/project --prefix "" 2>warning &&
-       test_must_fail grep -q prefix warning &&
+       ! grep -q prefix warning &&
        test_svn_configured_prefix "" &&
        rm -rf project &&
        rm -f warning
t/t9813-git-p4-preserve-users.sh +0 -0
index 0fe231280..2384535a7 100755

t/t9813-git-p4-preserve-users.sh test_expect_success 'not preserving user with mixed authorship' ' · line 130

Quoted 7 lines
t/t9813-git-p4-preserve-users.sh +2 -2
@@ -126,13 +126,13 @@ test_expect_success 'not preserving user with mixed authorship' '
                grep "git author [email protected] does not match" &&
 
                make_change_by_user usernamefile3 alice [email protected] &&
-               git p4 commit |\
-               test_must_fail grep "git author.*does not match" &&
+               ! git p4 commit |\
+               grep "git author.*does not match" &&

Would it be clearer to use this?

    git p4 commit |\
    grep -q -v "git author.*does not match" &&

With your original change, I think that if "git p4 commit" fails, then that expression will be treated as a pass. What we want is for "git p4 commit" to pass, but the string to be missing.

(I would have used "--invert-match" rather than "-v", but it seems that's not supported on Solaris).

Luke

#2 lore raw

Am 01.01.2017 um 15:23 schrieb Luke Diamand:

Quoted 16 lines · Pranit Bauva

t/t9813-git-p4-preserve-users.sh test_expect_success 'not preserving user with mixed authorship' ' · line 130

Quoted 12 lines
t/t9813-git-p4-preserve-users.sh +2 -2
index 0fe231280..2384535a7 100755
@@ -126,13 +126,13 @@ test_expect_success 'not preserving user with mixed authorship' '
                grep "git author [email protected] does not match" &&
 
                make_change_by_user usernamefile3 alice [email protected] &&
-               git p4 commit |\
-               test_must_fail grep "git author.*does not match" &&
+               ! git p4 commit |\
+               grep "git author.*does not match" &&

Would it be clearer to use this?

Quoted 5 lines
    git p4 commit |\
    grep -q -v "git author.*does not match" &&

With your original change, I think that if "git p4 commit" fails, then that expression will be treated as a pass.

No. The exit code of the upstream in a pipe is ignored. For this reason, having a git invocation as the upstream of a pipe *anywhere* in the test suite is frowned upon. Hence, a better rewrite would be

	git p4 commit >actual &&
	! grep "git author.*does not match" actual &&

which makes me wonder: Is the message that we do expect not to occur actually printed on stdout? It sounds much more like an error message, i.e., text that is printed on stderr. Wouldn't we need this?

	git p4 commit >actual 2>&1 &&
	! grep "git author.*does not match" actual &&

-- Hannes

#3 lore raw
Quoted 37 lines · Johannes Sixt

Am 01.01.2017 um 15:23 schrieb Luke Diamand:

Quoted 22 lines · Pranit Bauva
Quoted 12 lines
t/t9813-git-p4-preserve-users.sh +0 -0
index 0fe231280..2384535a7 100755
@@ -126,13 +126,13 @@ test_expect_success 'not preserving user with mixed

authorship' '
grep "git author [email protected] does not match" &&

make_change_by_user usernamefile3 alice [email protected]
&&

t/t9813-git-p4-preserve-users.sh test_expect_success 'not preserving user with mixed authorship' ' · line 130

Quoted 4 lines
t/t9813-git-p4-preserve-users.sh +2 -2
-               git p4 commit |\
-               test_must_fail grep "git author.*does not match" &&
+               ! git p4 commit |\
+               grep "git author.*does not match" &&

Would it be clearer to use this?

Quoted 5 lines
    git p4 commit |\
    grep -q -v "git author.*does not match" &&

With your original change, I think that if "git p4 commit" fails, then that expression will be treated as a pass.

No. The exit code of the upstream in a pipe is ignored. For this reason, having a git invocation as the upstream of a pipe *anywhere* in the test suite is frowned upon. Hence, a better rewrite would be

        git p4 commit >actual &&
        ! grep "git author.*does not match" actual &&
Quoted 6 lines

which makes me wonder: Is the message that we do expect not to occur actually printed on stdout? It sounds much more like an error message, i.e., text that is printed on stderr. Wouldn't we need this?

        git p4 commit >actual 2>&1 &&
        ! grep "git author.*does not match" actual &&

The message is actually part of a template presented to the user via their chosen editor. For this test, we set the editor to be "cat", so it comes out on stdout.

Your first suggestion would therefore be fine (and similarly for the other cases).

#4 lore raw
In reply to Johannes Sixt

Hey Johannes,

Quoted 8 lines · Johannes Sixt

which makes me wonder: Is the message that we do expect not to occur actually printed on stdout? It sounds much more like an error message, i.e., text that is printed on stderr. Wouldn't we need this?

        git p4 commit >actual 2>&1 &&
        ! grep "git author.*does not match" actual &&

-- Hannes

This seems better! Since I am at it, I can remove the traces of pipes in an another patch.

Regards,
Pranit Bauva

#5 lore raw
Quoted 10 lines · Pranit Bauva

Hey Johannes,

Quoted 7 lines · Johannes Sixt

which makes me wonder: Is the message that we do expect not to occur actually printed on stdout? It sounds much more like an error message, i.e., text that is printed on stderr. Wouldn't we need this?

        git p4 commit >actual 2>&1 &&
        ! grep "git author.*does not match" actual &&
Quoted 7 lines
Quoted 1 line

-- Hannes

This seems better! Since I am at it, I can remove the traces of pipes in an another patch.

Regards,
Pranit Bauva

I see v3 that has 2>&1 but according to Luke's comment ("the message comes from cat"), it shouldn't be there? I am behind clearing the backlog in my mailbox and I could tweak it out from v3 while queuing, or I may forget about it after looking at other topics ;-) in which case you may want to send v4 with the fix?

#6 lore raw

Hey Junio,

Quoted 5 lines · Junio C Hamano

I see v3 that has 2>&1 but according to Luke's comment ("the message comes from cat"), it shouldn't be there? I am behind clearing the backlog in my mailbox and I could tweak it out from v3 while queuing, or I may forget about it after looking at other topics ;-) in which case you may want to send v4 with the fix?

Yeah sure! No problem! :)

Regards,
Pranit Bauva

#7 lore raw

PATCH v2 1/2 don't use test_must_fail with grep

In reply to Pranit Bauva

test_must_fail should only be used for testing git commands. To test the failure of other commands use !.

---
 t/t3510-cherry-pick-sequence.sh  |  6 +++---
 t/t5504-fetch-receive-strict.sh  |  2 +-
 t/t5516-fetch-push.sh            |  2 +-
 t/t5601-clone.sh                 |  2 +-
 t/t6030-bisect-porcelain.sh      |  2 +-
 t/t7610-mergetool.sh             |  2 +-
 t/t9001-send-email.sh            |  2 +-
 t/t9117-git-svn-init-clone.sh    | 12 ++++++------
 t/t9813-git-p4-preserve-users.sh |  8 ++++----
 t/t9814-git-p4-rename.sh         |  6 +++---
 10 files changed, 22 insertions(+), 22 deletions(-)
t/t3510-cherry-pick-sequence.sh +3 -3
index 372307c21..0acf4b146 100755
@@ -385,7 +385,7 @@ test_expect_success '--continue respects opts' '
 	git cat-file commit HEAD~1 >picked_msg &&
 	git cat-file commit HEAD~2 >unrelatedpick_msg &&
 	git cat-file commit HEAD~3 >initial_msg &&
-	test_must_fail grep "cherry picked from" initial_msg &&
+	! grep "cherry picked from" initial_msg &&
 	grep "cherry picked from" unrelatedpick_msg &&
 	grep "cherry picked from" picked_msg &&
 	grep "cherry picked from" anotherpick_msg
@@ -426,9 +426,9 @@ test_expect_failure '--signoff is automatically propagated to resolved conflict'
 	git cat-file commit HEAD~1 >picked_msg &&
 	git cat-file commit HEAD~2 >unrelatedpick_msg &&
 	git cat-file commit HEAD~3 >initial_msg &&
-	test_must_fail grep "Signed-off-by:" initial_msg &&
+	! grep "Signed-off-by:" initial_msg &&
 	grep "Signed-off-by:" unrelatedpick_msg &&
-	test_must_fail grep "Signed-off-by:" picked_msg &&
+	! grep "Signed-off-by:" picked_msg &&
 	grep "Signed-off-by:" anotherpick_msg
 '
 
t/t5504-fetch-receive-strict.sh +1 -1
index 9b19cff72..49d3621a9 100755
@@ -152,7 +152,7 @@ test_expect_success 'push with receive.fsck.missingEmail=warn' '
 	git --git-dir=dst/.git config --add \
 		receive.fsck.badDate warn &&
 	git push --porcelain dst bogus >act 2>&1 &&
-	test_must_fail grep "missingEmail" act
+	! grep "missingEmail" act
 '
 
 test_expect_success \
t/t5516-fetch-push.sh +1 -1
index 26b2cafc4..0fc5a7c59 100755
@@ -1004,7 +1004,7 @@ test_expect_success 'push --porcelain' '
 test_expect_success 'push --porcelain bad url' '
 	mk_empty testrepo &&
 	test_must_fail git push >.git/bar --porcelain asdfasdfasd refs/heads/master:refs/remotes/origin/master &&
-	test_must_fail grep -q Done .git/bar
+	! grep -q Done .git/bar
 '
 
 test_expect_success 'push --porcelain rejected' '
t/t5601-clone.sh +1 -1
index a43339420..4241ea5b3 100755
@@ -151,7 +151,7 @@ test_expect_success 'clone --mirror does not repeat tags' '
 	git clone --mirror src mirror2 &&
 	(cd mirror2 &&
 	 git show-ref 2> clone.err > clone.out) &&
-	test_must_fail grep Duplicate mirror2/clone.err &&
+	! grep Duplicate mirror2/clone.err &&
 	grep some-tag mirror2/clone.out
 
 '
t/t6030-bisect-porcelain.sh +1 -1
index 5e5370feb..8c2c6eaef 100755
@@ -407,7 +407,7 @@ test_expect_success 'good merge base when good and bad are siblings' '
 	test_i18ngrep "merge base must be tested" my_bisect_log.txt &&
 	grep $HASH4 my_bisect_log.txt &&
 	git bisect good > my_bisect_log.txt &&
-	test_must_fail grep "merge base must be tested" my_bisect_log.txt &&
+	! grep "merge base must be tested" my_bisect_log.txt &&
 	grep $HASH6 my_bisect_log.txt &&
 	git bisect reset
 '
t/t7610-mergetool.sh +1 -1
index 63d36fb28..0fe7e58cf 100755
@@ -602,7 +602,7 @@ test_expect_success MKTEMP 'temporary filenames are used with mergetool.writeToT
 	test_config mergetool.myecho.trustExitCode true &&
 	test_must_fail git merge master &&
 	git mergetool --no-prompt --tool myecho -- both >actual &&
-	test_must_fail grep ^\./both_LOCAL_ actual >/dev/null &&
+	! grep ^\./both_LOCAL_ actual >/dev/null &&
 	grep /both_LOCAL_ actual >/dev/null &&
 	git reset --hard master >/dev/null 2>&1
 '
t/t9001-send-email.sh +1 -1
index 3dc4a3454..0f398dd16 100755
@@ -50,7 +50,7 @@ test_no_confirm () {
 		--smtp-server="$(pwd)/fake.sendmail" \
 		$@ \
 		$patches >stdout &&
-		test_must_fail grep "Send this email" stdout &&
+		! grep "Send this email" stdout &&
 		>no_confirm_okay
 }
 
t/t9117-git-svn-init-clone.sh +6 -6
index 69a675052..044f65e91 100755
@@ -55,7 +55,7 @@ test_expect_success 'clone to target directory with --stdlayout' '
 test_expect_success 'init without -s/-T/-b/-t does not warn' '
 	test ! -d trunk &&
 	git svn init "$svnrepo"/project/trunk trunk 2>warning &&
-	test_must_fail grep -q prefix warning &&
+	! grep -q prefix warning &&
 	rm -rf trunk &&
 	rm -f warning
 	'
@@ -63,7 +63,7 @@ test_expect_success 'init without -s/-T/-b/-t does not warn' '
 test_expect_success 'clone without -s/-T/-b/-t does not warn' '
 	test ! -d trunk &&
 	git svn clone "$svnrepo"/project/trunk 2>warning &&
-	test_must_fail grep -q prefix warning &&
+	! grep -q prefix warning &&
 	rm -rf trunk &&
 	rm -f warning
 	'
@@ -86,7 +86,7 @@ EOF
 test_expect_success 'init with -s/-T/-b/-t assumes --prefix=origin/' '
 	test ! -d project &&
 	git svn init -s "$svnrepo"/project project 2>warning &&
-	test_must_fail grep -q prefix warning &&
+	! grep -q prefix warning &&
 	test_svn_configured_prefix "origin/" &&
 	rm -rf project &&
 	rm -f warning
@@ -95,7 +95,7 @@ test_expect_success 'init with -s/-T/-b/-t assumes --prefix=origin/' '
 test_expect_success 'clone with -s/-T/-b/-t assumes --prefix=origin/' '
 	test ! -d project &&
 	git svn clone -s "$svnrepo"/project 2>warning &&
-	test_must_fail grep -q prefix warning &&
+	! grep -q prefix warning &&
 	test_svn_configured_prefix "origin/" &&
 	rm -rf project &&
 	rm -f warning
@@ -104,7 +104,7 @@ test_expect_success 'clone with -s/-T/-b/-t assumes --prefix=origin/' '
 test_expect_success 'init with -s/-T/-b/-t and --prefix "" still works' '
 	test ! -d project &&
 	git svn init -s "$svnrepo"/project project --prefix "" 2>warning &&
-	test_must_fail grep -q prefix warning &&
+	! grep -q prefix warning &&
 	test_svn_configured_prefix "" &&
 	rm -rf project &&
 	rm -f warning
@@ -113,7 +113,7 @@ test_expect_success 'init with -s/-T/-b/-t and --prefix "" still works' '
 test_expect_success 'clone with -s/-T/-b/-t and --prefix "" still works' '
 	test ! -d project &&
 	git svn clone -s "$svnrepo"/project --prefix "" 2>warning &&
-	test_must_fail grep -q prefix warning &&
+	! grep -q prefix warning &&
 	test_svn_configured_prefix "" &&
 	rm -rf project &&
 	rm -f warning
t/t9813-git-p4-preserve-users.sh +4 -4
index 0fe231280..798bf2b67 100755
@@ -126,13 +126,13 @@ test_expect_success 'not preserving user with mixed authorship' '
 		grep "git author [email protected] does not match" &&
 
 		make_change_by_user usernamefile3 alice [email protected] &&
-		git p4 commit |\
-		test_must_fail grep "git author.*does not match" &&
+		git p4 commit >actual 2>&1 &&
+		! grep "git author.*does not match" actual &&
 
 		git config git-p4.skipUserNameCheck true &&
 		make_change_by_user usernamefile3 Charlie [email protected] &&
-		git p4 commit |\
-		test_must_fail grep "git author.*does not match" &&
+		git p4 commit >actual 2>&1 &&
+		! grep "git author.*does not match" actual &&
 
 		p4_check_commit_author usernamefile3 alice
 	)
t/t9814-git-p4-rename.sh +3 -3
index c89992cf9..e7e0268e9 100755
@@ -141,7 +141,7 @@ test_expect_success 'detect copies' '
 		git diff-tree -r -C HEAD &&
 		git p4 submit &&
 		p4 filelog //depot/file8 &&
-		p4 filelog //depot/file8 | test_must_fail grep -q "branch from" &&
+		! p4 filelog //depot/file8 | grep -q "branch from" &&
 
 		echo "file9" >>file2 &&
 		git commit -a -m "Differentiate file2" &&
@@ -154,7 +154,7 @@ test_expect_success 'detect copies' '
 		git config git-p4.detectCopies true &&
 		git p4 submit &&
 		p4 filelog //depot/file9 &&
-		p4 filelog //depot/file9 | test_must_fail grep -q "branch from" &&
+		! p4 filelog //depot/file9 | grep -q "branch from" &&
 
 		echo "file10" >>file2 &&
 		git commit -a -m "Differentiate file2" &&
@@ -202,7 +202,7 @@ test_expect_success 'detect copies' '
 		git config git-p4.detectCopies $(($level + 2)) &&
 		git p4 submit &&
 		p4 filelog //depot/file12 &&
-		p4 filelog //depot/file12 | test_must_fail grep -q "branch from" &&
+		! p4 filelog //depot/file12 | grep -q "branch from" &&
 
 		echo "file13" >>file2 &&
 		git commit -a -m "Differentiate file2" &&
Signature · 1 line
2.11.0
#8 lore raw

PATCH v2 2/2 t9813: avoid using pipes

The exit code of the upstream in a pipe is ignored thus we should avoid using it. By writing out the output of the git command to a file, we can test the exit codes of both the commands.

---
 t/t9813-git-p4-preserve-users.sh | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
t/t9813-git-p4-preserve-users.sh +4 -4
index 798bf2b67..9d7550ff3 100755
@@ -118,12 +118,12 @@ test_expect_success 'not preserving user with mixed authorship' '
 		make_change_by_user usernamefile3 Derek [email protected] &&
 		P4EDITOR=cat P4USER=alice P4PASSWD=secret &&
 		export P4EDITOR P4USER P4PASSWD &&
-		git p4 commit |\
-		grep "git author [email protected] does not match" &&
+		git p4 commit >actual 2>&1 &&
+		grep "git author [email protected] does not match" actual &&
 
 		make_change_by_user usernamefile3 Charlie [email protected] &&
-		git p4 commit |\
-		grep "git author [email protected] does not match" &&
+		git p4 commit >actual 2>&1 &&
+		grep "git author [email protected] does not match" actual &&
 
 		make_change_by_user usernamefile3 alice [email protected] &&
 		git p4 commit >actual 2>&1 &&
Signature · 1 line
2.11.0
#9 lore raw

Re: [PATCH v2 2/2] t9813: avoid using pipes

Quoted 2 lines · Pranit Bauva

The exit code of the upstream in a pipe is ignored thus we should avoid using it.

for commands under test, i.e. git things. Other parts can be piped if that makes the test easier. Though I guess that can be guessed by the reader as well, as you only convert git commands on upstream pipes.

Quoted 4 lines

By writing out the output of the git command to a file, we can test the exit codes of both the commands.

Thanks for taking ownership of this issue as well. :)

Quoted 9 lines
---
 t/t9813-git-p4-preserve-users.sh | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
t/t9813-git-p4-preserve-users.sh +0 -0
index 798bf2b67..9d7550ff3 100755

t/t9813-git-p4-preserve-users.sh test_expect_success 'not preserving user with mixed authorship' ' · line 121

Quoted 6 lines
t/t9813-git-p4-preserve-users.sh +1 -2
@@ -118,12 +118,12 @@ test_expect_success 'not preserving user with mixed authorship' '
                make_change_by_user usernamefile3 Derek [email protected] &&
                P4EDITOR=cat P4USER=alice P4PASSWD=secret &&
                export P4EDITOR P4USER P4PASSWD &&
-               git p4 commit |\
-               grep "git author [email protected] does not match" &&
+               git p4 commit >actual 2>&1 &&

Why do we need to pipe 2>&1 here?
Originally the piping only fed the stdout to grep, so this patch changes the test? Maybe

    2>actual.err &&
    test_must_be_empty actual.err

instead?

Thanks,
Stefan

#10 lore raw

Re: [PATCH v2 2/2] t9813: avoid using pipes

Hey Stefan,

Quoted 8 lines · Stefan Beller
Quoted 2 lines · Pranit Bauva

The exit code of the upstream in a pipe is ignored thus we should avoid using it.

for commands under test, i.e. git things. Other parts can be piped if that makes the test easier. Though I guess that can be guessed by the reader as well, as you only convert git commands on upstream pipes.

Quoted 6 lines
Quoted 4 lines

By writing out the output of the git command to a file, we can test the exit codes of both the commands.

Thanks for taking ownership of this issue as well. :)

Welcome! ;)

Quoted 20 lines
Quoted 9 lines
---
 t/t9813-git-p4-preserve-users.sh | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
t/t9813-git-p4-preserve-users.sh +0 -0
index 798bf2b67..9d7550ff3 100755

t/t9813-git-p4-preserve-users.sh test_expect_success 'not preserving user with mixed authorship' ' · line 121

Quoted 6 lines
t/t9813-git-p4-preserve-users.sh +1 -2
@@ -118,12 +118,12 @@ test_expect_success 'not preserving user with mixed authorship' '
                make_change_by_user usernamefile3 Derek [email protected] &&
                P4EDITOR=cat P4USER=alice P4PASSWD=secret &&
                export P4EDITOR P4USER P4PASSWD &&
-               git p4 commit |\
-               grep "git author [email protected] does not match" &&
+               git p4 commit >actual 2>&1 &&

Why do we need to pipe 2>&1 here?
Originally the piping only fed the stdout to grep, so this patch changes the test? Maybe

Quoted 4 lines
    2>actual.err &&
    test_must_be_empty actual.err

instead?

I tried this out but it seems that travis-ci build fails[1]. And I don't have p4 on my machine to test what's happening actually. But I just pushed out a few thing modifications to travis and it seems that actual.err isn't really empty for some reason. So I think, I just leave it as,

git p4 commit >actual &&
grep "git author [email protected] does not match" actual &&

What do you think?

[1]: https://travis-ci.org/pranitbauva1997/git/jobs/188633734

Regards,
Pranit Bauva

#11 lore raw

Re: [PATCH v2 2/2] t9813: avoid using pipes

Quoted 5 lines

git p4 commit >actual &&
grep "git author [email protected] does not match" actual &&

What do you think?

From the travis logs:

'actual.err' is not empty, it contains:
... - file(s) up-to-date.

I think(/hope) such a progress is tested for at another test, and not relevant here so I'd think the proposed

    git p4 commit >actual &&
    grep "git author [email protected] does not match" actual &&

is fine here.

Thanks,
Stefan

#12 lore raw

PATCH v3 1/2 don't use test_must_fail with grep

In reply to Pranit Bauva

test_must_fail should only be used for testing git commands. To test the failure of other commands use !.

---
 t/t3510-cherry-pick-sequence.sh  |  6 +++---
 t/t5504-fetch-receive-strict.sh  |  2 +-
 t/t5516-fetch-push.sh            |  2 +-
 t/t5601-clone.sh                 |  2 +-
 t/t6030-bisect-porcelain.sh      |  2 +-
 t/t7610-mergetool.sh             |  2 +-
 t/t9001-send-email.sh            |  2 +-
 t/t9117-git-svn-init-clone.sh    | 12 ++++++------
 t/t9813-git-p4-preserve-users.sh |  8 ++++----
 t/t9814-git-p4-rename.sh         |  6 +++---
 10 files changed, 22 insertions(+), 22 deletions(-)
t/t3510-cherry-pick-sequence.sh +3 -3
index 372307c21..0acf4b146 100755
@@ -385,7 +385,7 @@ test_expect_success '--continue respects opts' '
 	git cat-file commit HEAD~1 >picked_msg &&
 	git cat-file commit HEAD~2 >unrelatedpick_msg &&
 	git cat-file commit HEAD~3 >initial_msg &&
-	test_must_fail grep "cherry picked from" initial_msg &&
+	! grep "cherry picked from" initial_msg &&
 	grep "cherry picked from" unrelatedpick_msg &&
 	grep "cherry picked from" picked_msg &&
 	grep "cherry picked from" anotherpick_msg
@@ -426,9 +426,9 @@ test_expect_failure '--signoff is automatically propagated to resolved conflict'
 	git cat-file commit HEAD~1 >picked_msg &&
 	git cat-file commit HEAD~2 >unrelatedpick_msg &&
 	git cat-file commit HEAD~3 >initial_msg &&
-	test_must_fail grep "Signed-off-by:" initial_msg &&
+	! grep "Signed-off-by:" initial_msg &&
 	grep "Signed-off-by:" unrelatedpick_msg &&
-	test_must_fail grep "Signed-off-by:" picked_msg &&
+	! grep "Signed-off-by:" picked_msg &&
 	grep "Signed-off-by:" anotherpick_msg
 '
 
t/t5504-fetch-receive-strict.sh +1 -1
index 9b19cff72..49d3621a9 100755
@@ -152,7 +152,7 @@ test_expect_success 'push with receive.fsck.missingEmail=warn' '
 	git --git-dir=dst/.git config --add \
 		receive.fsck.badDate warn &&
 	git push --porcelain dst bogus >act 2>&1 &&
-	test_must_fail grep "missingEmail" act
+	! grep "missingEmail" act
 '
 
 test_expect_success \
t/t5516-fetch-push.sh +1 -1
index 26b2cafc4..0fc5a7c59 100755
@@ -1004,7 +1004,7 @@ test_expect_success 'push --porcelain' '
 test_expect_success 'push --porcelain bad url' '
 	mk_empty testrepo &&
 	test_must_fail git push >.git/bar --porcelain asdfasdfasd refs/heads/master:refs/remotes/origin/master &&
-	test_must_fail grep -q Done .git/bar
+	! grep -q Done .git/bar
 '
 
 test_expect_success 'push --porcelain rejected' '
t/t5601-clone.sh +1 -1
index a43339420..4241ea5b3 100755
@@ -151,7 +151,7 @@ test_expect_success 'clone --mirror does not repeat tags' '
 	git clone --mirror src mirror2 &&
 	(cd mirror2 &&
 	 git show-ref 2> clone.err > clone.out) &&
-	test_must_fail grep Duplicate mirror2/clone.err &&
+	! grep Duplicate mirror2/clone.err &&
 	grep some-tag mirror2/clone.out
 
 '
t/t6030-bisect-porcelain.sh +1 -1
index 5e5370feb..8c2c6eaef 100755
@@ -407,7 +407,7 @@ test_expect_success 'good merge base when good and bad are siblings' '
 	test_i18ngrep "merge base must be tested" my_bisect_log.txt &&
 	grep $HASH4 my_bisect_log.txt &&
 	git bisect good > my_bisect_log.txt &&
-	test_must_fail grep "merge base must be tested" my_bisect_log.txt &&
+	! grep "merge base must be tested" my_bisect_log.txt &&
 	grep $HASH6 my_bisect_log.txt &&
 	git bisect reset
 '
t/t7610-mergetool.sh +1 -1
index 63d36fb28..0fe7e58cf 100755
@@ -602,7 +602,7 @@ test_expect_success MKTEMP 'temporary filenames are used with mergetool.writeToT
 	test_config mergetool.myecho.trustExitCode true &&
 	test_must_fail git merge master &&
 	git mergetool --no-prompt --tool myecho -- both >actual &&
-	test_must_fail grep ^\./both_LOCAL_ actual >/dev/null &&
+	! grep ^\./both_LOCAL_ actual >/dev/null &&
 	grep /both_LOCAL_ actual >/dev/null &&
 	git reset --hard master >/dev/null 2>&1
 '
t/t9001-send-email.sh +1 -1
index 3dc4a3454..0f398dd16 100755
@@ -50,7 +50,7 @@ test_no_confirm () {
 		--smtp-server="$(pwd)/fake.sendmail" \
 		$@ \
 		$patches >stdout &&
-		test_must_fail grep "Send this email" stdout &&
+		! grep "Send this email" stdout &&
 		>no_confirm_okay
 }
 
t/t9117-git-svn-init-clone.sh +6 -6
index 69a675052..044f65e91 100755
@@ -55,7 +55,7 @@ test_expect_success 'clone to target directory with --stdlayout' '
 test_expect_success 'init without -s/-T/-b/-t does not warn' '
 	test ! -d trunk &&
 	git svn init "$svnrepo"/project/trunk trunk 2>warning &&
-	test_must_fail grep -q prefix warning &&
+	! grep -q prefix warning &&
 	rm -rf trunk &&
 	rm -f warning
 	'
@@ -63,7 +63,7 @@ test_expect_success 'init without -s/-T/-b/-t does not warn' '
 test_expect_success 'clone without -s/-T/-b/-t does not warn' '
 	test ! -d trunk &&
 	git svn clone "$svnrepo"/project/trunk 2>warning &&
-	test_must_fail grep -q prefix warning &&
+	! grep -q prefix warning &&
 	rm -rf trunk &&
 	rm -f warning
 	'
@@ -86,7 +86,7 @@ EOF
 test_expect_success 'init with -s/-T/-b/-t assumes --prefix=origin/' '
 	test ! -d project &&
 	git svn init -s "$svnrepo"/project project 2>warning &&
-	test_must_fail grep -q prefix warning &&
+	! grep -q prefix warning &&
 	test_svn_configured_prefix "origin/" &&
 	rm -rf project &&
 	rm -f warning
@@ -95,7 +95,7 @@ test_expect_success 'init with -s/-T/-b/-t assumes --prefix=origin/' '
 test_expect_success 'clone with -s/-T/-b/-t assumes --prefix=origin/' '
 	test ! -d project &&
 	git svn clone -s "$svnrepo"/project 2>warning &&
-	test_must_fail grep -q prefix warning &&
+	! grep -q prefix warning &&
 	test_svn_configured_prefix "origin/" &&
 	rm -rf project &&
 	rm -f warning
@@ -104,7 +104,7 @@ test_expect_success 'clone with -s/-T/-b/-t assumes --prefix=origin/' '
 test_expect_success 'init with -s/-T/-b/-t and --prefix "" still works' '
 	test ! -d project &&
 	git svn init -s "$svnrepo"/project project --prefix "" 2>warning &&
-	test_must_fail grep -q prefix warning &&
+	! grep -q prefix warning &&
 	test_svn_configured_prefix "" &&
 	rm -rf project &&
 	rm -f warning
@@ -113,7 +113,7 @@ test_expect_success 'init with -s/-T/-b/-t and --prefix "" still works' '
 test_expect_success 'clone with -s/-T/-b/-t and --prefix "" still works' '
 	test ! -d project &&
 	git svn clone -s "$svnrepo"/project --prefix "" 2>warning &&
-	test_must_fail grep -q prefix warning &&
+	! grep -q prefix warning &&
 	test_svn_configured_prefix "" &&
 	rm -rf project &&
 	rm -f warning
t/t9813-git-p4-preserve-users.sh +4 -4
index 0fe231280..798bf2b67 100755
@@ -126,13 +126,13 @@ test_expect_success 'not preserving user with mixed authorship' '
 		grep "git author [email protected] does not match" &&
 
 		make_change_by_user usernamefile3 alice [email protected] &&
-		git p4 commit |\
-		test_must_fail grep "git author.*does not match" &&
+		git p4 commit >actual 2>&1 &&
+		! grep "git author.*does not match" actual &&
 
 		git config git-p4.skipUserNameCheck true &&
 		make_change_by_user usernamefile3 Charlie [email protected] &&
-		git p4 commit |\
-		test_must_fail grep "git author.*does not match" &&
+		git p4 commit >actual 2>&1 &&
+		! grep "git author.*does not match" actual &&
 
 		p4_check_commit_author usernamefile3 alice
 	)
t/t9814-git-p4-rename.sh +3 -3
index c89992cf9..e7e0268e9 100755
@@ -141,7 +141,7 @@ test_expect_success 'detect copies' '
 		git diff-tree -r -C HEAD &&
 		git p4 submit &&
 		p4 filelog //depot/file8 &&
-		p4 filelog //depot/file8 | test_must_fail grep -q "branch from" &&
+		! p4 filelog //depot/file8 | grep -q "branch from" &&
 
 		echo "file9" >>file2 &&
 		git commit -a -m "Differentiate file2" &&
@@ -154,7 +154,7 @@ test_expect_success 'detect copies' '
 		git config git-p4.detectCopies true &&
 		git p4 submit &&
 		p4 filelog //depot/file9 &&
-		p4 filelog //depot/file9 | test_must_fail grep -q "branch from" &&
+		! p4 filelog //depot/file9 | grep -q "branch from" &&
 
 		echo "file10" >>file2 &&
 		git commit -a -m "Differentiate file2" &&
@@ -202,7 +202,7 @@ test_expect_success 'detect copies' '
 		git config git-p4.detectCopies $(($level + 2)) &&
 		git p4 submit &&
 		p4 filelog //depot/file12 &&
-		p4 filelog //depot/file12 | test_must_fail grep -q "branch from" &&
+		! p4 filelog //depot/file12 | grep -q "branch from" &&
 
 		echo "file13" >>file2 &&
 		git commit -a -m "Differentiate file2" &&
Signature · 1 line
2.11.0
#13 lore raw

PATCH v3 2/2 t9813: avoid using pipes

The exit code of the upstream in a pipe is ignored thus we should avoid using it. By writing out the output of the git command to a file, we can test the exit codes of both the commands.

---
 t/t9813-git-p4-preserve-users.sh | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
t/t9813-git-p4-preserve-users.sh +4 -4
index 798bf2b67..2133b21ae 100755
@@ -118,12 +118,12 @@ test_expect_success 'not preserving user with mixed authorship' '
 		make_change_by_user usernamefile3 Derek [email protected] &&
 		P4EDITOR=cat P4USER=alice P4PASSWD=secret &&
 		export P4EDITOR P4USER P4PASSWD &&
-		git p4 commit |\
-		grep "git author [email protected] does not match" &&
+		git p4 commit >actual &&
+		grep "git author [email protected] does not match" actual &&
 
 		make_change_by_user usernamefile3 Charlie [email protected] &&
-		git p4 commit |\
-		grep "git author [email protected] does not match" &&
+		git p4 commit >actual &&
+		grep "git author [email protected] does not match" actual &&
 
 		make_change_by_user usernamefile3 alice [email protected] &&
 		git p4 commit >actual 2>&1 &&
Signature · 1 line
2.11.0
#14 lore raw

Re: [PATCH v3 2/2] t9813: avoid using pipes

Quoted 3 lines · Pranit Bauva

The exit code of the upstream in a pipe is ignored thus we should avoid using it. By writing out the output of the git command to a file, we can test the exit codes of both the commands.

Do we also need to fix t9814-git-p4-rename.sh ?

Quoted 30 lines
---
 t/t9813-git-p4-preserve-users.sh | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
t/t9813-git-p4-preserve-users.sh +4 -5
index 798bf2b67..2133b21ae 100755
@@ -118,12 +118,12 @@ test_expect_success 'not preserving user with mixed authorship' '
                make_change_by_user usernamefile3 Derek [email protected] &&
                P4EDITOR=cat P4USER=alice P4PASSWD=secret &&
                export P4EDITOR P4USER P4PASSWD &&
-               git p4 commit |\
-               grep "git author [email protected] does not match" &&
+               git p4 commit >actual &&
+               grep "git author [email protected] does not match" actual &&
 
                make_change_by_user usernamefile3 Charlie [email protected] &&
-               git p4 commit |\
-               grep "git author [email protected] does not match" &&
+               git p4 commit >actual &&
+               grep "git author [email protected] does not match" actual &&
 
                make_change_by_user usernamefile3 alice [email protected] &&
                git p4 commit >actual 2>&1 &&
--

2.11.0

#15 lore raw

Re: [PATCH v3 2/2] t9813: avoid using pipes

Hey Luke,

Quoted 6 lines · Luke Diamand
Quoted 3 lines · Pranit Bauva

The exit code of the upstream in a pipe is ignored thus we should avoid using it. By writing out the output of the git command to a file, we can test the exit codes of both the commands.

Do we also need to fix t9814-git-p4-rename.sh ?

I don't think so. As Johannes[1] and Stefan[2] pointed out, we should avoid upstream pipes for git. p4 can be treated as an "external command" just like grep/sed.

[1]: http://public-inbox.org/git/[email protected]/
[2]: http://public-inbox.org/git/CAGZ79kZRFLzD7wcAnFvke9vBxxTAgE7=Ud7F_O95EfkWqz=LJw@mail.gmail.com/

#16 lore raw

PATCH v4 1/2 don't use test_must_fail with grep

In reply to Pranit Bauva

test_must_fail should only be used for testing git commands. To test the failure of other commands use !.

---
 t/t3510-cherry-pick-sequence.sh  |  6 +++---
 t/t5504-fetch-receive-strict.sh  |  2 +-
 t/t5516-fetch-push.sh            |  2 +-
 t/t5601-clone.sh                 |  2 +-
 t/t6030-bisect-porcelain.sh      |  2 +-
 t/t7610-mergetool.sh             |  2 +-
 t/t9001-send-email.sh            |  2 +-
 t/t9117-git-svn-init-clone.sh    | 12 ++++++------
 t/t9813-git-p4-preserve-users.sh |  8 ++++----
 t/t9814-git-p4-rename.sh         |  6 +++---
 10 files changed, 22 insertions(+), 22 deletions(-)
t/t3510-cherry-pick-sequence.sh +3 -3
index 372307c..0acf4b1 100755
@@ -385,7 +385,7 @@ test_expect_success '--continue respects opts' '
 	git cat-file commit HEAD~1 >picked_msg &&
 	git cat-file commit HEAD~2 >unrelatedpick_msg &&
 	git cat-file commit HEAD~3 >initial_msg &&
-	test_must_fail grep "cherry picked from" initial_msg &&
+	! grep "cherry picked from" initial_msg &&
 	grep "cherry picked from" unrelatedpick_msg &&
 	grep "cherry picked from" picked_msg &&
 	grep "cherry picked from" anotherpick_msg
@@ -426,9 +426,9 @@ test_expect_failure '--signoff is automatically propagated to resolved conflict'
 	git cat-file commit HEAD~1 >picked_msg &&
 	git cat-file commit HEAD~2 >unrelatedpick_msg &&
 	git cat-file commit HEAD~3 >initial_msg &&
-	test_must_fail grep "Signed-off-by:" initial_msg &&
+	! grep "Signed-off-by:" initial_msg &&
 	grep "Signed-off-by:" unrelatedpick_msg &&
-	test_must_fail grep "Signed-off-by:" picked_msg &&
+	! grep "Signed-off-by:" picked_msg &&
 	grep "Signed-off-by:" anotherpick_msg
 '
 
t/t5504-fetch-receive-strict.sh +1 -1
index 9b19cff..49d3621 100755
@@ -152,7 +152,7 @@ test_expect_success 'push with receive.fsck.missingEmail=warn' '
 	git --git-dir=dst/.git config --add \
 		receive.fsck.badDate warn &&
 	git push --porcelain dst bogus >act 2>&1 &&
-	test_must_fail grep "missingEmail" act
+	! grep "missingEmail" act
 '
 
 test_expect_success \
t/t5516-fetch-push.sh +1 -1
index 26b2caf..0fc5a7c 100755
@@ -1004,7 +1004,7 @@ test_expect_success 'push --porcelain' '
 test_expect_success 'push --porcelain bad url' '
 	mk_empty testrepo &&
 	test_must_fail git push >.git/bar --porcelain asdfasdfasd refs/heads/master:refs/remotes/origin/master &&
-	test_must_fail grep -q Done .git/bar
+	! grep -q Done .git/bar
 '
 
 test_expect_success 'push --porcelain rejected' '
t/t5601-clone.sh +1 -1
index a433394..4241ea5 100755
@@ -151,7 +151,7 @@ test_expect_success 'clone --mirror does not repeat tags' '
 	git clone --mirror src mirror2 &&
 	(cd mirror2 &&
 	 git show-ref 2> clone.err > clone.out) &&
-	test_must_fail grep Duplicate mirror2/clone.err &&
+	! grep Duplicate mirror2/clone.err &&
 	grep some-tag mirror2/clone.out
 
 '
t/t6030-bisect-porcelain.sh +1 -1
index 5e5370f..8c2c6ea 100755
@@ -407,7 +407,7 @@ test_expect_success 'good merge base when good and bad are siblings' '
 	test_i18ngrep "merge base must be tested" my_bisect_log.txt &&
 	grep $HASH4 my_bisect_log.txt &&
 	git bisect good > my_bisect_log.txt &&
-	test_must_fail grep "merge base must be tested" my_bisect_log.txt &&
+	! grep "merge base must be tested" my_bisect_log.txt &&
 	grep $HASH6 my_bisect_log.txt &&
 	git bisect reset
 '
t/t7610-mergetool.sh +1 -1
index 63d36fb..0fe7e58 100755
@@ -602,7 +602,7 @@ test_expect_success MKTEMP 'temporary filenames are used with mergetool.writeToT
 	test_config mergetool.myecho.trustExitCode true &&
 	test_must_fail git merge master &&
 	git mergetool --no-prompt --tool myecho -- both >actual &&
-	test_must_fail grep ^\./both_LOCAL_ actual >/dev/null &&
+	! grep ^\./both_LOCAL_ actual >/dev/null &&
 	grep /both_LOCAL_ actual >/dev/null &&
 	git reset --hard master >/dev/null 2>&1
 '
t/t9001-send-email.sh +1 -1
index 3dc4a34..0f398dd 100755
@@ -50,7 +50,7 @@ test_no_confirm () {
 		--smtp-server="$(pwd)/fake.sendmail" \
 		$@ \
 		$patches >stdout &&
-		test_must_fail grep "Send this email" stdout &&
+		! grep "Send this email" stdout &&
 		>no_confirm_okay
 }
 
t/t9117-git-svn-init-clone.sh +6 -6
index 69a6750..044f65e 100755
@@ -55,7 +55,7 @@ test_expect_success 'clone to target directory with --stdlayout' '
 test_expect_success 'init without -s/-T/-b/-t does not warn' '
 	test ! -d trunk &&
 	git svn init "$svnrepo"/project/trunk trunk 2>warning &&
-	test_must_fail grep -q prefix warning &&
+	! grep -q prefix warning &&
 	rm -rf trunk &&
 	rm -f warning
 	'
@@ -63,7 +63,7 @@ test_expect_success 'init without -s/-T/-b/-t does not warn' '
 test_expect_success 'clone without -s/-T/-b/-t does not warn' '
 	test ! -d trunk &&
 	git svn clone "$svnrepo"/project/trunk 2>warning &&
-	test_must_fail grep -q prefix warning &&
+	! grep -q prefix warning &&
 	rm -rf trunk &&
 	rm -f warning
 	'
@@ -86,7 +86,7 @@ EOF
 test_expect_success 'init with -s/-T/-b/-t assumes --prefix=origin/' '
 	test ! -d project &&
 	git svn init -s "$svnrepo"/project project 2>warning &&
-	test_must_fail grep -q prefix warning &&
+	! grep -q prefix warning &&
 	test_svn_configured_prefix "origin/" &&
 	rm -rf project &&
 	rm -f warning
@@ -95,7 +95,7 @@ test_expect_success 'init with -s/-T/-b/-t assumes --prefix=origin/' '
 test_expect_success 'clone with -s/-T/-b/-t assumes --prefix=origin/' '
 	test ! -d project &&
 	git svn clone -s "$svnrepo"/project 2>warning &&
-	test_must_fail grep -q prefix warning &&
+	! grep -q prefix warning &&
 	test_svn_configured_prefix "origin/" &&
 	rm -rf project &&
 	rm -f warning
@@ -104,7 +104,7 @@ test_expect_success 'clone with -s/-T/-b/-t assumes --prefix=origin/' '
 test_expect_success 'init with -s/-T/-b/-t and --prefix "" still works' '
 	test ! -d project &&
 	git svn init -s "$svnrepo"/project project --prefix "" 2>warning &&
-	test_must_fail grep -q prefix warning &&
+	! grep -q prefix warning &&
 	test_svn_configured_prefix "" &&
 	rm -rf project &&
 	rm -f warning
@@ -113,7 +113,7 @@ test_expect_success 'init with -s/-T/-b/-t and --prefix "" still works' '
 test_expect_success 'clone with -s/-T/-b/-t and --prefix "" still works' '
 	test ! -d project &&
 	git svn clone -s "$svnrepo"/project --prefix "" 2>warning &&
-	test_must_fail grep -q prefix warning &&
+	! grep -q prefix warning &&
 	test_svn_configured_prefix "" &&
 	rm -rf project &&
 	rm -f warning
t/t9813-git-p4-preserve-users.sh +4 -4
index 0fe2312..76004a5 100755
@@ -126,13 +126,13 @@ test_expect_success 'not preserving user with mixed authorship' '
 		grep "git author [email protected] does not match" &&
 
 		make_change_by_user usernamefile3 alice [email protected] &&
-		git p4 commit |\
-		test_must_fail grep "git author.*does not match" &&
+		git p4 commit >actual &&
+		! grep "git author.*does not match" actual &&
 
 		git config git-p4.skipUserNameCheck true &&
 		make_change_by_user usernamefile3 Charlie [email protected] &&
-		git p4 commit |\
-		test_must_fail grep "git author.*does not match" &&
+		git p4 commit >actual &&
+		! grep "git author.*does not match" actual &&
 
 		p4_check_commit_author usernamefile3 alice
 	)
t/t9814-git-p4-rename.sh +3 -3
index c89992c..e7e0268 100755
@@ -141,7 +141,7 @@ test_expect_success 'detect copies' '
 		git diff-tree -r -C HEAD &&
 		git p4 submit &&
 		p4 filelog //depot/file8 &&
-		p4 filelog //depot/file8 | test_must_fail grep -q "branch from" &&
+		! p4 filelog //depot/file8 | grep -q "branch from" &&
 
 		echo "file9" >>file2 &&
 		git commit -a -m "Differentiate file2" &&
@@ -154,7 +154,7 @@ test_expect_success 'detect copies' '
 		git config git-p4.detectCopies true &&
 		git p4 submit &&
 		p4 filelog //depot/file9 &&
-		p4 filelog //depot/file9 | test_must_fail grep -q "branch from" &&
+		! p4 filelog //depot/file9 | grep -q "branch from" &&
 
 		echo "file10" >>file2 &&
 		git commit -a -m "Differentiate file2" &&
@@ -202,7 +202,7 @@ test_expect_success 'detect copies' '
 		git config git-p4.detectCopies $(($level + 2)) &&
 		git p4 submit &&
 		p4 filelog //depot/file12 &&
-		p4 filelog //depot/file12 | test_must_fail grep -q "branch from" &&
+		! p4 filelog //depot/file12 | grep -q "branch from" &&
 
 		echo "file13" >>file2 &&
 		git commit -a -m "Differentiate file2" &&

--
https://github.com/git/git/pull/314

#17 lore raw

PATCH v4 2/2 t9813: avoid using pipes

The exit code of the upstream in a pipe is ignored thus we should avoid using it. By writing out the output of the git command to a file, we can test the exit codes of both the commands.

---
 t/t9813-git-p4-preserve-users.sh | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
t/t9813-git-p4-preserve-users.sh +4 -4
index 76004a5..bda222a 100755
@@ -118,12 +118,12 @@ test_expect_success 'not preserving user with mixed authorship' '
 		make_change_by_user usernamefile3 Derek [email protected] &&
 		P4EDITOR=cat P4USER=alice P4PASSWD=secret &&
 		export P4EDITOR P4USER P4PASSWD &&
-		git p4 commit |\
-		grep "git author [email protected] does not match" &&
+		git p4 commit >actual &&
+		grep "git author [email protected] does not match" actual &&
 
 		make_change_by_user usernamefile3 Charlie [email protected] &&
-		git p4 commit |\
-		grep "git author [email protected] does not match" &&
+		git p4 commit >actual &&
+		grep "git author [email protected] does not match" actual &&
 
 		make_change_by_user usernamefile3 alice [email protected] &&
 		git p4 commit >actual &&

--
https://github.com/git/git/pull/314

#18 lore raw

Re: [PATCH v4 2/2] t9813: avoid using pipes

Quoted 3 lines · Pranit Bauva

The exit code of the upstream in a pipe is ignored thus we should avoid using it. By writing out the output of the git command to a file, we can test the exit codes of both the commands.

Looks good to me, thanks!

Ack.

Quoted 30 lines
---
 t/t9813-git-p4-preserve-users.sh | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
t/t9813-git-p4-preserve-users.sh +4 -5
index 76004a5..bda222a 100755
@@ -118,12 +118,12 @@ test_expect_success 'not preserving user with mixed authorship' '
                make_change_by_user usernamefile3 Derek [email protected] &&
                P4EDITOR=cat P4USER=alice P4PASSWD=secret &&
                export P4EDITOR P4USER P4PASSWD &&
-               git p4 commit |\
-               grep "git author [email protected] does not match" &&
+               git p4 commit >actual &&
+               grep "git author [email protected] does not match" actual &&
 
                make_change_by_user usernamefile3 Charlie [email protected] &&
-               git p4 commit |\
-               grep "git author [email protected] does not match" &&
+               git p4 commit >actual &&
+               grep "git author [email protected] does not match" actual &&
 
                make_change_by_user usernamefile3 alice [email protected] &&
                git p4 commit >actual &&
 
--

https://github.com/git/git/pull/314

#19 lore raw

Re: [PATCH v4 2/2] t9813: avoid using pipes

Quoted 8 lines · Luke Diamand
Quoted 3 lines · Pranit Bauva

The exit code of the upstream in a pipe is ignored thus we should avoid using it. By writing out the output of the git command to a file, we can test the exit codes of both the commands.

Looks good to me, thanks!

Ack.

Thanks, both.