Add test for over-read when using stop-at-size (#166).
This commit is contained in:
@@ -99,6 +99,7 @@ tests/Terminal_-_Detect_width.test \
|
||||
tests/Transfer_-_--rate-limit.test \
|
||||
tests/Transfer_-_--remote.test \
|
||||
tests/Transfer_-_--stop-at-size.test \
|
||||
tests/Transfer_-_--stop-at-size_reads.test \
|
||||
tests/Watchfd_-_Multiple_descriptors.test \
|
||||
tests/Watchfd_-_Single_descriptor.test
|
||||
|
||||
|
||||
Executable
+54
@@ -0,0 +1,54 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Make sure -S stops reading at the given size.
|
||||
#
|
||||
# See https://codeberg.org/ivarch/pv/issues/166
|
||||
|
||||
# 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'}"
|
||||
true "${workFile2:?not set - call this from 'make check'}"
|
||||
|
||||
printf '%s\n' 'abcdefghi' | (
|
||||
"${testSubject}" -qSs5 > "${workFile1}"
|
||||
cat > "${workFile2}"
|
||||
)
|
||||
|
||||
# pv should have read 5 bytes and put them into workFile1.
|
||||
pvOutput="$(cat "${workFile1}")"
|
||||
if ! test "${pvOutput}" = 'abcde'; then
|
||||
echo "expected pv to write [abcde], got [${pvOutput}]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# cat should have read the remaining bytes and put them into workFile2.
|
||||
catOutput="$(cat "${workFile2}")"
|
||||
if ! test "${catOutput}" = 'fghi'; then
|
||||
echo "expected cat to write [fghi], got [${catOutput}]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Now repeat the test with -X to make sure there's no over-read there either.
|
||||
|
||||
printf '%s\n' 'abcdefghi' | (
|
||||
"${testSubject}" -qXSs5 > "${workFile1}"
|
||||
cat > "${workFile2}"
|
||||
)
|
||||
|
||||
# pv should have read 5 bytes and put nothing into workFile1.
|
||||
pvOutput="$(cat "${workFile1}")"
|
||||
if test -s "${workFile1}"; then
|
||||
echo "with -X, expected pv to write nothing, got [${pvOutput}]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# cat should have read the remaining bytes and put them into workFile2.
|
||||
catOutput="$(cat "${workFile2}")"
|
||||
if ! test "${catOutput}" = 'fghi'; then
|
||||
echo "with pv -X, expected cat to write [fghi], got [${catOutput}]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
exit 0
|
||||
Reference in New Issue
Block a user