test-lib-functions.sh: add generate_zero_bytes function

t5318 and t5562 used /dev/zero, which is not portable. This function provides both a fixed block of NUL bytes and an infinite stream of NULs. Signed-off-by: Randall S. Becker <rsbecker@nexbridge.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Randall S. Becker committed Feb 9, 2019 at 13:59 UTC b0fa1a3f997403bc444cd7a65d798185e9d548ca
1 file changed +13
t/test-lib-functions.sh
+13
@@ -116,6 +116,19 @@ remove_cr () {
116 tr '\015' Q | sed -e 's/Q$//'
117 }
118
119 +# Generate an output of $1 bytes of all zeroes (NULs, not ASCII zeroes).
120 +# If $1 is 'infinity', output forever or until the receiving pipe stops reading,
121 +# whichever comes first.
122 +generate_zero_bytes () {
123 + perl -e 'if ($ARGV[0] == "infinity") {
124 + while (-1) {
125 + print "\0"
126 + }
127 + } else {
128 + print "\0" x $ARGV[0]
129 + }' "$@"
130 +}
131 +
132 # In some bourne shell implementations, the "unset" builtin returns
133 # nonzero status when a variable to be unset was not set in the first
134 # place.