1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
#!/bin/sh
#
# Check that line mode counts lines instead of bytes.
# Allow all tests to be skipped, e.g. during a release build
test "${SKIP_ALL_TESTS}" = "1" && exit 77
true "${testSubject:?not set - call this from 'make check'}"
true "${workFile1:?not set - call this from 'make check'}"
# Pass through 100 lines.
#
seq 1 100 \
| "${testSubject}" -bl -i 0.2 -f -L 50 >/dev/null 2>"${workFile1}"
lineCount=$(tr '\r' '\n' < "${workFile1}" | sort | uniq -u | wc -l | tr -dc '0-9')
lastNumber=$(tr '\r' '\n' < "${workFile1}" | awk '/[0-9]/{printf "%.0f\n",$1}' | sed -n '$p')
# The last number output should be the number of input lines.
if ! test "${lastNumber}" = "100"; then
echo "line counter was incorrect (${lastNumber} instead of 100)"
tr '\r' '\n' < "${workFile1}"
exit 1
fi
# There should be more than 3 output lines as the counter increased.
if ! test "${lineCount}" -gt 3; then
echo "fewer than 4 line counter values (${lineCount})"
tr '\r' '\n' < "${workFile1}"
exit 1
fi
exit 0
|