Skip to content

Commit 62f3a45

Browse files
avargitster
authored andcommitted
t/lib-patch-mode.sh: fix ignored exit codes
Fix code added in b319ef7 (Add a small patch-mode testing library, 2009-08-13) to use &&-chaining. This avoids losing both the exit code of a "git" and the "cat" processes. This fixes cases where we'd have e.g. missed memory leaks under SANITIZE=leak, this code doesn't leak now as far as I can tell, but I discovered it while looking at leaks in related code. For "verify_saved_head()" we could make use of "test_cmp_rev" with some changes, but it uses "git rev-parse --verify", and this existing test does not. I think it could safely use it, but let's avoid the while-at-it change, and narrowly fix the exit code problem. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fb18dd2 commit 62f3a45

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

t/lib-patch-mode.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,12 @@ set_and_save_state () {
2929

3030
# verify_state <path> <expected-worktree-content> <expected-index-content>
3131
verify_state () {
32-
test "$(cat "$1")" = "$2" &&
33-
test "$(git show :"$1")" = "$3"
32+
echo "$2" >expect &&
33+
test_cmp expect "$1" &&
34+
35+
echo "$3" >expect &&
36+
git show :"$1" >actual &&
37+
test_cmp expect actual
3438
}
3539

3640
# verify_saved_state <path>
@@ -46,5 +50,6 @@ save_head () {
4650
}
4751

4852
verify_saved_head () {
49-
test "$(cat _head)" = "$(git rev-parse HEAD)"
53+
git rev-parse HEAD >actual &&
54+
test_cmp _head actual
5055
}

0 commit comments

Comments
 (0)