git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jonathan Nieder <jrnieder@gmail.com>
To: Ramkumar Ramachandra <artagnon@gmail.com>
Cc: git@vger.kernel.org, "Shawn O. Pearce" <spearce@spearce.org>,
	Sverre Rabbelier <srabbelier@gmail.com>,
	David Barr <david.barr@cordelta.com>, Sam Vilain <sam@vilain.net>
Subject: [PATCH 01/24] t9300 (fast-import): avoid exiting early on failure
Date: Fri, 24 Sep 2010 02:04:19 -0500	[thread overview]
Message-ID: <20100924070418.GB4666@burratino> (raw)
In-Reply-To: <20100924065900.GA4666@burratino>

Exiting is not an appropriate way to signal a test failure, since it
bypasses the usual expect_success/expect_failure logic and prevents
later tests that might be able to help diagnose the problem from
running.

Still, exiting is a temptingly easy way to catch errors in shell
loops.  Alternatives:

 1) Ignore errors in the loop body.  This can leave problems hidden
    and undiagnosed so it is not really an option.

 2) Enclose the loop in a subshell which can catch the exit on
    failure.

 3) Enclose the loop in a function and return the exit code on
    failure.

 4) More ad-hoc methods.

Most instances in t9300 lend themselves well to (3), with the nice
side effect of avoiding some repetitive code.  Introduce a new
verify_packs () helper in this spirit.

One instance uses "verify-pack -v", making it slightly different from
the others; rather than spending effort on making the helper general
enough to be usable for it, too, enclose the strange loop in
a subshell (strategy (2)).  While at it, simplify the code a little
by redirecting stdout of the loop instead of its body.

Cc: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 t/t9300-fast-import.sh |   38 ++++++++++++++++++++++++--------------
 1 files changed, 24 insertions(+), 14 deletions(-)

diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh
index 7c05920..1eef926 100755
--- a/t/t9300-fast-import.sh
+++ b/t/t9300-fast-import.sh
@@ -23,6 +23,14 @@ file5_data='an inline file.
 file6_data='#!/bin/sh
 echo "$@"'
 
