From: Jonathan Nieder Date: Fri, 24 Sep 2010 07:04:19 GMT Subject: [PATCH 01/24] t9300 (fast-import): avoid exiting early on failure Message-ID: <20100924070418.GB4666@burratino> 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 Signed-off-by: Jonathan Nieder --- 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 < $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 <expect <expect < 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 <expect <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