test: run Lua harness with nvim -l

Problem:
The Lua test harness still ran through standalone -ll mode, so tests
depended on the low-level Lua path instead of the regular Nvim Lua
environment. That also meant os.exit() coverage had to carry an ASAN
workaround because Lua's raw process exit skipped Nvim teardown and let
LeakSanitizer interfere with the observed exit code.

Solution:
Run the harness and related fixtures with nvim -l. Patch os.exit() in
the main Lua state to exit through getout(), so scripts observe normal
Nvim shutdown while standalone -ll remains available for generator-style
scripts. As a consequence, the startup test can assert os.exit() without
disabling leak detection.

AI-assisted: Codex
This commit is contained in:
Lewis Russell
2026-05-08 11:35:50 +01:00
committed by Lewis Russell
parent 706cbbff33
commit 9432e6c1e2
17 changed files with 166 additions and 46 deletions

View File

@@ -601,6 +601,17 @@ static int nlua_check_interrupt(lua_State *lstate)
return 1;
}
static int nlua_os_exit(lua_State *lstate)
{
int status = 0;
if (lua_gettop(lstate) >= 1 && !lua_isnil(lstate, 1)) {
status = lua_isboolean(lstate, 1) ? (lua_toboolean(lstate, 1) ? 0 : 1)
: (int)luaL_checkinteger(lstate, 1);
}
getout(status);
return 0; // Unreachable, but MSVC does not infer getout() is noreturn.
}
static nlua_ref_state_t *nlua_new_ref_state(lua_State *lstate, bool is_thread)
FUNC_ATTR_NONNULL_ALL
{
@@ -841,6 +852,12 @@ static bool nlua_state_init(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL
lua_pop(lstate, 1);
#endif
// os.exit()
lua_getglobal(lstate, "os");
lua_pushcfunction(lstate, &nlua_os_exit);
lua_setfield(lstate, -2, "exit");
lua_pop(lstate, 1);
// vim
lua_newtable(lstate);