refactor(test): drop deprecated exc_exec #39242

This commit is contained in:
Justin M. Keyes
2026-04-20 14:16:41 -04:00
committed by GitHub
parent faa7c15b5a
commit 4ceca862fc
77 changed files with 1009 additions and 799 deletions

View File

@@ -2,7 +2,6 @@
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local exc_exec = n.exc_exec
local remove_trace = t.remove_trace
local fn = n.fn
local clear = n.clear
@@ -123,9 +122,12 @@ describe('luaeval(vim.api.…)', function()
-- API strings from Blobs can work as NUL-terminated C strings
eq(
'Vim(call):E5555: API call: Vim:E15: Invalid expression: ""',
exc_exec('call nvim_eval(v:_null_blob)')
pcall_err(n.command, 'call nvim_eval(v:_null_blob)')
)
eq(
'Vim(call):E5555: API call: Vim:E15: Invalid expression: ""',
pcall_err(n.command, 'call nvim_eval(0z)')
)
eq('Vim(call):E5555: API call: Vim:E15: Invalid expression: ""', exc_exec('call nvim_eval(0z)'))
eq(1, eval('nvim_eval(0z31)'))
eq(0, eval([[type(luaeval('vim.api.nvim__id(1)'))]]))
@@ -303,77 +305,92 @@ describe('luaeval(vim.api.…)', function()
it('validation', function()
-- Conversion errors
eq(
[[Vim(call):E5108: Lua: [string "luaeval()"]:1: Invalid 'obj': Cannot convert given Lua table]],
remove_trace(exc_exec([[call luaeval("vim.api.nvim__id({1, foo=42})")]]))
[[Vim(call):E5108: Lua: [string "luaeval()"]:0: Invalid 'obj': Cannot convert given Lua table]],
remove_trace(pcall_err(n.command, [[call luaeval("vim.api.nvim__id({1, foo=42})")]]))
)
-- Errors in number of arguments
eq(
'Vim(call):E5108: Lua: [string "luaeval()"]:1: Expected 1 argument',
remove_trace(exc_exec([[call luaeval("vim.api.nvim__id()")]]))
'Vim(call):E5108: Lua: [string "luaeval()"]:0: Expected 1 argument',
remove_trace(pcall_err(n.command, [[call luaeval("vim.api.nvim__id()")]]))
)
eq(
'Vim(call):E5108: Lua: [string "luaeval()"]:1: Expected 1 argument',
remove_trace(exc_exec([[call luaeval("vim.api.nvim__id(1, 2)")]]))
'Vim(call):E5108: Lua: [string "luaeval()"]:0: Expected 1 argument',
remove_trace(pcall_err(n.command, [[call luaeval("vim.api.nvim__id(1, 2)")]]))
)
eq(
'Vim(call):E5108: Lua: [string "luaeval()"]:1: Expected 2 arguments',
remove_trace(exc_exec([[call luaeval("vim.api.nvim_set_var(1, 2, 3)")]]))
'Vim(call):E5108: Lua: [string "luaeval()"]:0: Expected 2 arguments',
remove_trace(pcall_err(n.command, [[call luaeval("vim.api.nvim_set_var(1, 2, 3)")]]))
)
-- Error in argument types
eq(
[[Vim(call):E5108: Lua: [string "luaeval()"]:1: Invalid 'name': Expected Lua string]],
remove_trace(exc_exec([[call luaeval("vim.api.nvim_set_var(1, 2)")]]))
[[Vim(call):E5108: Lua: [string "luaeval()"]:0: Invalid 'name': Expected Lua string]],
remove_trace(pcall_err(n.command, [[call luaeval("vim.api.nvim_set_var(1, 2)")]]))
)
eq(
[[Vim(call):E5108: Lua: [string "luaeval()"]:1: Invalid 'start': Expected Lua number]],
remove_trace(exc_exec([[call luaeval("vim.api.nvim_buf_get_lines(0, 'test', 1, false)")]]))
)
eq(
[[Vim(call):E5108: Lua: [string "luaeval()"]:1: Invalid 'start': Number is not integral]],
remove_trace(exc_exec([[call luaeval("vim.api.nvim_buf_get_lines(0, 1.5, 1, false)")]]))
)
eq(
[[Vim(call):E5108: Lua: [string "luaeval()"]:1: Invalid 'win': Expected Lua number]],
remove_trace(exc_exec([[call luaeval("vim.api.nvim_win_is_valid(nil)")]]))
)
eq(
[[Vim(call):E5108: Lua: [string "luaeval()"]:1: Invalid 'flt': Expected Lua number]],
remove_trace(exc_exec([[call luaeval("vim.api.nvim__id_float('test')")]]))
)
eq(
[[Vim(call):E5108: Lua: [string "luaeval()"]:1: Invalid 'flt': Expected Float-like Lua table]],
[[Vim(call):E5108: Lua: [string "luaeval()"]:0: Invalid 'start': Expected Lua number]],
remove_trace(
exc_exec([[call luaeval("vim.api.nvim__id_float({[vim.type_idx]=vim.types.dictionary})")]])
pcall_err(n.command, [[call luaeval("vim.api.nvim_buf_get_lines(0, 'test', 1, false)")]])
)
)
eq(
[[Vim(call):E5108: Lua: [string "luaeval()"]:0: Invalid 'start': Number is not integral]],
remove_trace(
pcall_err(n.command, [[call luaeval("vim.api.nvim_buf_get_lines(0, 1.5, 1, false)")]])
)
)
eq(
[[Vim(call):E5108: Lua: [string "luaeval()"]:0: Invalid 'win': Expected Lua number]],
remove_trace(pcall_err(n.command, [[call luaeval("vim.api.nvim_win_is_valid(nil)")]]))
)
eq(
[[Vim(call):E5108: Lua: [string "luaeval()"]:0: Invalid 'flt': Expected Lua number]],
remove_trace(pcall_err(n.command, [[call luaeval("vim.api.nvim__id_float('test')")]]))
)
eq(
[[Vim(call):E5108: Lua: [string "luaeval()"]:0: Invalid 'flt': Expected Float-like Lua table]],
remove_trace(
pcall_err(
n.command,
[[call luaeval("vim.api.nvim__id_float({[vim.type_idx]=vim.types.dictionary})")]]
)
)
)
eq(
[[Vim(call):E5108: Lua: [string "luaeval()"]:1: Invalid 'arr': Expected Lua table]],
remove_trace(exc_exec([[call luaeval("vim.api.nvim__id_array(1)")]]))
[[Vim(call):E5108: Lua: [string "luaeval()"]:0: Invalid 'arr': Expected Lua table]],
remove_trace(pcall_err(n.command, [[call luaeval("vim.api.nvim__id_array(1)")]]))
)
eq(
[[Vim(call):E5108: Lua: [string "luaeval()"]:1: Invalid 'arr': Expected Array-like Lua table]],
[[Vim(call):E5108: Lua: [string "luaeval()"]:0: Invalid 'arr': Expected Array-like Lua table]],
remove_trace(
exc_exec([[call luaeval("vim.api.nvim__id_array({[vim.type_idx]=vim.types.dictionary})")]])
pcall_err(
n.command,
[[call luaeval("vim.api.nvim__id_array({[vim.type_idx]=vim.types.dictionary})")]]
)
)
)
eq(
[[Vim(call):E5108: Lua: [string "luaeval()"]:1: Invalid 'dct': Expected Lua table]],
remove_trace(exc_exec([[call luaeval("vim.api.nvim__id_dict(1)")]]))
[[Vim(call):E5108: Lua: [string "luaeval()"]:0: Invalid 'dct': Expected Lua table]],
remove_trace(pcall_err(n.command, [[call luaeval("vim.api.nvim__id_dict(1)")]]))
)
eq(
[[Vim(call):E5108: Lua: [string "luaeval()"]:1: Invalid 'dct': Expected Dict-like Lua table]],
[[Vim(call):E5108: Lua: [string "luaeval()"]:0: Invalid 'dct': Expected Dict-like Lua table]],
remove_trace(
exc_exec([[call luaeval("vim.api.nvim__id_dict({[vim.type_idx]=vim.types.array})")]])
pcall_err(
n.command,
[[call luaeval("vim.api.nvim__id_dict({[vim.type_idx]=vim.types.array})")]]
)
)
)
eq(
[[Vim(call):E5108: Lua: [string "luaeval()"]:1: Expected Lua table]],
remove_trace(exc_exec([[call luaeval("vim.api.nvim_set_keymap('', '', '', '')")]]))
[[Vim(call):E5108: Lua: [string "luaeval()"]:0: Expected Lua table]],
remove_trace(
pcall_err(n.command, [[call luaeval("vim.api.nvim_set_keymap('', '', '', '')")]])
)
)
-- TODO: check for errors with Tabpage argument

View File

@@ -16,7 +16,6 @@ local fn = n.fn
local source = n.source
local dedent = t.dedent
local command = n.command
local exc_exec = n.exc_exec
local pcall_err = t.pcall_err
local write_file = t.write_file
local remove_trace = t.remove_trace
@@ -63,18 +62,18 @@ describe(':lua', function()
pcall_err(command, 'lua ()')
)
eq(
[[Vim(lua):E5108: Lua: [string ":lua"]:1: TEST]],
remove_trace(exc_exec('lua error("TEST")'))
[[Vim(lua):E5108: Lua: [string ":lua"]:0: TEST]],
remove_trace(pcall_err(command, 'lua error("TEST")'))
)
eq(
[[Vim(lua):E5108: Lua: [string ":lua"]:1: Invalid buffer id: -10]],
remove_trace(exc_exec('lua vim.api.nvim_buf_set_lines(-10, 1, 1, false, {"TEST"})'))
[[Vim(lua):E5108: Lua: [string ":lua"]:0: Invalid buffer id: -10]],
remove_trace(pcall_err(command, 'lua vim.api.nvim_buf_set_lines(-10, 1, 1, false, {"TEST"})'))
)
eq({ '' }, api.nvim_buf_get_lines(0, 0, 100, false))
end)
it('works with NULL errors', function()
eq([=[Vim(lua):E5108: Lua: [NULL]]=], exc_exec('lua error(nil)'))
eq([=[Vim(lua):E5108: Lua: [NULL]]=], pcall_err(command, 'lua error(nil)'))
end)
it('accepts embedded NLs without heredoc', function()
@@ -144,10 +143,8 @@ describe(':lua', function()
remove_trace(eval('v:errmsg'))
)
local status, err = pcall(command, 'lua error("some error\\nin a\\nAPI command")')
local expected = 'Vim(lua):E5108: Lua: [string ":lua"]:1: some error\nin a\nAPI command'
eq(false, status)
eq(expected, string.sub(remove_trace(err), -string.len(expected)))
local expected = 'Vim(lua):E5108: Lua: [string ":lua"]:0: some error\nin a\nAPI command'
eq(expected, remove_trace(pcall_err(command, 'lua error("some error\\nin a\\nAPI command")')))
feed(':messages<cr>')
screen:expect([[
@@ -284,7 +281,7 @@ describe(':luado command', function()
end)
it('works with NULL errors', function()
eq([=[Vim(luado):E5111: Lua: [NULL]]=], exc_exec('luado error(nil)'))
eq([=[Vim(luado):E5111: Lua: [NULL]]=], pcall_err(command, 'luado error(nil)'))
end)
it('fails in sandbox when needed', function()
@@ -334,19 +331,19 @@ describe(':luafile', function()
write_file(fname, '()')
eq(
("Vim(luafile):E5112: Lua chunk: %s:1: unexpected symbol near ')'"):format(fname),
exc_exec('luafile ' .. fname)
pcall_err(command, 'luafile ' .. fname)
)
write_file(fname, 'vimm.api.nvim_buf_set_lines(1, 1, 2, false, {"ETTS"})')
eq(
("Vim(luafile):E5113: Lua chunk: %s:1: attempt to index global 'vimm' (a nil value)"):format(
fname
),
remove_trace(exc_exec('luafile ' .. fname))
remove_trace(pcall_err(command, 'luafile ' .. fname))
)
end)
it('works with NULL errors', function()
write_file(fname, 'error(nil)')
eq([=[Vim(luafile):E5113: Lua chunk: [NULL]]=], exc_exec('luafile ' .. fname))
eq([=[Vim(luafile):E5113: Lua chunk: [NULL]]=], pcall_err(command, 'luafile ' .. fname))
end)
end)

View File

@@ -4,7 +4,6 @@ local n = require('test.functional.testnvim')()
local Screen = require('test.functional.ui.screen')
local pcall_err = t.pcall_err
local exc_exec = n.exc_exec
local remove_trace = t.remove_trace
local exec_lua = n.exec_lua
local command = n.command
@@ -198,11 +197,17 @@ describe('luaeval()', function()
it('failure modes', function()
eq(
'Vim(call):E5100: Cannot convert given Lua table: table should contain either only integer keys or only string keys',
exc_exec('call luaeval("{1, foo=2}")')
pcall_err(command, 'call luaeval("{1, foo=2}")')
)
startswith('Vim(call):E5107: Lua: [string "luaeval()"]:', exc_exec('call luaeval("1, 2, 3")'))
startswith('Vim(call):E5108: Lua: [string "luaeval()"]:', exc_exec('call luaeval("(nil)()")'))
startswith(
'Vim(call):E5107: Lua: [string "luaeval()"]:',
pcall_err(command, 'call luaeval("1, 2, 3")')
)
startswith(
'Vim(call):E5108: Lua: [string "luaeval()"]:',
pcall_err(command, 'call luaeval("(nil)()")')
)
end)
it('handles sending lua functions to viml', function()
@@ -482,21 +487,24 @@ describe('luaeval()', function()
it('fails when doing incorrect things in lua', function()
-- Conversion errors
eq(
'Vim(call):E5108: Lua: [string "luaeval()"]:1: attempt to call field \'xxx_nonexistent_key_xxx\' (a nil value)',
remove_trace(exc_exec([[call luaeval("vim.xxx_nonexistent_key_xxx()")]]))
'Vim(call):E5108: Lua: [string "luaeval()"]:0: attempt to call field \'xxx_nonexistent_key_xxx\' (a nil value)',
remove_trace(pcall_err(command, [[call luaeval("vim.xxx_nonexistent_key_xxx()")]]))
)
eq(
'Vim(call):E5108: Lua: [string "luaeval()"]:1: ERROR',
remove_trace(exc_exec([[call luaeval("error('ERROR')")]]))
'Vim(call):E5108: Lua: [string "luaeval()"]:0: ERROR',
remove_trace(pcall_err(command, [[call luaeval("error('ERROR')")]]))
)
eq(
'Vim(call):E5108: Lua: [NULL]',
remove_trace(pcall_err(command, [[call luaeval("error(nil)")]]))
)
eq('Vim(call):E5108: Lua: [NULL]', remove_trace(exc_exec([[call luaeval("error(nil)")]])))
end)
it('does not leak memory when called with too long line', function()
local s = ('x'):rep(65536)
eq(
'Vim(call):E5107: Lua: [string "luaeval()"]:1: unexpected symbol near \')\'',
exc_exec([[call luaeval("(']] .. s .. [[' + )")]])
'Vim(call):E5107: Lua: [string "luaeval()"]:0: unexpected symbol near \')\'',
pcall_err(command, [[call luaeval("(']] .. s .. [[' + )")]])
)
eq(s, fn.luaeval('"' .. s .. '"'))
end)

View File

@@ -1,5 +1,6 @@
local n = require('test.functional.testnvim')()
local t = require('test.testutil')
local pcall_err = t.pcall_err
local skip_integ = os.getenv('NVIM_TEST_INTEG') ~= '1'
local exec_lua = n.exec_lua

View File

@@ -4,6 +4,7 @@ local n = require('test.functional.testnvim')()
local clear = n.clear
local exec_lua = n.exec_lua
local eq = t.eq
local pcall_err = t.pcall_err
local function system_sync(cmd, opts)
return exec_lua(function()

View File

@@ -1,6 +1,7 @@
local t = require('test.testutil')
local eq = t.eq
local pcall_err = t.pcall_err
describe('vim.text', function()
describe('indent()', function()

View File

@@ -2,6 +2,7 @@ local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local eq = t.eq
local pcall_err = t.pcall_err
local ok = t.ok
local exec_lua = n.exec_lua
local clear = n.clear