mirror of
https://github.com/neovim/neovim.git
synced 2025-09-05 19:08:15 +00:00
test(log): use tempfile for expected error logs #33017
This commit is contained in:
@@ -32,7 +32,6 @@ describe('vim.ui_attach', function()
|
||||
]]
|
||||
|
||||
screen = Screen.new(40, 5)
|
||||
screen:add_extra_attr_ids({ [100] = { bold = true, foreground = Screen.colors.SeaGreen } })
|
||||
end)
|
||||
|
||||
local function expect_events(expected)
|
||||
@@ -216,7 +215,7 @@ describe('vim.ui_attach', function()
|
||||
},
|
||||
messages = {
|
||||
{
|
||||
content = { { '\nSave changes?\n', 100, 10 } },
|
||||
content = { { '\nSave changes?\n', 6, 10 } },
|
||||
history = false,
|
||||
kind = 'confirm',
|
||||
},
|
||||
@@ -316,16 +315,38 @@ describe('vim.ui_attach', function()
|
||||
},
|
||||
})
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('vim.ui_attach', function()
|
||||
before_each(function()
|
||||
clear({ env = { NVIM_LOG_FILE = testlog } })
|
||||
end)
|
||||
|
||||
after_each(function()
|
||||
check_close()
|
||||
os.remove(testlog)
|
||||
end)
|
||||
|
||||
it('error in callback is logged', function()
|
||||
exec_lua([[
|
||||
local ns = vim.api.nvim_create_namespace('test')
|
||||
vim.ui_attach(ns, { ext_popupmenu = true }, function() error(42) end)
|
||||
]])
|
||||
feed('ifoo<CR>foobar<CR>fo<C-X><C-N>')
|
||||
assert_log('Error in "popupmenu_show" UI event handler %(ns=test%):', testlog, 100)
|
||||
assert_log('Error executing lua: .*: 42', testlog, 100)
|
||||
end)
|
||||
|
||||
it('detaches after excessive errors', function()
|
||||
screen:try_resize(86, 10)
|
||||
local screen = Screen.new(86, 10)
|
||||
screen:add_extra_attr_ids({ [100] = { bold = true, foreground = Screen.colors.SeaGreen } })
|
||||
exec_lua([[
|
||||
vim.ui_attach(vim.api.nvim_create_namespace(''), { ext_messages = true }, function(ev)
|
||||
if ev:find('msg') then
|
||||
vim.api.nvim_buf_set_lines(0, -2, -1, false, { err[1] })
|
||||
end
|
||||
end)
|
||||
]])
|
||||
]])
|
||||
local s1 = [[
|
||||
^ |
|
||||
{1:~ }|*9
|
||||
@@ -418,27 +439,6 @@ describe('vim.ui_attach', function()
|
||||
{9:Excessive errors in vim.ui_attach() callback (ns=(UNKNOWN PLUGIN))} |
|
||||
]])
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('vim.ui_attach', function()
|
||||
before_each(function()
|
||||
clear({ env = { NVIM_LOG_FILE = testlog } })
|
||||
end)
|
||||
|
||||
after_each(function()
|
||||
check_close()
|
||||
os.remove(testlog)
|
||||
end)
|
||||
|
||||
it('error in callback is logged', function()
|
||||
exec_lua([[
|
||||
local ns = vim.api.nvim_create_namespace('test')
|
||||
vim.ui_attach(ns, { ext_popupmenu = true }, function() error(42) end)
|
||||
]])
|
||||
feed('ifoo<CR>foobar<CR>fo<C-X><C-N>')
|
||||
assert_log('Error in "popupmenu_show" UI event handler %(ns=test%):', testlog, 100)
|
||||
assert_log('Error executing lua: .*: 42', testlog, 100)
|
||||
end)
|
||||
|
||||
it('sourcing invalid file does not crash #32166', function()
|
||||
exec_lua([[
|
||||
|
@@ -15,6 +15,26 @@ local eq = t.eq
|
||||
local assert_alive = n.assert_alive
|
||||
local pcall_err = t.pcall_err
|
||||
|
||||
--- @return integer
|
||||
local function setup_provider(code)
|
||||
return exec_lua ([[
|
||||
local api = vim.api
|
||||
_G.ns1 = api.nvim_create_namespace "ns1"
|
||||
]] .. (code or [[
|
||||
beamtrace = {}
|
||||
local function on_do(kind, ...)
|
||||
table.insert(beamtrace, {kind, ...})
|
||||
end
|
||||
]]) .. [[
|
||||
api.nvim_set_decoration_provider(_G.ns1, {
|
||||
on_start = on_do; on_buf = on_do;
|
||||
on_win = on_do; on_line = on_do;
|
||||
on_end = on_do; _on_spell_nav = on_do;
|
||||
})
|
||||
return _G.ns1
|
||||
]])
|
||||
end
|
||||
|
||||
describe('decorations providers', function()
|
||||
local screen ---@type test.functional.ui.screen
|
||||
before_each(function()
|
||||
@@ -52,26 +72,6 @@ describe('decorations providers', function()
|
||||
posp = getmark(mark, false);
|
||||
restore_buffer(&save_buf); ]]
|
||||
|
||||
--- @return integer
|
||||
local function setup_provider(code)
|
||||
return exec_lua ([[
|
||||
local api = vim.api
|
||||
_G.ns1 = api.nvim_create_namespace "ns1"
|
||||
]] .. (code or [[
|
||||
beamtrace = {}
|
||||
local function on_do(kind, ...)
|
||||
table.insert(beamtrace, {kind, ...})
|
||||
end
|
||||
]]) .. [[
|
||||
api.nvim_set_decoration_provider(_G.ns1, {
|
||||
on_start = on_do; on_buf = on_do;
|
||||
on_win = on_do; on_line = on_do;
|
||||
on_end = on_do; _on_spell_nav = on_do;
|
||||
})
|
||||
return _G.ns1
|
||||
]])
|
||||
end
|
||||
|
||||
local function check_trace(expected)
|
||||
local actual = exec_lua [[ local b = beamtrace beamtrace = {} return b ]]
|
||||
expect_events(expected, actual, "beam trace")
|
||||
@@ -758,28 +758,6 @@ describe('decorations providers', function()
|
||||
]])
|
||||
end)
|
||||
|
||||
it('errors gracefully', function()
|
||||
screen:try_resize(65, screen._height)
|
||||
insert(mulholland)
|
||||
|
||||
setup_provider [[
|
||||
function on_do(...)
|
||||
error "Foo"
|
||||
end
|
||||
]]
|
||||
|
||||
screen:expect([[
|
||||
// just to see if there was an accident |
|
||||
{8: }|
|
||||
{2:Error in decoration provider "start" (ns=ns1):} |
|
||||
{2:Error executing lua: [string "<nvim>"]:4: Foo} |
|
||||
{2:stack traceback:} |
|
||||
{2: [C]: in function 'error'} |
|
||||
{2: [string "<nvim>"]:4: in function <[string "<nvim>"]:3>} |
|
||||
{18:Press ENTER or type command to continue}^ |
|
||||
]])
|
||||
end)
|
||||
|
||||
it('can add new providers during redraw #26652', function()
|
||||
setup_provider [[
|
||||
local ns = api.nvim_create_namespace('test_no_add')
|
||||
@@ -835,6 +813,32 @@ describe('decorations providers', function()
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('decoration_providers', function()
|
||||
it('errors and logs gracefully', function()
|
||||
local testlog = 'Xtest_decorations_log'
|
||||
clear({ env = { NVIM_LOG_FILE = testlog } })
|
||||
local screen = Screen.new(65, 7)
|
||||
setup_provider([[
|
||||
function on_do(...)
|
||||
error "Foo"
|
||||
end
|
||||
]])
|
||||
screen:expect([[
|
||||
{3: }|
|
||||
{9:Error in decoration provider "start" (ns=ns1):} |
|
||||
{9:Error executing lua: [string "<nvim>"]:4: Foo} |
|
||||
{9:stack traceback:} |
|
||||
{9: [C]: in function 'error'} |
|
||||
{9: [string "<nvim>"]:4: in function <[string "<nvim>"]:3>} |
|
||||
{6:Press ENTER or type command to continue}^ |
|
||||
]])
|
||||
t.assert_log('Error in decoration provider "start" %(ns=ns1%):', testlog, 100)
|
||||
t.assert_log('Error executing lua: %[string "<nvim>"%]:4: Foo', testlog, 100)
|
||||
n.check_close()
|
||||
os.remove(testlog)
|
||||
end)
|
||||
end)
|
||||
|
||||
local example_text = [[
|
||||
for _,item in ipairs(items) do
|
||||
local text, hl_id_cell, count = unpack(item)
|
||||
@@ -6834,4 +6838,3 @@ describe('decorations: window scoped', function()
|
||||
eq({ wins = {} }, api.nvim__ns_get(ns))
|
||||
end)
|
||||
end)
|
||||
|
||||
|
Reference in New Issue
Block a user