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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Jan 6 15:31:32 CST 2009


Author: mnicholson
Date: Tue Jan  6 15:31:32 2009
New Revision: 167292

URL: http://svn.digium.com/view/asterisk?view=rev&rev=167292
Log:
Added 'error' failure condition for tests.

 * asttest/include/asttest/testsuite.h: added TS_ERROR and updated function
 declarations
 * asttest/lib/testsuite.c (ts_error): added
 * asttest/lib/testsuite.c: updated ts result functions to return the
 corresponding ts_result
 * asttest/asttest.c: updated for TS_ERROR and ts result function changes

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

Modified: team/mnicholson/asttest/asttest/asttest.c
URL: http://svn.digium.com/view/asterisk/team/mnicholson/asttest/asttest/asttest.c?view=diff&rev=167292&r1=167291&r2=167292
==============================================================================
--- team/mnicholson/asttest/asttest/asttest.c (original)
+++ team/mnicholson/asttest/asttest/asttest.c Tue Jan  6 15:31:32 2009
@@ -74,15 +74,14 @@
  * \endcode
  */
 enum ts_result process_test_result(struct testsuite *ts, const char *test_name, lua_State *L) {
-	enum ts_result res = TS_SKIP;
+	enum ts_result res = TS_ERROR;
 
 	if (lua_isstring(L, -1)) {
 		/* this is not a test result, log the error */
 		ts_log(ts, test_name, "error: %s\n", lua_tostring(L, -1));
 		lua_pop(L, 1);
 
-		ts_skip(ts, test_name);
-		res = TS_SKIP;
+		res = ts_error(ts, test_name);
 	} else if (lua_type(L, -1) == LUA_TTABLE) {
 		int result_table = lua_gettop(L);
 		int reason_string = 0;
@@ -98,8 +97,7 @@
 		if (lua_isnil(L, -1)) {
 			lua_pop(L, 1);
 			ts_log(ts, test_name, "error reading test result\n");
-			ts_skip(ts, test_name);
-			res = TS_SKIP;
+			res = ts_error(ts, test_name);
 		} else {
 			test_result = lua_gettop(L);
 
@@ -107,21 +105,18 @@
 				ts_log(ts, test_name, "%s\n", lua_tostring(L, reason_string));
 
 			if (result_equals(L, test_result, "pass")) {
-				ts_pass(ts, test_name);
-				res = TS_PASS;
+				res = ts_pass(ts, test_name);
 			} else if (result_equals(L, test_result, "fail")) {
-				ts_fail(ts, test_name);
-				res = TS_FAIL;
+				res = ts_fail(ts, test_name);
 			} else if (result_equals(L, test_result, "xfail")) {
-				ts_xfail(ts, test_name);
-				res = TS_XFAIL;
+				res = ts_xfail(ts, test_name);
 			} else if (result_equals(L, test_result, "skip")) {
-				ts_skip(ts, test_name);
-				res = TS_SKIP;
+				res = ts_skip(ts, test_name);
+			} else if (result_equals(L, test_result, "error")) {
+				res = ts_error(ts, test_name);
 			} else {
 				ts_log(ts, test_name, "unknown result '%s'\n", lua_tostring(L, test_result));
-				ts_skip(ts, test_name);
-				res = TS_SKIP;
+				res = ts_error(ts, test_name);
 			}
 		}
 
@@ -134,8 +129,7 @@
 	} else {
 		lua_pop(L, 1);
 		ts_log(ts, test_name, "missing test result\n");
-		ts_skip(ts, test_name);
-		res = TS_SKIP;
+		res = ts_error(ts, test_name);
 	}
 
 	return res;
@@ -175,6 +169,9 @@
 		case TS_SKIP:
 			printf("skip\n");
 			break;
+		case TS_ERROR:
+			printf("error\n");
+			break;
 		default:
 			printf("unknown\n");
 			break;
@@ -184,20 +181,18 @@
 enum ts_result run_test(struct testsuite *ts, const char *test_name, const char *test_dir_path) {
 	char test_file_path[1024];
 	lua_State *L = get_lua_state(ts, test_name);
-	enum ts_result result = TS_SKIP;
+	enum ts_result result = TS_ERROR;
 	if (!L) {
 		ts_log(ts, test_name, "internal error, cannot run test\n");
-		ts_skip(ts, test_name);
-		return result;
+		return ts_error(ts, test_name);
 	}
 
 	snprintf(test_file_path, sizeof(test_file_path), "%s/test.lua", test_dir_path);
 	if (luaL_dofile(L, test_file_path)) {
 		result = process_test_result(ts, test_name, L);
 	} else {
-		/* we got not explicit result, consider it a pass */
-		ts_pass(ts, test_name);
-		result = TS_PASS;
+		/* we got no explicit result, consider it a pass */
+		result = ts_pass(ts, test_name);
 	}
 
 	lua_close(L);
@@ -260,9 +255,9 @@
 	if (ts.fail)
 		res = 1;
 
-	if (opts->warn_on_skip && ts.skip) {
-		printf("\n***WARNING: some tests were skipped, see log for details\n");
-	} else if (ts.skip) {
+	if (opts->warn_on_error && ts.error) {
+		printf("\n***WARNING: some tests failed to run, see log for details\n");
+	} else if (ts.error) {
 		/* signal a failure */
 		res = 1;
 	}
@@ -281,9 +276,10 @@
 		"                 created for each test directory in that test directory\n"
 		"                 using the given name.  The default filename is\n"
 		"                 asttest.log.\n"
-		"  -w             warn if tests were skipped.  This option will cause a\n"
-		"                 warning to print instead of an error being generated if\n"
-		"                 any tests are skipped.\n" 
+		"  -w             warn if tests were skipped because of errors.  This\n"
+		"                 option will cause a warning to print instead of an\n"
+		"                 error being generated if any tests fail because of\n"
+		"                 errors.\n" 
 		"  -h             print this help message\n"
 		"\n"
 		, prog_name);
@@ -307,7 +303,7 @@
 	memset(opts, 0, sizeof(struct asttest_opts));
 
 	/* set some default options */
-	opts->warn_on_skip = 0;
+	opts->warn_on_error = 0;
 	opts->log_filename = default_log_filename;
 
 	/* parse options */	
@@ -317,7 +313,7 @@
 			opts->log_filename = optarg;
 			break;
 		case 'w':
-			opts->warn_on_skip = 1;
+			opts->warn_on_error = 1;
 			break;
 		case 'h':
 			return 1;

Modified: team/mnicholson/asttest/asttest/include/asttest/testsuite.h
URL: http://svn.digium.com/view/asterisk/team/mnicholson/asttest/asttest/include/asttest/testsuite.h?view=diff&rev=167292&r1=167291&r2=167292
==============================================================================
--- team/mnicholson/asttest/asttest/include/asttest/testsuite.h (original)
+++ team/mnicholson/asttest/asttest/include/asttest/testsuite.h Tue Jan  6 15:31:32 2009
@@ -26,6 +26,7 @@
 	unsigned int fail;
 	unsigned int xfail;
 	unsigned int skip;
+	unsigned int error;
 	unsigned int total;
 	FILE *log;
 };
@@ -35,6 +36,7 @@
 	TS_FAIL,
 	TS_XFAIL,
 	TS_SKIP,
+	TS_ERROR,
 };
 
 int ts_init(struct testsuite *ts, const char *path, struct asttest_opts *opts);
