From abe6a07c54c0e927cf43f7f61b05ac91547daeed Mon Sep 17 00:00:00 2001 From: bfredl Date: Fri, 8 Nov 2024 11:45:55 +0100 Subject: refactor(tests): continue the global highlight definition work --- test/functional/vimscript/api_functions_spec.lua | 15 ++++----------- test/functional/vimscript/eval_spec.lua | 21 ++++++++------------- test/functional/vimscript/timer_spec.lua | 6 +----- 3 files changed, 13 insertions(+), 29 deletions(-) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/api_functions_spec.lua b/test/functional/vimscript/api_functions_spec.lua index 30d6c969ca..0dbbace8f8 100644 --- a/test/functional/vimscript/api_functions_spec.lua +++ b/test/functional/vimscript/api_functions_spec.lua @@ -193,13 +193,6 @@ describe('eval-API', function() it('are highlighted by vim.vim syntax file', function() local screen = Screen.new(40, 8) screen:attach() - screen:set_default_attr_ids({ - [1] = { bold = true, foreground = Screen.colors.Brown }, - [2] = { foreground = Screen.colors.DarkCyan }, - [3] = { foreground = Screen.colors.SlateBlue }, - [4] = { foreground = Screen.colors.Fuchsia }, - [5] = { bold = true, foreground = Screen.colors.Blue }, - }) command('set ft=vim') command('set rtp^=build/runtime/') @@ -210,10 +203,10 @@ describe('eval-API', function() call not_a_function(42)]]) screen:expect([[ - {1:call} {2:bufnr}{3:(}{4:'%'}{3:)} | - {1:call} {2:nvim_input}{3:(}{4:'typing...'}{3:)} | - {1:call} not_a_function{3:(}{4:42}{3:^)} | - {5:~ }|*4 + {15:call} {25:bufnr}{16:(}{26:'%'}{16:)} | + {15:call} {25:nvim_input}{16:(}{26:'typing...'}{16:)} | + {15:call} not_a_function{16:(}{26:42}{16:^)} | + {1:~ }|*4 | ]]) end) diff --git a/test/functional/vimscript/eval_spec.lua b/test/functional/vimscript/eval_spec.lua index 0c812d968e..840e311dd8 100644 --- a/test/functional/vimscript/eval_spec.lua +++ b/test/functional/vimscript/eval_spec.lua @@ -189,11 +189,6 @@ describe('uncaught exception', function() it('multiline exception remains multiline #25350', function() local screen = Screen.new(80, 11) - screen:set_default_attr_ids({ - [1] = { bold = true, reverse = true }, -- MsgSeparator - [2] = { foreground = Screen.colors.White, background = Screen.colors.Red }, -- ErrorMsg - [3] = { bold = true, foreground = Screen.colors.SeaGreen }, -- MoreMsg - }) screen:attach() exec_lua([[ function _G.Oops() @@ -203,17 +198,17 @@ describe('uncaught exception', function() feed(':try\rlua _G.Oops()\rendtry\r') screen:expect { grid = [[ - {1: }| + {3: }| :try | : lua _G.Oops() | : endtry | - {2:Error detected while processing :} | - {2:E5108: Error executing lua [string ""]:2: oops} | - {2:stack traceback:} | - {2: [C]: in function 'error'} | - {2: [string ""]:2: in function 'Oops'} | - {2: [string ":lua"]:1: in main chunk} | - {3:Press ENTER or type command to continue}^ | + {9:Error detected while processing :} | + {9:E5108: Error executing lua [string ""]:2: oops} | + {9:stack traceback:} | + {9: [C]: in function 'error'} | + {9: [string ""]:2: in function 'Oops'} | + {9: [string ":lua"]:1: in main chunk} | + {6:Press ENTER or type command to continue}^ | ]], } end) diff --git a/test/functional/vimscript/timer_spec.lua b/test/functional/vimscript/timer_spec.lua index f075e382bc..1e484c9ff9 100644 --- a/test/functional/vimscript/timer_spec.lua +++ b/test/functional/vimscript/timer_spec.lua @@ -109,9 +109,6 @@ describe('timers', function() it('can invoke redraw in blocking getchar() call', function() local screen = Screen.new(40, 6) screen:attach() - screen:set_default_attr_ids({ - [1] = { bold = true, foreground = Screen.colors.Blue }, - }) api.nvim_buf_set_lines(0, 0, -1, true, { 'ITEM 1', 'ITEM 2' }) source([[ @@ -229,7 +226,6 @@ describe('timers', function() it("doesn't mess up the cmdline", function() local screen = Screen.new(40, 6) screen:attach() - screen:set_default_attr_ids({ [0] = { bold = true, foreground = 255 } }) source([[ let g:val = 0 func! MyHandler(timer) @@ -247,7 +243,7 @@ describe('timers', function() feed(':good') screen:expect([[ | - {0:~ }|*4 + {1:~ }|*4 :good^ | ]]) command('let g:val = 1') -- cgit From e61228a214ebda9845db9462dad0a8c362d3963f Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 11 Nov 2024 22:15:19 +0100 Subject: fix(tests): needing two calls to setup a screen is cringe Before calling "attach" a screen object is just a dummy container for (row, col) values whose purpose is to be sent as part of the "attach" function call anyway. Just create the screen in an attached state directly. Keep the complete (row, col, options) config together. It is still completely valid to later detach and re-attach as needed, including to another session. --- test/functional/vimscript/api_functions_spec.lua | 3 --- test/functional/vimscript/eval_spec.lua | 7 ++----- test/functional/vimscript/execute_spec.lua | 4 ---- test/functional/vimscript/has_spec.lua | 9 +++++---- test/functional/vimscript/input_spec.lua | 1 - test/functional/vimscript/match_functions_spec.lua | 1 - test/functional/vimscript/system_spec.lua | 8 -------- test/functional/vimscript/timer_spec.lua | 3 --- 8 files changed, 7 insertions(+), 29 deletions(-) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/api_functions_spec.lua b/test/functional/vimscript/api_functions_spec.lua index 0dbbace8f8..5db8c24120 100644 --- a/test/functional/vimscript/api_functions_spec.lua +++ b/test/functional/vimscript/api_functions_spec.lua @@ -129,8 +129,6 @@ describe('eval-API', function() end) it('use buffer numbers and windows ids as handles', function() - local screen = Screen.new(40, 8) - screen:attach() local bnr = eval("bufnr('')") local bhnd = eval('nvim_get_current_buf()') local wid = eval('win_getid()') @@ -192,7 +190,6 @@ describe('eval-API', function() it('are highlighted by vim.vim syntax file', function() local screen = Screen.new(40, 8) - screen:attach() command('set ft=vim') command('set rtp^=build/runtime/') diff --git a/test/functional/vimscript/eval_spec.lua b/test/functional/vimscript/eval_spec.lua index 840e311dd8..de1a3d7c73 100644 --- a/test/functional/vimscript/eval_spec.lua +++ b/test/functional/vimscript/eval_spec.lua @@ -189,7 +189,6 @@ describe('uncaught exception', function() it('multiline exception remains multiline #25350', function() local screen = Screen.new(80, 11) - screen:attach() exec_lua([[ function _G.Oops() error("oops") @@ -230,8 +229,7 @@ describe('listing functions using :function', function() end) it('does not crash if another function is deleted while listing', function() - local screen = Screen.new(80, 24) - screen:attach() + local _ = Screen.new(80, 24) matches( 'Vim%(function%):E454: Function list was modified$', pcall_err( @@ -264,8 +262,7 @@ describe('listing functions using :function', function() end) it('does not crash if the same function is deleted while listing', function() - local screen = Screen.new(80, 24) - screen:attach() + local _ = Screen.new(80, 24) matches( 'Vim%(function%):E454: Function list was modified$', pcall_err( diff --git a/test/functional/vimscript/execute_spec.lua b/test/functional/vimscript/execute_spec.lua index 8caaea39a7..2404538e77 100644 --- a/test/functional/vimscript/execute_spec.lua +++ b/test/functional/vimscript/execute_spec.lua @@ -114,7 +114,6 @@ describe('execute()', function() it('does not corrupt the command display #5422', function() local screen = Screen.new(70, 7) - screen:attach() feed(':echo execute("hi ErrorMsg")') screen:expect( [[ @@ -136,7 +135,6 @@ describe('execute()', function() it('places cursor correctly #6035', function() local screen = Screen.new(40, 6) - screen:attach() source([=[ " test 1: non-silenced output goes as usual function! Test1() @@ -263,7 +261,6 @@ describe('execute()', function() describe('{silent} argument', function() it('captures & displays output for ""', function() local screen = Screen.new(40, 5) - screen:attach() command('let g:mes = execute("echon 42", "")') screen:expect([[ ^ | @@ -287,7 +284,6 @@ describe('execute()', function() it('captures but does not display output for "silent"', function() local screen = Screen.new(40, 5) - screen:attach() command('let g:mes = execute("echon 42")') screen:expect([[ ^ | diff --git a/test/functional/vimscript/has_spec.lua b/test/functional/vimscript/has_spec.lua index 1d2187be6b..ff90edfe30 100644 --- a/test/functional/vimscript/has_spec.lua +++ b/test/functional/vimscript/has_spec.lua @@ -4,6 +4,7 @@ local Screen = require('test.functional.ui.screen') local clear = n.clear local connect = n.connect +local get_session = n.get_session local eq = t.eq local fn = n.fn local is_os = t.is_os @@ -74,12 +75,12 @@ describe('has()', function() it('"gui_running"', function() eq(0, fn.has('gui_running')) - local tui = Screen.new(50, 15) + local tui_session = get_session() local gui_session = connect(fn.serverstart()) - local gui = Screen.new(50, 15) eq(0, fn.has('gui_running')) - tui:attach({ ext_linegrid = true, rgb = true, stdin_tty = true, stdout_tty = true }) - gui:attach({ ext_multigrid = true, rgb = true }, gui_session) + local tui = Screen.new(50, 5, { rgb = true, stdin_tty = true, stdout_tty = true }, tui_session) + eq(0, fn.has('gui_running')) + local gui = Screen.new(50, 15, { ext_multigrid = true, rgb = true }, gui_session) eq(1, fn.has('gui_running')) tui:detach() eq(1, fn.has('gui_running')) diff --git a/test/functional/vimscript/input_spec.lua b/test/functional/vimscript/input_spec.lua index 0b774404eb..1995b033b9 100644 --- a/test/functional/vimscript/input_spec.lua +++ b/test/functional/vimscript/input_spec.lua @@ -17,7 +17,6 @@ local screen before_each(function() clear() screen = Screen.new(25, 5) - screen:attach() source([[ hi Test ctermfg=Red guifg=Red term=bold function CustomCompl(...) diff --git a/test/functional/vimscript/match_functions_spec.lua b/test/functional/vimscript/match_functions_spec.lua index 87c57f1c15..46c876da99 100644 --- a/test/functional/vimscript/match_functions_spec.lua +++ b/test/functional/vimscript/match_functions_spec.lua @@ -174,7 +174,6 @@ describe('matchaddpos()', function() end) it('works with zero length', function() local screen = Screen.new(40, 5) - screen:attach() fn.setline(1, 'abcdef') command('hi PreProc guifg=Red') eq(4, fn.matchaddpos('PreProc', { { 1, 2, 0 } }, 3, 4)) diff --git a/test/functional/vimscript/system_spec.lua b/test/functional/vimscript/system_spec.lua index 792e4c46c3..b5c4972d7b 100644 --- a/test/functional/vimscript/system_spec.lua +++ b/test/functional/vimscript/system_spec.lua @@ -132,7 +132,6 @@ describe('system()', function() before_each(function() screen = Screen.new() - screen:attach() end) if is_os('win') then @@ -430,11 +429,6 @@ describe('systemlist()', function() before_each(function() screen = Screen.new() - screen:attach() - end) - - after_each(function() - screen:detach() end) it('`echo` and waits for its return', function() @@ -567,7 +561,6 @@ describe('shell :!', function() it(':{range}! with powershell filter/redirect #16271 #19250', function() local screen = Screen.new(500, 8) - screen:attach() local found = n.set_shell_powershell(true) insert([[ 3 @@ -598,7 +591,6 @@ describe('shell :!', function() it(':{range}! without redirecting to buffer', function() local screen = Screen.new(500, 10) - screen:attach() insert([[ 3 1 diff --git a/test/functional/vimscript/timer_spec.lua b/test/functional/vimscript/timer_spec.lua index 1e484c9ff9..d1b8bfe5d9 100644 --- a/test/functional/vimscript/timer_spec.lua +++ b/test/functional/vimscript/timer_spec.lua @@ -108,7 +108,6 @@ describe('timers', function() it('can invoke redraw in blocking getchar() call', function() local screen = Screen.new(40, 6) - screen:attach() api.nvim_buf_set_lines(0, 0, -1, true, { 'ITEM 1', 'ITEM 2' }) source([[ @@ -225,7 +224,6 @@ describe('timers', function() it("doesn't mess up the cmdline", function() local screen = Screen.new(40, 6) - screen:attach() source([[ let g:val = 0 func! MyHandler(timer) @@ -263,7 +261,6 @@ describe('timers', function() it('can be triggered after an empty string mapping #17257', function() local screen = Screen.new(40, 6) - screen:attach() command([=[imap [timer_start(0, { _ -> execute("throw 'x'", "") }), ''][-1]]=]) feed('i') screen:expect({ any = 'E605: Exception not caught: x' }) -- cgit From de48fbbd5f8800bd7f1909a6fb41e53e871cf74c Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Thu, 20 Jun 2024 14:48:06 +0200 Subject: fix(messages)!: vim.ui_attach message callbacks are unsafe Problem: Lua callbacks for "msg_show" events with vim.ui_attach() are executed when it is not safe. Solution: Disallow non-fast API calls for "msg_show" event callbacks. Automatically detach callback after excessive errors. Make sure fast APIs do not modify Nvim state. --- test/functional/vimscript/eval_spec.lua | 68 --------------------------------- 1 file changed, 68 deletions(-) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/eval_spec.lua b/test/functional/vimscript/eval_spec.lua index de1a3d7c73..2a4835f7e1 100644 --- a/test/functional/vimscript/eval_spec.lua +++ b/test/functional/vimscript/eval_spec.lua @@ -25,8 +25,6 @@ local command = n.command local write_file = t.write_file local api = n.api local sleep = vim.uv.sleep -local matches = t.matches -local pcall_err = t.pcall_err local assert_alive = n.assert_alive local poke_eventloop = n.poke_eventloop local feed = n.feed @@ -227,72 +225,6 @@ describe('listing functions using :function', function() exec_capture(('function %s'):format(num)) ) end) - - it('does not crash if another function is deleted while listing', function() - local _ = Screen.new(80, 24) - matches( - 'Vim%(function%):E454: Function list was modified$', - pcall_err( - exec_lua, - [=[ - vim.cmd([[ - func Func1() - endfunc - func Func2() - endfunc - func Func3() - endfunc - ]]) - - local ns = vim.api.nvim_create_namespace('test') - - vim.ui_attach(ns, { ext_messages = true }, function(event, _, content) - if event == 'msg_show' and content[1][2] == 'function Func1()' then - vim.cmd('delfunc Func3') - end - end) - - vim.cmd('function') - - vim.ui_detach(ns) - ]=] - ) - ) - assert_alive() - end) - - it('does not crash if the same function is deleted while listing', function() - local _ = Screen.new(80, 24) - matches( - 'Vim%(function%):E454: Function list was modified$', - pcall_err( - exec_lua, - [=[ - vim.cmd([[ - func Func1() - endfunc - func Func2() - endfunc - func Func3() - endfunc - ]]) - - local ns = vim.api.nvim_create_namespace('test') - - vim.ui_attach(ns, { ext_messages = true }, function(event, _, content) - if event == 'msg_show' and content[1][2] == 'function Func1()' then - vim.cmd('delfunc Func2') - end - end) - - vim.cmd('function') - - vim.ui_detach(ns) - ]=] - ) - ) - assert_alive() - end) end) it('no double-free in garbage collection #16287', function() -- cgit