Files
neovim/test/functional/api/rpc_fixture.lua
Lewis Russell 9432e6c1e2 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
2026-05-13 13:14:07 +01:00

33 lines
813 B
Lua

--- RPC server fixture.
--
-- Lua's paths are passed as arguments to reflect the path in the test itself.
package.path = arg[1]
package.cpath = arg[2]
local StdioStream = require 'test.client.uv_stream'.StdioStream
local Session = require 'test.client.session'
local stdio_stream = StdioStream.open()
local session = Session.new(stdio_stream)
local function on_request(method, args)
if method == 'poll' then
return 'ok'
elseif method == 'write_stderr' then
io.stderr:write(args[1])
return 'done!'
elseif method == 'exit' then
session:stop()
return vim.NIL
end
end
local function on_notification(event, args)
if event == 'ping' and #args == 0 then
session:notify('nvim_eval', "rpcnotify(g:channel, 'pong')")
end
end
session:run(on_request, on_notification)
session:close()