From f7e32fb6e626ab198bf401765236783890f3a0d6 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Wed, 6 Nov 2024 11:05:27 +0000 Subject: fix(test): better management of tmpfiles Problem: When tmpdir is local. The returned values from tmpname may already exist. This can cause problems for tests which pass `create=false` as they may require the file to not exist yet. Solution: When creating tmp names, always remove it to ensure it doesn't exist, and optionally open it if `create~=false` Additionally refactor the tmpname code and flattrn some functions into constants. Also while debugging this issue. It was discovered that `exec_lua()` doesn't report error messages properly. This has been fixed. --- test/functional/testnvim.lua | 48 +++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 23 deletions(-) (limited to 'test/functional/testnvim.lua') diff --git a/test/functional/testnvim.lua b/test/functional/testnvim.lua index 8a2281e2a1..60b2f872fc 100644 --- a/test/functional/testnvim.lua +++ b/test/functional/testnvim.lua @@ -920,36 +920,38 @@ function M.exec_lua(code, ...) return M.api.nvim_exec_lua(code, { ... }) end - assert(session) + assert(session, 'no Nvim session') if not session.exec_lua_setup then - M.api.nvim_exec_lua( - [[ - _G.__test_exec_lua = { - get_upvalues = loadstring((select(1,...))), - set_upvalues = loadstring((select(2,...))), - handler = loadstring((select(3,...))) - } - setmetatable(_G.__test_exec_lua, { __index = _G.__test_exec_lua }) - ]], - { string.dump(get_upvalues), string.dump(set_upvalues), string.dump(exec_lua_handler) } + assert( + session:request( + 'nvim_exec_lua', + [[ + _G.__test_exec_lua = { + get_upvalues = loadstring((select(1,...))), + set_upvalues = loadstring((select(2,...))), + handler = loadstring((select(3,...))) + } + setmetatable(_G.__test_exec_lua, { __index = _G.__test_exec_lua }) + ]], + { string.dump(get_upvalues), string.dump(set_upvalues), string.dump(exec_lua_handler) } + ) ) session.exec_lua_setup = true end + local stat, rv = session:request( + 'nvim_exec_lua', + 'return { _G.__test_exec_lua:handler(...) }', + { string.dump(code), get_upvalues(code), ... } + ) + + if not stat then + error(rv[2]) + end + --- @type any[], table - local ret, upvalues = unpack(M.api.nvim_exec_lua( - [[ - return { - _G.__test_exec_lua:handler(...) - } - ]], - { - string.dump(code), - get_upvalues(code), - ..., - } - )) + local ret, upvalues = unpack(rv) -- Update upvalues if next(upvalues) then -- cgit