logo

utils-std

Collection of commonly available Unix tools
commit: 2ae981824b512e0550a695c4b36ad27f4d68c254
parent 146de4b710aefadd58adabba35a6c1c6783a8984
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Mon,  8 Jul 2024 03:58:49 +0200

test-cmd/base64.sh: Move t_file fonction into test-cmd/tap.sh

Diffstat:

Mtest-cmd/base64.sh26--------------------------
Mtest-cmd/tap.sh31++++++++++++++++++++++++++++---
2 files changed, 28 insertions(+), 29 deletions(-)

diff --git a/test-cmd/base64.sh b/test-cmd/base64.sh @@ -7,32 +7,6 @@ target="${WD}/../cmd/base64" plans=22 . "$(dirname "$0")/tap.sh" -# $1 -> name -# $2 -> arguments -# $3 -> file to compare output against -t_file() -{ - exp_ret=0 - - count=$((count+1)) - out="$(mktemp)" - "${target?}" $2 2>&1 >"$out" - ret="$?" - - if [ "$ret" != "$exp_ret" ]; then - printf 'not ok %d - %s\n' "$count" "$1" - printf '# Expected exit code %d, got %d\n' "$exp_ret" "$ret" - printf "$out" | sed -e 's;^;# ;' - err=1 - elif ! cmp -s "$out" "$3"; then - printf 'not ok %d - %s\n' "$count" "$1" - diff -u "$out" "$3" | sed -e 's;^;# ;' - err=1 - else - printf 'ok %d - %s\n' "$count" "$1" - fi -} - t devnull '/dev/null' '' t_file all_byte "$WD/inputs/all_bytes" "$WD/outputs/base64/all_bytes" diff --git a/test-cmd/tap.sh b/test-cmd/tap.sh @@ -6,9 +6,7 @@ count=0 err=0 -# $1 -> name -# $2 -> arguments -# $3 -> expected output +# t [--exit=n] [--input=str] <test_name> <arguments> <expected_output> t () { exp_ret=0 @@ -67,6 +65,33 @@ t () fi } +# $1 -> name +# $2 -> arguments +# $3 -> file to compare output against +t_file() +{ + exp_ret=0 + file="${3?}" + + count=$((count+1)) + out="$(mktemp)" + "${target?}" $2 2>&1 >"$out" + ret="$?" + + if [ "$ret" != "$exp_ret" ]; then + printf 'not ok %d - %s\n' "$count" "$1" + printf '# Expected exit code %d, got %d\n' "$exp_ret" "$ret" + printf "$out" | sed -e 's;^;# ;' + err=1 + elif ! cmp -s "${out?}" "$file"; then + printf 'not ok %d - %s\n' "$count" "$1" + diff -u "$out" "$file" | sed -e 's;^;# ;' + err=1 + else + printf 'ok %d - %s\n' "$count" "$1" + fi +} + t_end () { if [ $count -ne $plans ]