@@ -45,9 +47,10 @@
 int ts_log_va(struct testsuite *ts, const char *test_name, const char *fmt, va_list ap);
 int __attribute__((format(printf, 3, 4))) ts_log(struct testsuite *ts, const char *test_name, const char *fmt, ...);
 
-void ts_pass(struct testsuite *ts, const char *test_name);
-void ts_fail(struct testsuite *ts, const char *test_name);
-void ts_xfail(struct testsuite *ts, const char *test_name);
-void ts_skip(struct testsuite *ts, const char *test_name);
+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_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);
 
 #endif

Modified: team/mnicholson/asttest/asttest/lib/asttest.lua
URL: http://svn.digium.com/view/asterisk/team/mnicholson/asttest/asttest/lib/asttest.lua?view=diff&rev=167292&r1=167291&r2=167292
==============================================================================
--- team/mnicholson/asttest/asttest/lib/asttest.lua (original)
+++ team/mnicholson/asttest/asttest/lib/asttest.lua Tue Jan  6 15:31:32 2009
@@ -16,25 +16,49 @@
 -- at the top of the source tree.
 --
 
+-- 
+-- replacements for global functions
+--
+
+-- print to the test log instead of stdout
+function print(...)
+	local string = ""
+	for i, v in ipairs(arg) do
+		if i == 1 then
+			string = string .. tostring(v)
+		else
+			string = string .. "\t" .. tostring(v)
+		end
+	end
+	string = string .. "\n"
+	ts_log(string)
+end
+
+lua_error = error
+
 --
 -- basic pass/fail/xfail/skip functions
 -- note: none of these functions actually return
 --
 
 function pass(reason)
