t/lib-patch-mode.sh: fix ignored exit codes

Fix code added in b319ef70a94 (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 <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Feb 6, 2023 at 23:44 UTC 62f3a45bb49f9436f1cd754b02ac549b1f6514cf
1 file changed +8 -3
t/lib-patch-mode.sh
+8 -3
@@ -29,8 +29,12 @@ set_and_save_state () {
29
30 # verify_state <path> <expected-worktree-content> <expected-index-content>
31 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
38 }
39
40 # verify_saved_state <path>
@@ -46,5 +50,6 @@ save_head () {
50 }
51
52 verify_saved_head () {
49 - test "$(cat _head)" = "$(git rev-parse HEAD)"
53 + git rev-parse HEAD >actual &&
54 + test_cmp _head actual
55 }