diff options
author | luukvbaal <luukvbaal@gmail.com> | 2025-03-24 00:12:50 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-23 16:12:50 -0700 |
commit | 958df63606687fff6f805255ff3848dd34f33082 (patch) | |
tree | 9cae101fbc0df59de743e75f8a756d24d241d892 /test/functional/ui | |
parent | 9516997eb0ad20146ddddb48ba48c905d512998c (diff) | |
download | rneovim-958df63606687fff6f805255ff3848dd34f33082.tar.gz rneovim-958df63606687fff6f805255ff3848dd34f33082.tar.bz2 rneovim-958df63606687fff6f805255ff3848dd34f33082.zip |
test(log): use tempfile for expected error logs #33017
Diffstat (limited to 'test/functional/ui')
-rw-r--r-- | test/functional/ui/decorations_spec.lua | 89 |
1 files changed, 46 insertions, 43 deletions
diff --git a/test/functional/ui/decorations_spec.lua b/test/functional/ui/decorations_spec.lua index ccc7841856..639d43b560 100644 --- a/test/functional/ui/decorations_spec.lua +++ b/test/functional/ui/decorations_spec.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) - |