#!/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 # Test again with -C to ensure that it works with splice turned off. printf '%s\n' 'abcdefghi' | ( "${testSubject}" -qCSs5 > "${workFile1}" cat > "${workFile2}" ) # pv should have read 5 bytes and put them into workFile1. pvOutput="$(cat "${workFile1}")" if ! test "${pvOutput}" = 'abcde'; then echo "with -C, 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 "with pv -C, expected cat to write [fghi], got [${catOutput}]" exit 1 fi exit 0