git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Elijah Newren <newren@gmail.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com, sunshine@sunshineco.com,
	martin.agren@gmail.com, szeder.dev@gmail.com,
	Elijah Newren <newren@gmail.com>
Subject: [PATCHv3 2/5] t7406: avoid having git commands upstream of a pipe
Date: Tue,  7 Aug 2018 09:49:02 -0700	[thread overview]
Message-ID: <20180807164905.3859-3-newren@gmail.com> (raw)
In-Reply-To: <20180807164905.3859-1-newren@gmail.com>

When a git command is on the left side of a pipe, the pipe will swallow
its exit status, preventing us from detecting failures in said commands.
Restructure the tests to put the output in a temporary file to avoid
this problem.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 t/t7406-submodule-update.sh | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
index e2405c96b5..c6b7b59350 100755
--- a/t/t7406-submodule-update.sh
+++ b/t/t7406-submodule-update.sh
@@ -481,7 +481,8 @@ test_expect_success 'recursive submodule update - command in .git/config catches
 
 test_expect_success 'submodule init does not copy command into .git/config' '
 	(cd super &&
-	 H=$(git ls-files -s submodule | cut -d" " -f2) &&
+	 git ls-files -s submodule >out &&
+	 H=$(cut -d" " -f2 out) &&
 	 mkdir submodule1 &&
 	 git update-index --add --cacheinfo 160000 $H submodule1 &&
 	 git config -f .gitmodules submodule.submodule1.path submodule1 &&
@@ -579,9 +580,11 @@ test_expect_success 'submodule update - update=none in .git/config' '
 	  git checkout master &&
 	  compare_head
 	 ) &&
-	 git diff --name-only | grep submodule &&
+	 git diff --name-only >out &&
+	 grep submodule out &&
 	 git submodule update &&
-	 git diff --name-only | grep submodule &&
+	 git diff --name-only >out &&
+	 grep submodule out &&
 	 (cd submodule &&
 	  compare_head
 	 ) &&
@@ -597,7 +600,8 @@ test_expect_success 'submodule update - update=none in .git/config but --checkou
 	  git checkout master &&
 	  compare_head
 	 ) &&
-	 git diff --name-only | grep submodule &&
+	 git diff --name-only >out &&
+	 grep submodule out &&
 	 git submodule update --checkout &&
 	 test_must_fail git diff --name-only \| grep submodule &&
 	 (cd submodule &&
@@ -885,7 +889,8 @@ test_expect_success 'submodule update properly revives a moved submodule' '
 	 H=$(git rev-parse --short HEAD) &&
 	 git commit -am "pre move" &&
 	 H2=$(git rev-parse --short HEAD) &&
-	 git status | sed "s/$H/XXX/" >expect &&
+	 git status >out &&
+	 sed "s/$H/XXX/" out >expect &&
 	 H=$(cd submodule2 && git rev-parse HEAD) &&
 	 git rm --cached submodule2 &&
 	 rm -rf submodule2 &&
@@ -894,7 +899,8 @@ test_expect_success 'submodule update properly revives a moved submodule' '
 	 git config -f .gitmodules submodule.submodule2.path "moved/sub module" &&
 	 git commit -am "post move" &&
 	 git submodule update &&
-	 git status | sed "s/$H2/XXX/" >actual &&
+	 git status > out &&
+	 sed "s/$H2/XXX/" out >actual &&
 	 test_cmp expect actual
 	)
 '
@@ -912,7 +918,7 @@ test_expect_success SYMLINKS 'submodule update can handle symbolic links in pwd'
 
 test_expect_success 'submodule update clone shallow submodule' '
 	test_when_finished "rm -rf super3" &&
-	first=$(git -C cloned submodule status submodule |cut -c2-41) &&
+	first=$(git -C cloned rev-parse HEAD:submodule) &&
 	second=$(git -C submodule rev-parse HEAD) &&
 	commit_count=$(git -C submodule rev-list --count $first^..$second) &&
 	git clone cloned super3 &&
@@ -922,7 +928,8 @@ test_expect_success 'submodule update clone shallow submodule' '
 		sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp &&
 		mv -f .gitmodules.tmp .gitmodules &&
 		git submodule update --init --depth=$commit_count &&
