diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2012-09-17 00:03:08 +0100 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2012-09-17 00:03:08 +0100 |
commit | 0a6cc823727f95c515a1d927b9bc47027a4b1cf3 (patch) | |
tree | 9f522777c3636ec897e72e546469089dd3374d66 | |
download | shcmdtest-0a6cc823727f95c515a1d927b9bc47027a4b1cf3.tar.bz2 |
Initial badger
-rwxr-xr-x | echo-tests/hello.script | 2 | ||||
-rwxr-xr-x | echo-tests/hello.setup | 3 | ||||
-rw-r--r-- | echo-tests/hello.stdout | 1 | ||||
-rwxr-xr-x | echo-tests/setup_once | 4 | ||||
-rwxr-xr-x | fail-tests/fail-code.script | 4 | ||||
-rwxr-xr-x | fail-tests/fail.script | 4 | ||||
-rwxr-xr-x | shcmdtest | 132 | ||||
-rwxr-xr-x | sort-tests/empty.script | 3 | ||||
-rwxr-xr-x | sort-tests/empty.setup | 3 | ||||
-rw-r--r-- | sort-tests/empty.stdin | 0 | ||||
-rw-r--r-- | sort-tests/empty.stdout | 0 | ||||
-rwxr-xr-x | sort-tests/setup | 3 | ||||
-rwxr-xr-x | sort-tests/setup_once | 3 | ||||
-rwxr-xr-x | sort-tests/single-line.script | 3 | ||||
-rw-r--r-- | sort-tests/single-line.stdin | 1 | ||||
-rw-r--r-- | sort-tests/single-line.stdout | 1 | ||||
-rwxr-xr-x | space provided-tests/something with spaces.script | 3 | ||||
-rw-r--r-- | space provided-tests/something with spaces.stdout | 1 |
18 files changed, 171 insertions, 0 deletions
diff --git a/echo-tests/hello.script b/echo-tests/hello.script new file mode 100755 index 0000000..9b24f76 --- /dev/null +++ b/echo-tests/hello.script @@ -0,0 +1,2 @@ +#!/bin/sh +echo hello, world diff --git a/echo-tests/hello.setup b/echo-tests/hello.setup new file mode 100755 index 0000000..55c29a9 --- /dev/null +++ b/echo-tests/hello.setup @@ -0,0 +1,3 @@ +#!/bin/sh + +echo "hello.setup runs" diff --git a/echo-tests/hello.stdout b/echo-tests/hello.stdout new file mode 100644 index 0000000..4b5fa63 --- /dev/null +++ b/echo-tests/hello.stdout @@ -0,0 +1 @@ +hello, world diff --git a/echo-tests/setup_once b/echo-tests/setup_once new file mode 100755 index 0000000..19c5bba --- /dev/null +++ b/echo-tests/setup_once @@ -0,0 +1,4 @@ +#!/bin/sh + +echo "setup-once runs" + diff --git a/fail-tests/fail-code.script b/fail-tests/fail-code.script new file mode 100755 index 0000000..69c3dc4 --- /dev/null +++ b/fail-tests/fail-code.script @@ -0,0 +1,4 @@ +#!/bin/sh + +exit 1 + diff --git a/fail-tests/fail.script b/fail-tests/fail.script new file mode 100755 index 0000000..60fefe9 --- /dev/null +++ b/fail-tests/fail.script @@ -0,0 +1,4 @@ +#!/bin/sh + +echo "file used by test" > "$DATADIR/file.txt" +echo "this is not empty output to make test fail" diff --git a/shcmdtest b/shcmdtest new file mode 100755 index 0000000..77277a8 --- /dev/null +++ b/shcmdtest @@ -0,0 +1,132 @@ +#!/bin/sh + +TESTS="" +ONCE="" + +for D in "$@"; do + for TEST in "$D/"*.script; do + if test "x${ONCE}" = "x"; then + ONCE=1 + set -- "${TEST}" + else + set -- "$@" "${TEST}" + fi + done +done + +OLD_DIR="" +LOCALTMPDIR=$(mktemp -d) +DATADIR="${LOCALTMPDIR}/data" +SRCDIR=$(pwd) + +export DATADIR SRCDIR + +mkdir "${DATADIR}" +blow_away () { rm -fr "${LOCALTMPDIR}"; } +trap blow_away 0 + +TEST_COUNT=0 +PASSES=0 +FAILS=0 + +teardown_once () { + test -x "$1/teardown-once" && "$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 +} + +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 +} + +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 +} + +FAILMSGS="" + +pass_fail () { + TEST_COUNT=$(($TEST_COUNT + 1)) + if test "x$1" = "x0"; then + PASSES=$(($PASSES + 1)) + else + FAILS=$(($FAILS + 1)) + THIS_FAIL=1 + if test "x$4" != "x"; then + FAILMSGS="${FAILMSGS}\n$(cat $4)" + else + FAILMSGS="${FAILMSGS}\n$2: $3\n" + fi + fi +} + +runtest () { + THIS_FAIL=0 + TESTNAME="$2" + export TESTNAME + 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" + TEST_EXIT=$? + else + "$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") + WANT_EXIT=${WANT_EXIT:-0} + test "x$TEST_EXIT" = "x$WANT_EXIT" + 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" + else + diff -u /dev/null "$1/$2.stdout-actual" > "$1/$2.stdout-diff" + pass_fail "$?" "$1/$2" "stdout differs" "$1/$2.stdout-diff" + fi + if test -r "$1/$2.stderr"; then + diff -u "$1/$2.stderr" "$1/$2.stderr-actual" > "$1/$2.stderr-diff" + 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" + fi + if test "x$THIS_FAIL" = "x0"; then + rm -f "$1/$2.stdout-actual" "$1/$2.stderr-actual" + rm -f "$1/$2.stdout-diff" "$1/$2.stderr-diff" + 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}" + setup_once "${CUR_DIR}" + OLD_DIR="${CUR_DIR}" + fi + TEST_NAME=$(basename "$T" .script) + setup_for "${CUR_DIR}" "${TEST_NAME}" + runtest "${CUR_DIR}" "${TEST_NAME}" + teardown_for "${CUR_DIR}" "${TEST_NAME}" +done + +test "x${OLD_DIR}" != "x" && teardown_once "${OLD_DIR}" + +echo "${PASSES} / ${TEST_COUNT}" +echo "${FAILMSGS}" + +for F in "$@"; do + echo "$F:" + cat "$F" +done diff --git a/sort-tests/empty.script b/sort-tests/empty.script new file mode 100755 index 0000000..fcd5074 --- /dev/null +++ b/sort-tests/empty.script @@ -0,0 +1,3 @@ +#!/bin/sh +set -e +sort "$@" diff --git a/sort-tests/empty.setup b/sort-tests/empty.setup new file mode 100755 index 0000000..89dccbe --- /dev/null +++ b/sort-tests/empty.setup @@ -0,0 +1,3 @@ +#!/bin/sh + +# nothing here diff --git a/sort-tests/empty.stdin b/sort-tests/empty.stdin new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/sort-tests/empty.stdin diff --git a/sort-tests/empty.stdout b/sort-tests/empty.stdout new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/sort-tests/empty.stdout diff --git a/sort-tests/setup b/sort-tests/setup new file mode 100755 index 0000000..89dccbe --- /dev/null +++ b/sort-tests/setup @@ -0,0 +1,3 @@ +#!/bin/sh + +# nothing here diff --git a/sort-tests/setup_once b/sort-tests/setup_once new file mode 100755 index 0000000..89dccbe --- /dev/null +++ b/sort-tests/setup_once @@ -0,0 +1,3 @@ +#!/bin/sh + +# nothing here diff --git a/sort-tests/single-line.script b/sort-tests/single-line.script new file mode 100755 index 0000000..fcd5074 --- /dev/null +++ b/sort-tests/single-line.script @@ -0,0 +1,3 @@ +#!/bin/sh +set -e +sort "$@" diff --git a/sort-tests/single-line.stdin b/sort-tests/single-line.stdin new file mode 100644 index 0000000..4b5fa63 --- /dev/null +++ b/sort-tests/single-line.stdin @@ -0,0 +1 @@ +hello, world diff --git a/sort-tests/single-line.stdout b/sort-tests/single-line.stdout new file mode 100644 index 0000000..4b5fa63 --- /dev/null +++ b/sort-tests/single-line.stdout @@ -0,0 +1 @@ +hello, world diff --git a/space provided-tests/something with spaces.script b/space provided-tests/something with spaces.script new file mode 100755 index 0000000..ef1c770 --- /dev/null +++ b/space provided-tests/something with spaces.script @@ -0,0 +1,3 @@ +#!/bin/sh + +echo Hurrah diff --git a/space provided-tests/something with spaces.stdout b/space provided-tests/something with spaces.stdout new file mode 100644 index 0000000..3db845c --- /dev/null +++ b/space provided-tests/something with spaces.stdout @@ -0,0 +1 @@ +Hurrah |