Merge branch 'sg/test-i18ngrep'
authorJunio C Hamano <gitster@pobox.com>
Wed, 21 Feb 2018 20:45:05 +0000 (12:45 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 21 Feb 2018 20:45:05 +0000 (12:45 -0800)
Test fixes.

* sg/test-i18ngrep:
t: make 'test_i18ngrep' more informative on failure
t: validate 'test_i18ngrep's parameters
t: move 'test_i18ncmp' and 'test_i18ngrep' to 'test-lib-functions.sh'
t5536: let 'test_i18ngrep' read the file without redirection
t5510: consolidate 'grep' and 'test_i18ngrep' patterns
t4001: don't run 'git status' upstream of a pipe
t6022: don't run 'git merge' upstream of a pipe
t5812: add 'test_i18ngrep's missing filename parameter
t5541: add 'test_i18ngrep's missing filename parameter

1  2 
t/test-lib-functions.sh
t/test-lib.sh
diff --combined t/test-lib-functions.sh
index a679b02a1c3bd181aff94d36e6e2f3347cf2c34f,1de31fae7fd173d0f1e74c8a2eacf3e7e94a1722..67b5994afb76810b15634e1b3bb6f9717298b029
@@@ -705,6 -705,60 +705,60 @@@ test_cmp_bin() 
        cmp "$@"
  }
  
+ # Use this instead of test_cmp to compare files that contain expected and
+ # actual output from git commands that can be translated.  When running
+ # under GETTEXT_POISON this pretends that the command produced expected
+ # results.
+ test_i18ncmp () {
+       test -n "$GETTEXT_POISON" || test_cmp "$@"
+ }
+ # Use this instead of "grep expected-string actual" to see if the
+ # output from a git command that can be translated either contains an
+ # expected string, or does not contain an unwanted one.  When running
+ # under GETTEXT_POISON this pretends that the command produced expected
+ # results.
+ test_i18ngrep () {
+       eval "last_arg=\${$#}"
+       test -f "$last_arg" ||
+       error "bug in the test script: test_i18ngrep requires a file" \
+             "to read as the last parameter"
+       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
+               return 0
+       fi
+       if test "x!" = "x$1"
+       then
+               shift
+               ! grep "$@" && return 0
+               echo >&2 "error: '! grep $@' did find a match in:"
+       else
+               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 "<File '$last_arg' is empty>"
+       fi
+       return 1
+ }
  # Call any command "$@" but be more verbose about its
  # failure. This is handy for commands like "test" which do
  # not output anything when they fail.
@@@ -1020,37 -1074,3 +1074,37 @@@ nongit () 
                "$@"
        )
  }
 +
 +# convert stdin to pktline representation; note that empty input becomes an
 +# empty packet, not a flush packet (for that you can just print 0000 yourself).
 +packetize() {
 +      cat >packetize.tmp &&
 +      len=$(wc -c <packetize.tmp) &&
 +      printf '%04x%s' "$(($len + 4))" &&
 +      cat packetize.tmp &&
 +      rm -f packetize.tmp
 +}
 +
 +# Parse the input as a series of pktlines, writing the result to stdout.
 +# Sideband markers are removed automatically, and the output is routed to
 +# stderr if appropriate.
 +#
 +# NUL bytes are converted to "\\0" for ease of parsing with text tools.
 +depacketize () {
 +      perl -e '
 +              while (read(STDIN, $len, 4) == 4) {
 +                      if ($len eq "0000") {
 +                              print "FLUSH\n";
 +                      } else {
 +                              read(STDIN, $buf, hex($len) - 4);
 +                              $buf =~ s/\0/\\0/g;
 +                              if ($buf =~ s/^[\x2\x3]//) {
 +                                      print STDERR $buf;
 +                              } else {
 +                                      $buf =~ s/^\x1//;
 +                                      print $buf;
 +                              }
 +                      }
 +              }
 +      '
 +}
diff --combined t/test-lib.sh
index 452dec10e586117d7beddaa41b0004d6378b824a,852b22c80ab4c38183391813c333185e6050a664..33f6ce26f69d442238c60619a5f70673d451a7fb
@@@ -939,7 -939,7 +939,7 @@@ the
        fi
  fi
  
 -GITPERLLIB="$GIT_BUILD_DIR"/perl/blib/lib:"$GIT_BUILD_DIR"/perl/blib/arch/auto/Git
 +GITPERLLIB="$GIT_BUILD_DIR"/perl/build/lib
  export GITPERLLIB
  test -d "$GIT_BUILD_DIR"/templates/blt || {
        error "You haven't built things yet, have you?"
@@@ -1062,32 -1062,6 +1062,6 @@@ els
        test_set_prereq C_LOCALE_OUTPUT
  fi
  
- # Use this instead of test_cmp to compare files that contain expected and
- # actual output from git commands that can be translated.  When running
- # under GETTEXT_POISON this pretends that the command produced expected
- # results.
- test_i18ncmp () {
-       test -n "$GETTEXT_POISON" || test_cmp "$@"
- }
- # Use this instead of "grep expected-string actual" to see if the
- # output from a git command that can be translated either contains an
- # expected string, or does not contain an unwanted one.  When running
- # under GETTEXT_POISON this pretends that the command produced expected
- # results.
- test_i18ngrep () {
-       if test -n "$GETTEXT_POISON"
-       then
-           : # pretend success
-       elif test "x!" = "x$1"
-       then
-               shift
-               ! grep "$@"
-       else
-               grep "$@"
-       fi
- }
  test_lazy_prereq PIPE '
        # test whether the filesystem supports FIFOs
        test_have_prereq !MINGW,!CYGWIN &&
@@@ -1132,10 -1106,6 +1106,10 @@@ test_lazy_prereq EXPENSIVE 
        test -n "$GIT_TEST_LONG"
  '
  
 +test_lazy_prereq EXPENSIVE_ON_WINDOWS '
 +      test_have_prereq EXPENSIVE || test_have_prereq !MINGW,!CYGWIN
 +'
 +
  test_lazy_prereq USR_BIN_TIME '
        test -x /usr/bin/time
  '