From ae28ef327e02ac87ef26f941c401312ed0462d8c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 6 Apr 2024 11:18:43 +0800 Subject: fix: adjust error message for error in UI event callback (#28200) Also close Nvim instance before removing log file, otherwise the Nvim instance will still write to the log file. Also adjust log level in libuv_process_spawn(). Ref #27660 --- test/functional/lua/ui_event_spec.lua | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'test/functional/lua/ui_event_spec.lua') diff --git a/test/functional/lua/ui_event_spec.lua b/test/functional/lua/ui_event_spec.lua index 3e46018682..39c51d242c 100644 --- a/test/functional/lua/ui_event_spec.lua +++ b/test/functional/lua/ui_event_spec.lua @@ -5,6 +5,10 @@ local exec_lua = helpers.exec_lua local clear = helpers.clear local feed = helpers.feed local fn = helpers.fn +local assert_log = helpers.assert_log +local check_close = helpers.check_close + +local testlog = 'Xtest_lua_ui_event_log' describe('vim.ui_attach', function() local screen @@ -150,3 +154,22 @@ describe('vim.ui_attach', function() }, actual, vim.inspect(actual)) end) end) + +describe('vim.ui_attach', function() + after_each(function() + check_close() + os.remove(testlog) + end) + + it('error in callback is logged', function() + clear({ env = { NVIM_LOG_FILE = testlog } }) + local screen = Screen.new() + screen:attach() + exec_lua([[ + local ns = vim.api.nvim_create_namespace('testspace') + vim.ui_attach(ns, { ext_popupmenu = true }, function() error(42) end) + ]]) + feed('ifoofoobarfo') + assert_log('Error executing UI event callback: Error executing lua: .*: 42', testlog, 100) + end) +end) -- cgit From 7035125b2b26aa68fcfb7cda39377ac79926a0f9 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 8 Apr 2024 11:03:20 +0200 Subject: test: improve test conventions Work on https://github.com/neovim/neovim/issues/27004. --- test/functional/lua/ui_event_spec.lua | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'test/functional/lua/ui_event_spec.lua') diff --git a/test/functional/lua/ui_event_spec.lua b/test/functional/lua/ui_event_spec.lua index 39c51d242c..1283448db5 100644 --- a/test/functional/lua/ui_event_spec.lua +++ b/test/functional/lua/ui_event_spec.lua @@ -1,12 +1,12 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local eq = helpers.eq -local exec_lua = helpers.exec_lua -local clear = helpers.clear -local feed = helpers.feed -local fn = helpers.fn -local assert_log = helpers.assert_log -local check_close = helpers.check_close +local eq = t.eq +local exec_lua = t.exec_lua +local clear = t.clear +local feed = t.feed +local fn = t.fn +local assert_log = t.assert_log +local check_close = t.check_close local testlog = 'Xtest_lua_ui_event_log' @@ -112,7 +112,7 @@ describe('vim.ui_attach', function() it('does not crash on exit', function() fn.system({ - helpers.nvim_prog, + t.nvim_prog, '-u', 'NONE', '-i', @@ -124,7 +124,7 @@ describe('vim.ui_attach', function() '--cmd', 'quitall!', }) - eq(0, helpers.eval('v:shell_error')) + eq(0, t.eval('v:shell_error')) end) it('can receive accurate message kinds even if they are history', function() -- cgit From 81fc27124b9e1b375e0ce9605ae69c3c2a2d9222 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Tue, 9 Apr 2024 12:26:16 +0100 Subject: refactor(test): inject after_each differently --- test/functional/lua/ui_event_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/lua/ui_event_spec.lua') diff --git a/test/functional/lua/ui_event_spec.lua b/test/functional/lua/ui_event_spec.lua index 1283448db5..d6572f9ae5 100644 --- a/test/functional/lua/ui_event_spec.lua +++ b/test/functional/lua/ui_event_spec.lua @@ -1,4 +1,4 @@ -local t = require('test.functional.testutil')(after_each) +local t = require('test.functional.testutil')() local Screen = require('test.functional.ui.screen') local eq = t.eq local exec_lua = t.exec_lua -- cgit From 052498ed42780a76daea589d063cd8947a894673 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sat, 20 Apr 2024 17:44:13 +0200 Subject: test: improve test conventions Specifically, functions that are run in the context of the test runner are put in module `test/testutil.lua` while the functions that are run in the context of the test session are put in `test/functional/testnvim.lua`. Closes https://github.com/neovim/neovim/issues/27004. --- test/functional/lua/ui_event_spec.lua | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'test/functional/lua/ui_event_spec.lua') diff --git a/test/functional/lua/ui_event_spec.lua b/test/functional/lua/ui_event_spec.lua index d6572f9ae5..5fe51a2c35 100644 --- a/test/functional/lua/ui_event_spec.lua +++ b/test/functional/lua/ui_event_spec.lua @@ -1,12 +1,14 @@ -local t = require('test.functional.testutil')() +local t = require('test.testutil') +local n = require('test.functional.testnvim')() local Screen = require('test.functional.ui.screen') + local eq = t.eq -local exec_lua = t.exec_lua -local clear = t.clear -local feed = t.feed -local fn = t.fn +local exec_lua = n.exec_lua +local clear = n.clear +local feed = n.feed +local fn = n.fn local assert_log = t.assert_log -local check_close = t.check_close +local check_close = n.check_close local testlog = 'Xtest_lua_ui_event_log' @@ -112,7 +114,7 @@ describe('vim.ui_attach', function() it('does not crash on exit', function() fn.system({ - t.nvim_prog, + n.nvim_prog, '-u', 'NONE', '-i', @@ -124,7 +126,7 @@ describe('vim.ui_attach', function() '--cmd', 'quitall!', }) - eq(0, t.eval('v:shell_error')) + eq(0, n.eval('v:shell_error')) end) it('can receive accurate message kinds even if they are history', function() -- cgit From 7626f431d84fc3a6eb82d0d23d436e3e31e991ce Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Fri, 26 Apr 2024 16:21:56 +0200 Subject: fix(ui): update ext_ui widgets when attaching non-remote UI Problem: Updating internalized UI capabilities is postponed until a remote UI attaches. Solution: Always update active UI widgets in ui_refresh(). --- test/functional/lua/ui_event_spec.lua | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test/functional/lua/ui_event_spec.lua') diff --git a/test/functional/lua/ui_event_spec.lua b/test/functional/lua/ui_event_spec.lua index 5fe51a2c35..60f8706e2d 100644 --- a/test/functional/lua/ui_event_spec.lua +++ b/test/functional/lua/ui_event_spec.lua @@ -155,6 +155,14 @@ describe('vim.ui_attach', function() }, }, actual, vim.inspect(actual)) end) + + it('ui_refresh() works without remote UI', function() + screen:detach() + exec_lua('vim.ui_attach(ns, { ext_messages = true }, on_event)') + n.api.nvim_set_option_value('cmdheight', 1, {}) + screen:attach() + eq(1, n.api.nvim_get_option_value('cmdheight', {})) + end) end) describe('vim.ui_attach', function() -- cgit From b8c1b36061f443f82f34f3d4fe7807fc33edefa6 Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Sat, 27 Apr 2024 01:00:55 +0200 Subject: fix(ui): set 'cmdheight' to zero for all open tabpages Problem: Enabling ext_messages claims to set 'cmdheight' to zero, but only does so for the current tabpage. Solution: Set stored 'cmdheight' value to zero for all tabpages. --- test/functional/lua/ui_event_spec.lua | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'test/functional/lua/ui_event_spec.lua') diff --git a/test/functional/lua/ui_event_spec.lua b/test/functional/lua/ui_event_spec.lua index 60f8706e2d..ae39172145 100644 --- a/test/functional/lua/ui_event_spec.lua +++ b/test/functional/lua/ui_event_spec.lua @@ -163,6 +163,13 @@ describe('vim.ui_attach', function() screen:attach() eq(1, n.api.nvim_get_option_value('cmdheight', {})) end) + + it("ui_refresh() sets 'cmdheight' for all open tabpages with ext_messages", function() + exec_lua('vim.cmd.tabnew()') + exec_lua('vim.ui_attach(ns, { ext_messages = true }, on_event)') + exec_lua('vim.cmd.tabnext()') + eq(0, n.api.nvim_get_option_value('cmdheight', {})) + end) end) describe('vim.ui_attach', function() -- cgit From ab1c2220f0c7f63e2081eb22544fed9fc4b4c611 Mon Sep 17 00:00:00 2001 From: luukvbaal Date: Mon, 29 Apr 2024 02:51:33 +0200 Subject: fix(ui): activating all ext capabilities without remote UI #28555 --- test/functional/lua/ui_event_spec.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'test/functional/lua/ui_event_spec.lua') diff --git a/test/functional/lua/ui_event_spec.lua b/test/functional/lua/ui_event_spec.lua index ae39172145..4ac0268c4b 100644 --- a/test/functional/lua/ui_event_spec.lua +++ b/test/functional/lua/ui_event_spec.lua @@ -156,8 +156,11 @@ describe('vim.ui_attach', function() }, actual, vim.inspect(actual)) end) - it('ui_refresh() works without remote UI', function() + it('ui_refresh() activates correct capabilities without remote UI', function() screen:detach() + exec_lua('vim.ui_attach(ns, { ext_cmdline = true }, on_event)') + eq(1, n.api.nvim_get_option_value('cmdheight', {})) + exec_lua('vim.ui_detach(ns)') exec_lua('vim.ui_attach(ns, { ext_messages = true }, on_event)') n.api.nvim_set_option_value('cmdheight', 1, {}) screen:attach() -- cgit From e778e0116198470ba037b9426f4ff7fa5cb7f880 Mon Sep 17 00:00:00 2001 From: luukvbaal Date: Wed, 1 May 2024 22:51:06 +0200 Subject: fix(ui): avoid recursiveness and invalid memory access #28578 Problem: Calling :redraw from vim.ui_attach() callback results in recursive cmdline/message events. Solution: Avoid recursiveness where possible and replace global "call_buf" with separate, temporary buffers for each event so that when a Lua callback for one event fires another event, that does not result in invalid memory access. --- test/functional/lua/ui_event_spec.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'test/functional/lua/ui_event_spec.lua') diff --git a/test/functional/lua/ui_event_spec.lua b/test/functional/lua/ui_event_spec.lua index 4ac0268c4b..1e80c88403 100644 --- a/test/functional/lua/ui_event_spec.lua +++ b/test/functional/lua/ui_event_spec.lua @@ -173,6 +173,21 @@ describe('vim.ui_attach', function() exec_lua('vim.cmd.tabnext()') eq(0, n.api.nvim_get_option_value('cmdheight', {})) end) + + it('avoids recursive flushing and invalid memory access with :redraw', function() + exec_lua([[ + _G.cmdline = 0 + vim.ui_attach(ns, { ext_messages = true }, function(ev) + vim.cmd.redraw() + _G.cmdline = _G.cmdline + (ev == 'cmdline_show' and 1 or 0) + end + )]]) + feed(':') + eq(1, exec_lua('return _G.cmdline')) + n.assert_alive() + feed('versionv') + n.assert_alive() + end) end) describe('vim.ui_attach', function() -- cgit