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

@@ -157,14 +157,6 @@ describe('startup', function()
end)
it('os.exit() sets Nvim exitcode', function()
-- tricky: LeakSanitizer triggers on os.exit() and disrupts the return value, disable it
exec_lua [[
local asan_options = os.getenv('ASAN_OPTIONS') or ''
if asan_options ~= '' then
asan_options = asan_options .. ':'
end
vim.uv.os_setenv('ASAN_OPTIONS', asan_options .. ':detect_leaks=0')
]]
-- nvim -l foo.lua -arg1 -- a b c
assert_l_out(
[[
@@ -179,6 +171,38 @@ describe('startup', function()
eq(73, eval('v:shell_error'))
end)
it('os.exit() runs Nvim teardown', function()
local exit_file = t.tmpname(false)
finally(function()
os.remove(exit_file)
end)
fn.system(
{
nvim_prog,
'-u',
'NONE',
'-i',
'NONE',
'--cmd',
'set shada=',
'-l',
'-',
},
([[
vim.api.nvim_create_autocmd('VimLeave', {
callback = function()
vim.fn.writefile({ tostring(vim.v.exiting) }, %s)
end,
})
os.exit(73)
]]):format(vim.inspect(exit_file))
)
eq(73, eval('v:shell_error'))
eq('73\n', read_file(exit_file))
end)
it('Lua-error sets Nvim exitcode', function()
local proc = n.spawn_wait('-l', 'test/functional/fixtures/startup-fail.lua')
matches('E5113: .* my pearls!!', (proc:output()))