From d864c3f1f72b368056da894a2a813563b19ffaa8 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sun, 15 Nov 2026 00:55:21 -0600 Subject: [PATCH] Add tst and tsc functions to run testing and tstcmd with only 3 args. --- scripts/runtest.sh | 29 ++++++++--------------------- tests/basename.test | 37 ++++++++++++------------------------- 2 files changed, 20 insertions(+), 46 deletions(-) diff --git a/scripts/runtest.sh b/scripts/runtest.sh index 0f9f6792..e3dfd712 100644 --- a/scripts/runtest.sh +++ b/scripts/runtest.sh @@ -44,18 +44,13 @@ fi # Helper functions -skip_all() -{ - echo "$SHOWSKIP: $CMDNAME ($1)" - touch ../continue - exit 0 -} - +# Wrapper for "testing", adds command name being tested to start of command line +testcmd() { wrong_args "$@"; testing "$1" "\"$C\" $2" "$3" "$4" "$5"; } +tst() { testing "$1" "$2" "43" '' ''; } +tsc() { testcmd "$1" "$2" "$3" '' ''; } +skip_all() { echo "$SHOWSKIP: $CMDNAME ($1)"; touch ../continue; exit 0; } # Check if VERBOSE= contains a given string. (This allows combining.) -verbose_has() -{ - [ "${VERBOSE/$1/}" != "$VERBOSE" ] -} +verbose_has() { [ "${VERBOSE/$1/}" != "$VERBOSE" ]; } wrong_args() { @@ -68,10 +63,7 @@ wrong_args() } # Announce success -do_pass() -{ - verbose_has nopass || printf "%s\n" "$SHOWPASS: $NAME" -} +do_pass() { verbose_has nopass || printf "%s\n" "$SHOWPASS: $NAME"; } # Announce failure and handle fallout for txpect do_fail() @@ -170,12 +162,7 @@ testing() } # Wrapper for "testing", adds command name being tested to start of command line -testcmd() -{ - wrong_args "$@" - - testing "$1" "\"$C\" $2" "$3" "$4" "$5" -} +testcmd() { wrong_args "$@"; testing "$1" "\"$C\" $2" "$3" "$4" "$5"; } utf8locale() { diff --git a/tests/basename.test b/tests/basename.test index 9fd570f0..1c952932 100755 --- a/tests/basename.test +++ b/tests/basename.test @@ -4,28 +4,15 @@ #testing "name" "command" "result" "infile" "stdin" -# Removal of extra /'s -testcmd "/-only" "///////" "/\n" "" "" -testcmd "trailing /" "a//////" "a\n" "" "" -testcmd "combined" "/////a///b///c///d/////" "d\n" "" "" - -# Standard suffix behavior. -testcmd "suffix" "a/b/c/d.suffix .suffix" "d\n" "" "" - -# A suffix cannot be the entire result. -testcmd "suffix=result" ".txt .txt" ".txt\n" "" "" - -# Deal with suffix appearing in the filename -testcmd "reappearing suffix 1" "a.txt.txt .txt" "a.txt\n" "" "" -testcmd "reappearing suffix 2" "a.txt.old .txt" "a.txt.old\n" "" "" - -# A suffix should be a real suffix, only a the end. -testcmd "invalid suffix" "isthisasuffix? suffix" "isthisasuffix?\n" "" "" - -# Zero-length suffix -testcmd "zero-length suffix" "a/b/c ''" "c\n" "" "" - -# -s. -testcmd "-s" "-s .txt /a/b/c.txt" "c\n" "" "" -testcmd "-s implies -a" "-s .txt /a/b/c.txt /a/b/d.txt" "c\nd\n" "" "" -testcmd "-a" "-a /a/b/f1 /c/d/f2" "f1\nf2\n" "" "" +tsc '/-only' '///////' '/\n' +tsc 'trailing /' 'a//////' 'a\n' +tsc 'combined' '/////a///b///c///d/////' 'd\n' +tsc 'suffix' 'a/b/c/d.suffix .suffix' 'd\n' +tsc 'suffix=result' '.txt .txt' '.txt\n' +tsc 'suffix in name 1' 'a.txt.txt .txt' 'a.txt\n' +tsc 'suffix in name 2' 'a.txt.old .txt' 'a.txt.old\n' +tsc 'invalid suffix' 'isthisasuffix? suffix' 'isthisasuffix?\n' +tsc 'zero-length suffix' 'a/b/c ""' 'c\n' +tsc '-s' '-s .txt /a/b/c.txt' 'c\n' +tsc '-s implies -a' '-s .txt /a/b/c.txt /a/b/d.txt' 'c\nd\n' +tsc '-a' '-a /a/b/f1 /c/d/f2' 'f1\nf2\n' -- 2.39.5