Add more tests

This commit is contained in:
Andrew Wood
2023-07-25 21:21:37 +01:00
parent 678f655116
commit f83927e451
3 changed files with 117 additions and 0 deletions
@@ -0,0 +1,32 @@
#!/bin/sh
#
# Check that the progress bar increases in size when data is coming in.
# Dummy assignments for "shellcheck".
testSubject="${testSubject:-false}"; workFile1="${workFile1:-.tmp1}"
dd if=/dev/zero bs=100 count=1 2>/dev/null \
| "${testSubject}" -f -p -i 0.1 -L 50 -s 100 >/dev/null 2>"${workFile1}"
# There should be more than 5 different lines of output.
#
lineCount=$(tr '\r' '\n' < "${workFile1}" | sort | uniq -u | wc -l | tr -dc '0-9')
if ! test "${lineCount}" -gt 5; then
echo "fewer than 6 different progress lines (${lineCount})"
tr '\r' '\n' < "${workFile1}" | sort | uniq -u
exit 1
fi
# Counting the "=" characters in each line that make up the progress bar
# should give at least 5 different line lengths.
#
differentBarLengthsCount=$(tr '\r' '\n' < "${workFile1}" | tr -dc '=\n' | awk '{print length($1)}' | sort | uniq -u | wc -l | tr -dc '0-9')
if ! test "${differentBarLengthsCount}" -gt 5; then
echo "fewer than 6 different progress bar lengths detected (${differentBarLengthsCount})"
tr '\r' '\n' < "${workFile1}" | sort | uniq -u
exit 1
fi
exit 0
# EOF
+49
View File
@@ -0,0 +1,49 @@
#!/bin/sh
#
# Check that process ID can be written to a file as described in the manual.
# Dummy assignments for "shellcheck".
testSubject="${testSubject:-false}"; workFile1="${workFile1:-.tmp1}"
# Check we can run "kill -s 0".
if ! kill -s 0 $$ >/dev/null 2>&1; then
echo "cannot check process existence with \`kill -s 0'"
exit 2
fi
dd if=/dev/zero bs=150 count=1 2>/dev/null \
| "${testSubject}" -q -L 50 -P "${workFile1}" >/dev/null 2>/dev/null \
&
testPid="$!"
sleep 1
storedPid=$(cat "${workFile1}" 2>/dev/null)
pidValid="0"
kill -s 0 "${storedPid}" 2>/dev/null && pidValid="1"
wait
sleep 1
if test -s "${workFile1}"; then
echo "PID file was not removed on exit"
exit 1
fi
true > "${workFile1}"
if ! test "${testPid}" = "${storedPid}"; then
echo "stored PID [${storedPid}] did not match actual PID [${testPid}]"
exit 1
fi
if ! test "${pidValid}" = "1"; then
echo "stored PID [${storedPid}] was not reachable"
exit 1
fi
exit 0
# EOF
+36
View File
@@ -0,0 +1,36 @@
#!/bin/sh
#
# Check that the progress bar is produced when "--force" is used, and is not
# when it is not, providing stderr is a file.
# Dummy assignments for "shellcheck".
testSubject="${testSubject:-false}"; workFile1="${workFile1:-.tmp1}";
dd if=/dev/zero bs=100 count=1 2>/dev/null \
| "${testSubject}" -f -p -i 0.1 -L 100 >/dev/null 2>"${workFile1}"
# There should be more than 2 different lines of output.
#
lineCount=$(tr '\r' '\n' < "${workFile1}" | sort | uniq -u | wc -l | tr -dc '0-9')
if ! test "${lineCount}" -gt 2; then
echo "fewer than 3 different progress lines with \"--force\" (${lineCount})"
tr '\r' '\n' < "${workFile1}" | sort | uniq -u
exit 1
fi
# Now try again without "--force".
dd if=/dev/zero bs=100 count=1 2>/dev/null \
| "${testSubject}" -p -i 0.1 -L 100 >/dev/null 2>"${workFile1}"
# There should be no output without "--force".
#
if test -s "${workFile1}"; then
echo "unexpected output when not using \"--force\""
tr '\r' '\n' < "${workFile1}" | sort | uniq -u
exit 1
fi
exit 0
# EOF