summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <daniel.silverstone@codethink.co.uk>2012-09-17 10:14:42 +0100
committerDaniel Silverstone <daniel.silverstone@codethink.co.uk>2012-09-17 10:14:42 +0100
commit37b2d1e01f05834f9326c371bd8df92c59581a0e (patch)
treeb9d3737461084aa8c7207cb6f22349bf2386dfa5
parentc616e9f6983c5cbe07150f9e4dfb293e6abbbe7d (diff)
downloadshcmdtest-master.tar.bz2
More cleanupsHEADmaster
-rwxr-xr-xshcmdtest73
1 files changed, 33 insertions, 40 deletions
diff --git a/shcmdtest b/shcmdtest
index 494fbec..cf98abe 100755
--- a/shcmdtest
+++ b/shcmdtest
@@ -17,12 +17,10 @@ for D in "$@"; do
done
OLD_DIR=""
-LOCALTMPDIR=$(mktemp -d)
+LOCALTMPDIR=$(mktemp -d -t cmdtestXXXXXX)
DATADIR="${LOCALTMPDIR}/data"
SRCDIR=$(pwd)
-export DATADIR SRCDIR
-
mkdir "${DATADIR}"
blow_away () { rm -fr "${LOCALTMPDIR}"; }
trap blow_away 0
@@ -32,28 +30,40 @@ TEST_COUNT=0
PASSES=0
FAILS=0
+envme () {
+ env DATADIR="${DATADIR}" SRCDIR="${SRCDIR}" TESTNAME="${TEST_NAME}" "$@"
+}
+
teardown_once () {
- test -x "$1/teardown-once" && "$1/teardown-once" >/dev/null 2>/dev/null
+ test -x "$1/teardown-once" && envme "$1/teardown-once" >/dev/null 2>/dev/null
rm -fr "${DATADIR}"
mkdir "${DATADIR}"
}
setup_once () {
test -d "${DATADIR}" || mkdir "${DATADIR}"
- test -x "$1/setup-once" && "$1/setup-once" >/dev/null 2>/dev/null
+ test -x "$1/setup-once" && envme "$1/setup-once" >/dev/null 2>/dev/null
}
setup_for () {
- test -x "$1/setup" && "$1/setup" >/dev/null 2>/dev/null
- test -x "$1/$2.setup" && "$1/$2.setup" >/dev/null 2>/dev/null
+ test -x "$1/setup" && envme "$1/setup" >/dev/null 2>/dev/null
+ test -x "$1/$2.setup" && envme "$1/$2.setup" >/dev/null 2>/dev/null
}
teardown_for () {
- test -x "$1/$2.teardown" && "$1/$2.teardown" >/dev/null 2>/dev/null
- test -x "$1/teardown" && "$1/teardown" >/dev/null 2>/dev/null
+ test -x "$1/$2.teardown" && envme "$1/$2.teardown" >/dev/null 2>/dev/null
+ test -x "$1/teardown" && envme "$1/teardown" >/dev/null 2>/dev/null
}
-FAILMSGS=""
+
+clear_line () {
+ SPACES=$((${#LONGEST_NAME} + ${#SCRIPTS_RUN} + ${#SCRIPT_COUNT} + 3))
+ while test $SPACES -gt 0; do
+ echo -n " "
+ SPACES=$(($SPACES - 1))
+ done
+ echo -n -e '\r'
+}
pass_fail () {
TEST_COUNT=$(($TEST_COUNT + 1))
@@ -62,10 +72,11 @@ pass_fail () {
else
FAILS=$(($FAILS + 1))
THIS_FAIL=1
+ clear_line
if test "x$4" != "x"; then
- FAILMSGS="${FAILMSGS}\n$(cat $4)"
+ cat "$4"
else
- FAILMSGS="${FAILMSGS}\n$2: $3\n"
+ echo "$2: $3"
fi
fi
}
@@ -73,11 +84,9 @@ pass_fail () {
LONGEST_NAME=0
runtest () {
THIS_FAIL=0
- TESTNAME="$2"
- export TESTNAME
SCRIPTS_RUN=$(($SCRIPTS_RUN + 1))
- echo -n "${SCRIPTS_RUN}/${SCRIPT_COUNT}: ${TESTNAME}"
- TEST_LEN=${#TESTNAME}
+ echo -n "${SCRIPTS_RUN}/${SCRIPT_COUNT}: ${TEST_NAME}"
+ TEST_LEN=${#TEST_NAME}
if test $TEST_LEN -gt $LONGEST_NAME; then
LONGEST_NAME=$TEST_LEN
else
@@ -90,10 +99,12 @@ runtest () {
echo -n -e '\r'
if test -r "$1/$2.stdin"; then
# Run the test with stdin
- "$1/$2.script" < "$1/$2.stdin" > "$1/$2.stdout-actual" 2> "$1/$2.stderr-actual"
+ envme "$1/$2.script" < "$1/$2.stdin" \
+ > "$1/$2.stdout-actual" 2> "$1/$2.stderr-actual"
TEST_EXIT=$?
else
- "$1/$2.script" < /dev/null > "$1/$2.stdout-actual" 2> "$1/$2.stderr-actual"
+ envme "$1/$2.script" < /dev/null \
+ > "$1/$2.stdout-actual" 2> "$1/$2.stderr-actual"
TEST_EXIT=$?
fi
WANT_EXIT=$(test -r "$1/$2.exit" && cat "$1/$2.exit")
@@ -102,7 +113,7 @@ runtest () {
pass_fail "$?" "$1/$2" "exit code $TEST_EXIT is not $WANT_EXIT"
if test -r "$1/$2.stdout"; then
diff -u "$1/$2.stdout" "$1/$2.stdout-actual" > "$1/$2.stdout-diff"
- pass_fail "$?" "$1/$2" "stdout differs"
+ pass_fail "$?" "$1/$2" "stdout differs" "$1/$2.stdout-diff"
else
diff -u /dev/null "$1/$2.stdout-actual" > "$1/$2.stdout-diff"
pass_fail "$?" "$1/$2" "stdout differs" "$1/$2.stdout-diff"
@@ -112,7 +123,7 @@ runtest () {
pass_fail "$?" "$1/$2" "stderr differs" "$1/$2.stderr-diff"
else
diff -u /dev/null "$1/$2.stderr-actual" > "$1/$2.stdout-diff"
- pass_fail "$?" "$1/$2" "stderr differs"
+ pass_fail "$?" "$1/$2" "stderr differs" "$1/$2.stderr-diff"
fi
if test "x$THIS_FAIL" = "x0"; then
rm -f "$1/$2.stdout-actual" "$1/$2.stderr-actual"
@@ -120,12 +131,7 @@ runtest () {
fi
}
-ONCE=""
for T in "$@"; do
- if test "x${ONCE}" = "x"; then
- ONCE=1
- set --
- fi
CUR_DIR=$(dirname "$T")
if test "x${OLD_DIR}" != "x${CUR_DIR}"; then
test "x${OLD_DIR}" != "x" && teardown_once "${OLD_DIR}"
@@ -140,20 +146,7 @@ done
test "x${OLD_DIR}" != "x" && teardown_once "${OLD_DIR}"
-SPACES=$((${#LONGEST_NAME} + ${#SCRIPTS_RUN} + ${#SCRIPT_COUNT} + 3))
-while test $SPACES -gt 0; do
- echo -n " "
- SPACES=$(($SPACES - 1))
-done
-
-echo -n -e '\r'
+clear_line
-echo "Totals: ${SCRIPTS_RUN} tests run, comprising ${TEST_COUNT}."
+echo "Totals: ${SCRIPTS_RUN} tests run, comprising ${TEST_COUNT} assertions."
echo "Of those, ${PASSES} passed and ${FAILS} failed."
-
-echo "${FAILMSGS}"
-
-for F in "$@"; do
- echo "$F:"
- cat "$F"
-done