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

Fix code added in b319ef70a9 (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>
This commit is contained in:
Ævar Arnfjörð Bjarmason 2023-02-06 23:44:29 +01:00 committed by Junio C Hamano
parent fb18dd2831
commit 62f3a45bb4

View File

@ -29,8 +29,12 @@ set_and_save_state () {
# verify_state <path> <expected-worktree-content> <expected-index-content>
verify_state () {
test "$(cat "$1")" = "$2" &&
test "$(git show :"$1")" = "$3"
echo "$2" >expect &&
test_cmp expect "$1" &&
echo "$3" >expect &&
git show :"$1" >actual &&
test_cmp expect actual
}
# verify_saved_state <path>
@ -46,5 +50,6 @@ save_head () {
}
verify_saved_head () {
test "$(cat _head)" = "$(git rev-parse HEAD)"
git rev-parse HEAD >actual &&
test_cmp _head actual
}