summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@samsung.com>2019-02-27 18:38:43 +0100
committerDaniel Kolesa <d.kolesa@samsung.com>2019-02-27 18:40:10 +0100
commit7924660d54500285d3844bfa384394c683825cd9 (patch)
tree2e25211189112f3d58dade602da6e1bce1a7029a
parent300b1993d830eaab0bcd85774c22759bf3cb4864 (diff)
elua tests: fix distcheck
The elua tests need to create a temporary file, so chdir'ing first will not work, as the tests source dir is immutable during distcheck. Therefore, only chdir once absolutely necessary, and before that make sure that all file accesses are to temporary ones.
-rw-r--r--src/tests/elua/elua_lib.c48
1 files changed, 26 insertions, 22 deletions
diff --git a/src/tests/elua/elua_lib.c b/src/tests/elua/elua_lib.c
index bcf1b26f90..c39d056701 100644
--- a/src/tests/elua/elua_lib.c
+++ b/src/tests/elua/elua_lib.c
@@ -29,11 +29,6 @@ EFL_START_TEST(elua_api)
29 st = elua_state_new("test"); 29 st = elua_state_new("test");
30 fail_if(!st); 30 fail_if(!st);
31 31
32 /* elua APIs here try accessing files by relative path,
33 * prevent any unintentional file accesses in cwd
34 */
35 fail_if(chdir(TESTS_SRC_DIR));
36
37 /* test env vars */ 32 /* test env vars */
38 setenv("ELUA_CORE_DIR", "foo", 1); 33 setenv("ELUA_CORE_DIR", "foo", 1);
39 setenv("ELUA_MODULES_DIR", "bar", 1); 34 setenv("ELUA_MODULES_DIR", "bar", 1);
@@ -85,22 +80,6 @@ EFL_START_TEST(elua_api)
85 fail_if(lua_type(lst, -1) != LUA_TFUNCTION); 80 fail_if(lua_type(lst, -1) != LUA_TFUNCTION);
86 lua_pop(lst, 1); 81 lua_pop(lst, 1);
87 82
88 fail_if(!elua_util_require(st, "util"));
89 fail_if(!elua_util_string_run(st, "return 1337", "foo"));
90 fail_if(elua_util_string_run(st, "foo bar", "foo")); /* invalid code */
91 fail_if(elua_util_app_load(st, "test"));
92 fail_if(lua_type(lst, -1) != LUA_TFUNCTION);
93 lua_pop(lst, 1);
94 fail_if(!elua_util_app_load(st, "non_existent_app"));
95 fail_if(lua_type(lst, -1) != LUA_TSTRING);
96 lua_pop(lst, 1);
97 fail_if(elua_io_loadfile(st, ELUA_CORE_DIR "/util.lua"));
98 fail_if(lua_type(lst, -1) != LUA_TFUNCTION);
99 lua_pop(lst, 1);
100 fail_if(!elua_io_loadfile(st, ELUA_CORE_DIR "/non_existent_file.lua"));
101 fail_if(lua_type(lst, -1) != LUA_TSTRING);
102 lua_pop(lst, 1);
103
104 fd = mkstemp(buf); 83 fd = mkstemp(buf);
105 fail_if(fd < 0); 84 fail_if(fd < 0);
106 f = fdopen(fd, "wb"); 85 f = fdopen(fd, "wb");
@@ -118,6 +97,11 @@ EFL_START_TEST(elua_api)
118 fail_if(!elua_util_error_report(st, 5)); 97 fail_if(!elua_util_error_report(st, 5));
119 fail_if(lua_gettop(lst) > 0); 98 fail_if(lua_gettop(lst) > 0);
120 99
100 f = fopen(buf, "wb");
101 fail_if(!f);
102 fprintf(f, "return true");
103 fclose(f);
104 cargv[1] = buf;
121 fail_if(!elua_util_script_run(st, 2, cargv, 1, &quit)); 105 fail_if(!elua_util_script_run(st, 2, cargv, 1, &quit));
122 fail_if(quit != 1); 106 fail_if(quit != 1);
123 107
@@ -125,11 +109,31 @@ EFL_START_TEST(elua_api)
125 fail_if(!f); 109 fail_if(!f);
126 fprintf(f, "return false"); 110 fprintf(f, "return false");
127 fclose(f); 111 fclose(f);
128 cargv[1] = buf;
129 fail_if(!elua_util_script_run(st, 2, cargv, 1, &quit)); 112 fail_if(!elua_util_script_run(st, 2, cargv, 1, &quit));
130 fail_if(quit != 0); 113 fail_if(quit != 0);
131 fail_if(remove(buf)); 114 fail_if(remove(buf));
132 115
116 /* elua API here tries accessing files by relative path,
117 * prevent any unintentional file accesses in cwd
118 */
119 fail_if(chdir(TESTS_SRC_DIR));
120
121 fail_if(!elua_util_require(st, "util"));
122 fail_if(!elua_util_string_run(st, "return 1337", "foo"));
123 fail_if(elua_util_string_run(st, "foo bar", "foo")); /* invalid code */
124 fail_if(elua_util_app_load(st, "test"));
125 fail_if(lua_type(lst, -1) != LUA_TFUNCTION);
126 lua_pop(lst, 1);
127 fail_if(!elua_util_app_load(st, "non_existent_app"));
128 fail_if(lua_type(lst, -1) != LUA_TSTRING);
129 lua_pop(lst, 1);
130 fail_if(elua_io_loadfile(st, ELUA_CORE_DIR "/util.lua"));
131 fail_if(lua_type(lst, -1) != LUA_TFUNCTION);
132 lua_pop(lst, 1);
133 fail_if(!elua_io_loadfile(st, ELUA_CORE_DIR "/non_existent_file.lua"));
134 fail_if(lua_type(lst, -1) != LUA_TSTRING);
135 lua_pop(lst, 1);
136
133 elua_state_free(st); 137 elua_state_free(st);
134} 138}
135EFL_END_TEST 139EFL_END_TEST