logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git
commit: 907b6082ff1356dbb8b60f83a705897f192ed6dc
parent 328a837b9672224c6dfca20d17845ca8a2655907
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Thu, 19 Sep 2024 08:50:10 +0200

test-cmd/tap.sh: add --exit and --infile to t_file

Diffstat:

Mtest-cmd/tap.sh32++++++++++++++++++++++++++++++--
1 file changed, 30 insertions(+), 2 deletions(-)

diff --git a/test-cmd/tap.sh b/test-cmd/tap.sh @@ -125,11 +125,35 @@ t_args() { fi } -# t_file <test_name> <file_expected> <arguments ...> +# t_file [--exit=n] [--infile=file] <test_name> <file_expected> [arguments ...] # file_expected is an existing file to compare output against t_file() { exp_ret=0 + for i; do + case "$i" in + --exit=*) + exp_ret="${i#*=}" + shift + ;; + --infile=*) + infile="${i#*=}" + shift + ;; + --) + shift + break + ;; + # Note: * is still a wildcard, even with a range before + -[a-zA-Z0-9]|--[a-zA-Z0-9]*=*) + printf 'Unknown option: %s\n' "$i" + exit 2 + ;; + *) + break + ;; + esac + done name="$1"; shift file="$1"; shift @@ -138,7 +162,11 @@ t_file() count=$((count+1)) out="$(mktemp)" - "${target?}" "$@" 2>&1 >"$out" + if [ "${infile+set}" = "set" ]; then + <"$infile" "${target?}" "$@" 2>&1 >"$out" + else + "${target?}" "$@" 2>&1 >"$out" + fi ret="$?" if [ "$ret" != "$exp_ret" ]; then