test case framework
authordiv0 <div0@f962a42d-fe04-0410-a3ab-8c8b0445ebaa>
Sat, 27 Feb 2010 17:32:04 +0000 (17:32 +0000)
committerdiv0 <div0@f962a42d-fe04-0410-a3ab-8c8b0445ebaa>
Sat, 27 Feb 2010 17:32:04 +0000 (17:32 +0000)
git-svn-id: svn://svn.icculus.org/nexuiz/trunk@8675 f962a42d-fe04-0410-a3ab-8c8b0445ebaa

data/qcsrc/server-testcase/framework.qc [new file with mode: 0644]
data/qcsrc/server-testcase/progs.src [new file with mode: 0644]
data/qcsrc/server-testcase/run.sh [new file with mode: 0755]

diff --git a/data/qcsrc/server-testcase/framework.qc b/data/qcsrc/server-testcase/framework.qc
new file mode 100644 (file)
index 0000000..1929849
--- /dev/null
@@ -0,0 +1,14 @@
+void error(string e) = #10;
+float test();
+
+void spawnfunc_worldspawn()
+{
+       float r;
+       r = test();
+       if(r == 1)
+               error("TESTCASE: PASS"); 
+       else if(r == 0)
+               error("TESTCASE: FAIL"); 
+       else
+               error("TESTCASE: INVALID"); 
+}
diff --git a/data/qcsrc/server-testcase/progs.src b/data/qcsrc/server-testcase/progs.src
new file mode 100644 (file)
index 0000000..bd5c571
--- /dev/null
@@ -0,0 +1,4 @@
+../../progs-testcase.dat
+../server/sys.qh
+framework.qc
+testcase.qc
diff --git a/data/qcsrc/server-testcase/run.sh b/data/qcsrc/server-testcase/run.sh
new file mode 100755 (executable)
index 0000000..a6e2120
--- /dev/null
@@ -0,0 +1,43 @@
+#!/bin/sh
+
+if [ "$#" -lt 3 ]; then
+       echo "Usage: $0 'float test() { if(fail) return 0; else if(good) return 1; else return -1; }' ./darkplaces-dedicated basement +sv_cheats 1"
+       exit 125
+fi
+
+case "$0" in
+       */*)
+               dir=${0%/*}
+               ;;
+       *)
+               dir=`pwd`
+               ;;
+esac
+testcase=$1; shift
+engine=$1; shift
+map=$1; shift
+echo "$testcase" > "$dir/testcase.qc"
+if ( cd $dir && fteqcc ); then
+       r=`"$engine" -nexuiz -basedir "$dir/../../.." +sv_progs progs-testcase.dat "$@" +map "$map" | tee /dev/stderr`
+       case "$r" in
+               *"TESTCASE: PASS"*)
+                       echo "PASS detected"
+                       exit 0
+                       ;;
+               *"TESTCASE: FAIL"*)
+                       echo "FAIL detected"
+                       exit 1
+                       ;;
+               *"TESTCASE: INVALID"*)
+                       echo "INVALID detected"
+                       exit 125
+                       ;;
+               *)
+                       echo "Running failed"
+                       exit 125
+                       ;;
+       esac
+else
+       echo "Compilation failed"
+       exit 125
+fi