mirror of
https://github.com/neovim/neovim.git
synced 2026-05-26 23:08:36 +00:00
Merge pull request #39920 from bfredl/luastring
fix(lua): use even safer and even better error() message conversion
This commit is contained in:
@@ -72,8 +72,22 @@ describe(':lua', function()
|
||||
eq({ '' }, api.nvim_buf_get_lines(0, 0, 100, false))
|
||||
end)
|
||||
|
||||
it('works with NULL errors', function()
|
||||
eq([=[Vim(lua):E5108: Lua: [NULL]]=], pcall_err(command, 'lua error(nil)'))
|
||||
it('works with nil errors', function()
|
||||
eq([=[Vim(lua):E5108: Lua: nil]=], pcall_err(command, 'lua error(nil)'))
|
||||
end)
|
||||
|
||||
it('works with errors with __tostring failure', function()
|
||||
eq(
|
||||
[=[Vim(lua):E5108: Lua: [UNPRINTABLE ERROR]]=],
|
||||
pcall_err(command, 'lua error(setmetatable({}, {__tostring=error}))')
|
||||
)
|
||||
end)
|
||||
|
||||
it('works with printable errors', function()
|
||||
eq([=[Vim(lua):E5108: Lua: false]=], pcall_err(command, 'lua error(false)'))
|
||||
-- numbers get the location prefixed because numbers are almost strings (know the workplace rules)
|
||||
eq([=[Vim(lua):E5108: Lua: [string ":lua"]:0: 39]=], pcall_err(command, 'lua error(39)'))
|
||||
matches([=[Vim%(lua%):E5108: Lua: table: 0x%x+]=], pcall_err(command, 'lua error({})'))
|
||||
end)
|
||||
|
||||
it('accepts embedded NLs without heredoc', function()
|
||||
@@ -280,8 +294,8 @@ describe(':luado command', function()
|
||||
)
|
||||
end)
|
||||
|
||||
it('works with NULL errors', function()
|
||||
eq([=[Vim(luado):E5111: Lua: [NULL]]=], pcall_err(command, 'luado error(nil)'))
|
||||
it('works with nil errors', function()
|
||||
eq([=[Vim(luado):E5111: Lua: nil]=], pcall_err(command, 'luado error(nil)'))
|
||||
end)
|
||||
|
||||
it('fails in sandbox when needed', function()
|
||||
@@ -342,8 +356,8 @@ describe(':luafile', function()
|
||||
)
|
||||
end)
|
||||
|
||||
it('works with NULL errors', function()
|
||||
it('works with nil errors', function()
|
||||
write_file(fname, 'error(nil)')
|
||||
eq([=[Vim(luafile):E5113: Lua chunk: [NULL]]=], pcall_err(command, 'luafile ' .. fname))
|
||||
eq([=[Vim(luafile):E5113: Lua chunk: nil]=], pcall_err(command, 'luafile ' .. fname))
|
||||
end)
|
||||
end)
|
||||
|
||||
@@ -495,7 +495,7 @@ describe('luaeval()', function()
|
||||
remove_trace(pcall_err(command, [[call luaeval("error('ERROR')")]]))
|
||||
)
|
||||
eq(
|
||||
'Vim(call):E5108: Lua: [NULL]',
|
||||
'Vim(call):E5108: Lua: nil',
|
||||
remove_trace(pcall_err(command, [[call luaeval("error(nil)")]]))
|
||||
)
|
||||
end)
|
||||
|
||||
@@ -4,6 +4,7 @@ local n = require('test.functional.testnvim')()
|
||||
local Screen = require('test.functional.ui.screen')
|
||||
|
||||
local eq = t.eq
|
||||
local matches = t.matches
|
||||
local NIL = vim.NIL
|
||||
local feed = n.feed
|
||||
local clear = n.clear
|
||||
@@ -105,13 +106,13 @@ describe('print', function()
|
||||
'Vim(lua):E5108: Lua: Xtest-functional-lua-overrides-luafile:2: 1234',
|
||||
pcall_err(command, 'lua number_error()')
|
||||
)
|
||||
eq('Vim(lua):E5108: Lua: [NULL]', pcall_err(command, 'lua nil_error()'))
|
||||
eq('Vim(lua):E5108: Lua: [NULL]', pcall_err(command, 'lua table_error()'))
|
||||
eq('Vim(lua):E5108: Lua: nil', pcall_err(command, 'lua nil_error()'))
|
||||
matches('^Vim%(lua%):E5108: Lua: table: 0x%x+$', pcall_err(command, 'lua table_error()'))
|
||||
eq(
|
||||
'Vim(lua):E5108: Lua: Internal Error [11234] my mistake',
|
||||
pcall_err(command, 'lua custom_error()')
|
||||
)
|
||||
eq('Vim(lua):E5108: Lua: [NULL]', pcall_err(command, 'lua bad_custom_error()'))
|
||||
eq('Vim(lua):E5108: Lua: [UNPRINTABLE ERROR]', pcall_err(command, 'lua bad_custom_error()'))
|
||||
end)
|
||||
it('prints strings with NULs and NLs correctly', function()
|
||||
api.nvim_set_option_value('more', true, {})
|
||||
|
||||
@@ -32,7 +32,7 @@ describe('thread', function()
|
||||
{1:~ }|*5
|
||||
{3: }|
|
||||
{9:Luv thread:} |
|
||||
{9:[NULL]} |
|
||||
{9:nil} |
|
||||
{6:Press ENTER or type command to continue}^ |
|
||||
]])
|
||||
feed('<cr>')
|
||||
|
||||
@@ -174,7 +174,7 @@ describe('vim.uv', function()
|
||||
{1:~ }|*5
|
||||
{3: }|
|
||||
{9:Lua callback:} |
|
||||
{9:[NULL]} |
|
||||
{9:nil} |
|
||||
{6:Press ENTER or type command to continue}^ |
|
||||
]]
|
||||
screen:expect(s)
|
||||
@@ -209,7 +209,7 @@ describe('vim.uv', function()
|
||||
screen:expect([[
|
||||
{3: }|
|
||||
{9:Lua callback:} |
|
||||
{9:[NULL]} |
|
||||
{9:nil} |
|
||||
{6:Press ENTER or type command to continue}^ |
|
||||
]])
|
||||
feed('<cr>')
|
||||
|
||||
Reference in New Issue
Block a user