aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--scripts/runtest.sh46
-rwxr-xr-xtests/base64.test16
-rwxr-xr-xtests/basename.test18
3 files changed, 49 insertions, 31 deletions
diff --git a/scripts/runtest.sh b/scripts/runtest.sh
index 6e94d945..e07c6a2e 100644
--- a/scripts/runtest.sh
+++ b/scripts/runtest.sh
@@ -2,28 +2,34 @@
#
# Copyright 2005 by Rob Landley
-# This file defines two functions, "testing" and "optionflag"
+# This file defines two main functions, "testcmd" and "optional". The
+# first performs a test, the second enables/disables tests based on
+# configuration options.
# The following environment variables enable optional behavior in "testing":
# DEBUG - Show every command run by test script.
# VERBOSE - Print the diff -u of each failed test case.
# If equal to "fail", stop after first failed test.
-# SKIP - do not perform this test (this is set by "optionflag")
#
-# The "testing" function takes five arguments:
+# The "testcmd" function takes five arguments:
# $1) Description to display when running command
# $2) Command line arguments to command
# $3) Expected result (on stdout)
# $4) Data written to file "input"
# $5) Data written to stdin
#
-# The exit value of testing is the exit value of the command it ran.
+# The "testing" function is like testcmd but takes a complete command line
+# (I.E. you have to include the command name.) The variable $C is an absolute
+# path to the command being tested, which can bypass shell builtins.
+#
+# The exit value of testcmd is the exit value of the command it ran.
#
# The environment variable "FAILCOUNT" contains a cumulative total of the
# number of failed tests.
-
-# The "optional" function is used to skip certain tests, ala:
-# optionflag CFG_THINGY
+#
+# The "optional" function is used to skip certain tests (by setting the
+# environment variable SKIP), ala:
+# optional CFG_THINGY
#
# The "optional" function checks the environment variable "OPTIONFLAGS",
# which is either empty (in which case it always clears SKIP) or
@@ -60,18 +66,23 @@ optional()
SKIP=1
}
-# The testing function
-
-testing()
+wrong_args()
{
- NAME="$CMDNAME $1"
- [ -z "$1" ] && NAME=$2
-
if [ $# -ne 5 ]
then
echo "Test $NAME has the wrong number of arguments ($# $*)" >&2
exit
fi
+}
+
+# The testing function
+
+testing()
+{
+ wrong_args "$@"
+
+ NAME="$CMDNAME $1"
+ [ -z "$1" ] && NAME=$2
[ -n "$DEBUG" ] && set -x
@@ -89,7 +100,7 @@ testing()
# Catch segfaults
[ $RETVAL -gt 128 ] && [ $RETVAL -lt 255 ] &&
echo "exited with signal (or returned $RETVAL)" >> actual
-
+
DIFF="$(diff -au${NOSPACE:+b} expected actual)"
if [ ! -z "$DIFF" ]
then
@@ -112,6 +123,13 @@ testing()
return 0
}
+testcmd()
+{
+ wrong_args "$@"
+
+ testing "$1" "$C $2" "$3" "$4" "$5"
+}
+
# Recursively grab an executable and all the libraries needed to run it.
# Source paths beginning with / will be copied into destpath, otherwise
# the file is assumed to already be there and only its library dependencies
diff --git a/tests/base64.test b/tests/base64.test
index 2058198b..7e5a99a3 100755
--- a/tests/base64.test
+++ b/tests/base64.test
@@ -4,21 +4,21 @@
#testing "name" "command" "result" "infile" "stdin"
-testing "simple" "base64" "c2ltcGxlCg==\n" "" "simple\n"
-testing "file" "base64 input" "c2ltcGxlCg==\n" "simple\n" ""
-testing "simple -d" "base64 -d" "simple\n" "" "c2ltcGxlCg==\n"
-testing "simple -d" "base64 -d input" "simple\n" "c2ltcGxlCg==" ""
-testing "default wrap" "base64" \
+testcmd "simple" "" "c2ltcGxlCg==\n" "" "simple\n"
+testcmd "file" "input" "c2ltcGxlCg==\n" "simple\n" ""
+testcmd "simple -d" "-d" "simple\n" "" "c2ltcGxlCg==\n"
+testcmd "simple -d" "-d input" "simple\n" "c2ltcGxlCg==" ""
+testcmd "default wrap" "" \
"V2UndmUgcmVwbGFjZWQgdGhlIGRpbGl0aGl1bSB0aGV5IG5vcm1hbGx5IHVzZSB3aXRoIEZvbGdl\ncidzIENyeXN0YWxzLg==\n" \
"" "We've replaced the dilithium they normally use with Folger's Crystals."
-testing "multiline -d " "base64 -d" \
+testcmd "multiline -d " "-d" \
"We've replaced the dilithium they normally use with Folger's Crystals." "" \
"V2UndmUgcmVwbGFjZWQgdGhlIGRpbGl0aGl1bSB0aGV5IG5vcm1hbGx5IHVzZSB3aXRoIEZvbGdl\ncidzIENyeXN0YWxzLg==\n"
-testing "-w" "base64 -w 10" \
+testcmd "-w" "-w 10" \
"TWFyY2hpbm\ncgdG8gdGhl\nIGJlYXQgb2\nYgYSBkaWZm\nZXJlbnQga2\nV0dGxlIG9m\nIGZpc2guCg\n==\n" \
"" "Marching to the beat of a different kettle of fish.\n"
-testing "-w0" "base64 -w0 input" \
+testcmd "-w0" "-w0 input" \
"VmlraW5ncz8gVGhlcmUgYWluJ3Qgbm8gdmlraW5ncyBoZXJlLiBKdXN0IHVzIGhvbmVzdCBmYXJtZXJzLiBUaGUgdG93biB3YXMgYnVybmluZywgdGhlIHZpbGxhZ2VycyB3ZXJlIGRlYWQuIFRoZXkgZGlkbid0IG5lZWQgdGhvc2Ugc2hlZXAgYW55d2F5LiBUaGF0J3Mgb3VyIHN0b3J5IGFuZCB3ZSdyZSBzdGlja2luZyB0byBpdC4K" \
"Vikings? There ain't no vikings here. Just us honest farmers. The town was burning, the villagers were dead. They didn't need those sheep anyway. That's our story and we're sticking to it.\n" ""
diff --git a/tests/basename.test b/tests/basename.test
index ab2cc20a..25e5493f 100755
--- a/tests/basename.test
+++ b/tests/basename.test
@@ -5,22 +5,22 @@
#testing "name" "command" "result" "infile" "stdin"
# Removal of extra /'s
-testing "/-only" "basename ///////" "/\n" "" ""
-testing "trailing /" "basename a//////" "a\n" "" ""
-testing "combined" "basename /////a///b///c///d/////" "d\n" "" ""
+testcmd "/-only" "///////" "/\n" "" ""
+testcmd "trailing /" "a//////" "a\n" "" ""
+testcmd "combined" "/////a///b///c///d/////" "d\n" "" ""
# Standard suffix behavior.
-testing "suffix" "basename a/b/c/d.suffix .suffix" "d\n" "" ""
+testcmd "suffix" "a/b/c/d.suffix .suffix" "d\n" "" ""
# A suffix cannot be the entire result.
-testing "suffix=result" "basename .txt .txt" ".txt\n" "" ""
+testcmd "suffix=result" ".txt .txt" ".txt\n" "" ""
# Deal with suffix appearing in the filename
-testing "reappearing suffix 1" "basename a.txt.txt .txt" "a.txt\n" "" ""
-testing "reappearing suffix 2" "basename a.txt.old .txt" "a.txt.old\n" "" ""
+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.
-testing "invalid suffix" "basename isthisasuffix? suffix" "isthisasuffix?\n" "" ""
+testcmd "invalid suffix" "isthisasuffix? suffix" "isthisasuffix?\n" "" ""
# Zero-length suffix
-testing "zero-length suffix" "basename a/b/c ''" "c\n" "" ""
+testcmd "zero-length suffix" "a/b/c ''" "c\n" "" ""