From 9432e6c1e2e93ffffabeeeaeb6ccc0cbdf9609dd Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 8 May 2026 11:35:50 +0100 Subject: 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 --- src/nvim/lua/executor.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/nvim/lua/executor.c') diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index 199813bf4a..c2b1887d60 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -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); -- cgit