[asterisk-commits] mnicholson: branch mnicholson/asttest r170386 - /team/mnicholson/asttest/astt...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Jan 22 20:33:26 CST 2009


Author: mnicholson
Date: Thu Jan 22 20:33:26 2009
New Revision: 170386

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=170386
Log:
chdir() into the test directory before executing a test

Modified:
    team/mnicholson/asttest/asttest/asttest.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=170386&r1=170385&r2=170386
==============================================================================
--- team/mnicholson/asttest/asttest/asttest.c (original)
+++ team/mnicholson/asttest/asttest/asttest.c Thu Jan 22 20:33:26 2009
@@ -186,16 +186,28 @@
 }
 
 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_ERROR;
-	if (!L) {
+	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);
 	}
 
-	snprintf(test_file_path, sizeof(test_file_path), "%s/test.lua", test_dir_path);
-	if (luaL_dofile(L, test_file_path)) {
+	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*/
@@ -204,6 +216,9 @@
 		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;




More information about the asterisk-commits mailing list