From f83927e4515168df0e4a53371d680bea4c0dcc2f Mon Sep 17 00:00:00 2001 From: Andrew Wood Date: Tue, 25 Jul 2023 21:21:37 +0100 Subject: [PATCH] Add more tests --- tests/Display_-_--progress_-_increasing.sh | 32 ++++++++++++++ tests/General_-_--pidfile.sh | 49 ++++++++++++++++++++++ tests/Modifiers_-_--force.sh | 36 ++++++++++++++++ 3 files changed, 117 insertions(+) create mode 100644 tests/Display_-_--progress_-_increasing.sh create mode 100644 tests/General_-_--pidfile.sh create mode 100644 tests/Modifiers_-_--force.sh diff --git a/tests/Display_-_--progress_-_increasing.sh b/tests/Display_-_--progress_-_increasing.sh new file mode 100644 index 0000000..af05604 --- /dev/null +++ b/tests/Display_-_--progress_-_increasing.sh @@ -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 diff --git a/tests/General_-_--pidfile.sh b/tests/General_-_--pidfile.sh new file mode 100644 index 0000000..15aacef --- /dev/null +++ b/tests/General_-_--pidfile.sh @@ -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 diff --git a/tests/Modifiers_-_--force.sh b/tests/Modifiers_-_--force.sh new file mode 100644 index 0000000..33a4c34 --- /dev/null +++ b/tests/Modifiers_-_--force.sh @@ -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