From: René Scharfe Date: Fri, 02 Dec 2022 01:30:35 GMT Subject: Re: [PATCH v2 4/8] test-lib-functions: add and use test_cmp_cmd Message-ID: <6f6350b7-a479-c05d-6100-cb2aad72a658@web.de> In-Reply-To: Am 02.12.2022 um 01:06 schrieb Ævar Arnfjörð Bjarmason: > 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" -- > test_cmp_cmd --stdin test_cmp_cmd --ignore-stderr "output" > > 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 > --- > 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 && > +# >actual && > +# test_cmp expect actual > +# > +# As: > +# > +# test_cmp_cmd something > +test_cmp_cmd () { > + local expect="$1" && > + shift && > + printf "%s\n" "$expect" >expect && > + "$@" >actual 2>err && > + test_must_be_empty err > + test_cmp expect actual err, 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? > +} > + > # Compare paths respecting core.ignoreCase > test_cmp_fspath () { > if test "x$1" = "x$2"