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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Feb 5 20:41:56 CST 2009


Author: mnicholson
Date: Thu Feb  5 20:41:56 2009
New Revision: 173840

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=173840
Log:
Moved the test related functions out of asttest.c and into testutils.c.  And
added astlib lua library skeleton.

Added:
    team/mnicholson/asttest/asttest/include/asttest/lua/astlib.h   (with props)
    team/mnicholson/asttest/asttest/include/asttest/testutils.h   (with props)
    team/mnicholson/asttest/asttest/lib/testutils.c   (with props)
    team/mnicholson/asttest/asttest/lua/astlib.c   (with props)
    team/mnicholson/asttest/asttest/lua/astlib.lua   (with props)
Modified:
    team/mnicholson/asttest/asttest/Makefile
    team/mnicholson/asttest/asttest/asttest.c
    team/mnicholson/asttest/asttest/lib/lua.c

Modified: team/mnicholson/asttest/asttest/Makefile
URL: http://svn.digium.com/svn-view/asterisk/team/mnicholson/asttest/asttest/Makefile?view=diff&rev=173840&r1=173839&r2=173840
==============================================================================
--- team/mnicholson/asttest/asttest/Makefile (original)
+++ team/mnicholson/asttest/asttest/Makefile Thu Feb  5 20:41:56 2009
@@ -21,9 +21,9 @@
 .PHONY: clean dist-clean distclean test check asterisk
 
 # Basic set of sources and flags/libraries/includes
-OBJS:=asttest.o lib/lua.o lib/testsuite.o
+OBJS:=asttest.o lib/lua.o lib/testsuite.o lib/testutils.o
 CFLAGS:=-g -c -D_GNU_SOURCE -Wall -I/usr/include/lua5.1 -Iinclude -Ilua
-L_OBJS:=lua/testlib.o
+L_OBJS:=lua/testlib.o lua/astlib.o
 T_LIBS:=-llua5.1
 
 AST_INSTALL_DIR = $(PWD)/asterisk
@@ -74,8 +74,10 @@
 
 lib/lua.o: lib/lua.c include/asttest/lua.h include/asttest/testsuite.h include/asttest/lua/*.h
 lib/testsuite.o: lib/testsuite.c include/asttest/testsuite.h include/asttest/asttest.h
+lib/testutils.o: lib/testutils.c include/asttest/testutils.h include/asttest/asttest.h include/asttest/testsuite.h include/asttest/lua.h
+
 lua/testlib.o: lua/testlib.c lua/testlib_lua.h include/asttest/lua/testlib.h
-#lua/astlib.o: lua/astlib.c lua/astlib_lua.h include/asttest/lua/astlib.h
+lua/astlib.o: lua/astlib.c lua/astlib_lua.h include/asttest/lua/astlib.h
 
 asttest: asttest.c $(OBJS) $(T_OBJS) $(L_OBJS) include/asttest/asttest.h
 	$(CC) -o $@ $(OBJS) $(L_OBJS) $(T_LIBS)
@@ -90,7 +92,7 @@
 
 clean:
 	rm -f asttest $(OBJS) $(M_OBJS) $(C_OBJS) $(G_OBJS) $(N_OBJS) $(L_OBJS)
-	rm -f lua/*.h
+	rm -f lua/*_lua.h
 	rm -f tools/mkstring
 	rm -rf $(AST_INSTALL_DIR)
 

Modified: team/mnicholson/asttest/asttest/asttest.c
URL: http://svn.digium.com/svn-view/asterisk/team/mnicholson/asttest/asttest/asttest.c?view=diff&rev=173840&r1=173839&r2=173840
==============================================================================
--- team/mnicholson/asttest/asttest/asttest.c (original)
+++ team/mnicholson/asttest/asttest/asttest.c Thu Feb  5 20:41:56 2009
@@ -16,281 +16,15 @@
  * at the top of the source tree.
  */
 
-#include <errno.h>
 #include <stdio.h>
-#include <stdlib.h>
 #include <string.h>
-
-#include <sys/types.h>
-#include <sys/stat.h>
 #include <unistd.h>
-#include <dirent.h>
-#include <libgen.h>
-
-#include <lua.h>
-#include <lauxlib.h>
-#include <lualib.h>
 
 #include "asttest/asttest.h"
-#include "asttest/lua.h"
-#include "asttest/testsuite.h"
+#include "asttest/testutils.h"
 
 const char *default_log_filename = "asttest.log";
 
