aboutsummaryrefslogtreecommitdiff
path: root/tests/libtest.sh
diff options
context:
space:
mode:
authorRuss Allbery <rra@stanford.edu>2008-01-05 00:01:54 +0000
committerRuss Allbery <rra@stanford.edu>2008-01-05 00:01:54 +0000
commitb10beb347238b153af8aa544fb276485b34e970e (patch)
tree4105c927be0912b2fa9f479a1aaf785091ff8f64 /tests/libtest.sh
parenta67ad3fc36765f4b948a3e9c941318ff8931a11d (diff)
The wallet client can now get the server, port, principal, and remctl
type from krb5.conf as well as from compile-time defaults and command-line options.
Diffstat (limited to 'tests/libtest.sh')
-rw-r--r--tests/libtest.sh82
1 files changed, 82 insertions, 0 deletions
diff --git a/tests/libtest.sh b/tests/libtest.sh
new file mode 100644
index 0000000..ed46d0e
--- /dev/null
+++ b/tests/libtest.sh
@@ -0,0 +1,82 @@
+# $Id$
+#
+# Shell function library for test cases.
+#
+# Written by Russ Allbery <rra@stanford.edu>
+# Copyright 2006, 2007, 2008 Board of Trustees, Leland Stanford Jr. University
+#
+# See LICENSE for licensing terms.
+
+# The count starts at 1 and is updated each time ok is printed. printcount
+# takes "ok" or "not ok".
+count=1
+printcount () {
+ echo "$1 $count $2"
+ count=`expr $count + 1`
+}
+
+# Run a program expected to succeed, and print ok if it does and produces
+# the correct output. Takes the output as the first argument, the command to
+# run as the second argument, and then all subsequent arguments are arguments
+# to the command.
+runsuccess () {
+ w_output="$1"
+ shift
+ output=`"$@" 2>&1`
+ status=$?
+ if [ $status = 0 ] && [ x"$output" = x"$w_output" ] ; then
+ printcount 'ok'
+ else
+ printcount 'not ok'
+ echo " saw: $output"
+ echo " not: $w_output"
+ fi
+}
+
+# Run a program expected to fail and make sure it fails with the correct exit
+# status and the correct failure message. Takes the expected status, the
+# expected output, and then everything else is the command and arguments.
+# Strip the second colon and everything after it off the error message since
+# it's system-specific.
+runfailure () {
+ w_status="$1"
+ shift
+ w_output="$1"
+ shift
+ output=`"$@" 2>&1`
+ status=$?
+ output=`echo "$output" | sed 's/\(:[^:]*\):.*/\1/'`
+ if [ $status = $w_status ] && [ x"$output" = x"$w_output" ] ; then
+ printcount 'ok'
+ else
+ printcount 'not ok'
+ echo " saw: ($status) $output"
+ echo " not: ($w_status) $w_output"
+ fi
+}
+
+# Skip tests from $1 to $2 inclusive with reason $3.
+skip () {
+ n="$1"
+ while [ "$n" -le "$2" ] ; do
+ echo ok "$n # skip $3"
+ n=`expr "$n" + 1`
+ done
+}
+
+# Given a file name or relative file path, try to cd to the correct directory
+# so that the relative file path is valid. Exits with an error if that isn't
+# possible.
+chdir_data () {
+ if [ -f "../$1" ] ; then
+ cd ..
+ else
+ if [ -f "tests/$1" ] ; then
+ cd tests
+ fi
+ fi
+ if [ ! -f "$1" ] ; then
+ echo "Cannot locate $1" >&2
+ exit 1
+ fi
+}