logo

utils-std

Collection of commonly available Unix tools
commit: 5b511928e0516a0df63e99070956d5d41102ba4a
parent 3beb5bd08df7a57d37cfbc4b541e9d8f34a4e40a
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Thu, 13 Jun 2024 19:12:52 +0200

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

Diffstat:

Mtest-cmd/basename.sh8++++----
Mtest-cmd/echo.sh8++++----
Mtest-cmd/tap.sh24+++++++++++++++++++++++-
Mtest-cmd/uname.sh8++++----
4 files changed, 35 insertions(+), 13 deletions(-)

diff --git a/test-cmd/basename.sh b/test-cmd/basename.sh @@ -16,13 +16,13 @@ t '-- /usr//bin' '-- /usr//bin' 'bin ' t 'suffix' '/usr//bin-test -test' 'bin ' -t '-' '-' '- +t dash '-' '- ' -t '--' '--' '. +t double-dash '--' '. ' -t '---' '---' '--- +t triple-dash '---' '--- ' -t '--a a' '--a a' '-- +t double-dash-letter '--a a' '-- ' #atf_test_case usage diff --git a/test-cmd/echo.sh b/test-cmd/echo.sh @@ -13,7 +13,7 @@ t 'hello' 'hello' 'hello t '-- hello' '-- hello' '-- hello ' -t '-n' '-n' '' -t '-n foo' '-n foo' 'foo' -t '-n foo bar' '-n foo bar' 'foo bar' -t '-n -- foo' '-n -- foo' '-- foo' +t -- '-n' '-n' '' +t -- '-n foo' '-n foo' 'foo' +t -- '-n foo bar' '-n foo bar' 'foo bar' +t -- '-n -- foo' '-n -- foo' '-- foo' diff --git a/test-cmd/tap.sh b/test-cmd/tap.sh @@ -11,12 +11,34 @@ err=0 # $3 -> expected output t () { + exp_ret=0 + for i; do + case "$i" in + --exit=*) + exp_ret="${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 + 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="$?" out="${out%/}" - if [ "$?" != 0 ]; then + if [ "$ret" != "$exp_ret" ]; then printf 'not ok %d - %s\n' "$count" "$1" echo "$out" | sed -e 's;^;# ;' err=1 diff --git a/test-cmd/uname.sh b/test-cmd/uname.sh @@ -15,11 +15,11 @@ plans=5 t 'no args' '' "$(uname -s) " -t '-s' '-s' "$(uname -s) +t 's' '-s' "$(uname -s) " -t '-a' '-a' "$(uname -s) $(uname -n) $(uname -r) $(uname -v) $(uname -m) +t 'a' '-a' "$(uname -s) $(uname -n) $(uname -r) $(uname -v) $(uname -m) " -t '-n' '-n' "$(hostname) +t 'n' '-n' "$(hostname) " -if has_cmd arch; then t '-m' '-m' "$(arch) +if has_cmd arch; then t 'm' '-m' "$(arch) "; else skip '-m' "no arch command"; fi