From 63b1a175ee284f37c009e0afd7ee88a7c04ca515 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?SZEDER=20G=C3=A1bor?= Date: Thu, 8 Feb 2018 16:56:56 +0100 Subject: t: make 'test_i18ngrep' more informative on failure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When 'test_i18ngrep' can't find the expected pattern, it exits completely silently; when its negated form does find the pattern that shouldn't be there, it prints the matching line(s) but otherwise exits without any error message. This leaves the developer puzzled about what could have gone wrong. Make 'test_i18ngrep' more informative on failure by printing an error message including the invoked 'grep' command and the contents of the file it had to scan through. Note that this "dump the scanned file" part is not quite perfect, as it dumps only the file specified as the function's last positional parameter, thus assuming that there is only a single file parameter. I think that's a reasonable assumption to make, one that holds true in the current code base. And even if someone were to scan multiple files at once in the future, the worst thing that could happen is that the verbose error message won't include the contents of all those files, only the last one. Alas, we can't really do any better than this, because checking whether the other positional parameters match a filename can result in false positives: 't3400-rebase.sh' and 't3404-rebase-interactive.sh' contain one test each, where the 'test_i18ngrep's pattern verbatimly matches a file in the trash directory. Signed-off-by: SZEDER Gábor Reviewed-by: Jeff King Signed-off-by: Junio C Hamano --- t/test-lib-functions.sh | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index 64f793e3d7..1de31fae7f 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -733,14 +733,30 @@ test_i18ngrep () { if test -n "$GETTEXT_POISON" then - : # pretend success - elif test "x!" = "x$1" + # pretend success + return 0 + fi + + if test "x!" = "x$1" then shift - ! grep "$@" + ! grep "$@" && return 0 + + echo >&2 "error: '! grep $@' did find a match in:" else - grep "$@" + grep "$@" && return 0 + + echo >&2 "error: 'grep $@' didn't find a match in:" fi + + if test -s "$last_arg" + then + cat >&2 "$last_arg" + else + echo >&2 "" + fi + + return 1 } # Call any command "$@" but be more verbose about its -- cgit v1.2.1