[PATCH 01/24] t9300 (fast-import): avoid exiting early on failure

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxx>
Signed-off-by: Jonathan Nieder <jrnieder@xxxxxxxxx>
---
 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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]