logo

utils-std

Collection of commonly available Unix tools
commit: 4450c9b322c7b5a3857ed0f7e2ff5027edecca5d
parent 1ead2b566dabc6a1708358b4f4605d9cc017a517
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Mon,  8 Jul 2024 01:38:59 +0200

test-cmd/tap.sh: Add --input option

Diffstat:

Mtest-cmd/tap.sh23++++++++++++++++++-----
1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/test-cmd/tap.sh b/test-cmd/tap.sh @@ -18,6 +18,10 @@ t () exp_ret="${i#*=}" shift ;; + --input=*) + input="${i#*=}" + shift + ;; --) shift break @@ -33,14 +37,23 @@ t () esac done - count=$((count+1)) - # Append a final slash so sh(1) doesn't trims final newlines - out="$("${target?}" $2 2>&1;r=$?;echo -n /;exit $r)" - ret="$?" + if [ "${input+set}" = "set" ]; then + # Append a final slash so sh(1) doesn't trims final newlines + out="$(printf "${input?}" | "${target?}" $2 2>&1;r=$?;echo -n /;exit $r)" + ret="$?" + else + # Append a final slash so sh(1) doesn't trims final newlines + out="$("${target?}" $2 2>&1;r=$?;echo -n /;exit $r)" + ret="$?" + fi + out="${out%/}" + count=$((count+1)) + if [ "$ret" != "$exp_ret" ]; then printf 'not ok %d - %s\n' "$count" "$1" - echo "$out" | sed -e 's;^;# ;' + printf '# Expected exit code %d, got %d\n' "$exp_ret" "$ret" + printf "$out" | sed -e 's;^;# ;' err=1 elif [ "$out" != "$3" ]; then printf 'not ok %d - %s\n' "$count" "$1"