-		test 1 = $(git -C submodule log --oneline | wc -l)
+		git -C submodule log --oneline >out &&
+		test_line_count = 1 out
 	)
 '
 
@@ -938,7 +945,8 @@ test_expect_success 'submodule update clone shallow submodule outside of depth'
 		test_i18ngrep "Direct fetching of that commit failed." actual &&
 		git -C ../submodule config uploadpack.allowReachableSHA1InWant true &&
 		git submodule update --init --depth=1 >actual &&
-		test 1 = $(git -C submodule log --oneline | wc -l)
+		git -C submodule log --oneline >out &&
+		test_line_count = 1 out
 	)
 '
 
-- 
2.18.0.550.geb414df874.dirty


  parent reply	other threads:[~2018-08-07 16:49 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-03 23:14 [PATCH] t7406: Make a test_must_fail call fail for the right reason Elijah Newren
2018-08-03 23:40 ` Eric Sunshine
2018-08-03 23:42   ` Eric Sunshine
2018-08-03 23:41 ` Junio C Hamano
2018-08-06 15:25 ` [PATCH 0/2] Simple fixes to t7406 Elijah Newren
2018-08-06 15:25   ` [PATCH 1/3] t7406: simplify by using diff --name-only instead of diff --raw Elijah Newren
2018-08-06 15:25   ` [PATCH 2/3] t7406: avoid having git commands upstream of a pipe Elijah Newren
2018-08-06 15:48     ` SZEDER Gábor
2018-08-06 16:09       ` Elijah Newren
2018-08-06 15:25   ` [PATCH 3/3] t7406: make a test_must_fail call fail for the right reason Elijah Newren
2018-08-07  9:07     ` SZEDER Gábor
2018-08-07 13:46       ` Elijah Newren
2018-08-07  7:50   ` [PATCH 0/2] Simple fixes to t7406 Martin Ågren
2018-08-07 13:40     ` Elijah Newren
2018-08-07 16:49   ` [PATCHv3 0/5] " Elijah Newren
2018-08-07 16:49     ` [PATCHv3 1/5] t7406: simplify by using diff --name-only instead of diff --raw Elijah Newren
2018-08-07 17:29       ` Junio C Hamano
2018-08-07 17:40         ` Elijah Newren
2018-08-07 18:18           ` Junio C Hamano
2018-08-07 16:49     ` Elijah Newren [this message]
2018-08-07 16:49     ` [PATCHv3 3/5] t7406: prefer test_* helper functions to test -[feds] Elijah Newren
2018-08-07 17:34       ` Junio C Hamano
2018-08-07 16:49     ` [PATCHv3 4/5] t7406: avoid using test_must_fail for commands other than git Elijah Newren
2018-08-07 16:49     ` [PATCHv3 5/5] t7406: fix call that was failing for the wrong reason Elijah Newren
2018-08-07 17:37       ` Junio C Hamano
2018-08-08 16:31     ` [PATCHv4 0/5] Simple fixes to t7406 Elijah Newren
2018-08-08 16:31       ` [PATCHv4 1/5] t7406: fix call that was failing for the wrong reason Elijah Newren
2018-08-08 16:31       ` [PATCHv4 2/5] t7406: simplify by using diff --name-only instead of diff --raw Elijah Newren
2018-08-08 16:31       ` [PATCHv4 3/5] t7406: avoid having git commands upstream of a pipe Elijah Newren
2018-08-08 16:31       ` [PATCHv4 4/5] t7406: prefer test_* helper functions to test -[feds] Elijah Newren
2018-08-08 16:31       ` [PATCHv4 5/5] t7406: avoid using test_must_fail for commands other than git Elijah Newren
2018-08-13 20:28     ` [PATCHv3 0/5] Simple fixes to t7406 SZEDER Gábor
2018-08-18 20:52       ` Elijah Newren

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180807164905.3859-3-newren@gmail.com \
    --to=newren@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=martin.agren@gmail.com \
    --cc=sunshine@sunshineco.com \
    --cc=szeder.dev@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).