Ensure the lua state gets closed when running tests
This is required for the gc metamethods to actually get run.
This commit is contained in:
parent
de686bdb6f
commit
eb0cf90433
1 changed files with 14 additions and 0 deletions
|
@ -33,6 +33,12 @@ void check(lua_State *L, int status) {
|
||||||
exit(status);
|
exit(status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int close_and_exit(lua_State *L) {
|
||||||
|
int status = lua_tointeger(L, 1);
|
||||||
|
lua_close(L);
|
||||||
|
exit(status);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
|
@ -54,6 +60,13 @@ int main(int argc, char **argv) {
|
||||||
preload_modules(L);
|
preload_modules(L);
|
||||||
Install(L, {"include"});
|
Install(L, {"include"});
|
||||||
|
|
||||||
|
// Patch os.exit to close the lua state first since busted calls it when
|
||||||
|
// it's done
|
||||||
|
lua_getglobal(L, "os");
|
||||||
|
lua_pushcfunction(L, close_and_exit);
|
||||||
|
lua_setfield(L, -2, "exit");
|
||||||
|
lua_pop(L, 1);
|
||||||
|
|
||||||
// Build arg table for scripts
|
// Build arg table for scripts
|
||||||
lua_createtable(L, argc - 1, 0);
|
lua_createtable(L, argc - 1, 0);
|
||||||
for (int i = 1; i < argc; ++i) {
|
for (int i = 1; i < argc; ++i) {
|
||||||
|
@ -76,5 +89,6 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
int base = lua_gettop(L) - argc + 1;
|
int base = lua_gettop(L) - argc + 1;
|
||||||
check(L, lua_pcall(L, argc - 2, LUA_MULTRET, base));
|
check(L, lua_pcall(L, argc - 2, LUA_MULTRET, base));
|
||||||
|
lua_close(L);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue