[vala/tests: 2/2] tests: Support negative test cases



commit a0b44156250a6b884edd0a48ef3d4a10c762d811
Author: Luca Bruno <lucabru src gnome org>
Date:   Sat Jun 4 11:16:44 2011 +0200

    tests: Support negative test cases
    
    Fixes bug 630597.

 tests/Makefile.am                                  |    2 +-
 .../{bug646945.vala => bug646945.test}             |    9 ++++
 tests/testrunner.sh                                |   40 +++++++++++++------
 3 files changed, 37 insertions(+), 14 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index bec9a3f..83fa746 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -108,7 +108,7 @@ TESTS = \
 	asynchronous/bug620740.vala \
 	asynchronous/bug639591.vala \
 	asynchronous/bug641182.vala \
-	asynchronous/bug646945.vala \
+	asynchronous/bug646945.test \
 	asynchronous/closures.vala \
 	dbus/basic-types.test \
 	dbus/arrays.test \
diff --git a/tests/asynchronous/bug646945.vala b/tests/asynchronous/bug646945.test
similarity index 71%
rename from tests/asynchronous/bug646945.vala
rename to tests/asynchronous/bug646945.test
index ad17d48..2708b65 100644
--- a/tests/asynchronous/bug646945.vala
+++ b/tests/asynchronous/bug646945.test
@@ -1,3 +1,12 @@
+
+Negative: negative
+
+async void foo () { bar.callback (); }
+
+async void bar () { foo.callback (); }
+
+Program: positive
+
 class Foo : Object {
 	public virtual async void method1 () { }
 }
diff --git a/tests/testrunner.sh b/tests/testrunner.sh
index 7e52859..7b8ba48 100755
--- a/tests/testrunner.sh
+++ b/tests/testrunner.sh
@@ -54,6 +54,12 @@ function sourceheader() {
 		SOURCEFILES="$SOURCEFILES $SOURCEFILE"
 		echo "	case \"/$testpath\": $ns.main (); break;" >> main.vala
 		echo "namespace $ns {" > $SOURCEFILE
+	elif [ "$1" = "Negative:" ]; then
+		testpath=${testfile/.test/}/$2
+		ns=${testpath//\//.}
+		ns=${ns//-/_}
+		SOURCEFILE=$ns.vala
+		NEGATIVETEST=1
 	elif [ $GIRTEST -eq 1 ]; then
 		if [ "$1" = "Input:" ]; then
 			testpath=${testfile/.test/}
@@ -91,6 +97,9 @@ function sourceend() {
 				echo "</repository>" >> $SOURCEFILE
 			fi
 			echo "$VAPIGEN $VAPIGENFLAGS --library $ns $ns.gir && tail -n +5 $ns.vapi|head -n -1|sed '/^$/d'|sed 's/^\s*//'|cmp --quiet $ns.vapi.ref" > check
+		elif [ $NEGATIVETEST -eq 1 ]; then
+			echo "! $VALAC --vapidir $vapidir --fatal-warnings $([ -z "$PACKAGES" ] || echo $PACKAGES | xargs -n 1 echo -n " --pkg") -C $SOURCEFILE" > check
+			addtocheck
 		else
 			echo "}" >> $SOURCEFILE
 			echo "./test$EXEEXT /$testpath" > check
@@ -98,6 +107,21 @@ function sourceend() {
 	fi
 }
 
+function addtocheck() {
+	cat prepare check > $ns.check
+	cat << EOF >> checkall
+echo -n -e "  /$testpath: \033[72G"
+((all++))
+if bash $ns.check &>log; then
+	echo -e "\033[0;32mOK\033[m"
+else
+	((fail++))
+	echo -e "\033[0;31mFAIL\033[m"
+	cat log
+fi
+EOF
+}
+
 testdir=_test
 rm -rf $testdir
 mkdir $testdir
@@ -140,6 +164,7 @@ for testfile in "$@"; do
 		PART=0
 		INHEADER=1
 		GIRTEST=0
+		NEGATIVETEST=0
 		testpath=
 		while IFS="" read -r line; do
 			if [ $PART -eq 0 ]; then
@@ -160,6 +185,7 @@ for testfile in "$@"; do
 						sourceend
 						PART=$(($PART + 1))
 						INHEADER=1
+						NEGATIVETEST=0
 						testpath=
 						sourceheader $line
 					else
@@ -177,19 +203,7 @@ for testfile in "$@"; do
 		sourceend
 		;;
 	esac
-
-	cat prepare check > $ns.check
-	cat << EOF >> checkall
-echo -n -e "  /$testpath: \033[72G"
-((all++))
-if bash $ns.check &>log; then
-	echo -e "\033[0;32mOK\033[m"
-else
-	((fail++))
-	echo -e "\033[0;31mFAIL\033[m"
-	cat log
-fi
-EOF
+	addtocheck
 done
 
 cat << "EOF" >> checkall



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]