-
-/*
- * \brief Check if the given result string equals the string stored at the 
- * given index.
- * \param L the lua state to use
- * \param result_index the index of the result string
- * \param result_string the result string to check for equality with the string 
- * at the given index
- */
-int result_equals(lua_State *L, int result_index, const char *result_string) {
-	int res;
-	lua_pushstring(L, result_string);
-	res = lua_equal(L, -1, result_index);
-	lua_pop(L, 1);
-	return res;
-}
-
-/*
- * \brief Process the result of a test.
- * \param ts the current test suite
- * \param L the lua state the test was run in
- *
- * This function expects to be called after luaL_dofile/lua_pcall and will 
- * analyze the result of running the test.  The testing framework will pass a 
- * special table containg the test result to lua_error() that is used by this 
- * function.
- *
- * The table is expected in the following format:
- *
- * \code
- * table = {
- *    result = "pass" or "fail" or "xfail" or "skip";
- *    reason = nil or "reason string";
- * }
- * \endcode
- */
-enum ts_result process_test_result(struct testsuite *ts, const char *test_name, lua_State *L) {
-	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);
-
-		res = ts_error(ts, test_name);
-	} else if (lua_type(L, -1) == LUA_TTABLE) {
-		int result_table = lua_gettop(L);
-		int reason_string = 0;
-		int test_result = 0;
-
-		lua_getfield(L, result_table, "reason");
-		if (!lua_isnil(L, -1) && lua_isstring(L, -1))
-			reason_string = lua_gettop(L);
-		else
-			lua_pop(L, 1);
-
-		lua_getfield(L, result_table, "result");
-		if (lua_isnil(L, -1)) {
-			lua_pop(L, 1);
-			ts_log(ts, test_name, "error reading test result\n");
-			res = ts_error(ts, test_name);
-		} else {
-			test_result = lua_gettop(L);
-
-			if (reason_string)
-				ts_log(ts, test_name, "%s\n", lua_tostring(L, reason_string));
-
-			if (result_equals(L, test_result, "pass")) {
-				if (testlib_expected_fail(L))
-					res = ts_xpass(ts, test_name);
-				else
-					res = ts_pass(ts, test_name);
-			} else if (result_equals(L, test_result, "fail")) {
-				if (testlib_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")) {
-				res = ts_error(ts, test_name);
-			} else {
-				ts_log(ts, test_name, "unknown result '%s'\n", lua_tostring(L, test_result));
-				res = ts_error(ts, test_name);
-			}
-		}
-
-		if (reason_string)
-			lua_remove(L, reason_string);
-		if (test_result)
-			lua_remove(L, test_result);
-
-		lua_pop(L, 1);
-	} else {
-		lua_pop(L, 1);
-		ts_log(ts, test_name, "missing test result\n");
-		res = ts_error(ts, test_name);
-	}
-
-	return res;
-}
-
-void print_test_name(struct testsuite *ts, const char *test_name) {
-	int len, i;
-
-	/* first print a number */
-	len = printf("%d.", ts->total + 1);
-
-	/* pad the number printed */
-	for (i = 4 - len; i > 0; i--) {
-		printf(" ");
-	}
-
-	/* now print the test name */
-	len = printf(" %s ", test_name);
-
-	/* now pad the test name */
-	for (i = 31 - len; i > 0; i--) {
-		printf(" ");
-	}
-}
-
-void print_test_result(enum ts_result result) {
-	switch (result) {
-		case TS_PASS:
-			printf("pass\n");
-			break;
-		case TS_FAIL:
-			printf("fail\n");
-			break;
-		case TS_XPASS:
-			printf("xpass\n");
-			break;
-		case TS_XFAIL:
-			printf("xfail\n");
-			break;
-		case TS_SKIP:
-			printf("skip\n");
-			break;
-		case TS_ERROR:
-			printf("error\n");
-			break;
-		default:
-			printf("unknown\n");
-			break;
-	}
-}
-
-enum ts_result run_test(struct testsuite *ts, const char *test_name, const char *test_dir_path) {
-	lua_State *L;
-	char original_path[PATH_MAX];
-	enum ts_result result;
-
-	if (!getcwd(original_path, PATH_MAX)) {
-		ts_log(ts, test_name, "internal error storing current path, PATH_MAX is too small\n");
-		return ts_error(ts, test_name);
-	}
-
-	if (chdir(test_dir_path)) {
-		ts_log(ts, test_name, "error changing to test dir: %s\n", strerror(errno));
-		return ts_error(ts, test_name);
-	}
-
-	if (!(L = get_lua_state(ts, test_name))) {
-		ts_log(ts, test_name, "internal error, cannot run test\n");
-		if (chdir(original_path))
-			ts_log(ts, test_name, "additionaly, there was an error changing directories, this may cause further errors (%s)\n", strerror(errno));
-		return ts_error(ts, test_name);
-	}
-
-	if (luaL_dofile(L, "test.lua")) {
-		result = process_test_result(ts, test_name, L);
-	} else {
-		/* we got no explicit result, consider it a pass or xpass*/
-		if (testlib_expected_fail(L))
-			result = ts_xpass(ts, test_name);
-		else
-			result = ts_pass(ts, test_name);
-	}
-
-	if (chdir(original_path))
-		ts_log(ts, test_name, "error changing directories, this may cause further errors (%s)\n", strerror(errno));
-
-	lua_close(L);
-	return result;
-}
-
-int is_directory(const char *dir) {
-	struct stat st;
-	if (lstat(dir, &st)) {
-		return 0;
-	}
-
-	return S_ISDIR(st.st_mode);
-}
-
-int ignored_dir(const char *dir) {
-	char *dir_dup = strdup(dir);  /* dup the string as basename may modify it */
-	char *base_dir = basename(dir_dup);
-	int res = 0;
-
-	if (base_dir[0] == '.') {
-		res = 1;
-	}
-
-	free(dir_dup);
-	return res;
-}
-
-int process_test_dir(const char *path, struct asttest_opts *opts) {
-	DIR *main_dir = opendir(path);
-	char full_path[PATH_MAX];
-	struct testsuite ts;
-	struct dirent *ent;
-	enum ts_result result;
-	int res = 0;
-
-	printf("Processing tests in '%s':\n", path);
-
-	if (!main_dir) {
-		fprintf(stderr, "Error opening path '%s': %s\n", path, strerror(errno));
-		return 1;
-	}
-
-	ts_init(&ts, path, opts);
-
-	while ((ent = readdir(main_dir))) {
-		snprintf(full_path, sizeof(full_path), "%s/%s", path, ent->d_name);
-		if (is_directory(full_path) && !ignored_dir(full_path)) {
-			print_test_name(&ts, ent->d_name);
-			result = run_test(&ts, ent->d_name, full_path);
-			print_test_result(result);
-		}
-	}
-	closedir(main_dir);
-
-	printf("\n");
-	ts_print(&ts);
-
-	/* 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) {
-		printf("\n***WARNING: some tests failed to run, see log for details\n");
-	} else if (ts.error) {
-		/* signal a failure */
-		res = 1;
-	}
-
-	ts_cleanup(&ts);
-	return res;
-}
 
 void usage(const char *prog_name) {
 	fprintf(stderr,

Added: team/mnicholson/asttest/asttest/include/asttest/lua/astlib.h
URL: http://svn.digium.com/svn-view/asterisk/team/mnicholson/asttest/asttest/include/asttest/lua/astlib.h?view=auto&rev=173840
==============================================================================
--- team/mnicholson/asttest/asttest/include/asttest/lua/astlib.h (added)
+++ team/mnicholson/asttest/asttest/include/asttest/lua/astlib.h Thu Feb  5 20:41:56 2009
@@ -1,0 +1,26 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 1999 - 2008, Digium, Inc.
+ *
+ * Matthew Nichiolson <mnicholson at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+#ifndef ASTTEST_LUA_ASTLIB_H
+#define ASTTEST_LUA_ASTLIB_H
+
+#include <lua.h>
+
+int luaopen_astlib(lua_State *L);
+
+#endif

Propchange: team/mnicholson/asttest/asttest/include/asttest/lua/astlib.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/mnicholson/asttest/asttest/include/asttest/lua/astlib.h
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/mnicholson/asttest/asttest/include/asttest/lua/astlib.h
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: team/mnicholson/asttest/asttest/include/asttest/testutils.h
URL: http://svn.digium.com/svn-view/asterisk/team/mnicholson/asttest/asttest/include/asttest/testutils.h?view=auto&rev=173840
==============================================================================
--- team/mnicholson/asttest/asttest/include/asttest/testutils.h (added)
+++ team/mnicholson/asttest/asttest/include/asttest/testutils.h Thu Feb  5 20:41:56 2009
@@ -1,0 +1,26 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 1999 - 2008, Digium, Inc.
+ *
+ * Matthew Nichiolson <mnicholson at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+#ifndef ASTTEST_TESTUTILS_H
+#define ASTTEST_TESTUTILS_H
+
+#include "asttest/asttest.h"
+
+int process_test_dir(const char *path, struct asttest_opts *opts);
+
+#endif

Propchange: team/mnicholson/asttest/asttest/include/asttest/testutils.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/mnicholson/asttest/asttest/include/asttest/testutils.h
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/mnicholson/asttest/asttest/include/asttest/testutils.h
------------------------------------------------------------------------------
    svn:mime-type = text/plain

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=173840&r1=173839&r2=173840
==============================================================================
--- team/mnicholson/asttest/asttest/lib/lua.c (original)
+++ team/mnicholson/asttest/asttest/lib/lua.c Thu Feb  5 20:41:56 2009
@@ -23,6 +23,7 @@
 #include "asttest/lua.h"
 #include "asttest/testsuite.h"
 
+#include "asttest/lua/astlib.h"
 #include "asttest/lua/testlib.h"
 
 lua_State *get_lua_state(struct testsuite *ts, const char *test_name) {
@@ -40,14 +41,13 @@
 	if (lua_pcall(L, 2, 0, 0)) {
 		goto e_print_error;
 	}
-#if 0
+
 	/* load the asterisk lib */
 	lua_pushcfunction(L, luaopen_astlib);
 	lua_pushstring(L, ts->asterisk_path);
 	if (lua_pcall(L, 1, 0, 0)) {
 		goto e_print_error;
 	}
-#endif
 
 	return L;
 

Added: team/mnicholson/asttest/asttest/lib/testutils.c
URL: http://svn.digium.com/svn-view/asterisk/team/mnicholson/asttest/asttest/lib/testutils.c?view=auto&rev=173840
==============================================================================
--- team/mnicholson/asttest/asttest/lib/testutils.c (added)
+++ team/mnicholson/asttest/asttest/lib/testutils.c Thu Feb  5 20:41:56 2009
@@ -1,0 +1,292 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 1999 - 2008, Digium, Inc.
+ *
+ * Matthew Nichiolson <mnicholson at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <libgen.h>
+
+#include <lua.h>
+#include <lauxlib.h>
+#include <lualib.h>
+
+#include "asttest/asttest.h"
+#include "asttest/lua.h"
+#include "asttest/testsuite.h"
+#include "asttest/testutils.h"
+
+/*
+ * \brief Check if the given result string equals the string stored at the 
+ * given index.
+ * \param L the lua state to use
+ * \param result_index the index of the result string
+ * \param result_string the result string to check for equality with the string 
+ * at the given index
+ */
+static int result_equals(lua_State *L, int result_index, const char *result_string) {
+	int res;
+	lua_pushstring(L, result_string);
+	res = lua_equal(L, -1, result_index);
+	lua_pop(L, 1);
+	return res;
+}
+
+/*
+ * \brief Process the result of a test.
+ * \param ts the current test suite
+ * \param L the lua state the test was run in
+ *
+ * This function expects to be called after luaL_dofile/lua_pcall and will 
+ * analyze the result of running the test.  The testing framework will pass a 
+ * special table containg the test result to lua_error() that is used by this 
+ * function.
+ *
+ * The table is expected in the following format:
+ *
+ * \code
+ * table = {
+ *    result = "pass" or "fail" or "xfail" or "skip";
+ *    reason = nil or "reason string";
+ * }
+ * \endcode
+ */
+static enum ts_result process_test_result(struct testsuite *ts, const char *test_name, lua_State *L) {
+	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);
+
+		res = ts_error(ts, test_name);
+	} else if (lua_type(L, -1) == LUA_TTABLE) {
+		int result_table = lua_gettop(L);
+		int reason_string = 0;
+		int test_result = 0;
+
+		lua_getfield(L, result_table, "reason");
+		if (!lua_isnil(L, -1) && lua_isstring(L, -1))
+			reason_string = lua_gettop(L);
+		else
+			lua_pop(L, 1);
+
+		lua_getfield(L, result_table, "result");
+		if (lua_isnil(L, -1)) {
+			lua_pop(L, 1);
+			ts_log(ts, test_name, "error reading test result\n");
+			res = ts_error(ts, test_name);
+		} else {
+			test_result = lua_gettop(L);
+
+			if (reason_string)
+				ts_log(ts, test_name, "%s\n", lua_tostring(L, reason_string));
+
+			if (result_equals(L, test_result, "pass")) {
+				if (testlib_expected_fail(L))
+					res = ts_xpass(ts, test_name);
+				else
+					res = ts_pass(ts, test_name);
+			} else if (result_equals(L, test_result, "fail")) {
+				if (testlib_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")) {
+				res = ts_error(ts, test_name);
+			} else {
+				ts_log(ts, test_name, "unknown result '%s'\n", lua_tostring(L, test_result));
+				res = ts_error(ts, test_name);
+			}
+		}
+
+		if (reason_string)
+			lua_remove(L, reason_string);
+		if (test_result)
+			lua_remove(L, test_result);
+
+		lua_pop(L, 1);
+	} else {
+		lua_pop(L, 1);
+		ts_log(ts, test_name, "missing test result\n");
+		res = ts_error(ts, test_name);
+	}
+
+	return res;
+}
+
+static void print_test_name(struct testsuite *ts, const char *test_name) {
+	int len, i;
+
+	/* first print a number */
+	len = printf("%d.", ts->total + 1);
+
+	/* pad the number printed */
+	for (i = 4 - len; i > 0; i--) {
+		printf(" ");
+	}
+
+	/* now print the test name */
+	len = printf(" %s ", test_name);
+
+	/* now pad the test name */
+	for (i = 31 - len; i > 0; i--) {
+		printf(" ");
+	}
+}
+
+static void print_test_result(enum ts_result result) {
+	switch (result) {
+		case TS_PASS:
+			printf("pass\n");
+			break;
+		case TS_FAIL:
+			printf("fail\n");
+			break;
+		case TS_XPASS:
+			printf("xpass\n");
+			break;
+		case TS_XFAIL:
+			printf("xfail\n");
+			break;
+		case TS_SKIP:
+			printf("skip\n");
+			break;
+		case TS_ERROR:
+			printf("error\n");
+			break;
+		default:
+			printf("unknown\n");
+			break;
+	}
+}
+
+static enum ts_result run_test(struct testsuite *ts, const char *test_name, const char *test_dir_path) {
+	lua_State *L;
+	char original_path[PATH_MAX];
+	enum ts_result result;
+
+	if (!getcwd(original_path, PATH_MAX)) {
+		ts_log(ts, test_name, "internal error storing current path, PATH_MAX is too small\n");
+		return ts_error(ts, test_name);
+	}
+
+	if (chdir(test_dir_path)) {
+		ts_log(ts, test_name, "error changing to test dir: %s\n", strerror(errno));
+		return ts_error(ts, test_name);
+	}
+
+	if (!(L = get_lua_state(ts, test_name))) {
+		ts_log(ts, test_name, "internal error, cannot run test\n");
+		if (chdir(original_path))
+			ts_log(ts, test_name, "additionaly, there was an error changing directories, this may cause further errors (%s)\n", strerror(errno));
+		return ts_error(ts, test_name);
+	}
+
+	if (luaL_dofile(L, "test.lua")) {
+		result = process_test_result(ts, test_name, L);
+	} else {
+		/* we got no explicit result, consider it a pass or xpass*/
+		if (testlib_expected_fail(L))
+			result = ts_xpass(ts, test_name);
+		else
+			result = ts_pass(ts, test_name);
+	}
+
+	if (chdir(original_path))
+		ts_log(ts, test_name, "error changing directories, this may cause further errors (%s)\n", strerror(errno));
+
+	lua_close(L);
+	return result;
+}
+
+static int is_directory(const char *dir) {
+	struct stat st;
+	if (lstat(dir, &st)) {
+		return 0;
+	}
+
+	return S_ISDIR(st.st_mode);
+}
+
+static int ignored_dir(const char *dir) {
+	char *dir_dup = strdup(dir);  /* dup the string as basename may modify it */
+	char *base_dir = basename(dir_dup);
+	int res = 0;
+
+	if (base_dir[0] == '.') {
+		res = 1;
+	}
+
+	free(dir_dup);
+	return res;
+}
+
+int process_test_dir(const char *path, struct asttest_opts *opts) {
+	DIR *main_dir = opendir(path);
+	char full_path[PATH_MAX];
+	struct testsuite ts;
+	struct dirent *ent;
+	enum ts_result result;
+	int res = 0;
+
+	printf("Processing tests in '%s':\n", path);
+
+	if (!main_dir) {
+		fprintf(stderr, "Error opening path '%s': %s\n", path, strerror(errno));
+		return 1;
+	}
+
+	ts_init(&ts, path, opts);
+
+	while ((ent = readdir(main_dir))) {
+		snprintf(full_path, sizeof(full_path), "%s/%s", path, ent->d_name);
+		if (is_directory(full_path) && !ignored_dir(full_path)) {
+			print_test_name(&ts, ent->d_name);
+			result = run_test(&ts, ent->d_name, full_path);
+			print_test_result(result);
+		}
+	}
+	closedir(main_dir);
+
+	printf("\n");
+	ts_print(&ts);
+
+	/* 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) {
+		printf("\n***WARNING: some tests failed to run, see log for details\n");
+	} else if (ts.error) {
+		/* signal a failure */
+		res = 1;
+	}
+
+	ts_cleanup(&ts);
+	return res;
+}
+

Propchange: team/mnicholson/asttest/asttest/lib/testutils.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/mnicholson/asttest/asttest/lib/testutils.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/mnicholson/asttest/asttest/lib/testutils.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: team/mnicholson/asttest/asttest/lua/astlib.c
URL: http://svn.digium.com/svn-view/asterisk/team/mnicholson/asttest/asttest/lua/astlib.c?view=auto&rev=173840
==============================================================================
--- team/mnicholson/asttest/asttest/lua/astlib.c (added)
+++ team/mnicholson/asttest/asttest/lua/astlib.c Thu Feb  5 20:41:56 2009
@@ -1,0 +1,58 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 1999 - 2008, Digium, Inc.
+ *
+ * Matthew Nichiolson <mnicholson at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+#include <lua.h>
+#include <lauxlib.h>
+#include <lualib.h>
+
+#include "astlib_lua.h"
+
+static luaL_Reg astlib[] = {
+	{NULL, NULL},
+};
+
+int luaopen_astlib(lua_State *L) {
+	const char *asterisk_path = luaL_checkstring(L, 1);
+
+	/* set up some registry values */
+	lua_pushstring(L, asterisk_path);
+	lua_setfield(L, LUA_REGISTRYINDEX, "astlib_path");
+
+	/* register our functions */
+	luaL_register(L, "ast", astlib);
+	lua_pushstring(L, asterisk_path);
+	lua_setfield(L, -2, "path");
+	lua_pop(L, 1);
+	
+	/* load the lua portion of the lib */
+	if (luaL_loadbuffer(L, astlib_lua, sizeof(astlib_lua), "astlib"))
+		goto e_lua_error;
+	lua_pushstring(L, "ast");
+	if (lua_pcall(L, 1, 1, 0))
+		goto e_lua_error;
+
+	return 1;
+
+e_lua_error:
+	/* format the error message a little */
+	lua_pushstring(L, "error loading ast library: ");
+	lua_insert(L, -2);
+	lua_concat(L, 2);
+	return lua_error(L);
+}
+

Propchange: team/mnicholson/asttest/asttest/lua/astlib.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/mnicholson/asttest/asttest/lua/astlib.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/mnicholson/asttest/asttest/lua/astlib.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: team/mnicholson/asttest/asttest/lua/astlib.lua
URL: http://svn.digium.com/svn-view/asterisk/team/mnicholson/asttest/asttest/lua/astlib.lua?view=auto&rev=173840
==============================================================================
--- team/mnicholson/asttest/asttest/lua/astlib.lua (added)
+++ team/mnicholson/asttest/asttest/lua/astlib.lua Thu Feb  5 20:41:56 2009
@@ -1,0 +1,20 @@
+--
+-- Asterisk -- An open source telephony toolkit.
+--
+-- Copyright (C) 1999 - 2008, Digium, Inc.
+--
+-- Matthew Nichiolson <mnicholson at digium.com>
+--
+-- See http://www.asterisk.org for more information about
+-- the Asterisk project. Please do not directly contact
+-- any of the maintainers of this project for assistance;
+-- the project provides a web site, mailing lists and IRC
+-- channels for your use.
+--
+-- This program is free software, distributed under the terms of
+-- the GNU General Public License Version 2. See the LICENSE file
+-- at the top of the source tree.
+--
+
+module(..., package.seeall)
+

Propchange: team/mnicholson/asttest/asttest/lua/astlib.lua
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/mnicholson/asttest/asttest/lua/astlib.lua
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/mnicholson/asttest/asttest/lua/astlib.lua
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the asterisk-commits mailing list