Two of the previous patches in this series fixed two bogus
'test_i18ngrep' invocations that had neither a filename parameter not
anything piped into their standard input, yet both managed to remain
unnoticed for years.  A third similarly bogus invocation is currently
lurking in 'pu' for a couple of weeks now.

Try to catch similar mistakes in the future by ensuring that
'test_i18ngrep' has at least two parameters, not including an optional
'!' to negate the pattern.  Perform these checks after we made sure
that there is no data on the 'test_i18ngrep's standard input, so if
the filename parameter is missing because someone is piping a git
command's output into this function, then they would get the more
relevant error message.

Note that this is not quite perfect, as it doesn't account for any
'grep --options' given as parameters.  However, doing so would be far
too complicated, considering that patters can start with dashes as
well, and in the majority of the cases we don't use any such options
anyway.

Signed-off-by: SZEDER Gábor <[email protected]>
---

About that third one in 'pu': it's test '3b-check: Avoid implicit
rename if involved as source on current side' introduced in commit
fcd649216 (directory rename detection: testcases to avoid taking
detection too far, 2018-01-05) in branch
'en/rename-directory-detection'.

  
https://public-inbox.org/git/CAM0VKj=qhjqj7ujwbboustyd0fra1zp1gwxzmvxutif+c6g...@mail.gmail.com/T/#u

 t/test-lib-functions.sh | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index e381d50d0..b543fd0e0 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -723,6 +723,12 @@ test_i18ngrep () {
        error "bug in the test script: data on test_i18ngrep's stdin;" \
              "perhaps a git command's output is piped into it?"
 
+       if test $# -lt 2 ||
+          { test "x!" = "x$1" && test $# -lt 3 ; }
+       then
+               error "bug in the test script: too few parameters to 
test_i18ngrep"
+       fi
+
        if test -n "$GETTEXT_POISON"
        then
            : # pretend success
-- 
2.16.1.155.g5159265b1

Reply via email to