From 54db75e995f82a11f5d2a223d816d2ea0bd0467e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 17 Mar 2024 17:24:03 +0800 Subject: refactor(drawline): integrate terminal hl with eol loop (#27893) There is no test for using 'cursorline' in Normal mode in a terminal buffer, so add a test and fix 'cursorcolumn' remaining when entering Terminal mode. Also move synIDattr() tests to ui/highlight_spec.lua. --- test/functional/terminal/buffer_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/terminal/buffer_spec.lua') diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua index 376b7b849e..ea9d974dc3 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -54,7 +54,7 @@ describe(':terminal buffer', function() eq({ 0, 'both' }, eval('[&l:cursorline, &l:cursorlineopt]')) end) - it('terminal-mode disables cursorline when cursorlineopt is only set to "line', function() + it('terminal-mode disables cursorline when cursorlineopt is only set to "line"', function() feed([[]]) command('setlocal cursorline cursorlineopt=line') feed('i') -- cgit From 400ef8aaa0766544fb0bcb4d367fa2da5279c5f3 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 19 Mar 2024 12:44:14 +0800 Subject: test(terminal/buffer_spec): fix incorrect tests (#27923) The first describe() block enters terminal mode in before_each(), so feed_command() at the start of a test case writes it to the terminal instead of executing it. --- test/functional/terminal/buffer_spec.lua | 62 ++++++++++++++------------------ 1 file changed, 26 insertions(+), 36 deletions(-) (limited to 'test/functional/terminal/buffer_spec.lua') diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua index ea9d974dc3..0c6f74e583 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -205,22 +205,14 @@ describe(':terminal buffer', function() eq(tbuf, eval('bufnr("%")')) end) - it('term_close() use-after-free #4393', function() - feed_command('terminal yes') - feed([[]]) - feed_command('bdelete!') - end) - describe('handles confirmations', function() it('with :confirm', function() - feed_command('terminal') feed('') feed_command('confirm bdelete') screen:expect { any = 'Close "term://' } end) it('with &confirm', function() - feed_command('terminal') feed('') feed_command('bdelete') screen:expect { any = 'E89' } @@ -317,13 +309,22 @@ describe(':terminal buffer', function() pcall_err(command, 'write test/functional/fixtures/tty-test.c') ) end) +end) + +describe(':terminal buffer', function() + before_each(clear) + + it('term_close() use-after-free #4393', function() + command('terminal yes') + feed('') -- Add input to separate two RPC requests + command('bdelete!') + end) it('emits TermRequest events #26972', function() - command('new') local term = api.nvim_open_term(0, {}) local termbuf = api.nvim_get_current_buf() - -- Test that autocommand buffer is associated with the terminal buffer, not the current buffer + -- Test that is the terminal buffer, not the current buffer command('au TermRequest * let g:termbuf = +expand("")') command('wincmd p') @@ -337,7 +338,6 @@ describe(':terminal buffer', function() end) it('TermReqeust synchronization #27572', function() - command('new') command('autocmd! nvim_terminal TermRequest') local term = exec_lua([[ _G.input = {} @@ -364,20 +364,13 @@ describe(':terminal buffer', function() '\027[0n', }, exec_lua('return _G.input')) end) -end) - -describe('No heap-buffer-overflow when using', function() - local testfilename = 'Xtestfile-functional-terminal-buffers_spec' - before_each(function() + it('no heap-buffer-overflow when using termopen(echo) #3161', function() + local testfilename = 'Xtestfile-functional-terminal-buffers_spec' write_file(testfilename, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaa') - end) - - after_each(function() - os.remove(testfilename) - end) - - it('termopen(echo) #3161', function() + finally(function() + os.remove(testfilename) + end) feed_command('edit ' .. testfilename) -- Move cursor away from the beginning of the line feed('$') @@ -386,15 +379,22 @@ describe('No heap-buffer-overflow when using', function() assert_alive() feed_command('bdelete!') end) -end) -describe('No heap-buffer-overflow when', function() - it('set nowrap and send long line #11548', function() + it('no heap-buffer-overflow when sending long line with nowrap #11548', function() feed_command('set nowrap') feed_command('autocmd TermOpen * startinsert') feed_command('call feedkeys("4000ai\\:terminal!\\")') assert_alive() end) + + it('truncates number of composing characters to 5', function() + local chan = api.nvim_open_term(0, {}) + local composing = ('a̳'):sub(2) + api.nvim_chan_send(chan, 'a' .. composing:rep(8)) + retry(nil, nil, function() + eq('a' .. composing:rep(5), api.nvim_get_current_line()) + end) + end) end) describe('on_lines does not emit out-of-bounds line indexes when', function() @@ -431,16 +431,6 @@ describe('on_lines does not emit out-of-bounds line indexes when', function() end) end) -it('terminal truncates number of composing characters to 5', function() - clear() - local chan = api.nvim_open_term(0, {}) - local composing = ('a̳'):sub(2) - api.nvim_chan_send(chan, 'a' .. composing:rep(8)) - retry(nil, nil, function() - eq('a' .. composing:rep(5), api.nvim_get_current_line()) - end) -end) - describe('terminal input', function() before_each(function() clear() -- cgit From 16a416cb3c17ed3a7f21d35da5d211fcad947768 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 19 Mar 2024 16:56:51 +0800 Subject: fix(terminal): don't pass incomplete UTF-8 sequence to libvterm (#27922) --- test/functional/terminal/buffer_spec.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'test/functional/terminal/buffer_spec.lua') diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua index 0c6f74e583..741aaf2fe0 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -10,6 +10,7 @@ local pcall_err = helpers.pcall_err local eq, neq = helpers.eq, helpers.neq local api = helpers.api local retry = helpers.retry +local testprg = helpers.testprg local write_file = helpers.write_file local command = helpers.command local exc_exec = helpers.exc_exec @@ -395,6 +396,20 @@ describe(':terminal buffer', function() eq('a' .. composing:rep(5), api.nvim_get_current_line()) end) end) + + it('handles split UTF-8 sequences #16245', function() + local screen = Screen.new(50, 7) + screen:attach() + fn.termopen({ testprg('shell-test'), 'UTF-8' }) + screen:expect([[ + ^å | + ref: å̲ | + 1: å̲ | + 2: å̲ | + 3: å̲ | + |*2 + ]]) + end) end) describe('on_lines does not emit out-of-bounds line indexes when', function() -- 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/terminal/buffer_spec.lua | 48 ++++++++++++++++---------------- 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'test/functional/terminal/buffer_spec.lua') diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua index 741aaf2fe0..10d6445bf4 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -1,25 +1,25 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local thelpers = require('test.functional.terminal.helpers') -local assert_alive = helpers.assert_alive -local feed, clear = helpers.feed, helpers.clear -local poke_eventloop = helpers.poke_eventloop -local nvim_prog = helpers.nvim_prog -local eval, feed_command, source = helpers.eval, helpers.feed_command, helpers.source -local pcall_err = helpers.pcall_err -local eq, neq = helpers.eq, helpers.neq -local api = helpers.api -local retry = helpers.retry -local testprg = helpers.testprg -local write_file = helpers.write_file -local command = helpers.command -local exc_exec = helpers.exc_exec -local matches = helpers.matches -local exec_lua = helpers.exec_lua +local tt = require('test.functional.terminal.testutil') +local assert_alive = t.assert_alive +local feed, clear = t.feed, t.clear +local poke_eventloop = t.poke_eventloop +local nvim_prog = t.nvim_prog +local eval, feed_command, source = t.eval, t.feed_command, t.source +local pcall_err = t.pcall_err +local eq, neq = t.eq, t.neq +local api = t.api +local retry = t.retry +local testprg = t.testprg +local write_file = t.write_file +local command = t.command +local exc_exec = t.exc_exec +local matches = t.matches +local exec_lua = t.exec_lua local sleep = vim.uv.sleep -local fn = helpers.fn -local is_os = helpers.is_os -local skip = helpers.skip +local fn = t.fn +local is_os = t.is_os +local skip = t.skip describe(':terminal buffer', function() local screen @@ -27,7 +27,7 @@ describe(':terminal buffer', function() before_each(function() clear() command('set modifiable swapfile undolevels=20') - screen = thelpers.screen_setup() + screen = tt.screen_setup() end) it('terminal-mode forces various options', function() @@ -266,7 +266,7 @@ describe(':terminal buffer', function() it('does not segfault when pasting empty register #13955', function() feed('') feed_command('put a') -- register a is empty - helpers.assert_alive() + t.assert_alive() end) it([[can use temporary normal mode ]], function() @@ -473,7 +473,7 @@ end) describe('terminal input', function() it('sends various special keys with modifiers', function() clear() - local screen = thelpers.setup_child_nvim({ + local screen = tt.setup_child_nvim({ '-u', 'NONE', '-i', @@ -560,7 +560,7 @@ if is_os('win') then feed_command('set modifiable swapfile undolevels=20') poke_eventloop() local cmd = { 'cmd.exe', '/K', 'PROMPT=$g$s' } - screen = thelpers.screen_setup(nil, cmd) + screen = tt.screen_setup(nil, cmd) end) it('"put" operator sends data normally', function() -- cgit From 56123fb271d0cbd70faeadf06375988fe3b56986 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 9 Apr 2024 08:51:14 +0800 Subject: test(terminal/buffer_spec): avoid other keys in double clicks (#28245) Having unrelated keys between double clicks may make the test flaky as 'mousetime' is more easily reached. --- test/functional/terminal/buffer_spec.lua | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'test/functional/terminal/buffer_spec.lua') diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua index 10d6445bf4..080df4b25f 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -482,18 +482,16 @@ describe('terminal input', function() 'colorscheme vim', '--cmd', 'set notermguicolors', - '--cmd', - 'startinsert', + '-c', + 'while 1 | redraw | call setline(1, keytrans(getcharstr())) | endwhile', }) - screen:expect { - grid = [[ + screen:expect([[ {1: } | {4:~ }|*3 - {5:[No Name] 0,1 All}| - {3:-- INSERT --} | + {5:[No Name] 0,0-1 All}| + | {3:-- TERMINAL --} | - ]], - } + ]]) for _, key in ipairs({ '', '', @@ -543,9 +541,9 @@ describe('terminal input', function() '', '', }) do - feed('' .. key) + feed(key) retry(nil, nil, function() - eq(key, api.nvim_get_current_line()) + eq(key, vim.trim(api.nvim_get_current_line())) end) end end) -- cgit From 6d1e41432d6e8e0be586b5d9ba29e78ce2cba26d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 9 Apr 2024 09:32:27 +0800 Subject: test(terminal/buffer_spec): use screen:expect(), not retry() (#28246) Without creating new lines, using screen:expect() is faster and avoids RPC requests. --- test/functional/terminal/buffer_spec.lua | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'test/functional/terminal/buffer_spec.lua') diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua index 080df4b25f..341d6ee862 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -483,7 +483,7 @@ describe('terminal input', function() '--cmd', 'set notermguicolors', '-c', - 'while 1 | redraw | call setline(1, keytrans(getcharstr())) | endwhile', + 'while 1 | redraw | echo keytrans(getcharstr()) | endwhile', }) screen:expect([[ {1: } | @@ -542,9 +542,13 @@ describe('terminal input', function() '', }) do feed(key) - retry(nil, nil, function() - eq(key, vim.trim(api.nvim_get_current_line())) - end) + screen:expect(([[ + | + {4:~ }|*3 + {5:[No Name] 0,0-1 All}| + %s{1: }{MATCH: *}| + {3:-- TERMINAL --} | + ]]):format(key)) end end) end) -- 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/terminal/buffer_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/terminal/buffer_spec.lua') diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua index 341d6ee862..7cca620845 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_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 tt = require('test.functional.terminal.testutil') local assert_alive = t.assert_alive -- 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/terminal/buffer_spec.lua | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'test/functional/terminal/buffer_spec.lua') diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua index 7cca620845..96abd9f543 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -1,23 +1,25 @@ -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 tt = require('test.functional.terminal.testutil') -local assert_alive = t.assert_alive -local feed, clear = t.feed, t.clear -local poke_eventloop = t.poke_eventloop -local nvim_prog = t.nvim_prog -local eval, feed_command, source = t.eval, t.feed_command, t.source + +local assert_alive = n.assert_alive +local feed, clear = n.feed, n.clear +local poke_eventloop = n.poke_eventloop +local nvim_prog = n.nvim_prog +local eval, feed_command, source = n.eval, n.feed_command, n.source local pcall_err = t.pcall_err local eq, neq = t.eq, t.neq -local api = t.api +local api = n.api local retry = t.retry -local testprg = t.testprg +local testprg = n.testprg local write_file = t.write_file -local command = t.command -local exc_exec = t.exc_exec +local command = n.command +local exc_exec = n.exc_exec local matches = t.matches -local exec_lua = t.exec_lua +local exec_lua = n.exec_lua local sleep = vim.uv.sleep -local fn = t.fn +local fn = n.fn local is_os = t.is_os local skip = t.skip @@ -266,7 +268,7 @@ describe(':terminal buffer', function() it('does not segfault when pasting empty register #13955', function() feed('') feed_command('put a') -- register a is empty - t.assert_alive() + n.assert_alive() end) it([[can use temporary normal mode ]], function() -- cgit