-	return error{result = "pass", reason = reason}
+	return lua_error{result = "pass", reason = reason}
 end
 
 function fail(reason)
-	return error{result = "fail", reason = reason}
+	return lua_error{result = "fail", reason = reason}
 end
 
 function xfail(reason)
-	return error{result = "xfail", reason = reason}
+	return lua_error{result = "xfail", reason = reason}
 end
 
 function skip(reason)
-	return error{result = "skip", reason = reason}
+	return lua_error{result = "skip", reason = reason}
+end
+
+function error(reason)
+	return lua_error{result = "error", reason = reason}
 end
 
 --
@@ -55,21 +79,3 @@
 	end
 end
 
--- 
--- replacements for global functions
---
-
--- print to the test log instead of stdout
-function print(...)
-	local string = ""
-	for i, v in ipairs(arg) do
-		if i == 1 then
-			string = string .. tostring(v)
-		else
-			string = string .. "\t" .. tostring(v)
-		end
-	end
-	string = string .. "\n"
-	ts_log(string)
-end
-

Modified: team/mnicholson/asttest/asttest/lib/testsuite.c
URL: http://svn.digium.com/view/asterisk/team/mnicholson/asttest/asttest/lib/testsuite.c?view=diff&rev=167292&r1=167291&r2=167292
==============================================================================
--- team/mnicholson/asttest/asttest/lib/testsuite.c (original)
+++ team/mnicholson/asttest/asttest/lib/testsuite.c Tue Jan  6 15:31:32 2009
@@ -53,6 +53,7 @@
 	printf("  test failures:     %d\n", ts->fail);
 	printf("  expected failures: %d\n", ts->xfail);
 	printf("  tests skipped:     %d\n", ts->skip);
+	printf("  test errors:       %d\n", ts->error);
 	printf("\n");
 	printf("Total tests run:     %d\n", ts->total);
 }
@@ -73,31 +74,43 @@
 	return res;
 }
 
-void ts_pass(struct testsuite *ts, const char *test_name) {
+enum ts_result ts_pass(struct testsuite *ts, const char *test_name) {
 	ts->pass++;
 	ts->total++;
 	
 	ts_log(ts, test_name, "test passed\n");
+	return TS_PASS;
 }
 
-void ts_fail(struct testsuite *ts, const char *test_name) {
+enum ts_result ts_fail(struct testsuite *ts, const char *test_name) {
 	ts->fail++;
 	ts->total++;
 	
 	ts_log(ts, test_name, "test failed\n");
+	return TS_FAIL;
 }
 
-void ts_xfail(struct testsuite *ts, const char *test_name) {
+enum ts_result ts_xfail(struct testsuite *ts, const char *test_name) {
 	ts->xfail++;
 	ts->total++;
 
 	ts_log(ts, test_name, "expected failure\n");
+	return TS_XFAIL;
 }
 
-void ts_skip(struct testsuite *ts, const char *test_name) {
+enum ts_result ts_skip(struct testsuite *ts, const char *test_name) {
 	ts->skip++;
 	ts->total++;
 
 	ts_log(ts, test_name, "test skipped\n");
+	return TS_SKIP;
 }
 
+enum ts_result ts_error(struct testsuite *ts, const char *test_name) {
+	ts->error++;
+	ts->total++;
+
+	ts_log(ts, test_name, "error running test\n");
+	return TS_ERROR;
+}
+




More information about the asterisk-commits mailing list