summaryrefslogtreecommitdiff
path: root/t/test-lib-functions.sh
diff options
context:
space:
mode:
Diffstat (limited to 't/test-lib-functions.sh')
-rw-r--r--t/test-lib-functions.sh22
1 files changed, 15 insertions, 7 deletions
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 352c213d52..88b7dbd69a 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -1362,14 +1362,22 @@ nongit () {
)
} 7>&2 2>&4
-# 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).
+# convert function arguments or stdin (if not arguments given) to pktline
+# representation. If multiple arguments are given, they are separated by
+# whitespace and put in a single packet. Note that data containing NULs must be
+# given on stdin, and 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
+ if test $# -gt 0
+ then
+ packet="$*"
+ printf '%04x%s' "$((4 + ${#packet}))" "$packet"
+ else
+ perl -e '
+ my $packet = do { local $/; <STDIN> };
+ printf "%04x%s", 4 + length($packet), $packet;
+ '
+ fi
}
# Parse the input as a series of pktlines, writing the result to stdout.