On Fri, Oct 18, 2019 at 03:10:21PM -0700, Denton Liu wrote:
> Currently, in the case where we are using test_cmp_rev() to report
> not-equals, we write `! test_cmp_rev`. However, since test_cmp_rev()
> contains
> 
>       r1=$(git rev-parse --verify "$1") &&
>       r2=$(git rev-parse --verify "$2") &&
> 
> In the case where `git rev-parse` segfaults and dies unexpectedly, the
> failure will be ignored.
> 
> Rewrite test_cmp_rev() to optionally accept "!" as the first argument to
> do a not-equals comparison. Rewrite `! test_cmp_rev` to `test_cmp_rev !`
> in all tests to take advantage of this new functionality.
> 
> Signed-off-by: Denton Liu <liu.den...@gmail.com>


> diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
> index b299ecc326..76dce5f8ee 100644
> --- a/t/test-lib-functions.sh
> +++ b/t/test-lib-functions.sh
> @@ -1012,8 +1012,17 @@ test_must_be_empty () {
>       fi
>  }
>  
> -# Tests that its two parameters refer to the same revision
> +# Tests that its two parameters refer to the same revision, or if '!' is
> +# provided first, that its other two parameters refer to different
> +# revisions.
>  test_cmp_rev () {
> +     local inverted_op
> +     inverted_op='!='
> +     if test $# -ge 1 && test "x$1" = 'x!'
> +     then
> +         inverted_op='='
> +         shift
> +     fi
>       if test $# != 2
>       then
>               error "bug in the test script: test_cmp_rev requires two 
> revisions, but got $#"
> @@ -1021,7 +1030,7 @@ test_cmp_rev () {
>               local r1 r2
>               r1=$(git rev-parse --verify "$1") &&
>               r2=$(git rev-parse --verify "$2") &&
> -             if test "$r1" != "$r2"
> +             if test "$r1" "$inverted_op" "$r2"
>               then
>                       cat >&4 <<-EOF
>                       error: two revisions point to different objects:

A semi-rhetorical question: how will the output of 'test_cmp_rev ! HEAD
HEAD' look like? :)

Reply via email to