New tests added

This commit is contained in:
Andrew Wood
2023-07-23 22:00:19 +01:00
parent 99c5e0988c
commit d4590e1f3b
4 changed files with 109 additions and 0 deletions
+17
View File
@@ -0,0 +1,17 @@
#!/bin/sh
#
# Check that the byte counter counts in bits when --bits is selected.
# Dummy assignments for "shellcheck".
testSubject="${testSubject:-false}"; workFile1="${workFile1:-.tmp1}"
dd if=/dev/zero bs=100 count=1 2>/dev/null \
| "${testSubject}" -f -b -8 >/dev/null 2>"${workFile1}"
counterValue=$(tr '\r' '\n' < "${workFile1}" | tr -d ' ')
test "${counterValue}" = "800b" && exit 0
echo "unexpected bit counter value: ${counterValue}"
exit 1
# EOF
+21
View File
@@ -0,0 +1,21 @@
#!/bin/sh
#
# Check that "--buffer-percent" displays correctly.
# Dummy assignments for "shellcheck".
testSubject="${testSubject:-false}"; workFile1="${workFile1:-.tmp1}"
# The output should show 100% and 0% as the buffer initially fills up due to
# there being nowhere to write it to, and then empties.
( dd if=/dev/zero bs=1024 count=1024; sleep 2; ) 2>/dev/null \
| "${testSubject}" -f -T -i 0.5 -B 1024 2>"${workFile1}" \
| (sleep 1; dd bs=1024 count=512; sleep 1; cat; ) >/dev/null 2>&1
differentLines=$(tr '\r' '\n' < "${workFile1}" | sed '/^ *$/d' | sort | uniq | wc -l | tr -dc '0-9')
test "${differentLines}" -gt 1 && exit 0
echo "expected output changes not seen"
tr '\r' '\n' < "${workFile1}" | sed 's/^ *$/d' | sort | uniq
exit 1
# EOF
+34
View File
@@ -0,0 +1,34 @@
#!/bin/sh
#
# Check that "--last-written" works.
# Dummy assignments for "shellcheck".
testSubject="${testSubject:-false}"; workFile1="${workFile1:-.tmp1}"
# Slowly write a sequence of numbers (rate-limited by another `pv' instance)
# and watch the "--last-written" output of a second `pv' instance to make
# sure the buffer contents are visible (we use "-B" to disable splice mode).
seq -w 3 1 100 \
| "${testSubject}" -qL 200 \
| "${testSubject}" -f -B 1024 -A 16 -i 0.2 >/dev/null 2>"${workFile1}"
differentLines=$(tr '\r' '\n' < "${workFile1}" | sed '/^ *$/d' | sort | uniq | wc -l | tr -dc '0-9')
lastLine=$(tr '\r' '\n' < "${workFile1}" | sed '/^ *$/d' | sed -n '$p')
if ! test "${differentLines}" -gt 5; then
echo "fewer than 6 different outputs seen"
tr '\r' '\n' < "${workFile1}" | sed '/^ *$/d' | sort | uniq
exit 1
fi
expectedLastLine="097.098.099.100."
if ! test "${lastLine}" = "${expectedLastLine}"; then
echo "final output differs from expected value"
echo "expected value: [${expectedLastLine}]"
echo "observed value: [${lastLine}]"
exit 1
fi
exit 0
# EOF
@@ -0,0 +1,37 @@
#!/bin/sh
#
# Check that numeric output shows line counts instead of percentages, when
# used in line mode together with bytes mode.
# Dummy assignments for "shellcheck".
testSubject="${testSubject:-false}"; workFile1="${workFile1:-.tmp1}"; workFile2="${workFile2:-.tmp2}"
# Pass through 100 lines.
#
seq -w 3 1 100 \
| "${testSubject}" -bnl -i 0.2 -f -L 100 2>"${workFile1}" > "${workFile2}"
lineCount=$(wc -l < "${workFile1}" | tr -dc '0-9')
finalStdoutLine=$(sed -n '$p' < "${workFile2}")
# The number of output lines should be >3 and <10, and the final line of
# transferred data on stdout should be 100.
#
if ! test "${lineCount}" -gt 3; then
echo "fewer than 4 output lines (${lineCount})"
cat "${workFile1}"
exit 1
fi
if ! test "${lineCount}" -lt 10; then
echo "more than 9 output lines (${lineCount})"
cat "${workFile1}"
exit 1
fi
if ! test "${finalStdoutLine}" = "100"; then
echo "final transferred line was not 100 (${finalStdoutLine})"
exit 1
fi
exit 0
# EOF