[asterisk-commits] mnicholson: branch mnicholson/asttest r170043 - in /team/mnicholson/asttest/a...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jan 21 22:07:23 CST 2009


Author: mnicholson
Date: Wed Jan 21 22:07:23 2009
New Revision: 170043

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=170043
Log:
Added better xfail functionality.

 * asttest/include/asttest/lua.h: added lua_expected_fail()
 * asttest/lib/lua.c: use luaL_register to register global functions, and
 added xfail global function to notify the test driver that the current test
 is expected to fail
 * asttest/lib/asttest.lua: removed xfail() and xcheck()
 * asttest/lib/testsuite.c, asttest/include/asttest/testsuite.h: added
 TS_XPASS and ts_xpass().
 * asttest/asttest.c: updated to handle the new expected failure behavior

Modified:
    team/mnicholson/asttest/asttest/asttest.c
    team/mnicholson/asttest/asttest/include/asttest/lua.h
    team/mnicholson/asttest/asttest/include/asttest/testsuite.h
    team/mnicholson/asttest/asttest/lib/asttest.lua
    team/mnicholson/asttest/asttest/lib/lua.c
    team/mnicholson/asttest/asttest/lib/testsuite.c

Modified: team/mnicholson/asttest/asttest/asttest.c
URL: http://svn.digium.com/svn-view/asterisk/team/mnicholson/asttest/asttest/asttest.c?view=diff&rev=170043&r1=170042&r2=170043
==============================================================================
--- team/mnicholson/asttest/asttest/asttest.c (original)
+++ team/mnicholson/asttest/asttest/asttest.c Wed Jan 21 22:07:23 2009
@@ -105,11 +105,15 @@
 				ts_log(ts, test_name, "%s\n", lua_tostring(L, reason_string));
 
 			if (result_equals(L, test_result, "pass")) {
-				res = ts_pass(ts, test_name);
+				if (lua_expected_fail(L))
+					res = ts_xpass(ts, test_name);
+				else
+					res = ts_pass(ts, test_name);
 			} else if (result_equals(L, test_result, "fail")) {
-				res = ts_fail(ts, test_name);
-			} else if (result_equals(L, test_result, "xfail")) {
-				res = ts_xfail(ts, test_name);
+				if (lua_expected_fail(L))
+					res = ts_xfail(ts, test_name);
+				else
+					res = ts_fail(ts, test_name);
 			} else if (result_equals(L, test_result, "skip")) {
 				res = ts_skip(ts, test_name);
 			} else if (result_equals(L, test_result, "error")) {
@@ -163,6 +167,9 @@
 		case TS_FAIL:
 			printf("fail\n");
 			break;
+		case TS_XPASS:
+			printf("xpass\n");
+			break;
 		case TS_XFAIL:
 			printf("xfail\n");
 			break;
@@ -191,8 +198,11 @@
 	if (luaL_dofile(L, test_file_path)) {
 		result = process_test_result(ts, test_name, L);
 	} else {
-		/* we got no explicit result, consider it a pass */
-		result = ts_pass(ts, test_name);
+		/* we got no explicit result, consider it a pass or xpass*/
+		if (lua_expected_fail(L))
+			result = ts_xpass(ts, test_name);
+		else
+			result = ts_pass(ts, test_name);
 	}
 
 	lua_close(L);
@@ -251,8 +261,9 @@
 	printf("\n");
 	ts_print(&ts);
 
-	/* consider this run a failure if any tests failed */
-	if (ts.fail)
+	/* consider this run a failure if any tests failed or passed
+	 * unexpectedly */
+	if (ts.fail || ts.xpass)
 		res = 1;
 
 	if (opts->warn_on_error && ts.error) {

Modified: team/mnicholson/asttest/asttest/include/asttest/lua.h
URL: http://svn.digium.com/svn-view/asterisk/team/mnicholson/asttest/asttest/include/asttest/lua.h?view=diff&rev=170043&r1=170042&r2=170043
==============================================================================
--- team/mnicholson/asttest/asttest/include/asttest/lua.h (original)
+++ team/mnicholson/asttest/asttest/include/asttest/lua.h Wed Jan 21 22:07:23 2009
@@ -23,6 +23,7 @@
 
 #include "asttest/testsuite.h"
 
+int lua_expected_fail(lua_State *L);
 lua_State *get_lua_state(struct testsuite *ts, const char *test_name);
 
 #endif

Modified: team/mnicholson/asttest/asttest/include/asttest/testsuite.h
URL: http://svn.digium.com/svn-view/asterisk/team/mnicholson/asttest/asttest/include/asttest/testsuite.h?view=diff&rev=170043&r1=170042&r2=170043
==============================================================================
--- team/mnicholson/asttest/asttest/include/asttest/testsuite.h (original)
+++ team/mnicholson/asttest/asttest/include/asttest/testsuite.h Wed Jan 21 22:07:23 2009
@@ -25,6 +25,7 @@
 	unsigned int pass;
 	unsigned int fail;
 	unsigned int xfail;
+	unsigned int xpass;
 	unsigned int skip;
 	unsigned int error;
 	unsigned int total;
@@ -35,6 +36,7 @@
 	TS_PASS,
 	TS_FAIL,
 	TS_XFAIL,
+	TS_XPASS,
 	TS_SKIP,
 	TS_ERROR,
 };
@@ -49,6 +51,7 @@
 
 enum ts_result ts_pass(struct testsuite *ts, const char *test_name);
 enum ts_result ts_fail(struct testsuite *ts, const char *test_name);
+enum ts_result ts_xpass(struct testsuite *ts, const char *test_name);
 enum ts_result ts_xfail(struct testsuite *ts, const char *test_name);
 enum ts_result ts_skip(struct testsuite *ts, const char *test_name);
 enum ts_result ts_error(struct testsuite *ts, const char *test_name);

Modified: team/mnicholson/asttest/asttest/lib/asttest.lua
URL: http://svn.digium.com/svn-view/asterisk/team/mnicholson/asttest/asttest/lib/asttest.lua?view=diff&rev=170043&r1=170042&r2=170043
==============================================================================
--- team/mnicholson/asttest/asttest/lib/asttest.lua (original)
+++ team/mnicholson/asttest/asttest/lib/asttest.lua Wed Jan 21 22:07:23 2009
@@ -37,7 +37,7 @@
 lua_error = error
 
 --
--- basic pass/fail/xfail/skip functions
+-- basic pass/fail/skip/error functions
 -- note: none of these functions actually return
 --
 
@@ -47,10 +47,6 @@
 
 function fail(reason)
 	return lua_error{result = "fail", reason = reason}
-end
-
-function xfail(reason)
-	return lua_error{result = "xfail", reason = reason}
 end
 
 function skip(reason)
@@ -72,10 +68,3 @@
 	end
 end
 
--- xfail if condition is false using message as the reason
-function xcheck(condition, message)
-	if not condition then
-		return xfail(message)
-	end
-end
-

Modified: team/mnicholson/asttest/asttest/lib/lua.c
URL: http://svn.digium.com/svn-view/asterisk/team/mnicholson/asttest/asttest/lib/lua.c?view=diff&rev=170043&r1=170042&r2=170043
==============================================================================
--- team/mnicholson/asttest/asttest/lib/lua.c (original)
+++ team/mnicholson/asttest/asttest/lib/lua.c Wed Jan 21 22:07:23 2009
@@ -24,6 +24,20 @@
 #include "asttest/testsuite.h"
 
 #include "asttest_lua.h"
+
+/*
+ * \brief Check if the current test was expected to fail or not.
+ * \param L the lua state to use
+ * \return whether the current test was expected to fail or not
+ */
+int lua_expected_fail(lua_State *L) {
+	int res;
+	lua_getfield(L, LUA_REGISTRYINDEX, "asttest_xfail");
+	res = lua_toboolean(L, -1);
+	lua_pop(L, 1);
+	return res;
+}
+	
 
 /*
  * \brief Push the current testsuite on the stack and return a pointer to it.
@@ -58,6 +72,16 @@
 }
 
 /*
+ * \brief [lua_CFunction] Notify the test driver that this test is expected to
+ * fail.
+ */
+int lua_xfail(lua_State *L) {
+	lua_pushboolean(L, 1);
+	lua_setfield(L, LUA_REGISTRYINDEX, "asttest_xfail");
+	return 0;
+}
+
+/*
  * \brief Setup lua registry values.
  * \param ts the test suite
  * \param test_name the name of the current test
@@ -68,9 +92,18 @@
 
 	lua_pushstring(L, test_name);
 	lua_setfield(L, LUA_REGISTRYINDEX, "asttest_name");
+	
+	lua_pushboolean(L, 0);
+	lua_setfield(L, LUA_REGISTRYINDEX, "asttest_xfail");
 
 	return 0;
 }
+
+luaL_Reg global_functions[] = {
+	{"ts_log", lua_ts_log},
+	{"xfail", lua_xfail},
+	{NULL, NULL},
+};
 
 /*
  * \brief Setup lua global values.
@@ -83,8 +116,9 @@
 	lua_pushstring(L, test_name);
 	lua_setglobal(L, "name");
 
-	lua_pushcfunction(L, lua_ts_log);
-	lua_setglobal(L, "ts_log");
+	lua_pushvalue(L, LUA_GLOBALSINDEX);
+	luaL_register(L, NULL, global_functions);
+	lua_pop(L, 1);
 
 	return 0;
 }

Modified: team/mnicholson/asttest/asttest/lib/testsuite.c
URL: http://svn.digium.com/svn-view/asterisk/team/mnicholson/asttest/asttest/lib/testsuite.c?view=diff&rev=170043&r1=170042&r2=170043
==============================================================================
--- team/mnicholson/asttest/asttest/lib/testsuite.c (original)
+++ team/mnicholson/asttest/asttest/lib/testsuite.c Wed Jan 21 22:07:23 2009
@@ -51,6 +51,7 @@
 	printf("Test results:\n");
 	printf("  tests passed:      %d\n", ts->pass);
 	printf("  test failures:     %d\n", ts->fail);
+	printf("  unexpected passes: %d\n", ts->xpass);
 	printf("  expected failures: %d\n", ts->xfail);
 	printf("  tests skipped:     %d\n", ts->skip);
 	printf("  test errors:       %d\n", ts->error);
@@ -90,6 +91,14 @@
 	return TS_FAIL;
 }
 
+enum ts_result ts_xpass(struct testsuite *ts, const char *test_name) {
+	ts->xpass++;
+	ts->total++;
+
+	ts_log(ts, test_name, "unexpected pass\n");
+	return TS_XPASS;
+}
+
 enum ts_result ts_xfail(struct testsuite *ts, const char *test_name) {
 	ts->xfail++;
 	ts->total++;




More information about the asterisk-commits mailing list