Commits

Greg Ward  committed 41a33dc

Factor common.sh out of test-simple.

  • Participants
  • Parent commits a95fc88

Comments (0)

Files changed (3)

 
 .PHONY: check
 check: vcprompt
-	./tests/test-simple
+	cd tests && ./test-simple
 
 clean:
 	rm -f $(objects) vcprompt

File tests/common.sh

+# where to find all the test files
+testdir=`pwd`
+
+# other globals set by functions here
+vcprompt=""
+tmpdir=""
+
+find_vcprompt()
+{
+    vcprompt=$(dirname $(dirname $(readlink -f $0)))/vcprompt
+    if [ ! -x $vcprompt ]; then
+	echo "error: vcprompt executable not found (expected $vcprompt)" >&2
+	exit 1
+    fi
+}
+
+setup()
+{
+    tmpdir=`mktemp -d`
+    trap cleanup 0 1 2 15
+}
+
+cleanup()
+{
+    chmod -R u+rwx $tmpdir
+    rm -rf $tmpdir
+}
+
+assert_vcprompt()
+{
+    message=$1
+    expect=$2
+    format=$3
+    if [ -z "$format" ]; then
+        format="%b"
+    fi
+
+    if [ "$format" != '-' ]; then
+        actual=`VCPROMPT_FORMAT="$VCPROMPT_FORMAT" $vcprompt -f "$format"`
+    else
+        actual=`VCPROMPT_FORMAT="$VCPROMPT_FORMAT" $vcprompt`
+    fi
+
+    if [ "$expect" != "$actual" ]; then
+        echo "fail: $message: expected \"$expect\", but got \"$actual\"" >&2
+        failed="y"
+        return 1
+    else
+        echo "pass: $message"
+    fi
+}
+
+report()
+{
+    if [ "$failed" ]; then
+	echo "$0: some tests failed"
+	exit 1
+    else
+	echo "$0: all tests passed"
+	exit 0
+    fi
+}

File tests/test-simple

 # these just setup little fake working copies and make sure
 # that vcprompt does the right thing in them.
 
-vcprompt=$(dirname $(dirname $(readlink -f $0)))/vcprompt
-if [ ! -x $vcprompt ]; then
-    echo "error: vcprompt executable not found (expected $vcprompt)" >&2
-    exit 1
-fi
-
-setup()
-{
-    tmpdir=`mktemp -d`
-    trap cleanup 0 1 2 15
-}
-
-cleanup()
-{
-    chmod -R u+rwx $tmpdir
-    rm -rf $tmpdir
-}
-
-failed=""
-assert_vcprompt()
-{
-    message=$1
-    expect=$2
-    format=$3
-    if [ -z "$format" ]; then
-        format="%b"
-    fi
-
-    if [ "$format" != '-' ]; then
-        actual=`VCPROMPT_FORMAT="$VCPROMPT_FORMAT" $vcprompt -f "$format"`
-    else
-        actual=`VCPROMPT_FORMAT="$VCPROMPT_FORMAT" $vcprompt`
-    fi
-
-    if [ "$expect" != "$actual" ]; then
-        echo "fail: $message: expected \"$expect\", but got \"$actual\"" >&2
-        failed="y"
-        return 1
-    else
-        echo "pass: $message"
-    fi
-}
+source ./common.sh
 
 test_no_vc()
 {
     echo "pass: help text"
 }
 
-
 #set -e
 
+find_vcprompt
 setup
 
+failed=""
+
 test_no_vc
 test_root
 test_simple_cvs
 test_env_var
 test_help
 
-if [ "$failed" ]; then
-    echo "$0: some tests failed"
-    exit 1
-else
-    echo "$0: all tests passed"
-    exit 0
-fi
+report