aboutsummaryrefslogtreecommitdiff
path: root/test/functional/lua
diff options
context:
space:
mode:
authorGregory Anders <8965202+gpanders@users.noreply.github.com>2021-11-06 08:26:10 -0600
committerGitHub <noreply@github.com>2021-11-06 08:26:10 -0600
commit03b805aee617f67eb7f33a54822bc76c23a2c5f5 (patch)
treefc27127d462fe91159eb99c5a724c7b10e459f1b /test/functional/lua
parent1fdbd29dfa6366f8346693d0bf67f4f782ab0f32 (diff)
downloadrneovim-03b805aee617f67eb7f33a54822bc76c23a2c5f5.tar.gz
rneovim-03b805aee617f67eb7f33a54822bc76c23a2c5f5.tar.bz2
rneovim-03b805aee617f67eb7f33a54822bc76c23a2c5f5.zip
feat(lua): enable stack traces in error output (#16228)
Diffstat (limited to 'test/functional/lua')
-rw-r--r--test/functional/lua/api_spec.lua33
-rw-r--r--test/functional/lua/commands_spec.lua27
-rw-r--r--test/functional/lua/loop_spec.lua8
-rw-r--r--test/functional/lua/luaeval_spec.lua7
-rw-r--r--test/functional/lua/overrides_spec.lua12
-rw-r--r--test/functional/lua/vim_spec.lua139
6 files changed, 85 insertions, 141 deletions
diff --git a/test/functional/lua/api_spec.lua b/test/functional/lua/api_spec.lua
index 8551c3d2a0..81e00bba6d 100644
--- a/test/functional/lua/api_spec.lua
+++ b/test/functional/lua/api_spec.lua
@@ -2,6 +2,7 @@
local helpers = require('test.functional.helpers')(after_each)
local exc_exec = helpers.exc_exec
+local remove_trace = helpers.remove_trace
local funcs = helpers.funcs
local clear = helpers.clear
local eval = helpers.eval
@@ -159,44 +160,44 @@ describe('luaeval(vim.api.…)', function()
it('errors out correctly when working with API', function()
-- Conversion errors
eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Cannot convert given lua type',
- exc_exec([[call luaeval("vim.api.nvim__id(vim.api.nvim__id)")]]))
+ remove_trace(exc_exec([[call luaeval("vim.api.nvim__id(vim.api.nvim__id)")]])))
eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Cannot convert given lua table',
- exc_exec([[call luaeval("vim.api.nvim__id({1, foo=42})")]]))
+ remove_trace(exc_exec([[call luaeval("vim.api.nvim__id({1, foo=42})")]])))
eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Cannot convert given lua type',
- exc_exec([[call luaeval("vim.api.nvim__id({42, vim.api.nvim__id})")]]))
+ remove_trace(exc_exec([[call luaeval("vim.api.nvim__id({42, vim.api.nvim__id})")]])))
-- Errors in number of arguments
eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Expected 1 argument',
- exc_exec([[call luaeval("vim.api.nvim__id()")]]))
+ remove_trace(exc_exec([[call luaeval("vim.api.nvim__id()")]])))
eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Expected 1 argument',
- exc_exec([[call luaeval("vim.api.nvim__id(1, 2)")]]))
+ remove_trace(exc_exec([[call luaeval("vim.api.nvim__id(1, 2)")]])))
eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Expected 2 arguments',
- exc_exec([[call luaeval("vim.api.nvim_set_var(1, 2, 3)")]]))
+ remove_trace(exc_exec([[call luaeval("vim.api.nvim_set_var(1, 2, 3)")]])))
-- Error in argument types
eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Expected lua string',
- exc_exec([[call luaeval("vim.api.nvim_set_var(1, 2)")]]))
+ remove_trace(exc_exec([[call luaeval("vim.api.nvim_set_var(1, 2)")]])))
eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Expected lua number',
- exc_exec([[call luaeval("vim.api.nvim_buf_get_lines(0, 'test', 1, false)")]]))
+ remove_trace(exc_exec([[call luaeval("vim.api.nvim_buf_get_lines(0, 'test', 1, false)")]])))
eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Number is not integral',
- exc_exec([[call luaeval("vim.api.nvim_buf_get_lines(0, 1.5, 1, false)")]]))
+ remove_trace(exc_exec([[call luaeval("vim.api.nvim_buf_get_lines(0, 1.5, 1, false)")]])))
eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Expected lua table',
- exc_exec([[call luaeval("vim.api.nvim__id_float('test')")]]))
+ remove_trace(exc_exec([[call luaeval("vim.api.nvim__id_float('test')")]])))
eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Unexpected type',
- exc_exec([[call luaeval("vim.api.nvim__id_float({[vim.type_idx]=vim.types.dictionary})")]]))
+ remove_trace(exc_exec([[call luaeval("vim.api.nvim__id_float({[vim.type_idx]=vim.types.dictionary})")]])))
eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Expected lua table',
- exc_exec([[call luaeval("vim.api.nvim__id_array(1)")]]))
+ remove_trace(exc_exec([[call luaeval("vim.api.nvim__id_array(1)")]])))
eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Unexpected type',
- exc_exec([[call luaeval("vim.api.nvim__id_array({[vim.type_idx]=vim.types.dictionary})")]]))
+ remove_trace(exc_exec([[call luaeval("vim.api.nvim__id_array({[vim.type_idx]=vim.types.dictionary})")]])))
eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Expected lua table',
- exc_exec([[call luaeval("vim.api.nvim__id_dictionary(1)")]]))
+ remove_trace(exc_exec([[call luaeval("vim.api.nvim__id_dictionary(1)")]])))
eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Unexpected type',
- exc_exec([[call luaeval("vim.api.nvim__id_dictionary({[vim.type_idx]=vim.types.array})")]]))
+ remove_trace(exc_exec([[call luaeval("vim.api.nvim__id_dictionary({[vim.type_idx]=vim.types.array})")]])))
eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Expected lua table',
- exc_exec([[call luaeval("vim.api.nvim_set_keymap('', '', '', '')")]]))
+ remove_trace(exc_exec([[call luaeval("vim.api.nvim_set_keymap('', '', '', '')")]])))
-- TODO: check for errors with Tabpage argument
-- TODO: check for errors with Window argument
diff --git a/test/functional/lua/commands_spec.lua b/test/functional/lua/commands_spec.lua
index 2e0d0ea899..9b9ba531b0 100644
--- a/test/functional/lua/commands_spec.lua
+++ b/test/functional/lua/commands_spec.lua
@@ -17,6 +17,7 @@ local pcall_err = helpers.pcall_err
local write_file = helpers.write_file
local exec_capture = helpers.exec_capture
local curbufmeths = helpers.curbufmeths
+local remove_trace = helpers.remove_trace
before_each(clear)
@@ -46,9 +47,9 @@ describe(':lua command', function()
eq([[Vim(lua):E5107: Error loading lua [string ":lua"]:0: unexpected symbol near ')']],
pcall_err(command, 'lua ()'))
eq([[Vim(lua):E5108: Error executing lua [string ":lua"]:1: TEST]],
- exc_exec('lua error("TEST")'))
+ remove_trace(exc_exec('lua error("TEST")')))
eq([[Vim(lua):E5108: Error executing lua [string ":lua"]:1: Invalid buffer id: -10]],
- exc_exec('lua vim.api.nvim_buf_set_lines(-10, 1, 1, false, {"TEST"})'))
+ remove_trace(exc_exec('lua vim.api.nvim_buf_set_lines(-10, 1, 1, false, {"TEST"})')))
eq({''}, curbufmeths.get_lines(0, 100, false))
end)
it('works with NULL errors', function()
@@ -95,15 +96,15 @@ describe(':lua command', function()
feed(':lua error("fail\\nmuch error\\nsuch details")<cr>')
screen:expect{grid=[[
- |
- {1:~ }|
- {1:~ }|
- {1:~ }|
{2: }|
{3:E5108: Error executing lua [string ":lua}|
{3:"]:1: fail} |
{3:much error} |
{3:such details} |
+ {3:stack traceback:} |
+ {3: [C]: in function 'error'} |
+ {3: [string ":lua"]:1: in main chunk}|
+ |
{4:Press ENTER or type command to continue}^ |
]]}
feed('<cr>')
@@ -119,24 +120,24 @@ describe(':lua command', function()
{1:~ }|
|
]]}
- eq('E5108: Error executing lua [string ":lua"]:1: fail\nmuch error\nsuch details', eval('v:errmsg'))
+ eq('E5108: Error executing lua [string ":lua"]:1: fail\nmuch error\nsuch details', remove_trace(eval('v:errmsg')))
local status, err = pcall(command,'lua error("some error\\nin a\\nAPI command")')
local expected = 'Vim(lua):E5108: Error executing lua [string ":lua"]:1: some error\nin a\nAPI command'
eq(false, status)
- eq(expected, string.sub(err, -string.len(expected)))
+ eq(expected, string.sub(remove_trace(err), -string.len(expected)))
feed(':messages<cr>')
screen:expect{grid=[[
- |
- {1:~ }|
- {1:~ }|
- {1:~ }|
{2: }|
{3:E5108: Error executing lua [string ":lua}|
{3:"]:1: fail} |
{3:much error} |
{3:such details} |
+ {3:stack traceback:} |
+ {3: [C]: in function 'error'} |
+ {3: [string ":lua"]:1: in main chunk}|
+ |
{4:Press ENTER or type command to continue}^ |
]]}
end)
@@ -219,7 +220,7 @@ describe(':luafile', function()
exc_exec('luafile ' .. fname))
write_file(fname, 'vimm.api.nvim_buf_set_lines(1, 1, 2, false, {"ETTS"})')
eq(("Vim(luafile):E5113: Error while calling lua chunk: %s:1: attempt to index global 'vimm' (a nil value)"):format(fname),
- exc_exec('luafile ' .. fname))
+ remove_trace(exc_exec('luafile ' .. fname)))
end)
it('works with NULL errors', function()
write_file(fname, 'error(nil)')
diff --git a/test/functional/lua/loop_spec.lua b/test/functional/lua/loop_spec.lua
index 992d1666f6..7f3787d7bf 100644
--- a/test/functional/lua/loop_spec.lua
+++ b/test/functional/lua/loop_spec.lua
@@ -84,14 +84,14 @@ describe('vim.loop', function()
screen:expect([[
|
- {1:~ }|
- {1:~ }|
- {1:~ }|
- {1:~ }|
{2: }|
{3:Error executing luv callback:} |
{3:[string "<nvim>"]:5: E5560: nvim_set_var must not }|
{3:be called in a lua loop callback} |
+ {3:stack traceback:} |
+ {3: [C]: in function 'nvim_set_var'} |
+ {3: [string "<nvim>"]:5: in function <[string }|
+ {3:"<nvim>"]:2>} |
{4:Press ENTER or type command to continue}^ |
]])
feed('<cr>')
diff --git a/test/functional/lua/luaeval_spec.lua b/test/functional/lua/luaeval_spec.lua
index ab76e71a12..c543dd1995 100644
--- a/test/functional/lua/luaeval_spec.lua
+++ b/test/functional/lua/luaeval_spec.lua
@@ -4,6 +4,7 @@ local Screen = require('test.functional.ui.screen')
local pcall_err = helpers.pcall_err
local exc_exec = helpers.exc_exec
+local remove_trace = helpers.remove_trace
local exec_lua = helpers.exec_lua
local command = helpers.command
local meths = helpers.meths
@@ -424,11 +425,11 @@ describe('luaeval()', function()
it('errors out correctly when doing incorrect things in lua', function()
-- Conversion errors
eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: attempt to call field \'xxx_nonexistent_key_xxx\' (a nil value)',
- exc_exec([[call luaeval("vim.xxx_nonexistent_key_xxx()")]]))
+ remove_trace(exc_exec([[call luaeval("vim.xxx_nonexistent_key_xxx()")]])))
eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: ERROR',
- exc_exec([[call luaeval("error('ERROR')")]]))
+ remove_trace(exc_exec([[call luaeval("error('ERROR')")]])))
eq('Vim(call):E5108: Error executing lua [NULL]',
- exc_exec([[call luaeval("error(nil)")]]))
+ remove_trace(exc_exec([[call luaeval("error(nil)")]])))
end)
it('does not leak memory when called with too long line',
diff --git a/test/functional/lua/overrides_spec.lua b/test/functional/lua/overrides_spec.lua
index 636479b81f..b0712ff366 100644
--- a/test/functional/lua/overrides_spec.lua
+++ b/test/functional/lua/overrides_spec.lua
@@ -161,15 +161,15 @@ describe('debug.debug', function()
{0:~ }|
{0:~ }|
{0:~ }|
- {0:~ }|
- {0:~ }|
- {0:~ }|
nil |
lua_debug> print("TEST") |
TEST |
|
{E:E5108: Error executing lua [string ":lua"]:5: attempt}|
{E: to perform arithmetic on local 'a' (a nil value)} |
+ {E:stack traceback:} |
+ {E: [string ":lua"]:5: in function 'Test'} |
+ {E: [string ":lua"]:1: in main chunk} |
Interrupt: {cr:Press ENTER or type command to continue}^ |
]]}
feed('<C-l>:lua Test()\n')
@@ -197,13 +197,13 @@ describe('debug.debug', function()
{0:~ }|
{0:~ }|
{0:~ }|
- {0:~ }|
- {0:~ }|
- {0:~ }|
nil |
lua_debug> |
{E:E5108: Error executing lua [string ":lua"]:5: attempt}|
{E: to perform arithmetic on local 'a' (a nil value)} |
+ {E:stack traceback:} |
+ {E: [string ":lua"]:5: in function 'Test'} |
+ {E: [string ":lua"]:1: in main chunk} |
{cr:Press ENTER or type command to continue}^ |
]]}
end)
diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua
index 5f903e7d5f..3832d27a22 100644
--- a/test/functional/lua/vim_spec.lua
+++ b/test/functional/lua/vim_spec.lua
@@ -4,7 +4,6 @@ local Screen = require('test.functional.ui.screen')
local funcs = helpers.funcs
local meths = helpers.meths
-local dedent = helpers.dedent
local command = helpers.command
local insert = helpers.insert
local clear = helpers.clear
@@ -19,6 +18,7 @@ local source = helpers.source
local NIL = helpers.NIL
local retry = helpers.retry
local next_msg = helpers.next_msg
+local remove_trace = helpers.remove_trace
before_each(clear)
@@ -121,11 +121,6 @@ describe('lua stdlib', function()
eq(1, funcs.luaeval('vim.stricmp("\\0C\\0", "\\0B\\0")'))
end)
- -- for brevity, match only the error header (not the traceback)
- local function pcall_header(...)
- return string.gsub(string.gsub(pcall_err(exec_lua, ...), '[\r\n].*', ''), '^Error executing lua: ', '')
- end
-
it('vim.startswith', function()
eq(true, funcs.luaeval('vim.startswith("123", "1")'))
eq(true, funcs.luaeval('vim.startswith("123", "")'))
@@ -136,8 +131,10 @@ describe('lua stdlib', function()
eq(false, funcs.luaeval('vim.startswith("123", "2")'))
eq(false, funcs.luaeval('vim.startswith("123", "1234")'))
- eq("vim/shared.lua:0: prefix: expected string, got nil", pcall_header 'return vim.startswith("123", nil)')
- eq("vim/shared.lua:0: s: expected string, got nil", pcall_header 'return vim.startswith(nil, "123")')
+ eq("Error executing lua: vim/shared.lua:0: prefix: expected string, got nil",
+ pcall_err(exec_lua, 'return vim.startswith("123", nil)'))
+ eq("Error executing lua: vim/shared.lua:0: s: expected string, got nil",
+ pcall_err(exec_lua, 'return vim.startswith(nil, "123")'))
end)
it('vim.endswith', function()
@@ -150,8 +147,10 @@ describe('lua stdlib', function()
eq(false, funcs.luaeval('vim.endswith("123", "2")'))
eq(false, funcs.luaeval('vim.endswith("123", "1234")'))
- eq("vim/shared.lua:0: suffix: expected string, got nil", pcall_header 'return vim.endswith("123", nil)')
- eq("vim/shared.lua:0: s: expected string, got nil", pcall_header 'return vim.endswith(nil, "123")')
+ eq("Error executing lua: vim/shared.lua:0: suffix: expected string, got nil",
+ pcall_err(exec_lua, 'return vim.endswith("123", nil)'))
+ eq("Error executing lua: vim/shared.lua:0: s: expected string, got nil",
+ pcall_err(exec_lua, 'return vim.endswith(nil, "123")'))
end)
it("vim.str_utfindex/str_byteindex", function()
@@ -233,7 +232,7 @@ describe('lua stdlib', function()
]])
feed("<cr>")
- eq('Error executing vim.schedule lua callback: [string "<nvim>"]:2: big failure\nvery async', eval("v:errmsg"))
+ eq('Error executing vim.schedule lua callback: [string "<nvim>"]:2: big failure\nvery async', remove_trace(eval("v:errmsg")))
local screen = Screen.new(60,5)
screen:set_default_attr_ids({
@@ -259,10 +258,10 @@ describe('lua stdlib', function()
end)
]])
screen:expect{grid=[[
- |
- {2: }|
- {3:Error executing vim.schedule lua callback: [string "<nvim>"]}|
- {3::2: Vim(echo):E115: Missing quote: 'err} |
+ {3:stack traceback:} |
+ {3: [C]: in function 'nvim_command'} |
+ {3: [string "<nvim>"]:2: in function <[string "<nvim>"]:}|
+ {3:1>} |
{4:Press ENTER or type command to continue}^ |
]]}
end)
@@ -306,22 +305,11 @@ describe('lua stdlib', function()
-- Validates args.
eq(true, pcall(split, 'string', 'string'))
- eq(dedent([[
- Error executing lua: vim/shared.lua:0: s: expected string, got number
- stack traceback:
- vim/shared.lua:0: in function 'gsplit'
- vim/shared.lua:0: in function <vim/shared.lua:0>]]),
+ eq('Error executing lua: vim/shared.lua:0: s: expected string, got number',
pcall_err(split, 1, 'string'))
- eq(dedent([[
- Error executing lua: vim/shared.lua:0: sep: expected string, got number
- stack traceback:
- vim/shared.lua:0: in function 'gsplit'
- vim/shared.lua:0: in function <vim/shared.lua:0>]]),
+ eq('Error executing lua: vim/shared.lua:0: sep: expected string, got number',
pcall_err(split, 'string', 1))
- eq(dedent([[
- Error executing lua: vim/shared.lua:0: kwargs: expected table, got number
- stack traceback:
- vim/shared.lua:0: in function <vim/shared.lua:0>]]),
+ eq('Error executing lua: vim/shared.lua:0: kwargs: expected table, got number',
pcall_err(split, 'string', 'string', 1))
end)
@@ -342,10 +330,7 @@ describe('lua stdlib', function()
end
-- Validates args.
- eq(dedent([[
- Error executing lua: vim/shared.lua:0: s: expected string, got number
- stack traceback:
- vim/shared.lua:0: in function <vim/shared.lua:0>]]),
+ eq('Error executing lua: vim/shared.lua:0: s: expected string, got number',
pcall_err(trim, 2))
end)
@@ -424,10 +409,7 @@ describe('lua stdlib', function()
eq('foo%%%-bar', exec_lua([[return vim.pesc(vim.pesc('foo-bar'))]]))
-- Validates args.
- eq(dedent([[
- Error executing lua: vim/shared.lua:0: s: expected string, got number
- stack traceback:
- vim/shared.lua:0: in function <vim/shared.lua:0>]]),
+ eq('Error executing lua: vim/shared.lua:0: s: expected string, got number',
pcall_err(exec_lua, [[return vim.pesc(2)]]))
end)
@@ -710,10 +692,7 @@ describe('lua stdlib', function()
it('vim.list_extend', function()
eq({1,2,3}, exec_lua [[ return vim.list_extend({1}, {2,3}) ]])
- eq(dedent([[
- Error executing lua: vim/shared.lua:0: src: expected table, got nil
- stack traceback:
- vim/shared.lua:0: in function <vim/shared.lua:0>]]),
+ eq('Error executing lua: vim/shared.lua:0: src: expected table, got nil',
pcall_err(exec_lua, [[ return vim.list_extend({1}, nil) ]]))
eq({1,2}, exec_lua [[ return vim.list_extend({1}, {2;a=1}) ]])
eq(true, exec_lua [[ local a = {1} return vim.list_extend(a, {2;a=1}) == a ]])
@@ -845,12 +824,12 @@ describe('lua stdlib', function()
end)
]])
screen:expect{grid=[[
- foo |
- {1:~ }|
- {2: }|
- {3:Error executing luv callback:} |
{3:[string "<nvim>"]:6: E5560: rpcrequest must not be}|
{3: called in a lua loop callback} |
+ {3:stack traceback:} |
+ {3: [C]: in function 'rpcrequest'} |
+ {3: [string "<nvim>"]:6: in function <[string }|
+ {3:"<nvim>"]:2>} |
{4:Press ENTER or type command to continue}^ |
]]}
feed('<cr>')
@@ -914,76 +893,37 @@ describe('lua stdlib', function()
exec_lua("vim.validate{arg1={{}, 't' }, arg2={ 'foo', 's' }}")
exec_lua("vim.validate{arg1={2, function(a) return (a % 2) == 0 end, 'even number' }}")
- eq(dedent([[
- Error executing lua: [string "<nvim>"]:0: opt[1]: expected table, got number
- stack traceback:
- [string "<nvim>"]:0: in main chunk]]),
+ eq('Error executing lua: [string "<nvim>"]:0: opt[1]: expected table, got number',
pcall_err(exec_lua, "vim.validate{ 1, 'x' }"))
- eq(dedent([[
- Error executing lua: [string "<nvim>"]:0: invalid type name: x
- stack traceback:
- [string "<nvim>"]:0: in main chunk]]),
+ eq('Error executing lua: [string "<nvim>"]:0: invalid type name: x',
pcall_err(exec_lua, "vim.validate{ arg1={ 1, 'x' }}"))
- eq(dedent([[
- Error executing lua: [string "<nvim>"]:0: invalid type name: 1
- stack traceback:
- [string "<nvim>"]:0: in main chunk]]),
+ eq('Error executing lua: [string "<nvim>"]:0: invalid type name: 1',
pcall_err(exec_lua, "vim.validate{ arg1={ 1, 1 }}"))
- eq(dedent([[
- Error executing lua: [string "<nvim>"]:0: invalid type name: nil
- stack traceback:
- [string "<nvim>"]:0: in main chunk]]),
+ eq('Error executing lua: [string "<nvim>"]:0: invalid type name: nil',
pcall_err(exec_lua, "vim.validate{ arg1={ 1 }}"))
-- Validated parameters are required by default.
- eq(dedent([[
- Error executing lua: [string "<nvim>"]:0: arg1: expected string, got nil
- stack traceback:
- [string "<nvim>"]:0: in main chunk]]),
+ eq('Error executing lua: [string "<nvim>"]:0: arg1: expected string, got nil',
pcall_err(exec_lua, "vim.validate{ arg1={ nil, 's' }}"))
-- Explicitly required.
- eq(dedent([[
- Error executing lua: [string "<nvim>"]:0: arg1: expected string, got nil
- stack traceback:
- [string "<nvim>"]:0: in main chunk]]),
+ eq('Error executing lua: [string "<nvim>"]:0: arg1: expected string, got nil',
pcall_err(exec_lua, "vim.validate{ arg1={ nil, 's', false }}"))
- eq(dedent([[
- Error executing lua: [string "<nvim>"]:0: arg1: expected table, got number
- stack traceback:
- [string "<nvim>"]:0: in main chunk]]),
+ eq('Error executing lua: [string "<nvim>"]:0: arg1: expected table, got number',
pcall_err(exec_lua, "vim.validate{arg1={1, 't'}}"))
- eq(dedent([[
- Error executing lua: [string "<nvim>"]:0: arg2: expected string, got number
- stack traceback:
- [string "<nvim>"]:0: in main chunk]]),
+ eq('Error executing lua: [string "<nvim>"]:0: arg2: expected string, got number',
pcall_err(exec_lua, "vim.validate{arg1={{}, 't'}, arg2={1, 's'}}"))
- eq(dedent([[
- Error executing lua: [string "<nvim>"]:0: arg2: expected string, got nil
- stack traceback:
- [string "<nvim>"]:0: in main chunk]]),
+ eq('Error executing lua: [string "<nvim>"]:0: arg2: expected string, got nil',
pcall_err(exec_lua, "vim.validate{arg1={{}, 't'}, arg2={nil, 's'}}"))
- eq(dedent([[
- Error executing lua: [string "<nvim>"]:0: arg2: expected string, got nil
- stack traceback:
- [string "<nvim>"]:0: in main chunk]]),
+ eq('Error executing lua: [string "<nvim>"]:0: arg2: expected string, got nil',
pcall_err(exec_lua, "vim.validate{arg1={{}, 't'}, arg2={nil, 's'}}"))
- eq(dedent([[
- Error executing lua: [string "<nvim>"]:0: arg1: expected even number, got 3
- stack traceback:
- [string "<nvim>"]:0: in main chunk]]),
+ eq('Error executing lua: [string "<nvim>"]:0: arg1: expected even number, got 3',
pcall_err(exec_lua, "vim.validate{arg1={3, function(a) return a == 1 end, 'even number'}}"))
- eq(dedent([[
- Error executing lua: [string "<nvim>"]:0: arg1: expected ?, got 3
- stack traceback:
- [string "<nvim>"]:0: in main chunk]]),
+ eq('Error executing lua: [string "<nvim>"]:0: arg1: expected ?, got 3',
pcall_err(exec_lua, "vim.validate{arg1={3, function(a) return a == 1 end}}"))
-- Pass an additional message back.
- eq(dedent([[
- Error executing lua: [string "<nvim>"]:0: arg1: expected ?, got 3. Info: TEST_MSG
- stack traceback:
- [string "<nvim>"]:0: in main chunk]]),
+ eq('Error executing lua: [string "<nvim>"]:0: arg1: expected ?, got 3. Info: TEST_MSG',
pcall_err(exec_lua, "vim.validate{arg1={3, function(a) return a == 1, 'TEST_MSG' end}}"))
end)
@@ -2133,9 +2073,10 @@ describe('lua stdlib', function()
end)
it('should not crash when callback errors', function()
- eq({false, '[string "<nvim>"]:1: As Expected'}, exec_lua [[
+ local result = exec_lua [[
return {pcall(function() vim.wait(1000, function() error("As Expected") end) end)}
- ]])
+ ]]
+ eq({false, '[string "<nvim>"]:1: As Expected'}, {result[1], remove_trace(result[2])})
end)
it('if callback is passed, it must be a function', function()