Jeff King wrote:

> For small outputs, we sometimes use:
>
>   test "$(some_cmd)" = "something we expect"
>
> instead of a full test_cmp. The downside of this is that
> when it fails, there is no output at all from the script.

There's another downside to that construct: it loses the exit
status from some_cmd.

[...]
> --- a/t/t5304-prune.sh
> +++ b/t/t5304-prune.sh
> @@ -13,7 +13,7 @@ add_blob() {
>       before=$(git count-objects | sed "s/ .*//") &&
>       BLOB=$(echo aleph_0 | git hash-object -w --stdin) &&
>       BLOB_FILE=.git/objects/$(echo $BLOB | sed "s/^../&\//") &&
> -     test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
> +     verbose test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&

So ideally this would be something like:

        git count-objects >output &&
        verbose test "$((1 + $before))" = "$(sed "s/ .*//" output)" &&

[...]
> @@ -45,11 +45,11 @@ test_expect_success 'prune --expire' '
>  
>       add_blob &&
>       git prune --expire=1.hour.ago &&
> -     test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
> +     verbose test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&

and likewise elsewhere in the file.

Alternatively, maybe there could be a helper in the same spirit as
test_cmp_rev?

        test_object_count () {
                git count-objects >output &&
                sed "s/ .*//" output >count &&
                printf "%s\n" "$1" >expect &&
                test_cmp expect count
        }

My two cents,
Jonathan
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to