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" -- <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@xxxxxxxxx> > --- > 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 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"