Skip to content
Extraits de code Groupes Projets
Valider 60c51eb9 rédigé par Thomas Goyne's avatar Thomas Goyne
Parcourir les fichiers

Ensure the lua state gets closed when running tests

This is required for the gc metamethods to actually get run.
parent bf7503fe
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -33,6 +33,12 @@ void check(lua_State *L, int status) { ...@@ -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) { ...@@ -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) { ...@@ -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);
} }
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter