Re: [PATCH v2 5/8] t/lib-patch-mode.sh: fix ignored "git" exit codes
- From
René Scharfe <l.s.r@web.de>
- Date
- Dec 2, 2022, 01:31 UTC
- Message-ID
- <4f6f065c-1fd9-7c1a-f547-c568e930562d@web.de>
- In-Reply-To
- <patch-v2-5.8-f826a336c3d-20221202T000227Z-avarab@gmail.com>
Am 02.12.2022 um 01:06 schrieb Ævar Arnfjörð Bjarmason:
Show 30 quoted lines
> Fix code added in b319ef70a94 (Add a small patch-mode testing library,
> 2009-08-13) to use &&-chaining and the newly added "test_cmp_cmd"
> instead of interpolating "git" commands in a "test" statement.
>
> 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.
>
> The "cat _head >expect" here is redundant, we could simply give
> "_head" to "test_cmp", but let's be consistent in using the "expect"
> and "actual" names for clarity.
>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
> t/lib-patch-mode.sh | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/t/lib-patch-mode.sh b/t/lib-patch-mode.sh
> index cfd76bf987b..ae51f33a010 100644
> --- a/t/lib-patch-mode.sh
> +++ b/t/lib-patch-mode.sh
> @@ -29,8 +29,11 @@ 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 &&
> + cat "$1" >actual &&
> + test_cmp expect actual &&Hmm, I'd have expected this oneliner instead, matching the conversion of the second command:
test_cmp_cmd "$2" cat "$1" &&
cat is not a git command, though, so the extra checks of test_cmp_cmd are unnecessary. But how about avoiding its useless use then?
echo "$2" >expect && test_cmp expect "$1" &&
Show 12 quoted lines
> +
> + test_cmp_cmd "$3" git show :"$1"
> }
>
> # verify_saved_state <path>
> @@ -46,5 +49,5 @@ save_head () {
> }
>
> verify_saved_head () {
> - test "$(cat _head)" = "$(git rev-parse HEAD)"
> + test_cmp_cmd "$(cat _head)" git rev-parse HEAD
> }