Skip to content

Commit 63b1a17

Browse files
szedergitster
authored andcommitted
t: make 'test_i18ngrep' more informative on failure
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 <[email protected]> Reviewed-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fd29d7b commit 63b1a17

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

t/test-lib-functions.sh

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -733,14 +733,30 @@ test_i18ngrep () {
733733

734734
if test -n "$GETTEXT_POISON"
735735
then
736-
: # pretend success
737-
elif test "x!" = "x$1"
736+
# pretend success
737+
return 0
738+
fi
739+
740+
if test "x!" = "x$1"
738741
then
739742
shift
740-
! grep "$@"
743+
! grep "$@" && return 0
744+
745+
echo >&2 "error: '! grep $@' did find a match in:"
741746
else
742-
grep "$@"
747+
grep "$@" && return 0
748+
749+
echo >&2 "error: 'grep $@' didn't find a match in:"
743750
fi
751+
752+
if test -s "$last_arg"
753+
then
754+
cat >&2 "$last_arg"
755+
else
756+
echo >&2 "<File '$last_arg' is empty>"
757+
fi
758+
759+
return 1
744760
}
745761

746762
# Call any command "$@" but be more verbose about its

0 commit comments

Comments
 (0)