Re: [PATCH v2 03/21] t/test-lib-functions.sh: generalize test_cmp_rev
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Apr 11, 2016, 00:07 UTC
- Message-ID
- <CAPig+cSQtnk3wXg6agkHPgYzV-gV_cWv8G0rUO9NZCFxsZC5EA@mail.gmail.com>
- In-Reply-To
- <1460294354-7031-4-git-send-email-s-beyer@gmx.net>
On Sun, Apr 10, 2016 at 9:18 AM, Stephan Beyer <s-beyer@gmx.net> wrote:
Show 30 quoted lines
> test_cmp_rev() took exactly two parameters, the expected revision
> and the revision to test. This commit generalizes this function
> such that it takes any number of at least two revisions: the
> expected one and a list of actual ones. The function returns true
> if and only if at least one actual revision coincides with the
> expected revision.
>
> While at it, the side effect of generating two (temporary) files
> is removed.
>
> Signed-off-by: Stephan Beyer <s-beyer@gmx.net>
> ---
> diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
> @@ -711,11 +711,17 @@ test_must_be_empty () {
> -# Tests that its two parameters refer to the same revision
> +# Tests that the first parameter refers to the same revision
> +# of at least one other parameter
> test_cmp_rev () {
> - git rev-parse --verify "$1" >expect.rev &&
> - git rev-parse --verify "$2" >actual.rev &&
> - test_cmp expect.rev actual.rev
> + hash1="$(git rev-parse --verify "$1")" || return
> + shift
> + for rev
> + do
> + hash2="$(git rev-parse --verify "$rev")" || return
> + test "$hash1" = "$hash2" && return 0
> + done
> + return 1
> }The original code printed helpful diagnostic information when the comparison failed, but the new code does not. Is this intentional?