Merge branch 'sb/describe-blob' into next
[gitweb.git] / t / test-lib-functions.sh
index 64f793e3d73e6f7e0ab2d813487efb0b237489d0..67b5994afb76810b15634e1b3bb6f9717298b029 100644 (file)
@@ -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 "<File '$last_arg' is empty>"
+       fi
+
+       return 1
 }
 
 # Call any command "$@" but be more verbose about its
@@ -1058,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;
+                               }
+                       }
+               }
+       '
+}