Re: [PATCH v2 4/8] test-lib-functions: add and use test_cmp_cmd
- From
René Scharfe <l.s.r@web.de>
- Date
- Dec 2, 2022, 01:30 UTC
- Message-ID
- <6f6350b7-a479-c05d-6100-cb2aad72a658@web.de>
- In-Reply-To
- <patch-v2-4.8-c36060934a6-20221202T000227Z-avarab@gmail.com>
Am 02.12.2022 um 01:06 schrieb Ævar Arnfjörð Bjarmason:
Show 16 quoted lines
> Add a "test_cmp_cmd" helper for the common pattern discussed in the > documentation being added here to "t/test-lib-functions.sh". > > This implementation leaves the door open for extending this helper > past its obvious limitations, such as: > > test_cmp_cmd "some" "lines" -- <some-cmd> > test_cmp_cmd --stdin <some-cmd> <expect > test_cmp_cmd --ignore-stderr "output" <some-cmd> > > By using this in we'll catch cases where "git" or "test-tool" > errors (such as segfaults or abort()) were previously hidden, and we'd > either pass the test, or fail in some subsequent assertion. > > Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> > ---
Show 24 quoted lines
> diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
> index 796093a7b32..0e8e0f808e3 100644
> --- a/t/test-lib-functions.sh
> +++ b/t/test-lib-functions.sh
> @@ -1274,6 +1274,24 @@ test_cmp_rev () {
> fi
> }
>
> +# test_cmp_cmd is a convenience helper for doing the more verbose:
> +#
> +# echo something >expect &&
> +# <some-command-and-args> >actual &&
> +# test_cmp expect actual
> +#
> +# As:
> +#
> +# test_cmp_cmd something <some-command-and-args>
> +test_cmp_cmd () {
> + local expect="$1" &&
> + shift &&
> + printf "%s\n" "$expect" >expect &&
> + "$@" >actual 2>err &&
> + test_must_be_empty err
> + test_cmp expect actualerr, expect and actual are common filenames used in tests. Clobbering them might be surprising. Perhaps at least add some prefix (e.g. name them test_cmp_cmd_expect etc.), like other functions in that script do, to avoid collisions?
Show 5 quoted lines
> +}
> +
> # Compare paths respecting core.ignoreCase
> test_cmp_fspath () {
> if test "x$1" = "x$2"