+verify_packs () {
+	for p in .git/objects/pack/*.pack
+	do
+		git verify-pack $p ||
+		return
+	done
+}
+
 ###
 ### series A
 ###
@@ -69,7 +77,7 @@ test_expect_success \
 	 git whatchanged master'
 test_expect_success \
 	'A: verify pack' \
-	'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
+	'verify_packs'
 
 cat >expect <<EOF
 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
@@ -155,7 +163,7 @@ test_expect_success \
 	 git whatchanged verify--import-marks'
 test_expect_success \
 	'A: verify pack' \
-	'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
+	'verify_packs'
 cat >expect <<EOF
 :000000 100755 0000000000000000000000000000000000000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 A	copy-of-file2
 EOF
@@ -318,7 +326,7 @@ test_expect_success \
 	 git whatchanged branch'
 test_expect_success \
 	'C: verify pack' \
-	'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
+	'verify_packs'
 test_expect_success \
 	'C: validate reuse existing blob' \
 	'test $newf = `git rev-parse --verify branch:file2/newf`
@@ -376,7 +384,7 @@ test_expect_success \
 	 git whatchanged branch'
 test_expect_success \
 	'D: verify pack' \
-	'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
+	'verify_packs'
 
 cat >expect <<EOF
 :000000 100755 0000000000000000000000000000000000000000 35a59026a33beac1569b1c7f66f3090ce9c09afc A	newdir/exec.sh
@@ -422,7 +430,7 @@ test_expect_success \
     'git fast-import --date-format=rfc2822 <input'
 test_expect_success \
 	'E: verify pack' \
-	'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
+	'verify_packs'
 
 cat >expect <<EOF
 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> 1170778938 -0500
@@ -473,7 +481,7 @@ test_expect_success \
 	'
 test_expect_success \
 	'F: verify pack' \
-	'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
+	'verify_packs'
 
 cat >expect <<EOF
 tree `git rev-parse branch~1^{tree}`
@@ -509,7 +517,7 @@ test_expect_success \
     'git fast-import --force <input'
 test_expect_success \
 	'G: verify pack' \
-	'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
+	'verify_packs'
 test_expect_success \
 	'G: branch changed, but logged' \
 	'test $old_branch != `git rev-parse --verify branch^0` &&
@@ -546,7 +554,7 @@ test_expect_success \
 	 git whatchanged H'
 test_expect_success \
 	'H: verify pack' \
-	'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
+	'verify_packs'
 
 cat >expect <<EOF
 :100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D	file2/newf
@@ -1327,7 +1335,7 @@ test_expect_success \
 	 git whatchanged notes-test'
 test_expect_success \
 	'Q: verify pack' \
-	'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
+	'verify_packs'
 
 commit1=$(git rev-parse notes-test~2)
 commit2=$(git rev-parse notes-test^)
@@ -1675,11 +1683,13 @@ test_expect_success \
 	 git --git-dir=R/.git fast-import --big-file-threshold=1 <input'
 test_expect_success \
 	'R: verify created pack' \
-	': >verify &&
-	 for p in R/.git/objects/pack/*.pack;
-	 do
-	   git verify-pack -v $p >>verify || exit;
-	 done'
+	'(
+		for p in R/.git/objects/pack/*.pack
+		do
+			git verify-pack -v $p ||
+			exit
+		done
+	 ) >verify'
 test_expect_success \
 	'R: verify written objects' \
 	'git --git-dir=R/.git cat-file blob big-file:big1 >actual &&
-- 
1.7.2.3

  reply	other threads:[~2010-09-24  7:07 UTC|newest]

Thread overview: 75+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-01  3:18 [PATCH/RFC] Teach fast-import to import subtrees named by tree id Jonathan Nieder
2010-07-01  5:48 ` [WIP/PATCH] Teach fast-import to print the id of each imported commit Jonathan Nieder
2010-07-02  3:16   ` Sverre Rabbelier
2010-07-02  3:41     ` Jonathan Nieder
2010-07-02  4:29       ` Sverre Rabbelier
2010-07-02  5:12   ` Jonathan Nieder
2010-07-02 14:55     ` Sverre Rabbelier
2010-07-02 15:40       ` Jonathan Nieder
2010-07-02 15:48         ` Sverre Rabbelier
2010-07-04  0:02         ` Sam Vilain
2010-07-04  0:35           ` Jonathan Nieder
2010-07-04  3:44             ` Sam Vilain
2010-07-04  7:22               ` Jonathan Nieder
2010-08-17 17:02   ` Ramkumar Ramachandra
2010-09-05  3:15     ` [RFC/PATCH 0/3] fast-import: give importers access to the object store Jonathan Nieder
2010-09-05  3:22       ` [PATCH 1/3] t9300 (fast-import): style tweaks Jonathan Nieder
2010-09-24  6:59         ` [PATCH/RFC 00/24] " Jonathan Nieder
2010-09-24  7:04           ` Jonathan Nieder [this message]
2010-09-24  7:05           ` [PATCH 02/24] t9300 (fast-import): avoid hard-coded object names Jonathan Nieder
2010-09-24  7:09           ` [PATCH 03/24] t9300 (fast-import): guard "export large marks" test setup Jonathan Nieder
2010-09-24  9:38             ` Ramkumar Ramachandra
2010-09-24 10:56               ` Raja R Harinath
2010-09-24 10:34             ` Ramkumar Ramachandra
2010-09-24 11:01               ` Raja R Harinath
2010-09-24  7:11           ` [PATCH 04/24] t9300 (fast-import): check exit status from upstream of pipes Jonathan Nieder
2010-09-24  7:11           ` [PATCH 05/24] t9300 (fast-import): check exit status from command substitutions Jonathan Nieder
2010-09-24  7:12           ` [PATCH 06/24] t9300 (fast-import): use test_cmp in place of test $(foo) = $(bar) Jonathan Nieder
2010-09-24  7:13           ` [PATCH 07/24] t9300 (fast-import): use tabs to indent Jonathan Nieder
2010-09-24  8:54             ` Ramkumar Ramachandra
2010-09-24  9:21               ` Jonathan Nieder
2010-09-24  7:16           ` [PATCH 08/24] t9300 (fast-import), series A: re-indent Jonathan Nieder
2010-09-24  7:22             ` Sverre Rabbelier
2010-09-24  7:35               ` Jonathan Nieder
2010-09-24  7:18           ` [PATCH 09/24] t9300 (fast-import), series B: re-indent Jonathan Nieder
2010-09-24  7:19           ` [PATCH 10/24] t9300 (fast-import), series C: re-indent Jonathan Nieder
2010-09-24  7:19           ` [PATCH 11/24] t9300 (fast-import), series D: re-indent Jonathan Nieder
2010-09-24  7:21           ` [PATCH 12/24] t9300 (fast-import), series E: re-indent Jonathan Nieder
2010-09-24  7:22           ` [PATCH 13/24] t9300 (fast-import), series F: re-indent Jonathan Nieder
2010-09-24  7:22           ` [PATCH 14/24] t9300 (fast-import), series H: re-indent Jonathan Nieder
2010-09-24  7:23           ` [PATCH 15/24] t9300 (fast-import), series I: re-indent Jonathan Nieder
2010-09-24  7:24           ` [PATCH 16/24] t9300 (fast-import), series J: re-indent Jonathan Nieder
2010-09-24  7:25           ` [PATCH 17/24] t9300 (fast-import), series K: re-indent Jonathan Nieder
2010-09-24  7:25           ` [PATCH 18/24] t9300 (fast-import), series L: re-indent Jonathan Nieder
2010-09-24  7:26           ` [PATCH 19/24] t9300 (fast-import), series M: re-indent Jonathan Nieder
2010-09-24  7:26           ` [PATCH 20/24] t9300 (fast-import), series N: re-indent Jonathan Nieder
2010-09-24  7:27           ` [PATCH 21/24] t9300 (fast-import), series O: re-indent Jonathan Nieder
2010-09-24  7:27           ` [PATCH 22/24] t9300 (fast-import), series P: re-indent Jonathan Nieder
2010-09-24  7:28           ` [PATCH 23/24] t9300 (fast-import), series Q: re-indent Jonathan Nieder
2010-09-24  7:30           ` [PATCH 24/24] t9300 (fast-import), series R: re-indent Jonathan Nieder
2010-09-25  5:19           ` svn-fe status Jonathan Nieder
2010-09-25 10:25             ` Sverre Rabbelier
2010-09-27  2:54               ` Jonathan Nieder
2010-09-27  9:15                 ` Sverre Rabbelier
2010-09-05  3:29       ` [PATCH 2/3] Teach fast-import to print the id of each imported commit Jonathan Nieder
2010-09-05  3:41       ` [PATCH 3/3] fast-import: Let importers retrieve the objects being written Jonathan Nieder
2010-09-05  6:08       ` [RFC/PATCH 0/3] fast-import: give importers access to the object store Ramkumar Ramachandra
2010-09-05  6:28         ` Sverre Rabbelier
2010-09-05  8:47           ` Ramkumar Ramachandra
2010-09-05 16:20             ` Sverre Rabbelier
2010-09-05 17:31         ` Jonathan Nieder
2010-09-08  3:13       ` [PATCH 4/3] fast-import: typofix Jonathan Nieder
2010-09-08  3:17       ` [PATCH 5/3] fast-import: allow cat command with empty path Jonathan Nieder
2010-09-08  3:27       ` [PATCH 6/3] fast-import: Allow cat requests at arbitrary points in stream Jonathan Nieder
2010-09-08  3:38         ` Sverre Rabbelier
2010-09-08  3:57           ` Jonathan Nieder
2010-09-08 10:16         ` Ramkumar Ramachandra
2010-09-16  0:14       ` [RFC/PATCH 0/3] fast-import: give importers access to the object store Sam Vilain
2010-09-17 23:24         ` Sverre Rabbelier
2010-09-24 19:43         ` Jonathan Nieder
2010-09-24 23:44           ` Sverre Rabbelier
2010-09-25  0:01             ` Jonathan Nieder
2010-09-25  0:17               ` Sverre Rabbelier
2010-07-02  3:20 ` [PATCH/RFC] Teach fast-import to import subtrees named by tree id Sverre Rabbelier
2010-07-02  4:42   ` Jonathan Nieder
2010-07-02 12:44 ` Ramkumar Ramachandra

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=20100924070418.GB4666@burratino \
    --to=jrnieder@gmail.com \
    --cc=artagnon@gmail.com \
    --cc=david.barr@cordelta.com \
    --cc=git@vger.kernel.org \
    --cc=sam@vilain.net \
    --cc=spearce@spearce.org \
    --cc=srabbelier@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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).