Skip to content

Commit b0fa1a3

Browse files
rsbeckercagitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e9bd4aa commit b0fa1a3

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

t/test-lib-functions.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,19 @@ remove_cr () {
116116
tr '\015' Q | sed -e 's/Q$//'
117117
}
118118

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+
119132
# In some bourne shell implementations, the "unset" builtin returns
120133
# nonzero status when a variable to be unset was not set in the first
121134
# place.

0 commit comments

Comments
 (0)