From 2c5906b55bb6092121f4d3b032d5449da7675c2b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 2 Feb 2023 10:05:03 +0800 Subject: fix(exit): skip unnecessary steps in TUI preserve_exit() (#21897) This prevents the TUI from doing unexpected things when receiving a deadly signal or running out of memory. --- test/functional/terminal/tui_spec.lua | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'test/functional/terminal') diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index b28728057f..1d9e7b8e11 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -14,6 +14,7 @@ local clear = helpers.clear local command = helpers.command local dedent = helpers.dedent local exec = helpers.exec +local exec_lua = helpers.exec_lua local testprg = helpers.testprg local retry = helpers.retry local nvim_prog = helpers.nvim_prog @@ -1506,6 +1507,11 @@ describe('TUI', function() {3:-- TERMINAL --} | ]]} end) + + it('no assert failure on deadly signal #21896', function() + exec_lua([[vim.loop.kill(vim.fn.jobpid(vim.bo.channel), 'sigterm')]]) + screen:expect({any = '%[Process exited 1%]'}) + end) end) describe('TUI', function() -- cgit From b2b82ff14281a4784790af288cde13984d5d5727 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 9 Feb 2023 14:36:17 +0800 Subject: fix(rpc): ignore redraw events when exiting (#22184) When a TUI client has already stopped, handling UI events will cause a heap-use-after-free, so ignore them. --- test/functional/terminal/tui_spec.lua | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'test/functional/terminal') diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index 1d9e7b8e11..7294969ac8 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -2407,6 +2407,11 @@ describe("TUI as a client", function() {3:-- TERMINAL --} | ]]} + -- No heap-use-after-free when receiving UI events after deadly signal #22184 + server:request('nvim_input', ('a'):rep(1000)) + exec_lua([[vim.loop.kill(vim.fn.jobpid(vim.bo.channel), 'sigterm')]]) + screen:expect({any = '%[Process exited 1%]'}) + client_super:close() server:close() end) -- cgit From 5a8039a0cb544eac91c569439c61ba0a35950506 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 13 Feb 2023 17:39:28 +0800 Subject: test(tui_spec): remove unnecessary arguments for remote UI --- test/functional/terminal/tui_spec.lua | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'test/functional/terminal') diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index 7294969ac8..31e1f27363 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -2365,18 +2365,18 @@ describe("TUI as a client", function() set_session(client_super) local screen_client = thelpers.screen_setup(0, - string.format([=[["%s", "-u", "NONE", "-i", "NONE", "--server", "%s", "--remote-ui"]]=], + string.format([=[["%s", "--server", "%s", "--remote-ui"]]=], nvim_prog, server_pipe)) - screen_client:expect{grid=[[ - Hello, Worl{1:d} | - {4:~ }| - {4:~ }| - {4:~ }| - {5:[No Name] [+] }| - | - {3:-- TERMINAL --} | - ]]} + screen_client:expect{grid=[[ + Hello, Worl{1:d} | + {4:~ }| + {4:~ }| + {4:~ }| + {5:[No Name] [+] }| + | + {3:-- TERMINAL --} | + ]]} feed_data(":q!\n") @@ -2394,7 +2394,7 @@ describe("TUI as a client", function() set_session(client_super) local screen = thelpers.screen_setup(0, - string.format([=[["%s", "-u", "NONE", "-i", "NONE", "--server", "%s", "--remote-ui"]]=], + string.format([=[["%s", "--server", "%s", "--remote-ui"]]=], nvim_prog, server_pipe)) screen:expect{grid=[[ @@ -2416,11 +2416,10 @@ describe("TUI as a client", function() server:close() end) - it("throws error when no server exists", function() clear() local screen = thelpers.screen_setup(0, - string.format([=[["%s", "-u", "NONE", "-i", "NONE", "--server", "127.0.0.1:2436546", "--remote-ui"]]=], + string.format([=[["%s", "--server", "127.0.0.1:2436546", "--remote-ui"]]=], nvim_prog), 60) screen:expect([[ @@ -2467,7 +2466,7 @@ describe("TUI as a client", function() set_session(client_super) local screen_client = thelpers.screen_setup(0, - string.format([=[["%s", "-u", "NONE", "-i", "NONE", "--server", "%s", "--remote-ui"]]=], + string.format([=[["%s", "--server", "%s", "--remote-ui"]]=], nvim_prog, server_pipe)) screen_client:expect{grid=[[ -- cgit From 820430dc0bb84011edae801262e64a10be7ebb9d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 13 Feb 2023 16:33:20 +0800 Subject: fix(tui): exit on input eof --- test/functional/terminal/tui_spec.lua | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'test/functional/terminal') diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index 31e1f27363..4e62354ed8 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -2412,6 +2412,11 @@ describe("TUI as a client", function() exec_lua([[vim.loop.kill(vim.fn.jobpid(vim.bo.channel), 'sigterm')]]) screen:expect({any = '%[Process exited 1%]'}) + eq(0, meths.get_vvar('shell_error')) + -- exits on input eof #22244 + funcs.system({nvim_prog, '--server', server_pipe, '--remote-ui'}) + eq(1, meths.get_vvar('shell_error')) + client_super:close() server:close() end) -- cgit From 9b9f8dfcc41ceb80d3970eb58af8ee350b57dc7f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 18 Feb 2023 09:27:10 +0800 Subject: test: make {MATCH:} behave less unexpectedly in screen:expect() Include the rest of the line and allow multiple {MATCH:} patterns. --- test/functional/terminal/tui_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/terminal') diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index 4e62354ed8..4a0c482004 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -1544,7 +1544,7 @@ describe('TUI', function() {2:~ }│{4:~ }| {2:~ }│{5:[No Name] 0,0-1 All}| {2:~ }│ | - {5:new }{MATCH:<.*[/\]nvim }| + {5:new }{1:{MATCH:<.*[/\]nvim }}| | ]]) end) -- cgit From 9381d08e2916d6114c06336714e416bb834e5566 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 18 Feb 2023 10:22:22 +0800 Subject: test(tui_spec): use RPC request to setup autocommands This avoids changing cmdline and fixes a warning. --- test/functional/terminal/tui_spec.lua | 61 +++++++++++++++-------------------- 1 file changed, 26 insertions(+), 35 deletions(-) (limited to 'test/functional/terminal') diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index 4a0c482004..792ad63e76 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -109,14 +109,14 @@ describe('TUI', function() end) it('accepts resize while pager is active', function() - child_session:request("nvim_command", [[ + child_session:request("nvim_exec", [[ set more func! ManyErr() for i in range(10) echoerr "FAIL ".i endfor endfunc - ]]) + ]], false) feed_data(':call ManyErr()\r') screen:expect{grid=[[ {8:Error detected while processing function ManyErr:} | @@ -302,11 +302,11 @@ describe('TUI', function() end) it('accepts mouse wheel events #19992', function() - child_session:request('nvim_command', [[ + child_session:request('nvim_exec', [[ set number nostartofline nowrap mousescroll=hor:1,ver:1 call setline(1, repeat([join(range(10), '----')], 10)) vsplit - ]]) + ]], false) screen:expect([[ {11: 1 }{1:0}----1----2----3----4│{11: 1 }0----1----2----3----| {11: 2 }0----1----2----3----4│{11: 2 }0----1----2----3----| @@ -632,11 +632,11 @@ describe('TUI', function() | {3:-- TERMINAL --} | ]]) - child_session:request('nvim_command', [[ + child_session:request('nvim_exec', [[ tab split tabnew highlight Tabline ctermbg=NONE ctermfg=NONE cterm=underline - ]]) + ]], false) screen:expect([[ {12: + [No Name] + [No Name] }{3: [No Name] }{1: }{12:X}| {1: } | @@ -669,7 +669,7 @@ describe('TUI', function() end) it('mouse events work with right-click menu', function() - child_session:request('nvim_command', [[ + child_session:request('nvim_exec', [[ call setline(1, 'popup menu test') set mouse=a mousemodel=popup @@ -679,7 +679,7 @@ describe('TUI', function() menu PopUp.baz :let g:menustr = 'baz' highlight Pmenu ctermbg=NONE ctermfg=NONE cterm=underline,reverse highlight PmenuSel ctermbg=NONE ctermfg=NONE cterm=underline,reverse,bold - ]]) + ]], false) meths.input_mouse('right', 'press', '', 0, 0, 4) screen:expect([[ {1:p}opup menu test | @@ -1626,12 +1626,16 @@ end) describe('TUI FocusGained/FocusLost', function() local screen + local child_session before_each(function() clear() - screen = thelpers.screen_setup(0, '["'..nvim_prog - ..'", "-u", "NONE", "-i", "NONE", "--cmd", "set noswapfile noshowcmd noruler"]') - screen:expect{grid=[[ + local child_server = new_pipename() + screen = thelpers.screen_setup(0, + string.format( + [=[["%s", "--listen", "%s", "-u", "NONE", "-i", "NONE", "--cmd", "set noswapfile noshowcmd noruler"]]=], + nvim_prog, child_server)) + screen:expect([[ {1: } | {4:~ }| {4:~ }| @@ -1639,22 +1643,16 @@ describe('TUI FocusGained/FocusLost', function() {5:[No Name] }| | {3:-- TERMINAL --} | - ]]} - feed_data(":autocmd FocusGained * echo 'gained'\n") - feed_data(":autocmd FocusLost * echo 'lost'\n") + ]]) + child_session = helpers.connect(child_server) + child_session:request('nvim_exec', [[ + autocmd FocusGained * echo 'gained' + autocmd FocusLost * echo 'lost' + ]], false) feed_data("\034\016") -- CTRL-\ CTRL-N end) it('in normal-mode', function() - screen:expect{grid=[[ - {1: } | - {4:~ }| - {4:~ }| - {4:~ }| - {5:[No Name] }| - :autocmd FocusLost * echo 'lost' | - {3:-- TERMINAL --} | - ]]} retry(2, 3 * screen.timeout, function() feed_data('\027[I') screen:expect([[ @@ -1746,18 +1744,11 @@ describe('TUI FocusGained/FocusLost', function() -- Set up autocmds that modify the buffer, instead of just calling :echo. -- This is how we can test handling of focus gained/lost during cmdline-mode. -- See commit: 5cc87d4dabd02167117be7a978b5c8faaa975419. - feed_data(":autocmd!\n") - feed_data(":autocmd FocusLost * call append(line('$'), 'lost')\n") - feed_data(":autocmd FocusGained * call append(line('$'), 'gained')\n") - screen:expect{grid=[[ - {1: } | - {4:~ }| - {4:~ }| - {4:~ }| - {5:[No Name] }| - | - {3:-- TERMINAL --} | - ]]} + child_session:request('nvim_exec', [[ + autocmd! + autocmd FocusLost * call append(line('$'), 'lost') + autocmd FocusGained * call append(line('$'), 'gained') + ]], false) retry(2, 3 * screen.timeout, function() -- Enter cmdline-mode. feed_data(':') -- cgit From 7f424e2b65779c59fc0cac3cc7508ba2ec07f200 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 23 Feb 2023 18:29:36 +0100 Subject: feat(api): more fields in nvim_list_uis Problem: nvim_list_uis does not report all ":help ui-option" fields. Solution: Store ":help ui-option" fields on the `UI` object and update ui_array. --- test/functional/terminal/tui_spec.lua | 37 ++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) (limited to 'test/functional/terminal') diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index 792ad63e76..9db80e0db2 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -1398,17 +1398,32 @@ describe('TUI', function() ]]} end) - it('is included in nvim_list_uis()', function() - feed_data(':echo map(nvim_list_uis(), {k,v -> sort(items(filter(v, {k,v -> k[:3] !=# "ext_" })))})\r') - screen:expect([=[ - | - {4:~ }| - {5: }| - [[['chan', 1], ['height', 6], ['override', v:false| - ], ['rgb', v:false], ['width', 50]]] | - {10:Press ENTER or type command to continue}{1: } | - {3:-- TERMINAL --} | - ]=]) + it('in nvim_list_uis()', function() + local expected = { + { + chan = 1, + ext_cmdline = false, + ext_hlstate = false, + ext_linegrid = true, + ext_messages = false, + ext_multigrid = false, + ext_popupmenu = false, + ext_tabline = false, + ext_termcolors = true, + ext_wildmenu = false, + height = 6, + override = false, + rgb = false, + stdin_tty = true, + stdout_tty = true, + term_background = '', + term_colors = 256, + term_name = 'xterm-256color', -- $TERM in :terminal. + width = 50 + }, + } + local _, rv = child_session:request('nvim_list_uis') + eq(expected, rv) end) it('allows grid to assume wider ambiguous-width characters than host terminal #19686', function() -- cgit From ce597235a26839826de88ecd8b949ec54c310fbd Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 27 Feb 2023 16:31:05 +0100 Subject: feat(ui): restore has('gui_running') Problem: has('gui_running') is still common in the wild and our answer has changed over time, causing frustration. https://github.com/vimpostor/vim-tpipeline/commit/95a6ccbe9f33bc42dd4cee45731d8bc3fbcd92d1 Solution: Use stdin_tty/stdout_tty to decide if a UI is (not) a GUI. --- test/functional/terminal/tui_spec.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'test/functional/terminal') diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index 9db80e0db2..76ea6256a1 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -1399,6 +1399,8 @@ describe('TUI', function() end) it('in nvim_list_uis()', function() + -- $TERM in :terminal. + local exp_term = is_os('bsd') and 'builtin_xterm' or 'xterm-256color' local expected = { { chan = 1, @@ -1418,7 +1420,7 @@ describe('TUI', function() stdout_tty = true, term_background = '', term_colors = 256, - term_name = 'xterm-256color', -- $TERM in :terminal. + term_name = exp_term, width = 50 }, } -- cgit From 2630341db65772e0a636c2a1cfbd6bba8ca9b28d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 28 Feb 2023 07:19:03 +0800 Subject: fix(tui): avoid stack-use-after-scope with cursor color (#22435) --- test/functional/terminal/tui_spec.lua | 36 +++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'test/functional/terminal') diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index 792ad63e76..bbcf5ecad7 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -1512,6 +1512,42 @@ describe('TUI', function() exec_lua([[vim.loop.kill(vim.fn.jobpid(vim.bo.channel), 'sigterm')]]) screen:expect({any = '%[Process exited 1%]'}) end) + + it('no stack-use-after-scope with cursor color #22432', function() + screen:set_option('rgb', true) + command('set termguicolors') + child_session:request('nvim_exec', [[ + set tgc + hi Cursor guifg=Red guibg=Green + set guicursor=n:block-Cursor/lCursor + ]], false) + screen:set_default_attr_ids({ + [1] = {reverse = true}, + [2] = {bold = true, foreground = Screen.colors.Blue}, + [3] = {foreground = Screen.colors.Blue}, + [4] = {reverse = true, bold = true}, + [5] = {bold = true}, + }) + screen:expect([[ + {1: } | + {2:~}{3: }| + {2:~}{3: }| + {2:~}{3: }| + {4:[No Name] }| + | + {5:-- TERMINAL --} | + ]]) + feed('i') + screen:expect([[ + {1: } | + {2:~}{3: }| + {2:~}{3: }| + {2:~}{3: }| + {4:[No Name] }| + {5:-- INSERT --} | + {5:-- TERMINAL --} | + ]]) + end) end) describe('TUI', function() -- cgit From b466e1d289180fad212a93b173034787fd6be9a8 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Mon, 13 Mar 2023 04:15:24 +0100 Subject: test: unskip working Windows tests (#22537) Some tests that were previously not working have started to work again for unspecified reasons, so let's enable them. --- test/functional/terminal/mouse_spec.lua | 2 -- test/functional/terminal/scrollback_spec.lua | 2 -- 2 files changed, 4 deletions(-) (limited to 'test/functional/terminal') diff --git a/test/functional/terminal/mouse_spec.lua b/test/functional/terminal/mouse_spec.lua index 50c8f5e7df..ac76217023 100644 --- a/test/functional/terminal/mouse_spec.lua +++ b/test/functional/terminal/mouse_spec.lua @@ -68,7 +68,6 @@ describe(':terminal mouse', function() end) it('does not leave terminal mode on left-release', function() - skip(is_os('win')) feed('') eq('t', eval('mode(1)')) end) @@ -232,7 +231,6 @@ describe(':terminal mouse', function() end) describe('with a split window and other buffer', function() - skip(is_os('win')) before_each(function() feed(':vsp') screen:expect([[ diff --git a/test/functional/terminal/scrollback_spec.lua b/test/functional/terminal/scrollback_spec.lua index a4899c8219..00a35a5c6c 100644 --- a/test/functional/terminal/scrollback_spec.lua +++ b/test/functional/terminal/scrollback_spec.lua @@ -140,7 +140,6 @@ describe(':terminal scrollback', function() describe('and height decreased by 1', function() - if skip(is_os('win')) then return end local function will_hide_top_line() feed([[]]) screen:try_resize(screen._width - 2, screen._height - 1) @@ -347,7 +346,6 @@ end) describe(':terminal prints more lines than the screen height and exits', function() it('will push extra lines to scrollback', function() - skip(is_os('win')) clear() local screen = Screen.new(30, 7) screen:attach({rgb=false}) -- cgit From 8786b2066d39e45295eacfe7b10263af4a330f2e Mon Sep 17 00:00:00 2001 From: Enan Ajmain <3nan.ajmain@gmail.com> Date: Sun, 19 Mar 2023 23:23:34 +0600 Subject: fix: pasting in terminal buffer on windows #22566 Problem: On Windows, pasting multiple lines on a terminal buffer cause all the lines to appear on the same line, i.e., the line breaks are lost. Cause: Windows shells expect "\r\n" as line break but "terminal_paste" function uses "\n". Solution: Use "\r\n" as line break for pasting in terminal buffer on Windows. Note: Although this issue was reported with powershell set as 'shell', it occurs in cmd too. Fixes #14621 --- test/functional/terminal/buffer_spec.lua | 68 ++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) (limited to 'test/functional/terminal') diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua index 9c8b983ff7..676be151ee 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -429,3 +429,71 @@ it('terminal truncates number of composing characters to 5', function() meths.chan_send(chan, 'a' .. composing:rep(8)) retry(nil, nil, function() eq('a' .. composing:rep(5), meths.get_current_line()) end) end) + +if is_os('win') then + describe(':terminal in Windows', function() + local screen + + before_each(function() + clear() + feed_command('set modifiable swapfile undolevels=20') + poke_eventloop() + local cmd = '["cmd.exe","/K","PROMPT=$g$s"]' + screen = thelpers.screen_setup(nil, cmd) + end) + + it('"put" operator sends data normally', function() + feed('G') + feed_command('let @a = ":: tty ready"') + feed_command('let @a = @a . "\\n:: appended " . @a . "\\n\\n"') + feed('"ap"ap') + screen:expect([[ + | + > :: tty ready | + > :: appended :: tty ready | + > :: tty ready | + > :: appended :: tty ready | + ^> {2: } | + :let @a = @a . "\n:: appended " . @a . "\n\n" | + ]]) + -- operator count is also taken into consideration + feed('3"ap') + screen:expect([[ + > :: appended :: tty ready | + > :: tty ready | + > :: appended :: tty ready | + > :: tty ready | + > :: appended :: tty ready | + ^> {2: } | + :let @a = @a . "\n:: appended " . @a . "\n\n" | + ]]) + end) + + it('":put" command sends data normally', function() + feed('G') + feed_command('let @a = ":: tty ready"') + feed_command('let @a = @a . "\\n:: appended " . @a . "\\n\\n"') + feed_command('put a') + screen:expect([[ + | + > :: tty ready | + > :: appended :: tty ready | + > {2: } | + | + ^ | + :put a | + ]]) + -- line argument is only used to move the cursor + feed_command('6put a') + screen:expect([[ + | + > :: tty ready | + > :: appended :: tty ready | + > :: tty ready | + > :: appended :: tty ready | + ^> {2: } | + :6put a | + ]]) + end) + end) +end -- cgit From a40eb7cc991eb4f8b89f467e8e42563868efa76b Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 17 Mar 2023 01:12:33 +0100 Subject: feat(vim.version): more coercion with strict=false Problem: "tmux 3.2a" (output from "tmux -V") is not parsed easily. Solution: With `strict=false`, discard everything before the first digit. - rename Semver => Version - rename vim.version.version() => vim.version._version() - rename matches() => has() - remove `opts` from cmp() --- test/functional/terminal/buffer_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/terminal') diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua index 676be151ee..b983ea89d5 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -202,7 +202,7 @@ describe(':terminal buffer', function() -- Save the buffer number of the terminal for later testing. local tbuf = eval('bufnr("%")') - local exitcmd = helpers.is_os('win') + local exitcmd = is_os('win') and "['cmd', '/c', 'exit']" or "['sh', '-c', 'exit']" source([[ -- cgit From 34ac75b32927328a0c691c5bda987c0fdb5ce9eb Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Wed, 5 Apr 2023 17:19:53 +0100 Subject: refactor: rename local API alias from a to api Problem: Codebase inconsistently binds vim.api onto a or api. Solution: Use api everywhere. a as an identifier is too short to have at the module level. --- test/functional/terminal/scrollback_spec.lua | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'test/functional/terminal') diff --git a/test/functional/terminal/scrollback_spec.lua b/test/functional/terminal/scrollback_spec.lua index 00a35a5c6c..5d967e0340 100644 --- a/test/functional/terminal/scrollback_spec.lua +++ b/test/functional/terminal/scrollback_spec.lua @@ -575,12 +575,12 @@ describe("pending scrollback line handling", function() it("does not crash after setting 'number' #14891", function() exec_lua [[ - local a = vim.api - local buf = a.nvim_create_buf(true, true) - local chan = a.nvim_open_term(buf, {}) - a.nvim_win_set_option(0, "number", true) - a.nvim_chan_send(chan, ("a\n"):rep(11) .. "a") - a.nvim_win_set_buf(0, buf) + local api = vim.api + local buf = api.nvim_create_buf(true, true) + local chan = api.nvim_open_term(buf, {}) + api.nvim_win_set_option(0, "number", true) + api.nvim_chan_send(chan, ("a\n"):rep(11) .. "a") + api.nvim_win_set_buf(0, buf) ]] screen:expect [[ {1: 1 }^a | @@ -607,12 +607,11 @@ describe("pending scrollback line handling", function() it("does not crash after nvim_buf_call #14891", function() skip(is_os('win')) exec_lua [[ - local a = vim.api - local bufnr = a.nvim_create_buf(false, true) - a.nvim_buf_call(bufnr, function() + local bufnr = vim.api.nvim_create_buf(false, true) + vim.api.nvim_buf_call(bufnr, function() vim.fn.termopen({"echo", ("hi\n"):rep(11)}) end) - a.nvim_win_set_buf(0, bufnr) + vim.api.nvim_win_set_buf(0, bufnr) vim.cmd("startinsert") ]] screen:expect [[ -- cgit From 95c6e1b7418e37530352418e93a18366acef6242 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 19 Apr 2023 12:10:06 +0800 Subject: test(terminal/channel_spec): fix screen test immediate success (#23192) Check for the [No Name] after wiping the buffer. --- test/functional/terminal/channel_spec.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'test/functional/terminal') diff --git a/test/functional/terminal/channel_spec.lua b/test/functional/terminal/channel_spec.lua index 2ca7cdb0a2..2cd02be321 100644 --- a/test/functional/terminal/channel_spec.lua +++ b/test/functional/terminal/channel_spec.lua @@ -95,15 +95,19 @@ describe('terminal channel is closed and later released if', function() end) it('chansend sends lines to terminal channel in proper order', function() - clear() + clear({args = {'--cmd', 'set laststatus=2'}}) local screen = Screen.new(100, 20) screen:attach() local shells = is_os('win') and {'cmd.exe', 'pwsh.exe -nop', 'powershell.exe -nop'} or {'sh'} for _, sh in ipairs(shells) do - command([[bdelete! | let id = termopen(']] .. sh .. [[')]]) + command([[let id = termopen(']] .. sh .. [[')]]) command([[call chansend(id, ['echo "hello"', 'echo "world"', ''])]]) screen:expect{ any=[[echo "hello".*echo "world"]] } + command('bdelete!') + screen:expect{ + any='%[No Name%]' + } end end) -- cgit From 0f1b511f2302324684c3ed9ff586f51c2129694d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 1 May 2023 12:20:07 +0800 Subject: fix(tui): redraw on SIGWINCH even if size didn't change --- test/functional/terminal/tui_spec.lua | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'test/functional/terminal') diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index 069fbad803..f366c8a6d9 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -1565,6 +1565,29 @@ describe('TUI', function() {5:-- TERMINAL --} | ]]) end) + + it('redraws on SIGWINCH even if terminal size is unchanged #23411', function() + child_session:request('nvim_echo', {{'foo'}}, false, {}) + screen:expect([[ + {1: } | + {4:~ }| + {4:~ }| + {4:~ }| + {5:[No Name] }| + foo | + {3:-- TERMINAL --} | + ]]) + exec_lua([[vim.loop.kill(vim.fn.jobpid(vim.bo.channel), 'sigwinch')]]) + screen:expect([[ + {1: } | + {4:~ }| + {4:~ }| + {4:~ }| + {5:[No Name] }| + | + {3:-- TERMINAL --} | + ]]) + end) end) describe('TUI', function() -- cgit From 197827321a39168dbaa143c9f7b4f5db668f893c Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Mon, 1 May 2023 20:08:25 +0200 Subject: fix(tui): grid_clear properly clears the screen Problem: When setting a shell size smaller than the containing terminal window through `:winsize` or `:set lines/columns` the screen is not properly cleared. Solution: Clear the tui dimensions rather than the grid dimensions. --- test/functional/terminal/api_spec.lua | 8 ++++---- test/functional/terminal/tui_spec.lua | 13 +++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) (limited to 'test/functional/terminal') diff --git a/test/functional/terminal/api_spec.lua b/test/functional/terminal/api_spec.lua index 724791343d..93641fc576 100644 --- a/test/functional/terminal/api_spec.lua +++ b/test/functional/terminal/api_spec.lua @@ -66,10 +66,10 @@ describe('api', function() screen:expect([[ [tui] insert-mode | - [socket 1] this is more t{4: }| - han 25 columns {4: }| - [socket 2] input{1: } {4: }| - {4:~ }| + [socket 1] this is more t | + han 25 columns | + [socket 2] input{1: } | + {4:~ } | {3:-- INSERT --} | {3:-- TERMINAL --} | ]]) diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index 069fbad803..5fd3467949 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -2422,6 +2422,19 @@ describe("TUI as a client", function() {3:-- TERMINAL --} | ]]} + -- grid smaller than containing terminal window is cleared properly + feed_data(":call setline(1,['a'->repeat(&columns)]->repeat(&lines))\n") + feed_data("0:set lines=2\n") + screen_server:expect{grid=[[ + {1:a}aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {5:[No Name] [+] }| + | + | + | + | + {3:-- TERMINAL --} | + ]]} + feed_data(":q!\n") server_super:close() -- cgit From ecd6d679a020ff97156de2fd3c443a77a671ac3d Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sun, 14 May 2023 14:29:18 +0200 Subject: test: skip flaky test on Windows --- test/functional/terminal/buffer_spec.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'test/functional/terminal') diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua index b983ea89d5..fa587e9364 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -281,6 +281,7 @@ describe(':terminal buffer', function() end) it('requires bang (!) to close a running job #15402', function() + skip(is_os('win'), "Test freezes the CI and makes it time out") eq('Vim(wqall):E948: Job still running', exc_exec('wqall')) for _, cmd in ipairs({ 'bdelete', '%bdelete', 'bwipeout', 'bunload' }) do matches('^Vim%('..cmd:gsub('%%', '')..'%):E89: term://.*tty%-test.* will be killed %(add %! to override%)$', -- cgit From c9f47fca8b896ecb304294cce675fedac9ab926c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 17 May 2023 21:06:27 +0800 Subject: fix(messages): ensure msg_grid is at top at more prompt (#23584) --- test/functional/terminal/tui_spec.lua | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'test/functional/terminal') diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index b69867af89..352009a1b1 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -112,7 +112,7 @@ describe('TUI', function() child_session:request("nvim_exec", [[ set more func! ManyErr() - for i in range(10) + for i in range(20) echoerr "FAIL ".i endfor endfunc @@ -128,7 +128,35 @@ describe('TUI', function() {3:-- TERMINAL --} | ]]} - feed_data('d') + screen:try_resize(50,10) + screen:expect{grid=[[ + :call ManyErr() | + {8:Error detected while processing function ManyErr:} | + {11:line 2:} | + {8:FAIL 0} | + {8:FAIL 1} | + {8:FAIL 2} | + | + | + {10:-- More --}{1: } | + {3:-- TERMINAL --} | + ]]} + + feed_data('j') + screen:expect{grid=[[ + {8:Error detected while processing function ManyErr:} | + {11:line 2:} | + {8:FAIL 0} | + {8:FAIL 1} | + {8:FAIL 2} | + {8:FAIL 3} | + {8:FAIL 4} | + {8:FAIL 5} | + {10:-- More --}{1: } | + {3:-- TERMINAL --} | + ]]} + + screen:try_resize(50,7) screen:expect{grid=[[ {8:FAIL 1} | {8:FAIL 2} | -- cgit From 1fe1bb084d0099fc4f9bfdc11189485d0f74b75a Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Mon, 19 Dec 2022 16:37:45 +0000 Subject: refactor(options): deprecate nvim[_buf|_win]_[gs]et_option Co-authored-by: zeertzjq Co-authored-by: famiu --- test/functional/terminal/buffer_spec.lua | 2 +- test/functional/terminal/edit_spec.lua | 6 +-- test/functional/terminal/ex_terminal_spec.lua | 10 ++--- test/functional/terminal/mouse_spec.lua | 4 +- test/functional/terminal/scrollback_spec.lua | 46 +++++++++++----------- test/functional/terminal/tui_spec.lua | 10 ++--- test/functional/terminal/window_split_tab_spec.lua | 4 +- 7 files changed, 41 insertions(+), 41 deletions(-) (limited to 'test/functional/terminal') diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua index fa587e9364..4ce354b9a9 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -197,7 +197,7 @@ describe(':terminal buffer', function() it('handles loss of focus gracefully', function() -- Change the statusline to avoid printing the file name, which varies. - nvim('set_option', 'statusline', '==========') + nvim('set_option_value', 'statusline', '==========', {}) feed_command('set laststatus=0') -- Save the buffer number of the terminal for later testing. diff --git a/test/functional/terminal/edit_spec.lua b/test/functional/terminal/edit_spec.lua index 80287bb3d0..db5dba7374 100644 --- a/test/functional/terminal/edit_spec.lua +++ b/test/functional/terminal/edit_spec.lua @@ -21,8 +21,8 @@ describe(':edit term://*', function() before_each(function() clear() - meths.set_option('shell', testprg('shell-test')) - meths.set_option('shellcmdflag', 'EXE') + meths.set_option_value('shell', testprg('shell-test'), {}) + meths.set_option_value('shellcmdflag', 'EXE', {}) end) it('runs TermOpen event', function() @@ -40,7 +40,7 @@ describe(':edit term://*', function() local columns, lines = 20, 4 local scr = get_screen(columns, lines) local rep = 97 - meths.set_option('shellcmdflag', 'REP ' .. rep) + meths.set_option_value('shellcmdflag', 'REP ' .. rep, {}) command('set shellxquote=') -- win: avoid extra quotes local sb = 10 command('autocmd TermOpen * :setlocal scrollback='..tostring(sb) diff --git a/test/functional/terminal/ex_terminal_spec.lua b/test/functional/terminal/ex_terminal_spec.lua index 6b7e93a864..28751a3504 100644 --- a/test/functional/terminal/ex_terminal_spec.lua +++ b/test/functional/terminal/ex_terminal_spec.lua @@ -133,8 +133,8 @@ describe(':terminal (with fake shell)', function() screen = Screen.new(50, 4) screen:attach({rgb=false}) -- shell-test.c is a fake shell that prints its arguments and exits. - nvim('set_option', 'shell', testprg('shell-test')) - nvim('set_option', 'shellcmdflag', 'EXE') + nvim('set_option_value', 'shell', testprg('shell-test'), {}) + nvim('set_option_value', 'shellcmdflag', 'EXE', {}) end) -- Invokes `:terminal {cmd}` using a fake shell (shell-test.c) which prints @@ -157,7 +157,7 @@ describe(':terminal (with fake shell)', function() end) it("with no argument, and 'shell' is set to empty string", function() - nvim('set_option', 'shell', '') + nvim('set_option_value', 'shell', '', {}) terminal_with_fake_shell() screen:expect([[ ^ | @@ -169,7 +169,7 @@ describe(':terminal (with fake shell)', function() it("with no argument, but 'shell' has arguments, acts like termopen()", function() skip(is_os('win')) - nvim('set_option', 'shell', testprg('shell-test')..' -t jeff') + nvim('set_option_value', 'shell', testprg('shell-test')..' -t jeff', {}) terminal_with_fake_shell() screen:expect([[ ^jeff $ | @@ -193,7 +193,7 @@ describe(':terminal (with fake shell)', function() it("executes a given command through the shell, when 'shell' has arguments", function() skip(is_os('win')) - nvim('set_option', 'shell', testprg('shell-test')..' -t jeff') + nvim('set_option_value', 'shell', testprg('shell-test')..' -t jeff', {}) command('set shellxquote=') -- win: avoid extra quotes terminal_with_fake_shell('echo hi') screen:expect([[ diff --git a/test/functional/terminal/mouse_spec.lua b/test/functional/terminal/mouse_spec.lua index ac76217023..a2e9ffa1d7 100644 --- a/test/functional/terminal/mouse_spec.lua +++ b/test/functional/terminal/mouse_spec.lua @@ -11,7 +11,7 @@ describe(':terminal mouse', function() before_each(function() clear() - nvim('set_option', 'statusline', '==========') + nvim('set_option_value', 'statusline', '==========', {}) command('highlight StatusLine cterm=NONE') command('highlight StatusLineNC cterm=NONE') command('highlight VertSplit cterm=NONE') @@ -352,7 +352,7 @@ describe(':terminal mouse', function() end) it('handles terminal size when switching buffers', function() - nvim('set_option', 'hidden', true) + nvim('set_option_value', 'hidden', true, {}) feed('') screen:expect([[ {7: 27 }line │line30 | diff --git a/test/functional/terminal/scrollback_spec.lua b/test/functional/terminal/scrollback_spec.lua index 5d967e0340..48a9fa7171 100644 --- a/test/functional/terminal/scrollback_spec.lua +++ b/test/functional/terminal/scrollback_spec.lua @@ -8,7 +8,7 @@ local command = helpers.command local matches = helpers.matches local poke_eventloop = helpers.poke_eventloop local retry = helpers.retry -local curbufmeths = helpers.curbufmeths +local meths = helpers.meths local nvim = helpers.nvim local feed_data = thelpers.feed_data local pcall_err = helpers.pcall_err @@ -381,8 +381,8 @@ describe("'scrollback' option", function() local function set_fake_shell() -- shell-test.c is a fake shell that prints its arguments and exits. - nvim('set_option', 'shell', testprg('shell-test')) - nvim('set_option', 'shellcmdflag', 'EXE') + nvim('set_option_value', 'shell', testprg('shell-test'), {}) + nvim('set_option_value', 'shellcmdflag', 'EXE', {}) end local function expect_lines(expected, epsilon) @@ -401,7 +401,7 @@ describe("'scrollback' option", function() screen = thelpers.screen_setup(nil, "['sh']", 30) end - curbufmeths.set_option('scrollback', 0) + meths.set_option_value('scrollback', 0, {buf = 0}) feed_data(('%s REP 31 line%s'):format(testprg('shell-test'), is_os('win') and '\r' or '\n')) screen:expect{any='30: line '} retry(nil, nil, function() expect_lines(7) end) @@ -417,7 +417,7 @@ describe("'scrollback' option", function() screen = thelpers.screen_setup(nil, "['sh']", 30) end - curbufmeths.set_option('scrollback', 200) + meths.set_option_value('scrollback', 200, {buf=0}) -- Wait for prompt. screen:expect{any='%$'} @@ -426,10 +426,10 @@ describe("'scrollback' option", function() screen:expect{any='30: line '} retry(nil, nil, function() expect_lines(33, 2) end) - curbufmeths.set_option('scrollback', 10) + meths.set_option_value('scrollback', 10, {buf=0}) poke_eventloop() retry(nil, nil, function() expect_lines(16) end) - curbufmeths.set_option('scrollback', 10000) + meths.set_option_value('scrollback', 10000, {buf=0}) retry(nil, nil, function() expect_lines(16) end) -- Terminal job data is received asynchronously, may happen before the -- 'scrollback' option is synchronized with the internal sb_buffer. @@ -484,18 +484,18 @@ describe("'scrollback' option", function() ]]) local term_height = 6 -- Actual terminal screen height, not the scrollback -- Initial - local scrollback = curbufmeths.get_option('scrollback') + local scrollback = meths.get_option_value('scrollback', {buf=0}) eq(scrollback + term_height, eval('line("$")')) -- Reduction scrollback = scrollback - 2 - curbufmeths.set_option('scrollback', scrollback) + meths.set_option_value('scrollback', scrollback, {buf=0}) eq(scrollback + term_height, eval('line("$")')) end) it('defaults to 10000 in :terminal buffers', function() set_fake_shell() command('terminal') - eq(10000, curbufmeths.get_option('scrollback')) + eq(10000, meths.get_option_value('scrollback', {buf=0})) end) it('error if set to invalid value', function() @@ -507,7 +507,7 @@ describe("'scrollback' option", function() it('defaults to -1 on normal buffers', function() command('new') - eq(-1, curbufmeths.get_option('scrollback')) + eq(-1, meths.get_option_value('scrollback', {buf=0})) end) it(':setlocal in a :terminal buffer', function() @@ -516,45 +516,45 @@ describe("'scrollback' option", function() -- _Global_ scrollback=-1 defaults :terminal to 10_000. command('setglobal scrollback=-1') command('terminal') - eq(10000, curbufmeths.get_option('scrollback')) + eq(10000, meths.get_option_value('scrollback', {buf=0})) -- _Local_ scrollback=-1 in :terminal forces the _maximum_. command('setlocal scrollback=-1') retry(nil, nil, function() -- Fixup happens on refresh, not immediately. - eq(100000, curbufmeths.get_option('scrollback')) + eq(100000, meths.get_option_value('scrollback', {buf=0})) end) -- _Local_ scrollback=-1 during TermOpen forces the maximum. #9605 command('setglobal scrollback=-1') command('autocmd TermOpen * setlocal scrollback=-1') command('terminal') - eq(100000, curbufmeths.get_option('scrollback')) + eq(100000, meths.get_option_value('scrollback', {buf=0})) end) it(':setlocal in a normal buffer', function() command('new') -- :setlocal to -1. command('setlocal scrollback=-1') - eq(-1, curbufmeths.get_option('scrollback')) + eq(-1, meths.get_option_value('scrollback', {buf=0})) -- :setlocal to anything except -1. Currently, this just has no effect. command('setlocal scrollback=42') - eq(42, curbufmeths.get_option('scrollback')) + eq(42, meths.get_option_value('scrollback', {buf=0})) end) it(':set updates local value and global default', function() set_fake_shell() command('set scrollback=42') -- set global value - eq(42, curbufmeths.get_option('scrollback')) + eq(42, meths.get_option_value('scrollback', {buf=0})) command('terminal') - eq(42, curbufmeths.get_option('scrollback')) -- inherits global default + eq(42, meths.get_option_value('scrollback', {buf=0})) -- inherits global default command('setlocal scrollback=99') - eq(99, curbufmeths.get_option('scrollback')) + eq(99, meths.get_option_value('scrollback', {buf=0})) command('set scrollback<') -- reset to global default - eq(42, curbufmeths.get_option('scrollback')) + eq(42, meths.get_option_value('scrollback', {buf=0})) command('setglobal scrollback=734') -- new global default - eq(42, curbufmeths.get_option('scrollback')) -- local value did not change + eq(42, meths.get_option_value('scrollback', {buf=0})) -- local value did not change command('terminal') - eq(734, curbufmeths.get_option('scrollback')) + eq(734, meths.get_option_value('scrollback', {buf=0})) end) end) @@ -578,7 +578,7 @@ describe("pending scrollback line handling", function() local api = vim.api local buf = api.nvim_create_buf(true, true) local chan = api.nvim_open_term(buf, {}) - api.nvim_win_set_option(0, "number", true) + vim.wo.number = true api.nvim_chan_send(chan, ("a\n"):rep(11) .. "a") api.nvim_win_set_buf(0, buf) ]] diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index 352009a1b1..3cfd222336 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -1458,9 +1458,9 @@ describe('TUI', function() it('allows grid to assume wider ambiguous-width characters than host terminal #19686', function() child_session:request('nvim_buf_set_lines', 0, 0, -1, true, { ('℃'):rep(60), ('℃'):rep(60) }) - child_session:request('nvim_win_set_option', 0, 'cursorline', true) - child_session:request('nvim_win_set_option', 0, 'list', true) - child_session:request('nvim_win_set_option', 0, 'listchars', 'eol:$') + child_session:request('nvim_set_option_value', 'cursorline', true, {win=0}) + child_session:request('nvim_set_option_value', 'list', true, {win=0}) + child_session:request('nvim_set_option_value', 'listchars', 'eol:$', {win=0}) feed_data('gg') local singlewidth_screen = [[ {13:℃}{12:℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃℃}| @@ -1483,9 +1483,9 @@ describe('TUI', function() {3:-- TERMINAL --} | ]] screen:expect(singlewidth_screen) - child_session:request('nvim_set_option', 'ambiwidth', 'double') + child_session:request('nvim_set_option_value', 'ambiwidth', 'double', {}) screen:expect(doublewidth_screen) - child_session:request('nvim_set_option', 'ambiwidth', 'single') + child_session:request('nvim_set_option_value', 'ambiwidth', 'single', {}) screen:expect(singlewidth_screen) child_session:request('nvim_call_function', 'setcellwidths', {{{0x2103, 0x2103, 2}}}) screen:expect(doublewidth_screen) diff --git a/test/functional/terminal/window_split_tab_spec.lua b/test/functional/terminal/window_split_tab_spec.lua index 1d77e1e92e..3e1520e5fd 100644 --- a/test/functional/terminal/window_split_tab_spec.lua +++ b/test/functional/terminal/window_split_tab_spec.lua @@ -19,7 +19,7 @@ describe(':terminal', function() clear() -- set the statusline to a constant value because of variables like pid -- and current directory and to improve visibility of splits - meths.set_option('statusline', '==========') + meths.set_option_value('statusline', '==========', {}) command('highlight StatusLine cterm=NONE') command('highlight StatusLineNC cterm=NONE') command('highlight VertSplit cterm=NONE') @@ -71,7 +71,7 @@ describe(':terminal', function() end) it('does not change size if updated when not visible in any window #19665', function() - local channel = meths.buf_get_option(0, 'channel') + local channel = meths.get_option_value('channel', { buf = 0 }) command('enew') sleep(100) meths.chan_send(channel, 'foo') -- cgit From 576dddb46168e81aa0f78c28816082c662dedea1 Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Mon, 22 May 2023 12:47:10 +0600 Subject: test: don't unnecessarily specify win/buf for `nvim_(get|set)_option_value` `nvim_(get|set)_option_value` pick the current buffer / window by default for buffer-local/window-local (but not global-local) options. So specifying `buf = 0` or `win = 0` in opts is unnecessary for those options. This PR removes those to reduce code clutter. --- test/functional/terminal/scrollback_spec.lua | 38 +++++++++++----------- test/functional/terminal/tui_spec.lua | 4 +-- test/functional/terminal/window_split_tab_spec.lua | 2 +- 3 files changed, 22 insertions(+), 22 deletions(-) (limited to 'test/functional/terminal') diff --git a/test/functional/terminal/scrollback_spec.lua b/test/functional/terminal/scrollback_spec.lua index 48a9fa7171..5d3e55d898 100644 --- a/test/functional/terminal/scrollback_spec.lua +++ b/test/functional/terminal/scrollback_spec.lua @@ -401,7 +401,7 @@ describe("'scrollback' option", function() screen = thelpers.screen_setup(nil, "['sh']", 30) end - meths.set_option_value('scrollback', 0, {buf = 0}) + meths.set_option_value('scrollback', 0, {}) feed_data(('%s REP 31 line%s'):format(testprg('shell-test'), is_os('win') and '\r' or '\n')) screen:expect{any='30: line '} retry(nil, nil, function() expect_lines(7) end) @@ -417,7 +417,7 @@ describe("'scrollback' option", function() screen = thelpers.screen_setup(nil, "['sh']", 30) end - meths.set_option_value('scrollback', 200, {buf=0}) + meths.set_option_value('scrollback', 200, {}) -- Wait for prompt. screen:expect{any='%$'} @@ -426,10 +426,10 @@ describe("'scrollback' option", function() screen:expect{any='30: line '} retry(nil, nil, function() expect_lines(33, 2) end) - meths.set_option_value('scrollback', 10, {buf=0}) + meths.set_option_value('scrollback', 10, {}) poke_eventloop() retry(nil, nil, function() expect_lines(16) end) - meths.set_option_value('scrollback', 10000, {buf=0}) + meths.set_option_value('scrollback', 10000, {}) retry(nil, nil, function() expect_lines(16) end) -- Terminal job data is received asynchronously, may happen before the -- 'scrollback' option is synchronized with the internal sb_buffer. @@ -484,18 +484,18 @@ describe("'scrollback' option", function() ]]) local term_height = 6 -- Actual terminal screen height, not the scrollback -- Initial - local scrollback = meths.get_option_value('scrollback', {buf=0}) + local scrollback = meths.get_option_value('scrollback', {}) eq(scrollback + term_height, eval('line("$")')) -- Reduction scrollback = scrollback - 2 - meths.set_option_value('scrollback', scrollback, {buf=0}) + meths.set_option_value('scrollback', scrollback, {}) eq(scrollback + term_height, eval('line("$")')) end) it('defaults to 10000 in :terminal buffers', function() set_fake_shell() command('terminal') - eq(10000, meths.get_option_value('scrollback', {buf=0})) + eq(10000, meths.get_option_value('scrollback', {})) end) it('error if set to invalid value', function() @@ -507,7 +507,7 @@ describe("'scrollback' option", function() it('defaults to -1 on normal buffers', function() command('new') - eq(-1, meths.get_option_value('scrollback', {buf=0})) + eq(-1, meths.get_option_value('scrollback', {})) end) it(':setlocal in a :terminal buffer', function() @@ -516,45 +516,45 @@ describe("'scrollback' option", function() -- _Global_ scrollback=-1 defaults :terminal to 10_000. command('setglobal scrollback=-1') command('terminal') - eq(10000, meths.get_option_value('scrollback', {buf=0})) + eq(10000, meths.get_option_value('scrollback', {})) -- _Local_ scrollback=-1 in :terminal forces the _maximum_. command('setlocal scrollback=-1') retry(nil, nil, function() -- Fixup happens on refresh, not immediately. - eq(100000, meths.get_option_value('scrollback', {buf=0})) + eq(100000, meths.get_option_value('scrollback', {})) end) -- _Local_ scrollback=-1 during TermOpen forces the maximum. #9605 command('setglobal scrollback=-1') command('autocmd TermOpen * setlocal scrollback=-1') command('terminal') - eq(100000, meths.get_option_value('scrollback', {buf=0})) + eq(100000, meths.get_option_value('scrollback', {})) end) it(':setlocal in a normal buffer', function() command('new') -- :setlocal to -1. command('setlocal scrollback=-1') - eq(-1, meths.get_option_value('scrollback', {buf=0})) + eq(-1, meths.get_option_value('scrollback', {})) -- :setlocal to anything except -1. Currently, this just has no effect. command('setlocal scrollback=42') - eq(42, meths.get_option_value('scrollback', {buf=0})) + eq(42, meths.get_option_value('scrollback', {})) end) it(':set updates local value and global default', function() set_fake_shell() command('set scrollback=42') -- set global value - eq(42, meths.get_option_value('scrollback', {buf=0})) + eq(42, meths.get_option_value('scrollback', {})) command('terminal') - eq(42, meths.get_option_value('scrollback', {buf=0})) -- inherits global default + eq(42, meths.get_option_value('scrollback', {})) -- inherits global default command('setlocal scrollback=99') - eq(99, meths.get_option_value('scrollback', {buf=0})) + eq(99, meths.get_option_value('scrollback', {})) command('set scrollback<') -- reset to global default - eq(42, meths.get_option_value('scrollback', {buf=0})) + eq(42, meths.get_option_value('scrollback', {})) command('setglobal scrollback=734') -- new global default - eq(42, meths.get_option_value('scrollback', {buf=0})) -- local value did not change + eq(42, meths.get_option_value('scrollback', {})) -- local value did not change command('terminal') - eq(734, meths.get_option_value('scrollback', {buf=0})) + eq(734, meths.get_option_value('scrollback', {})) end) end) diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index 3cfd222336..1b65c1cddc 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -1458,8 +1458,8 @@ describe('TUI', function() it('allows grid to assume wider ambiguous-width characters than host terminal #19686', function() child_session:request('nvim_buf_set_lines', 0, 0, -1, true, { ('℃'):rep(60), ('℃'):rep(60) }) - child_session:request('nvim_set_option_value', 'cursorline', true, {win=0}) - child_session:request('nvim_set_option_value', 'list', true, {win=0}) + child_session:request('nvim_set_option_value', 'cursorline', true, {}) + child_session:request('nvim_set_option_value', 'list', true, {}) child_session:request('nvim_set_option_value', 'listchars', 'eol:$', {win=0}) feed_data('gg') local singlewidth_screen = [[ diff --git a/test/functional/terminal/window_split_tab_spec.lua b/test/functional/terminal/window_split_tab_spec.lua index 3e1520e5fd..da14531fa2 100644 --- a/test/functional/terminal/window_split_tab_spec.lua +++ b/test/functional/terminal/window_split_tab_spec.lua @@ -71,7 +71,7 @@ describe(':terminal', function() end) it('does not change size if updated when not visible in any window #19665', function() - local channel = meths.get_option_value('channel', { buf = 0 }) + local channel = meths.get_option_value('channel', {}) command('enew') sleep(100) meths.chan_send(channel, 'foo') -- cgit From c855eee919f2d4edc9b9fa91b277454290fbabfe Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Wed, 24 May 2023 10:04:49 +0200 Subject: feat(term): enable reflow by default (#21124) libvterm v0.3 supports reflow of terminal buffer when Nvim is resized Since v0.3 is now a required dependency, enable it by default to find (and fix) possible issues. Note: Neovim's scrollback buffer does not support reflow (yet), so lines vanishing into the buffer due to a too small window will be restored without reflow. --- test/functional/terminal/window_spec.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/functional/terminal') diff --git a/test/functional/terminal/window_spec.lua b/test/functional/terminal/window_spec.lua index 80e9d78400..f90e4f7e9d 100644 --- a/test/functional/terminal/window_spec.lua +++ b/test/functional/terminal/window_spec.lua @@ -64,7 +64,7 @@ describe(':terminal window', function() {7: 1 }tty ready | {7: 2 }rows: 6, cols: 48 | {7: 3 }abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNO| - {7: 4 }WXYZrows: 6, cols: 41 | + {7: 4 }PQRSTUVWXYZrows: 6, cols: 41 | {7: 5 }{1: } | {7: 6 } | {3:-- TERMINAL --} | @@ -74,7 +74,7 @@ describe(':terminal window', function() {7: 1 }tty ready | {7: 2 }rows: 6, cols: 48 | {7: 3 }abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNO| - {7: 4 }WXYZrows: 6, cols: 41 | + {7: 4 }PQRSTUVWXYZrows: 6, cols: 41 | {7: 5 } abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMN| {7: 6 }OPQRSTUVWXYZ{1: } | {3:-- TERMINAL --} | -- cgit From 2db719f6c2b677fcbc197b02fe52764a851523b2 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Sat, 3 Jun 2023 11:06:00 +0100 Subject: feat(lua): rename vim.loop -> vim.uv (#22846) --- test/functional/terminal/tui_spec.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test/functional/terminal') diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index 1b65c1cddc..7723b6c7e7 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -1554,7 +1554,7 @@ describe('TUI', function() end) it('no assert failure on deadly signal #21896', function() - exec_lua([[vim.loop.kill(vim.fn.jobpid(vim.bo.channel), 'sigterm')]]) + exec_lua([[vim.uv.kill(vim.fn.jobpid(vim.bo.channel), 'sigterm')]]) screen:expect({any = '%[Process exited 1%]'}) end) @@ -1605,7 +1605,7 @@ describe('TUI', function() foo | {3:-- TERMINAL --} | ]]) - exec_lua([[vim.loop.kill(vim.fn.jobpid(vim.bo.channel), 'sigwinch')]]) + exec_lua([[vim.uv.kill(vim.fn.jobpid(vim.bo.channel), 'sigwinch')]]) screen:expect([[ {1: } | {4:~ }| @@ -2517,7 +2517,7 @@ describe("TUI as a client", function() -- No heap-use-after-free when receiving UI events after deadly signal #22184 server:request('nvim_input', ('a'):rep(1000)) - exec_lua([[vim.loop.kill(vim.fn.jobpid(vim.bo.channel), 'sigterm')]]) + exec_lua([[vim.uv.kill(vim.fn.jobpid(vim.bo.channel), 'sigterm')]]) screen:expect({any = '%[Process exited 1%]'}) eq(0, meths.get_vvar('shell_error')) -- cgit From cba07dad494558a4a06e25a35521041864697be3 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 16 Jun 2023 08:01:43 +0800 Subject: vim-patch:9.0.1634: message is cleared when removing mode message Problem: Message is cleared when removing mode message (Gary Johnson). Solution: Do not clear the command line after displaying a message. https://github.com/vim/vim/commit/800cdbb7caeb5dd4379c6cb071bb12391f20bcf3 Co-authored-by: Bram Moolenaar --- test/functional/terminal/tui_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/terminal') diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index 7723b6c7e7..b1836f2e4d 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -2475,7 +2475,7 @@ describe("TUI as a client", function() -- grid smaller than containing terminal window is cleared properly feed_data(":call setline(1,['a'->repeat(&columns)]->repeat(&lines))\n") - feed_data("0:set lines=2\n") + feed_data("0:set lines=3\n") screen_server:expect{grid=[[ {1:a}aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| {5:[No Name] [+] }| -- cgit From aa4e47f704c53ab1d825260d2bf34e2872e3ca89 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Fri, 23 Jun 2023 22:32:07 +0100 Subject: fix(api): disallow some more functions during textlock Problem: nvim_buf_set_text(), nvim_open_term() and termopen() all change buffer text, which is forbidden during textlock. Additionally, nvim_open_term() and termopen() may be used to convert the cmdwin buffer into a terminal buffer, which is weird. Solution: Allow nvim_buf_set_text() and nvim_open_term() in the cmdwin, but disallow nvim_open_term() from converting the cmdwin buffer into a terminal buffer. termopen() is not allowed in the cmdwin (as it always operates on curbuf), so just check text_locked(). Also happens to improve the error in #21055: nvim_buf_set_text() was callable during textlock, but happened to check textlock indirectly via u_save(); however, this caused the error to be overwritten by an unhelpful "Failed to save undo information" message when msg_list == NULL (e.g: an `` mapping invoked outside of do_cmdline()). --- test/functional/terminal/buffer_spec.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test/functional/terminal') diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua index 4ce354b9a9..bd898ba99e 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -498,3 +498,17 @@ if is_os('win') then end) end) end + +describe('termopen()', function() + before_each(clear) + + it('disallowed when textlocked and in cmdwin buffer', function() + command("autocmd TextYankPost ++once call termopen('foo')") + matches("Vim%(call%):E565: Not allowed to change text or change window$", + pcall_err(command, "normal! yy")) + + feed("q:") + eq("Vim:E11: Invalid in command-line window; executes, CTRL-C quits", + pcall_err(funcs.termopen, "bar")) + end) +end) -- cgit From 8c9e37cc09f5b79a981c574ab8bcfb0b9ed58ca8 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 8 Jul 2023 18:27:53 +0800 Subject: test(tui): add test for overriding argv[0] (#24293) --- test/functional/terminal/tui_spec.lua | 43 ++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) (limited to 'test/functional/terminal') diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index b1836f2e4d..44e06a0baf 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -30,6 +30,7 @@ local spawn_argv = helpers.spawn_argv local set_session = helpers.set_session local feed = helpers.feed local eval = helpers.eval +local write_file = helpers.write_file if helpers.skip(helpers.is_os('win')) then return end @@ -1620,9 +1621,6 @@ end) describe('TUI', function() before_each(clear) - after_each(function() - os.remove('testF') - end) it('resize at startup #17285 #15044 #11330', function() local screen = Screen.new(50, 10) @@ -1653,7 +1651,46 @@ describe('TUI', function() ]]) end) + it('argv[0] can be overridden #23953', function() + if not exec_lua('return pcall(require, "ffi")') then + pending('missing LuaJIT FFI') + end + local script_file = 'Xargv0.lua' + write_file(script_file, [=[ + local ffi = require('ffi') + ffi.cdef([[int execl(const char *, const char *, ...);]]) + ffi.C.execl(vim.v.progpath, 'Xargv0nvim', '--clean') + ]=]) + finally(function() + os.remove(script_file) + end) + local screen = thelpers.screen_setup(0, string.format([=[["%s", "--clean", "-l", "%s"]]=], + nvim_prog, script_file)) + screen:expect{grid=[[ + {1: } | + {4:~ }| + {4:~ }| + {4:~ }| + {5:[No Name] 0,0-1 All}| + | + {3:-- TERMINAL --} | + ]]} + feed_data(':put =v:argv + [v:progname]\n') + screen:expect{grid=[[ + Xargv0nvim | + --embed | + --clean | + {1:X}argv0nvim | + {5:[No Name] [+] 5,1 Bot}| + 4 more lines | + {3:-- TERMINAL --} | + ]]} + end) + it('with non-tty (pipe) stdout/stderr', function() + finally(function() + os.remove('testF') + end) local screen = thelpers.screen_setup(0, '"'..nvim_prog ..' -u NONE -i NONE --cmd \'set noswapfile noshowcmd noruler\' --cmd \'normal iabc\' > /dev/null 2>&1 && cat testF && rm testF"') feed_data(':w testF\n:q\n') -- cgit From 622ae2f53e77873a114f86f5acaff341ef3098ac Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 15 Jul 2023 15:03:01 +0800 Subject: feat(tui): support Super and Meta modifiers (#24357) --- test/functional/terminal/tui_spec.lua | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'test/functional/terminal') diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index 44e06a0baf..f48d0e073c 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -697,6 +697,28 @@ describe('TUI', function() ]]) end) + it('supports Super and Meta modifiers', function() + feed_data('i') + feed_data('\022\027[106;9u') -- Super + j + feed_data('\022\027[107;33u') -- Meta + k + feed_data('\022\027[13;41u') -- Super + Meta + Enter + feed_data('\022\027[127;48u') -- Shift + Alt + Ctrl + Super + Meta + Backspace + feed('\n') + feed_data('\022\027[57376;9u') -- Super + F13 + feed_data('\022\027[57377;33u') -- Meta + F14 + feed_data('\022\027[57378;41u') -- Super + Meta + F15 + feed_data('\022\027[57379;48u') -- Shift + Alt + Ctrl + Super + Meta + F16 + screen:expect([[ + | + {1: } | + {4:~ }| + {4:~ }| + {5:[No Name] [+] }| + {3:-- INSERT --} | + {3:-- TERMINAL --} | + ]]) + end) + it('mouse events work with right-click menu', function() child_session:request('nvim_exec', [[ call setline(1, 'popup menu test') -- cgit From d0d132fbd055834cbecb3d4e3a123a6ea8f099ec Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 17 Jul 2023 21:42:55 +0800 Subject: fix(terminal): don't send unknown special keys to terminal (#24378) Special keys are negative integers, so sending them to terminal leads to strange behavior. --- test/functional/terminal/buffer_spec.lua | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'test/functional/terminal') diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua index bd898ba99e..8b43f5cf9c 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -431,6 +431,30 @@ it('terminal truncates number of composing characters to 5', function() retry(nil, nil, function() eq('a' .. composing:rep(5), meths.get_current_line()) end) end) +describe('terminal input', function() + before_each(function() + clear() + exec_lua([[ + _G.input_data = '' + vim.api.nvim_open_term(0, { on_input = function(_, _, _, data) + _G.input_data = _G.input_data .. data + end }) + ]]) + command('startinsert') + poke_eventloop() + end) + + it(' is sent as NUL byte', function() + feed('aaabbb') + eq('aaa\0bbb', exec_lua([[return _G.input_data]])) + end) + + it('unknown special keys are not sent', function() + feed('aaabbb') + eq('aaabbb', exec_lua([[return _G.input_data]])) + end) +end) + if is_os('win') then describe(':terminal in Windows', function() local screen -- cgit From b74262a336d3e5cf69930fcec69a12fdad16d76c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 22 Jul 2023 08:00:42 +0800 Subject: fix(terminal): send Shift-Home Shift-End Ctrl-Home Ctrl-End (#24418) --- test/functional/terminal/buffer_spec.lua | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'test/functional/terminal') diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua index 8b43f5cf9c..3bc03a4117 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -17,6 +17,7 @@ local sleep = helpers.sleep local funcs = helpers.funcs local is_os = helpers.is_os local skip = helpers.skip +local nvim_prog = helpers.nvim_prog describe(':terminal buffer', function() local screen @@ -455,6 +456,33 @@ describe('terminal input', function() end) end) +describe('terminal input', function() + it('sends various special keys with modifiers', function() + clear() + local screen = thelpers.screen_setup(0, + string.format([=[["%s", "-u", "NONE", "-i", "NONE", "--cmd", "startinsert"]]=], nvim_prog)) + screen:expect{grid=[[ + {1: } | + {4:~ }| + {4:~ }| + {4:~ }| + {5:[No Name] 0,1 All}| + {3:-- INSERT --} | + {3:-- TERMINAL --} | + ]]} + for _, key in ipairs({ + '', '', '', + '', '', '', '', '', '', + '', '', '', '', '', '', + '', '', '', '', '', '', + '', '', '', '', '', '', + }) do + feed('' .. key) + retry(nil, nil, function() eq(key, meths.get_current_line()) end) + end + end) +end) + if is_os('win') then describe(':terminal in Windows', function() local screen -- cgit From cdb758ef447e1f934966fab42d5db0bf929de89c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 23 Jul 2023 08:23:07 +0800 Subject: test: check real cursor position in Terminal mode (#24436) --- test/functional/terminal/cursor_spec.lua | 66 +++++++++++++++++--------------- 1 file changed, 36 insertions(+), 30 deletions(-) (limited to 'test/functional/terminal') diff --git a/test/functional/terminal/cursor_spec.lua b/test/functional/terminal/cursor_spec.lua index 98ac03211a..47bc02373c 100644 --- a/test/functional/terminal/cursor_spec.lua +++ b/test/functional/terminal/cursor_spec.lua @@ -187,13 +187,16 @@ describe('buffer cursor position is correct in terminal without number column', ..[[", "-u", "NONE", "-i", "NONE", "-E", "--cmd", "let @r = ']]..str..[['", ]] -- and don't always work ..[["--cmd", "cnoremap ", "--cmd", "cnoremap "]]..']', 70) + -- Also check for real cursor position, as it is used for stuff like input methods + screen._handle_busy_start = function() end + screen._handle_busy_stop = function() end screen:expect([[ | | | | Entering Ex mode. Type "visual" to go to Normal mode. | - :{1: } | + :{1:^ } | {3:-- TERMINAL --} | ]]) end @@ -213,7 +216,7 @@ describe('buffer cursor position is correct in terminal without number column', | | Entering Ex mode. Type "visual" to go to Normal mode. | - :aaaaaaaa{1: } | + :aaaaaaaa{1:^ } | {3:-- TERMINAL --} | ]]) eq({6, 9}, eval('nvim_win_get_cursor(0)')) @@ -238,7 +241,7 @@ describe('buffer cursor position is correct in terminal without number column', | | Entering Ex mode. Type "visual" to go to Normal mode. | - :aaaaaa{1:a}a | + :aaaaaa{1:^a}a | {3:-- TERMINAL --} | ]]) eq({6, 7}, eval('nvim_win_get_cursor(0)')) @@ -263,7 +266,7 @@ describe('buffer cursor position is correct in terminal without number column', | | Entering Ex mode. Type "visual" to go to Normal mode. | - :a{1:a}aaaaaa | + :a{1:^a}aaaaaa | {3:-- TERMINAL --} | ]]) eq({6, 2}, eval('nvim_win_get_cursor(0)')) @@ -294,7 +297,7 @@ describe('buffer cursor position is correct in terminal without number column', | | Entering Ex mode. Type "visual" to go to Normal mode. | - :µµµµµµµµ{1: } | + :µµµµµµµµ{1:^ } | {3:-- TERMINAL --} | ]]) eq({6, 17}, eval('nvim_win_get_cursor(0)')) @@ -319,7 +322,7 @@ describe('buffer cursor position is correct in terminal without number column', | | Entering Ex mode. Type "visual" to go to Normal mode. | - :µµµµµµ{1:µ}µ | + :µµµµµµ{1:^µ}µ | {3:-- TERMINAL --} | ]]) eq({6, 13}, eval('nvim_win_get_cursor(0)')) @@ -344,7 +347,7 @@ describe('buffer cursor position is correct in terminal without number column', | | Entering Ex mode. Type "visual" to go to Normal mode. | - :µ{1:µ}µµµµµµ | + :µ{1:^µ}µµµµµµ | {3:-- TERMINAL --} | ]]) eq({6, 3}, eval('nvim_win_get_cursor(0)')) @@ -377,7 +380,7 @@ describe('buffer cursor position is correct in terminal without number column', | | Entering Ex mode. Type "visual" to go to Normal mode. | - :µ̳µ̳µ̳µ̳µ̳µ̳µ̳µ̳{1: } | + :µ̳µ̳µ̳µ̳µ̳µ̳µ̳µ̳{1:^ } | {3:-- TERMINAL --} | ]]) eq({6, 33}, eval('nvim_win_get_cursor(0)')) @@ -402,7 +405,7 @@ describe('buffer cursor position is correct in terminal without number column', | | Entering Ex mode. Type "visual" to go to Normal mode. | - :µ̳µ̳µ̳µ̳µ̳µ̳{1:µ̳}µ̳ | + :µ̳µ̳µ̳µ̳µ̳µ̳{1:^µ̳}µ̳ | {3:-- TERMINAL --} | ]]) eq({6, 25}, eval('nvim_win_get_cursor(0)')) @@ -427,7 +430,7 @@ describe('buffer cursor position is correct in terminal without number column', | | Entering Ex mode. Type "visual" to go to Normal mode. | - :µ̳{1:µ̳}µ̳µ̳µ̳µ̳µ̳µ̳ | + :µ̳{1:^µ̳}µ̳µ̳µ̳µ̳µ̳µ̳ | {3:-- TERMINAL --} | ]]) eq({6, 5}, eval('nvim_win_get_cursor(0)')) @@ -446,7 +449,7 @@ describe('buffer cursor position is correct in terminal without number column', end) describe('in a line with double-cell multibyte characters and no trailing spaces,', function() - skip(is_os('win'), "Encoding problem?") + if skip(is_os('win'), "Encoding problem?") then return end before_each(function() setup_ex_register('哦哦哦哦哦哦哦哦') @@ -460,7 +463,7 @@ describe('buffer cursor position is correct in terminal without number column', | | Entering Ex mode. Type "visual" to go to Normal mode. | - :哦哦哦哦哦哦哦哦{1: } | + :哦哦哦哦哦哦哦哦{1:^ } | {3:-- TERMINAL --} | ]]) eq({6, 25}, eval('nvim_win_get_cursor(0)')) @@ -485,7 +488,7 @@ describe('buffer cursor position is correct in terminal without number column', | | Entering Ex mode. Type "visual" to go to Normal mode. | - :哦哦哦哦哦哦{1:哦}哦 | + :哦哦哦哦哦哦{1:^哦}哦 | {3:-- TERMINAL --} | ]]) eq({6, 19}, eval('nvim_win_get_cursor(0)')) @@ -510,7 +513,7 @@ describe('buffer cursor position is correct in terminal without number column', | | Entering Ex mode. Type "visual" to go to Normal mode. | - :哦{1:哦}哦哦哦哦哦哦 | + :哦{1:^哦}哦哦哦哦哦哦 | {3:-- TERMINAL --} | ]]) eq({6, 4}, eval('nvim_win_get_cursor(0)')) @@ -537,7 +540,7 @@ describe('buffer cursor position is correct in terminal without number column', | | Entering Ex mode. Type "visual" to go to Normal mode. | - :aaaaaaaa {1: } | + :aaaaaaaa {1:^ } | {3:-- TERMINAL --} | ]]) matches('^:aaaaaaaa [ ]*$', eval('nvim_get_current_line()')) @@ -564,13 +567,16 @@ describe('buffer cursor position is correct in terminal with number column', fun ..[[", "-u", "NONE", "-i", "NONE", "-E", "--cmd", "let @r = ']]..str..[['", ]] -- and don't always work ..[["--cmd", "cnoremap ", "--cmd", "cnoremap "]]..']', 70) + -- Also check for real cursor position, as it is used for stuff like input methods + screen._handle_busy_start = function() end + screen._handle_busy_stop = function() end screen:expect([[ {7: 1 } | {7: 2 } | {7: 3 } | {7: 4 } | {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. | - {7: 6 }:{1: } | + {7: 6 }:{1:^ } | {3:-- TERMINAL --} | ]]) end @@ -593,7 +599,7 @@ describe('buffer cursor position is correct in terminal with number column', fun {7: 3 } | {7: 4 } | {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. | - {7: 6 }:aaaaaaaa{1: } | + {7: 6 }:aaaaaaaa{1:^ } | {3:-- TERMINAL --} | ]]) eq({6, 9}, eval('nvim_win_get_cursor(0)')) @@ -618,7 +624,7 @@ describe('buffer cursor position is correct in terminal with number column', fun {7: 3 } | {7: 4 } | {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. | - {7: 6 }:aaaaaa{1:a}a | + {7: 6 }:aaaaaa{1:^a}a | {3:-- TERMINAL --} | ]]) eq({6, 7}, eval('nvim_win_get_cursor(0)')) @@ -643,7 +649,7 @@ describe('buffer cursor position is correct in terminal with number column', fun {7: 3 } | {7: 4 } | {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. | - {7: 6 }:a{1:a}aaaaaa | + {7: 6 }:a{1:^a}aaaaaa | {3:-- TERMINAL --} | ]]) eq({6, 2}, eval('nvim_win_get_cursor(0)')) @@ -674,7 +680,7 @@ describe('buffer cursor position is correct in terminal with number column', fun {7: 3 } | {7: 4 } | {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. | - {7: 6 }:µµµµµµµµ{1: } | + {7: 6 }:µµµµµµµµ{1:^ } | {3:-- TERMINAL --} | ]]) eq({6, 17}, eval('nvim_win_get_cursor(0)')) @@ -699,7 +705,7 @@ describe('buffer cursor position is correct in terminal with number column', fun {7: 3 } | {7: 4 } | {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. | - {7: 6 }:µµµµµµ{1:µ}µ | + {7: 6 }:µµµµµµ{1:^µ}µ | {3:-- TERMINAL --} | ]]) eq({6, 13}, eval('nvim_win_get_cursor(0)')) @@ -724,7 +730,7 @@ describe('buffer cursor position is correct in terminal with number column', fun {7: 3 } | {7: 4 } | {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. | - {7: 6 }:µ{1:µ}µµµµµµ | + {7: 6 }:µ{1:^µ}µµµµµµ | {3:-- TERMINAL --} | ]]) eq({6, 3}, eval('nvim_win_get_cursor(0)')) @@ -757,7 +763,7 @@ describe('buffer cursor position is correct in terminal with number column', fun {7: 3 } | {7: 4 } | {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. | - {7: 6 }:µ̳µ̳µ̳µ̳µ̳µ̳µ̳µ̳{1: } | + {7: 6 }:µ̳µ̳µ̳µ̳µ̳µ̳µ̳µ̳{1:^ } | {3:-- TERMINAL --} | ]]) eq({6, 33}, eval('nvim_win_get_cursor(0)')) @@ -782,7 +788,7 @@ describe('buffer cursor position is correct in terminal with number column', fun {7: 3 } | {7: 4 } | {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. | - {7: 6 }:µ̳µ̳µ̳µ̳µ̳µ̳{1:µ̳}µ̳ | + {7: 6 }:µ̳µ̳µ̳µ̳µ̳µ̳{1:^µ̳}µ̳ | {3:-- TERMINAL --} | ]]) eq({6, 25}, eval('nvim_win_get_cursor(0)')) @@ -807,7 +813,7 @@ describe('buffer cursor position is correct in terminal with number column', fun {7: 3 } | {7: 4 } | {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. | - {7: 6 }:µ̳{1:µ̳}µ̳µ̳µ̳µ̳µ̳µ̳ | + {7: 6 }:µ̳{1:^µ̳}µ̳µ̳µ̳µ̳µ̳µ̳ | {3:-- TERMINAL --} | ]]) eq({6, 5}, eval('nvim_win_get_cursor(0)')) @@ -826,7 +832,7 @@ describe('buffer cursor position is correct in terminal with number column', fun end) describe('in a line with double-cell multibyte characters and no trailing spaces,', function() - skip(is_os('win'), "Encoding problem?") + if skip(is_os('win'), "Encoding problem?") then return end before_each(function() setup_ex_register('哦哦哦哦哦哦哦哦') @@ -840,7 +846,7 @@ describe('buffer cursor position is correct in terminal with number column', fun {7: 3 } | {7: 4 } | {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. | - {7: 6 }:哦哦哦哦哦哦哦哦{1: } | + {7: 6 }:哦哦哦哦哦哦哦哦{1:^ } | {3:-- TERMINAL --} | ]]) eq({6, 25}, eval('nvim_win_get_cursor(0)')) @@ -865,7 +871,7 @@ describe('buffer cursor position is correct in terminal with number column', fun {7: 3 } | {7: 4 } | {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. | - {7: 6 }:哦哦哦哦哦哦{1:哦}哦 | + {7: 6 }:哦哦哦哦哦哦{1:^哦}哦 | {3:-- TERMINAL --} | ]]) eq({6, 19}, eval('nvim_win_get_cursor(0)')) @@ -890,7 +896,7 @@ describe('buffer cursor position is correct in terminal with number column', fun {7: 3 } | {7: 4 } | {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. | - {7: 6 }:哦{1:哦}哦哦哦哦哦哦 | + {7: 6 }:哦{1:^哦}哦哦哦哦哦哦 | {3:-- TERMINAL --} | ]]) eq({6, 4}, eval('nvim_win_get_cursor(0)')) @@ -917,7 +923,7 @@ describe('buffer cursor position is correct in terminal with number column', fun {7: 3 } | {7: 4 } | {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. | - {7: 6 }:aaaaaaaa {1: } | + {7: 6 }:aaaaaaaa {1:^ } | {3:-- TERMINAL --} | ]]) matches('^:aaaaaaaa [ ]*$', eval('nvim_get_current_line()')) -- cgit From f0d618667a8a460b2c6135da19c74f0a4ad52128 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 23 Jul 2023 08:53:59 +0800 Subject: test: check that TextChangedT cannot delete terminal buffer (#24437) --- test/functional/terminal/buffer_spec.lua | 8 -------- 1 file changed, 8 deletions(-) (limited to 'test/functional/terminal') diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua index 3bc03a4117..9b690bed74 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -414,14 +414,6 @@ describe('on_lines does not emit out-of-bounds line indexes when', function() feed_command('bdelete!') eq('', exec_lua([[return _G.cb_error]])) end) - - it('runs TextChangedT event', function() - meths.set_var('called', 0) - command('autocmd TextChangedT * ++once let g:called = 1') - feed_command('terminal') - feed('iaa') - eq(1, meths.get_var('called')) - end) end) it('terminal truncates number of composing characters to 5', function() -- cgit From ce56ad2ba7c93c5053b657cd99642b375a944607 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 23 Jul 2023 12:46:56 +0800 Subject: test: reduce flakiness (#24443) Avoid consecutive RPC requests involving :startinsert or :stopinsert, because consecutive RPC requests may be processed together, before the :startinsert or :stopinsert takes effect. Also change some feed_command() to command() to make tests faster. --- test/functional/terminal/buffer_spec.lua | 8 +--- test/functional/terminal/cursor_spec.lua | 5 ++- test/functional/terminal/ex_terminal_spec.lua | 10 +++-- test/functional/terminal/helpers.lua | 9 +++-- test/functional/terminal/scrollback_spec.lua | 5 +-- test/functional/terminal/tui_spec.lua | 53 ++++++++++++++------------- 6 files changed, 45 insertions(+), 45 deletions(-) (limited to 'test/functional/terminal') diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua index 9b690bed74..888d123b17 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -24,8 +24,7 @@ describe(':terminal buffer', function() before_each(function() clear() - feed_command('set modifiable swapfile undolevels=20') - poke_eventloop() + command('set modifiable swapfile undolevels=20') screen = thelpers.screen_setup() end) @@ -199,7 +198,6 @@ describe(':terminal buffer', function() it('handles loss of focus gracefully', function() -- Change the statusline to avoid printing the file name, which varies. nvim('set_option_value', 'statusline', '==========', {}) - feed_command('set laststatus=0') -- Save the buffer number of the terminal for later testing. local tbuf = eval('bufnr("%")') @@ -232,8 +230,6 @@ describe(':terminal buffer', function() neq(tbuf, eval('bufnr("%")')) feed_command('quit!') -- Should exit the new window, not the terminal. eq(tbuf, eval('bufnr("%")')) - - feed_command('set laststatus=1') -- Restore laststatus to the default. end) it('term_close() use-after-free #4393', function() @@ -433,7 +429,7 @@ describe('terminal input', function() _G.input_data = _G.input_data .. data end }) ]]) - command('startinsert') + feed('i') poke_eventloop() end) diff --git a/test/functional/terminal/cursor_spec.lua b/test/functional/terminal/cursor_spec.lua index 47bc02373c..8285bcc26e 100644 --- a/test/functional/terminal/cursor_spec.lua +++ b/test/functional/terminal/cursor_spec.lua @@ -6,7 +6,7 @@ local testprg, command = helpers.testprg, helpers.command local nvim_prog = helpers.nvim_prog local eq, eval = helpers.eq, helpers.eval local matches = helpers.matches -local feed_command = helpers.feed_command +local poke_eventloop = helpers.poke_eventloop local hide_cursor = thelpers.hide_cursor local show_cursor = thelpers.show_cursor local is_os = helpers.is_os @@ -153,7 +153,8 @@ describe('cursor with customized highlighting', function() }) screen:attach({rgb=false}) command('call termopen(["'..testprg('tty-test')..'"])') - feed_command('startinsert') + feed('i') + poke_eventloop() end) it('overrides the default highlighting', function() diff --git a/test/functional/terminal/ex_terminal_spec.lua b/test/functional/terminal/ex_terminal_spec.lua index 28751a3504..5204b61f57 100644 --- a/test/functional/terminal/ex_terminal_spec.lua +++ b/test/functional/terminal/ex_terminal_spec.lua @@ -99,7 +99,7 @@ describe(':terminal', function() end) it('nvim_get_mode() in :terminal', function() - command(':terminal') + command('terminal') eq({ blocking=false, mode='nt' }, nvim('get_mode')) feed('i') eq({ blocking=false, mode='t' }, nvim('get_mode')) @@ -108,17 +108,19 @@ describe(':terminal', function() end) it(':stopinsert RPC request exits terminal-mode #7807', function() - command(':terminal') + command('terminal') feed('i[tui] insert-mode') eq({ blocking=false, mode='t' }, nvim('get_mode')) command('stopinsert') + feed('') -- Add input to separate two RPC requests eq({ blocking=false, mode='nt' }, nvim('get_mode')) end) it(':stopinsert in normal mode doesn\'t break insert mode #9889', function() - command(':terminal') + command('terminal') eq({ blocking=false, mode='nt' }, nvim('get_mode')) - command(':stopinsert') + command('stopinsert') + feed('') -- Add input to separate two RPC requests eq({ blocking=false, mode='nt' }, nvim('get_mode')) feed('a') eq({ blocking=false, mode='t' }, nvim('get_mode')) diff --git a/test/functional/terminal/helpers.lua b/test/functional/terminal/helpers.lua index 7247361649..62d3dd67a3 100644 --- a/test/functional/terminal/helpers.lua +++ b/test/functional/terminal/helpers.lua @@ -5,7 +5,7 @@ local helpers = require('test.functional.helpers')(nil) local Screen = require('test.functional.ui.screen') local testprg = helpers.testprg local exec_lua = helpers.exec_lua -local feed_command, nvim = helpers.feed_command, helpers.nvim +local nvim = helpers.nvim local function feed_data(data) if type(data) == 'table' then @@ -82,15 +82,16 @@ local function screen_setup(extra_rows, command, cols, opts) screen:attach(opts or {rgb=false}) - feed_command('enew | call termopen('..command..')') + nvim('command', 'enew | call termopen('..command..')') nvim('input', '') local vim_errmsg = nvim('eval', 'v:errmsg') if vim_errmsg and "" ~= vim_errmsg then error(vim_errmsg) end - feed_command('setlocal scrollback=10') - feed_command('startinsert') + nvim('command', 'setlocal scrollback=10') + nvim('command', 'startinsert') + nvim('input', '') -- Add input to separate two RPC requests -- tty-test puts the terminal into raw mode and echoes input. Tests work by -- feeding termcodes to control the display and asserting by screen:expect. diff --git a/test/functional/terminal/scrollback_spec.lua b/test/functional/terminal/scrollback_spec.lua index 5d3e55d898..d20f5177b8 100644 --- a/test/functional/terminal/scrollback_spec.lua +++ b/test/functional/terminal/scrollback_spec.lua @@ -2,7 +2,7 @@ local Screen = require('test.functional.ui.screen') local helpers = require('test.functional.helpers')(after_each) local thelpers = require('test.functional.terminal.helpers') local clear, eq, curbuf = helpers.clear, helpers.eq, helpers.curbuf -local feed, testprg, feed_command = helpers.feed, helpers.testprg, helpers.feed_command +local feed, testprg = helpers.feed, helpers.testprg local eval = helpers.eval local command = helpers.command local matches = helpers.matches @@ -349,8 +349,7 @@ describe(':terminal prints more lines than the screen height and exits', functio clear() local screen = Screen.new(30, 7) screen:attach({rgb=false}) - feed_command(("call termopen(['%s', '10']) | startinsert"):format(testprg('tty-test'))) - poke_eventloop() + command(("call termopen(['%s', '10']) | startinsert"):format(testprg('tty-test'))) screen:expect([[ line6 | line7 | diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index f48d0e073c..7bf9e84bfb 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -8,7 +8,6 @@ local helpers = require('test.functional.helpers')(after_each) local thelpers = require('test.functional.terminal.helpers') local Screen = require('test.functional.ui.screen') local eq = helpers.eq -local feed_command = helpers.feed_command local feed_data = thelpers.feed_data local clear = helpers.clear local command = helpers.command @@ -110,14 +109,14 @@ describe('TUI', function() end) it('accepts resize while pager is active', function() - child_session:request("nvim_exec", [[ - set more - func! ManyErr() - for i in range(20) - echoerr "FAIL ".i - endfor - endfunc - ]], false) + child_session:request('nvim_exec2', [[ + set more + func! ManyErr() + for i in range(20) + echoerr "FAIL ".i + endfor + endfunc + ]], {}) feed_data(':call ManyErr()\r') screen:expect{grid=[[ {8:Error detected while processing function ManyErr:} | @@ -241,7 +240,7 @@ describe('TUI', function() it('interprets leading byte as ALT modifier in normal-mode', function() local keys = 'dfghjkl' for c in keys:gmatch('.') do - feed_command('nnoremap ialt-'..c..'') + feed_data(':nnoremap ialt-'..c..'\r') feed_data('\027'..c) end screen:expect([[ @@ -281,9 +280,11 @@ describe('TUI', function() end) it('interprets [27u as ', function() - feed_command('nnoremap ') - feed_command('nnoremap AESC') - feed_command('nnoremap ; Asemicolon') + child_session:request('nvim_exec2', [[ + nnoremap + nnoremap AESC + nnoremap ; Asemicolon + ]], {}) feed_data('\027[27u;') screen:expect([[ ESCsemicolo{1:n} | @@ -331,11 +332,11 @@ describe('TUI', function() end) it('accepts mouse wheel events #19992', function() - child_session:request('nvim_exec', [[ + child_session:request('nvim_exec2', [[ set number nostartofline nowrap mousescroll=hor:1,ver:1 call setline(1, repeat([join(range(10), '----')], 10)) vsplit - ]], false) + ]], {}) screen:expect([[ {11: 1 }{1:0}----1----2----3----4│{11: 1 }0----1----2----3----| {11: 2 }0----1----2----3----4│{11: 2 }0----1----2----3----| @@ -661,11 +662,11 @@ describe('TUI', function() | {3:-- TERMINAL --} | ]]) - child_session:request('nvim_exec', [[ + child_session:request('nvim_exec2', [[ tab split tabnew highlight Tabline ctermbg=NONE ctermfg=NONE cterm=underline - ]], false) + ]], {}) screen:expect([[ {12: + [No Name] + [No Name] }{3: [No Name] }{1: }{12:X}| {1: } | @@ -720,7 +721,7 @@ describe('TUI', function() end) it('mouse events work with right-click menu', function() - child_session:request('nvim_exec', [[ + child_session:request('nvim_exec2', [[ call setline(1, 'popup menu test') set mouse=a mousemodel=popup @@ -730,7 +731,7 @@ describe('TUI', function() menu PopUp.baz :let g:menustr = 'baz' highlight Pmenu ctermbg=NONE ctermfg=NONE cterm=underline,reverse highlight PmenuSel ctermbg=NONE ctermfg=NONE cterm=underline,reverse,bold - ]], false) + ]], {}) meths.input_mouse('right', 'press', '', 0, 0, 4) screen:expect([[ {1:p}opup menu test | @@ -1584,11 +1585,11 @@ describe('TUI', function() it('no stack-use-after-scope with cursor color #22432', function() screen:set_option('rgb', true) command('set termguicolors') - child_session:request('nvim_exec', [[ + child_session:request('nvim_exec2', [[ set tgc hi Cursor guifg=Red guibg=Green set guicursor=n:block-Cursor/lCursor - ]], false) + ]], {}) screen:set_default_attr_ids({ [1] = {reverse = true}, [2] = {bold = true, foreground = Screen.colors.Blue}, @@ -1808,10 +1809,10 @@ describe('TUI FocusGained/FocusLost', function() {3:-- TERMINAL --} | ]]) child_session = helpers.connect(child_server) - child_session:request('nvim_exec', [[ + child_session:request('nvim_exec2', [[ autocmd FocusGained * echo 'gained' autocmd FocusLost * echo 'lost' - ]], false) + ]], {}) feed_data("\034\016") -- CTRL-\ CTRL-N end) @@ -1842,7 +1843,7 @@ describe('TUI FocusGained/FocusLost', function() end) it('in insert-mode', function() - feed_command('set noshowmode') + feed_data(':set noshowmode\r') feed_data('i') screen:expect{grid=[[ {1: } | @@ -1907,11 +1908,11 @@ describe('TUI FocusGained/FocusLost', function() -- Set up autocmds that modify the buffer, instead of just calling :echo. -- This is how we can test handling of focus gained/lost during cmdline-mode. -- See commit: 5cc87d4dabd02167117be7a978b5c8faaa975419. - child_session:request('nvim_exec', [[ + child_session:request('nvim_exec2', [[ autocmd! autocmd FocusLost * call append(line('$'), 'lost') autocmd FocusGained * call append(line('$'), 'gained') - ]], false) + ]], {}) retry(2, 3 * screen.timeout, function() -- Enter cmdline-mode. feed_data(':') -- cgit From 0a7fda6fa0067ee61fee60d123967c3f14431007 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 4 Aug 2023 09:34:13 +0800 Subject: fix(terminal): include modifiers when forwarding mouse (#24549) --- test/functional/terminal/buffer_spec.lua | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'test/functional/terminal') diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua index 888d123b17..ce47e4715c 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -464,6 +464,10 @@ describe('terminal input', function() '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', + '', '', '<2-LeftMouse>', '<2-LeftRelease>', + '', '', '<2-RightMouse>', '<2-RightRelease>', + '', '', '<2-MiddleMouse>', '<2-MiddleRelease>', + '', '', '', '', }) do feed('' .. key) retry(nil, nil, function() eq(key, meths.get_current_line()) end) -- cgit From 21d466c1b985bcb0b80cd71d3b33eef6c24004f1 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 4 Aug 2023 10:24:27 +0800 Subject: fix(terminal): forward horizontal mouse scrolling (#24552) --- test/functional/terminal/buffer_spec.lua | 1 + test/functional/terminal/tui_spec.lua | 276 +++++++++++++++++++++++-------- 2 files changed, 212 insertions(+), 65 deletions(-) (limited to 'test/functional/terminal') diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua index ce47e4715c..6fcd029a5b 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -468,6 +468,7 @@ describe('terminal input', function() '', '', '<2-RightMouse>', '<2-RightRelease>', '', '', '<2-MiddleMouse>', '<2-MiddleRelease>', '', '', '', '', + '', '', '', '', }) do feed('' .. key) retry(nil, nil, function() eq(key, meths.get_current_line()) end) diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index 7bf9e84bfb..e8e65d18fa 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -331,7 +331,7 @@ describe('TUI', function() ]], attrs) end) - it('accepts mouse wheel events #19992', function() + local function test_mouse_wheel(esc) child_session:request('nvim_exec2', [[ set number nostartofline nowrap mousescroll=hor:1,ver:1 call setline(1, repeat([join(range(10), '----')], 10)) @@ -347,7 +347,11 @@ describe('TUI', function() {3:-- TERMINAL --} | ]]) -- in active window - feed_data('\027[<65;8;1M') + if esc then + feed_data('\027[<65;8;1M') + else + meths.input_mouse('wheel', 'down', '', 0, 0, 7) + end screen:expect([[ {11: 2 }{1:0}----1----2----3----4│{11: 1 }0----1----2----3----| {11: 3 }0----1----2----3----4│{11: 2 }0----1----2----3----| @@ -358,7 +362,11 @@ describe('TUI', function() {3:-- TERMINAL --} | ]]) -- in inactive window - feed_data('\027[<65;48;1M') + if esc then + feed_data('\027[<65;48;1M') + else + meths.input_mouse('wheel', 'down', '', 0, 0, 47) + end screen:expect([[ {11: 2 }{1:0}----1----2----3----4│{11: 2 }0----1----2----3----| {11: 3 }0----1----2----3----4│{11: 3 }0----1----2----3----| @@ -369,7 +377,11 @@ describe('TUI', function() {3:-- TERMINAL --} | ]]) -- in active window - feed_data('\027[<67;8;1M') + if esc then + feed_data('\027[<67;8;1M') + else + meths.input_mouse('wheel', 'right', '', 0, 0, 7) + end screen:expect([[ {11: 2 }{1:-}---1----2----3----4-│{11: 2 }0----1----2----3----| {11: 3 }----1----2----3----4-│{11: 3 }0----1----2----3----| @@ -380,7 +392,11 @@ describe('TUI', function() {3:-- TERMINAL --} | ]]) -- in inactive window - feed_data('\027[<67;48;1M') + if esc then + feed_data('\027[<67;48;1M') + else + meths.input_mouse('wheel', 'right', '', 0, 0, 47) + end screen:expect([[ {11: 2 }{1:-}---1----2----3----4-│{11: 2 }----1----2----3----4| {11: 3 }----1----2----3----4-│{11: 3 }----1----2----3----4| @@ -391,7 +407,11 @@ describe('TUI', function() {3:-- TERMINAL --} | ]]) -- in active window - feed_data('\027[<69;8;1M') + if esc then + feed_data('\027[<69;8;1M') + else + meths.input_mouse('wheel', 'down', 'S', 0, 0, 7) + end screen:expect([[ {11: 5 }{1:-}---1----2----3----4-│{11: 2 }----1----2----3----4| {11: 6 }----1----2----3----4-│{11: 3 }----1----2----3----4| @@ -402,7 +422,11 @@ describe('TUI', function() {3:-- TERMINAL --} | ]]) -- in inactive window - feed_data('\027[<69;48;1M') + if esc then + feed_data('\027[<69;48;1M') + else + meths.input_mouse('wheel', 'down', 'S', 0, 0, 47) + end screen:expect([[ {11: 5 }{1:-}---1----2----3----4-│{11: 5 }----1----2----3----4| {11: 6 }----1----2----3----4-│{11: 6 }----1----2----3----4| @@ -413,7 +437,11 @@ describe('TUI', function() {3:-- TERMINAL --} | ]]) -- in active window - feed_data('\027[<71;8;1M') + if esc then + feed_data('\027[<71;8;1M') + else + meths.input_mouse('wheel', 'right', 'S', 0, 0, 7) + end screen:expect([[ {11: 5 }{1:-}---6----7----8----9 │{11: 5 }----1----2----3----4| {11: 6 }----6----7----8----9 │{11: 6 }----1----2----3----4| @@ -424,7 +452,11 @@ describe('TUI', function() {3:-- TERMINAL --} | ]]) -- in inactive window - feed_data('\027[<71;48;1M') + if esc then + feed_data('\027[<71;48;1M') + else + meths.input_mouse('wheel', 'right', 'S', 0, 0, 47) + end screen:expect([[ {11: 5 }{1:-}---6----7----8----9 │{11: 5 }5----6----7----8----| {11: 6 }----6----7----8----9 │{11: 6 }5----6----7----8----| @@ -435,7 +467,11 @@ describe('TUI', function() {3:-- TERMINAL --} | ]]) -- in active window - feed_data('\027[<64;8;1M') + if esc then + feed_data('\027[<64;8;1M') + else + meths.input_mouse('wheel', 'up', '', 0, 0, 7) + end screen:expect([[ {11: 4 }----6----7----8----9 │{11: 5 }5----6----7----8----| {11: 5 }{1:-}---6----7----8----9 │{11: 6 }5----6----7----8----| @@ -446,7 +482,11 @@ describe('TUI', function() {3:-- TERMINAL --} | ]]) -- in inactive window - feed_data('\027[<64;48;1M') + if esc then + feed_data('\027[<64;48;1M') + else + meths.input_mouse('wheel', 'up', '', 0, 0, 47) + end screen:expect([[ {11: 4 }----6----7----8----9 │{11: 4 }5----6----7----8----| {11: 5 }{1:-}---6----7----8----9 │{11: 5 }5----6----7----8----| @@ -457,7 +497,11 @@ describe('TUI', function() {3:-- TERMINAL --} | ]]) -- in active window - feed_data('\027[<66;8;1M') + if esc then + feed_data('\027[<66;8;1M') + else + meths.input_mouse('wheel', 'left', '', 0, 0, 7) + end screen:expect([[ {11: 4 }5----6----7----8----9│{11: 4 }5----6----7----8----| {11: 5 }5{1:-}---6----7----8----9│{11: 5 }5----6----7----8----| @@ -468,7 +512,11 @@ describe('TUI', function() {3:-- TERMINAL --} | ]]) -- in inactive window - feed_data('\027[<66;48;1M') + if esc then + feed_data('\027[<66;48;1M') + else + meths.input_mouse('wheel', 'left', '', 0, 0, 47) + end screen:expect([[ {11: 4 }5----6----7----8----9│{11: 4 }-5----6----7----8---| {11: 5 }5{1:-}---6----7----8----9│{11: 5 }-5----6----7----8---| @@ -479,7 +527,11 @@ describe('TUI', function() {3:-- TERMINAL --} | ]]) -- in active window - feed_data('\027[<68;8;1M') + if esc then + feed_data('\027[<68;8;1M') + else + meths.input_mouse('wheel', 'up', 'S', 0, 0, 7) + end screen:expect([[ {11: 1 }5----6----7----8----9│{11: 4 }-5----6----7----8---| {11: 2 }5----6----7----8----9│{11: 5 }-5----6----7----8---| @@ -490,7 +542,11 @@ describe('TUI', function() {3:-- TERMINAL --} | ]]) -- in inactive window - feed_data('\027[<68;48;1M') + if esc then + feed_data('\027[<68;48;1M') + else + meths.input_mouse('wheel', 'up', 'S', 0, 0, 47) + end screen:expect([[ {11: 1 }5----6----7----8----9│{11: 1 }-5----6----7----8---| {11: 2 }5----6----7----8----9│{11: 2 }-5----6----7----8---| @@ -501,7 +557,11 @@ describe('TUI', function() {3:-- TERMINAL --} | ]]) -- in active window - feed_data('\027[<70;8;1M') + if esc then + feed_data('\027[<70;8;1M') + else + meths.input_mouse('wheel', 'left', 'S', 0, 0, 7) + end screen:expect([[ {11: 1 }0----1----2----3----4│{11: 1 }-5----6----7----8---| {11: 2 }0----1----2----3----4│{11: 2 }-5----6----7----8---| @@ -512,7 +572,11 @@ describe('TUI', function() {3:-- TERMINAL --} | ]]) -- in inactive window - feed_data('\027[<70;48;1M') + if esc then + feed_data('\027[<70;48;1M') + else + meths.input_mouse('wheel', 'left', 'S', 0, 0, 47) + end screen:expect([[ {11: 1 }0----1----2----3----4│{11: 1 }0----1----2----3----| {11: 2 }0----1----2----3----4│{11: 2 }0----1----2----3----| @@ -522,6 +586,136 @@ describe('TUI', function() | {3:-- TERMINAL --} | ]]) + end + + describe('accepts mouse wheel events', function() + it('(mouse events sent to host)', function() + test_mouse_wheel(false) + end) + + it('(escape sequences sent to child)', function() + test_mouse_wheel(true) + end) + end) + + local function test_mouse_popup(esc) + child_session:request('nvim_exec2', [[ + call setline(1, 'popup menu test') + set mouse=a mousemodel=popup + + aunmenu PopUp + menu PopUp.foo :let g:menustr = 'foo' + menu PopUp.bar :let g:menustr = 'bar' + menu PopUp.baz :let g:menustr = 'baz' + highlight Pmenu ctermbg=NONE ctermfg=NONE cterm=underline,reverse + highlight PmenuSel ctermbg=NONE ctermfg=NONE cterm=underline,reverse,bold + ]], {}) + if esc then + feed_data('\027[<2;5;1M') + else + meths.input_mouse('right', 'press', '', 0, 0, 4) + end + screen:expect([[ + {1:p}opup menu test | + {4:~ }{13: foo }{4: }| + {4:~ }{13: bar }{4: }| + {4:~ }{13: baz }{4: }| + {5:[No Name] [+] }| + | + {3:-- TERMINAL --} | + ]]) + if esc then + feed_data('\027[<2;5;1m') + else + meths.input_mouse('right', 'release', '', 0, 0, 4) + end + screen:expect_unchanged() + if esc then + feed_data('\027[<35;7;4M') + else + meths.input_mouse('move', '', '', 0, 3, 6) + end + screen:expect([[ + {1:p}opup menu test | + {4:~ }{13: foo }{4: }| + {4:~ }{13: bar }{4: }| + {4:~ }{14: baz }{4: }| + {5:[No Name] [+] }| + | + {3:-- TERMINAL --} | + ]]) + if esc then + feed_data('\027[<0;7;3M') + else + meths.input_mouse('left', 'press', '', 0, 2, 6) + end + screen:expect([[ + {1:p}opup menu test | + {4:~ }| + {4:~ }| + {4:~ }| + {5:[No Name] [+] }| + :let g:menustr = 'bar' | + {3:-- TERMINAL --} | + ]]) + if esc then + feed_data('\027[<0;7;3m') + else + meths.input_mouse('left', 'release', '', 0, 2, 6) + end + screen:expect_unchanged() + if esc then + feed_data('\027[<2;45;3M') + else + meths.input_mouse('right', 'press', '', 0, 2, 44) + end + screen:expect([[ + {1:p}opup menu test | + {4:~ }| + {4:~ }| + {4:~ }{13: foo }{4: }| + {5:[No Name] [+] }{13: bar }{5: }| + :let g:menustr = 'bar' {13: baz } | + {3:-- TERMINAL --} | + ]]) + if esc then + feed_data('\027[<34;48;6M') + else + meths.input_mouse('right', 'drag', '', 0, 5, 47) + end + screen:expect([[ + {1:p}opup menu test | + {4:~ }| + {4:~ }| + {4:~ }{13: foo }{4: }| + {5:[No Name] [+] }{13: bar }{5: }| + :let g:menustr = 'bar' {14: baz } | + {3:-- TERMINAL --} | + ]]) + if esc then + feed_data('\027[<2;48;6m') + else + meths.input_mouse('right', 'release', '', 0, 5, 47) + end + screen:expect([[ + {1:p}opup menu test | + {4:~ }| + {4:~ }| + {4:~ }| + {5:[No Name] [+] }| + :let g:menustr = 'baz' | + {3:-- TERMINAL --} | + ]]) + end + + describe('mouse events work with right-click menu', function() + it('(mouse events sent to host)', function() + test_mouse_popup(false) + end) + + it('(escape sequences sent to child)', function() + test_mouse_popup(true) + end) end) it('accepts keypad keys from kitty keyboard protocol #19180', function() @@ -720,54 +914,6 @@ describe('TUI', function() ]]) end) - it('mouse events work with right-click menu', function() - child_session:request('nvim_exec2', [[ - call setline(1, 'popup menu test') - set mouse=a mousemodel=popup - - aunmenu PopUp - menu PopUp.foo :let g:menustr = 'foo' - menu PopUp.bar :let g:menustr = 'bar' - menu PopUp.baz :let g:menustr = 'baz' - highlight Pmenu ctermbg=NONE ctermfg=NONE cterm=underline,reverse - highlight PmenuSel ctermbg=NONE ctermfg=NONE cterm=underline,reverse,bold - ]], {}) - meths.input_mouse('right', 'press', '', 0, 0, 4) - screen:expect([[ - {1:p}opup menu test | - {4:~ }{13: foo }{4: }| - {4:~ }{13: bar }{4: }| - {4:~ }{13: baz }{4: }| - {5:[No Name] [+] }| - | - {3:-- TERMINAL --} | - ]]) - meths.input_mouse('right', 'release', '', 0, 0, 4) - screen:expect_unchanged() - meths.input_mouse('move', '', '', 0, 3, 6) - screen:expect([[ - {1:p}opup menu test | - {4:~ }{13: foo }{4: }| - {4:~ }{13: bar }{4: }| - {4:~ }{14: baz }{4: }| - {5:[No Name] [+] }| - | - {3:-- TERMINAL --} | - ]]) - meths.input_mouse('left', 'press', '', 0, 2, 6) - screen:expect([[ - {1:p}opup menu test | - {4:~ }| - {4:~ }| - {4:~ }| - {5:[No Name] [+] }| - :let g:menustr = 'bar' | - {3:-- TERMINAL --} | - ]]) - meths.input_mouse('left', 'release', '', 0, 2, 6) - screen:expect_unchanged() - end) - it('paste: Insert mode', function() -- "bracketed paste" feed_data('i""\027i\027[200~') -- cgit From 673ee213e9d0900b1fa2638dc5373ee8167ed4fa Mon Sep 17 00:00:00 2001 From: Gregory Anders Date: Sat, 4 Sep 2021 15:28:08 -0600 Subject: test: update tests for auto-closing :term buffers The terminal buffer closes automatically when using `:terminal` and the command exits without an error. This messes up some tests that expect the terminal buffer to still be open. We can force the buffer not to close by passing an argument to `:terminal`. This can be anything, since the shell-test stub simply prints whatever argument it's given. --- test/functional/terminal/ex_terminal_spec.lua | 25 ++++++++++++++++--------- test/functional/terminal/scrollback_spec.lua | 4 +++- test/functional/terminal/tui_spec.lua | 18 +++++++++--------- 3 files changed, 28 insertions(+), 19 deletions(-) (limited to 'test/functional/terminal') diff --git a/test/functional/terminal/ex_terminal_spec.lua b/test/functional/terminal/ex_terminal_spec.lua index 5204b61f57..6020a12ddb 100644 --- a/test/functional/terminal/ex_terminal_spec.lua +++ b/test/functional/terminal/ex_terminal_spec.lua @@ -137,23 +137,29 @@ describe(':terminal (with fake shell)', function() -- shell-test.c is a fake shell that prints its arguments and exits. nvim('set_option_value', 'shell', testprg('shell-test'), {}) nvim('set_option_value', 'shellcmdflag', 'EXE', {}) + nvim('set_option_value', 'shellxquote', '', {}) end) -- Invokes `:terminal {cmd}` using a fake shell (shell-test.c) which prints - -- the {cmd} and exits immediately . + -- the {cmd} and exits immediately. + -- When no argument is given and the exit code is zero, the terminal buffer + -- closes automatically. local function terminal_with_fake_shell(cmd) feed_command("terminal "..(cmd and cmd or "")) end it('with no argument, acts like termopen()', function() skip(is_os('win')) - terminal_with_fake_shell() + -- Use the EXIT subcommand to end the process with a non-zero exit code to + -- prevent the buffer from closing automatically + nvim('set_option_value', 'shellcmdflag', 'EXIT', {}) + terminal_with_fake_shell(1) retry(nil, 4 * screen.timeout, function() screen:expect([[ - ^ready $ | - [Process exited 0] | + ^ | + [Process exited 1] | | - :terminal | + :terminal 1 | ]]) end) end) @@ -245,12 +251,13 @@ describe(':terminal (with fake shell)', function() it('works with :find', function() skip(is_os('win')) - terminal_with_fake_shell() + nvim('set_option_value', 'shellcmdflag', 'EXIT', {}) + terminal_with_fake_shell(1) screen:expect([[ - ^ready $ | - [Process exited 0] | + ^ | + [Process exited 1] | | - :terminal | + :terminal 1 | ]]) eq('term://', string.match(eval('bufname("%")'), "^term://")) feed([[]]) diff --git a/test/functional/terminal/scrollback_spec.lua b/test/functional/terminal/scrollback_spec.lua index d20f5177b8..ba0b663285 100644 --- a/test/functional/terminal/scrollback_spec.lua +++ b/test/functional/terminal/scrollback_spec.lua @@ -514,7 +514,9 @@ describe("'scrollback' option", function() -- _Global_ scrollback=-1 defaults :terminal to 10_000. command('setglobal scrollback=-1') - command('terminal') + -- Pass a command to prevent the terminal buffer from automatically + -- closing. The ':' command is just a no-op. + command('terminal :') eq(10000, meths.get_option_value('scrollback', {})) -- _Local_ scrollback=-1 in :terminal forces the _maximum_. diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index e8e65d18fa..1958281592 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -2075,26 +2075,26 @@ describe('TUI FocusGained/FocusLost', function() end) it('in terminal-mode', function() - feed_data(':set shell='..testprg('shell-test')..'\n') + feed_data(':set shell='..testprg('shell-test')..' shellcmdflag=EXE\n') feed_data(':set noshowmode laststatus=0\n') - feed_data(':terminal\n') + feed_data(':terminal zia\n') -- Wait for terminal to be ready. screen:expect{grid=[[ - {1:r}eady $ | - [Process exited 0] | + {1:r}eady $ zia | | + [Process exited 0] | | | - :terminal | + :terminal zia | {3:-- TERMINAL --} | ]]} feed_data('\027[I') screen:expect{grid=[[ - {1:r}eady $ | - [Process exited 0] | + {1:r}eady $ zia | | + [Process exited 0] | | | gained | @@ -2103,9 +2103,9 @@ describe('TUI FocusGained/FocusLost', function() feed_data('\027[O') screen:expect([[ - {1:r}eady $ | - [Process exited 0] | + {1:r}eady $ zia | | + [Process exited 0] | | | lost | -- cgit From 06bce8bf5c3b6a2753778461426212c61e9f2036 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 14 Aug 2023 06:47:09 +0800 Subject: test(terminal): fix scrollback test flakiness (#24708) Problem: Terminal scrollback test is flaky. Solution: Use INTERACT flag so the job doesn't exit immediately. --- test/functional/terminal/scrollback_spec.lua | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'test/functional/terminal') diff --git a/test/functional/terminal/scrollback_spec.lua b/test/functional/terminal/scrollback_spec.lua index ba0b663285..4a3005e082 100644 --- a/test/functional/terminal/scrollback_spec.lua +++ b/test/functional/terminal/scrollback_spec.lua @@ -379,9 +379,7 @@ describe("'scrollback' option", function() end) local function set_fake_shell() - -- shell-test.c is a fake shell that prints its arguments and exits. - nvim('set_option_value', 'shell', testprg('shell-test'), {}) - nvim('set_option_value', 'shellcmdflag', 'EXE', {}) + nvim('set_option_value', 'shell', string.format('"%s" INTERACT', testprg('shell-test')), {}) end local function expect_lines(expected, epsilon) @@ -514,9 +512,7 @@ describe("'scrollback' option", function() -- _Global_ scrollback=-1 defaults :terminal to 10_000. command('setglobal scrollback=-1') - -- Pass a command to prevent the terminal buffer from automatically - -- closing. The ':' command is just a no-op. - command('terminal :') + command('terminal') eq(10000, meths.get_option_value('scrollback', {})) -- _Local_ scrollback=-1 in :terminal forces the _maximum_. -- cgit From d401b33314a4178b23443c78119055c3d34a407e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 21 Aug 2023 23:19:12 +0800 Subject: fix(terminal): handle horizontal scrolling in another window (#24828) --- test/functional/terminal/mouse_spec.lua | 49 +++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 15 deletions(-) (limited to 'test/functional/terminal') diff --git a/test/functional/terminal/mouse_spec.lua b/test/functional/terminal/mouse_spec.lua index a2e9ffa1d7..6dccd14994 100644 --- a/test/functional/terminal/mouse_spec.lua +++ b/test/functional/terminal/mouse_spec.lua @@ -287,7 +287,7 @@ describe(':terminal mouse', function() ]]) end) - it("won't lose focus if another window is scrolled", function() + it("scrolling another window keeps focus and respects 'mousescroll'", function() feed('<4,0><4,0>') screen:expect([[ {7: 21 }line │line30 | @@ -308,20 +308,6 @@ describe(':terminal mouse', function() ========== ========== | {3:-- TERMINAL --} | ]]) - end) - - it("scrolling another window respects 'mousescroll'", function() - command('set mousescroll=ver:1') - feed('<4,0>') - screen:expect([[ - {7: 26 }line │line30 | - {7: 27 }line │rows: 5, cols: 25 | - {7: 28 }line │rows: 5, cols: 24 | - {7: 29 }line │mouse enabled | - {7: 30 }line │{1: } | - ========== ========== | - {3:-- TERMINAL --} | - ]]) command('set mousescroll=ver:10') feed('<4,0>') screen:expect([[ @@ -336,6 +322,39 @@ describe(':terminal mouse', function() command('set mousescroll=ver:0') feed('<4,0>') screen:expect_unchanged() + feed([[w]]) + command('setlocal nowrap') + feed('0gg3ly$4pwi') + screen:expect([[ + {7: 1 }linelinelinelineline │line30 | + {7: 2 }linelinelinelineline │rows: 5, cols: 25 | + {7: 3 }linelinelinelineline │rows: 5, cols: 24 | + {7: 4 }linelinelinelineline │mouse enabled | + {7: 5 }linelinelinelineline │{1: } | + ========== ========== | + {3:-- TERMINAL --} | + ]]) + feed('<4,0>') + screen:expect([[ + {7: 1 }nelinelineline │line30 | + {7: 2 }nelinelineline │rows: 5, cols: 25 | + {7: 3 }nelinelineline │rows: 5, cols: 24 | + {7: 4 }nelinelineline │mouse enabled | + {7: 5 }nelinelineline │{1: } | + ========== ========== | + {3:-- TERMINAL --} | + ]]) + command('set mousescroll=hor:4') + feed('<4,0>') + screen:expect([[ + {7: 1 }nelinelinelineline │line30 | + {7: 2 }nelinelinelineline │rows: 5, cols: 25 | + {7: 3 }nelinelinelineline │rows: 5, cols: 24 | + {7: 4 }nelinelinelineline │mouse enabled | + {7: 5 }nelinelinelineline │{1: } | + ========== ========== | + {3:-- TERMINAL --} | + ]]) end) it('will lose focus if another window is clicked', function() -- cgit From 0c86828ac57429e3dea1bb4a9e686dc4f0dc9ddb Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 2 Sep 2023 18:50:12 +0800 Subject: fix(ui): avoid ambiguity about chunk that clears part of line (#24982) Co-authored-by: bfredl --- test/functional/terminal/tui_spec.lua | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) (limited to 'test/functional/terminal') diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index 1958281592..57dcb14cf8 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -27,8 +27,6 @@ local is_os = helpers.is_os local new_pipename = helpers.new_pipename local spawn_argv = helpers.spawn_argv local set_session = helpers.set_session -local feed = helpers.feed -local eval = helpers.eval local write_file = helpers.write_file if helpers.skip(helpers.is_os('win')) then return end @@ -898,7 +896,7 @@ describe('TUI', function() feed_data('\022\027[107;33u') -- Meta + k feed_data('\022\027[13;41u') -- Super + Meta + Enter feed_data('\022\027[127;48u') -- Shift + Alt + Ctrl + Super + Meta + Backspace - feed('\n') + feed_data('\n') feed_data('\022\027[57376;9u') -- Super + F13 feed_data('\022\027[57377;33u') -- Meta + F14 feed_data('\022\027[57378;41u') -- Super + Meta + F15 @@ -1752,7 +1750,7 @@ describe('TUI', function() | {5:-- TERMINAL --} | ]]) - feed('i') + feed_data('i') screen:expect([[ {1: } | {2:~}{3: }| @@ -1898,6 +1896,30 @@ describe('TUI', function() {3:-- TERMINAL --} | ]]) end) + + it('draws line with many trailing spaces correctly #24955', function() + local screen = thelpers.screen_setup(0, '["'..nvim_prog..[[", "-u", "NONE", "-i", "NONE"]] + ..[[, "--cmd", "call setline(1, ['1st line' .. repeat(' ', 153), '2nd line'])"]]..']', 80) + screen:expect{grid=[[ + {1:1}st line | + | + | + 2nd line | + {5:[No Name] [+] 1,1 All}| + | + {3:-- TERMINAL --} | + ]]} + feed_data('$') + screen:expect{grid=[[ + 1st line | + | + {1: } | + 2nd line | + {5:[No Name] [+] 1,161 All}| + | + {3:-- TERMINAL --} | + ]]} + end) end) describe('TUI UIEnter/UILeave', function() @@ -2703,8 +2725,8 @@ describe("TUI as a client", function() local client_super = spawn_argv(true) set_session(server) - local server_pipe = eval'v:servername' - feed'iHalloj!' + local server_pipe = meths.get_vvar('servername') + server:request('nvim_input', 'iHalloj!') set_session(client_super) local screen = thelpers.screen_setup(0, -- cgit From 2d9e7a33f41c842521c74d45927cfcb1874c711b Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Fri, 15 Sep 2023 10:33:26 +0200 Subject: test(windows): unskip working tests (#25153) Also simplify home detection with os_homedir() --- test/functional/terminal/edit_spec.lua | 1 - 1 file changed, 1 deletion(-) (limited to 'test/functional/terminal') diff --git a/test/functional/terminal/edit_spec.lua b/test/functional/terminal/edit_spec.lua index db5dba7374..29361bc0fa 100644 --- a/test/functional/terminal/edit_spec.lua +++ b/test/functional/terminal/edit_spec.lua @@ -36,7 +36,6 @@ describe(':edit term://*', function() end) it("runs TermOpen early enough to set buffer-local 'scrollback'", function() - if helpers.skip(helpers.is_os('win')) then return end local columns, lines = 20, 4 local scr = get_screen(columns, lines) local rep = 97 -- cgit From 9cadbf1d36b63f53f0de48c8c5ff6c752ff05d70 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 18 Sep 2023 12:16:32 +0800 Subject: test(tui_spec): update cursor_address test for wrap flag (#25228) --- test/functional/terminal/tui_spec.lua | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'test/functional/terminal') diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index 57dcb14cf8..2d4613dda4 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -1663,21 +1663,18 @@ describe('TUI', function() it('draws correctly when cursor_address overflows #21643', function() helpers.skip(helpers.is_os('mac'), 'FIXME: crashes/errors on macOS') - screen:try_resize(77, 834) + screen:try_resize(77, 855) retry(nil, nil, function() - eq({true, 831}, {child_session:request('nvim_win_get_height', 0)}) + eq({true, 852}, {child_session:request('nvim_win_get_height', 0)}) end) -- Use full screen message so that redrawing afterwards is more deterministic. child_session:notify('nvim_command', 'intro') screen:expect({any = 'Nvim'}) -- Going to top-left corner needs 3 bytes. -- Setting underline attribute needs 9 bytes. - -- With screen width 77, 63857 characters need 829 full screen lines. - -- Drawing each full screen line needs 77 + 2 = 79 bytes (2 bytes for CR LF). - -- The incomplete screen line needs 24 + 3 = 27 bytes. - -- The whole line needs 3 + 9 + 79 * 829 + 27 = 65530 bytes. + -- The whole line needs 3 + 9 + 65515 + 3 = 65530 bytes. -- The cursor_address that comes after will overflow the 65535-byte buffer. - local line = ('a'):rep(63857) .. '℃' + local line = ('a'):rep(65515) .. '℃' child_session:notify('nvim_exec_lua', [[ vim.api.nvim_buf_set_lines(0, 0, -1, true, {...}) vim.o.cursorline = true @@ -1686,8 +1683,8 @@ describe('TUI', function() feed_data('\n') screen:expect( '{13:a}{12:' .. ('a'):rep(76) .. '}|\n' - .. ('{12:' .. ('a'):rep(77) .. '}|\n'):rep(828) - .. '{12:' .. ('a'):rep(24) .. '℃' .. (' '):rep(52) .. '}|\n' .. dedent([[ + .. ('{12:' .. ('a'):rep(77) .. '}|\n'):rep(849) + .. '{12:' .. ('a'):rep(65) .. '℃' .. (' '):rep(11) .. '}|\n' .. dedent([[ b | {5:[No Name] [+] }| | -- cgit From c26b39a9aa56e834262753e08372240fde9dcdf1 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 23 Sep 2023 11:00:20 +0800 Subject: fix(tui): make :cquit work properly with remote TUI (#25313) --- test/functional/terminal/tui_spec.lua | 66 +++++++++++++++++++++++++++++++---- 1 file changed, 59 insertions(+), 7 deletions(-) (limited to 'test/functional/terminal') diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index 2d4613dda4..f8d2c01771 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -1720,7 +1720,15 @@ describe('TUI', function() it('no assert failure on deadly signal #21896', function() exec_lua([[vim.uv.kill(vim.fn.jobpid(vim.bo.channel), 'sigterm')]]) - screen:expect({any = '%[Process exited 1%]'}) + screen:expect{grid=[[ + Vim: Caught deadly signal 'SIGTERM' | + | + | + [Process exited 1]{1: } | + | + | + {3:-- TERMINAL --} | + ]]} end) it('no stack-use-after-scope with cursor color #22432', function() @@ -2743,7 +2751,15 @@ describe("TUI as a client", function() -- No heap-use-after-free when receiving UI events after deadly signal #22184 server:request('nvim_input', ('a'):rep(1000)) exec_lua([[vim.uv.kill(vim.fn.jobpid(vim.bo.channel), 'sigterm')]]) - screen:expect({any = '%[Process exited 1%]'}) + screen:expect{grid=[[ + Vim: Caught deadly signal 'SIGTERM' | + | + | + [Process exited 1]{1: } | + | + | + {3:-- TERMINAL --} | + ]]} eq(0, meths.get_vvar('shell_error')) -- exits on input eof #22244 @@ -2771,7 +2787,7 @@ describe("TUI as a client", function() ]]) end) - it("exits when server quits", function() + local function test_remote_tui_quit(status) local server_super = spawn_argv(false) -- equivalent to clear() local client_super = spawn_argv(true) @@ -2780,6 +2796,15 @@ describe("TUI as a client", function() local screen_server = thelpers.screen_setup(0, string.format([=[["%s", "--listen", "%s", "-u", "NONE", "-i", "NONE", "--cmd", "%s laststatus=2 background=dark"]]=], nvim_prog, server_pipe, nvim_set)) + screen_server:expect{grid=[[ + {1: } | + {4:~ }| + {4:~ }| + {4:~ }| + {5:[No Name] }| + | + {3:-- TERMINAL --} | + ]]} feed_data("iHello, World") screen_server:expect{grid=[[ @@ -2819,13 +2844,40 @@ describe("TUI as a client", function() -- quitting the server set_session(server_super) - feed_data(":q!\n") - screen_server:expect({any="Process exited 0"}) - + feed_data(status and ':' .. status .. 'cquit!\n' or ":quit!\n") + status = status and status or 0 + screen_server:expect{grid=[[ + | + [Process exited ]] .. status .. [[]{1: }{MATCH:%s+}| + | + | + | + | + {3:-- TERMINAL --} | + ]]} -- assert that client has exited - screen_client:expect({any="Process exited 0"}) + screen_client:expect{grid=[[ + | + [Process exited ]] .. status .. [[]{1: }{MATCH:%s+}| + | + | + | + | + {3:-- TERMINAL --} | + ]]} + server_super:close() client_super:close() + end + + describe("exits when server quits", function() + it("with :quit", function() + test_remote_tui_quit() + end) + + it("with :cquit", function() + test_remote_tui_quit(42) + end) end) end) -- cgit From cfb898cd8a42ff2262c96a12919a3cacef9d2973 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 24 Sep 2023 08:05:18 +0800 Subject: test(tui_spec): small consistency fixes (#25332) - Make indent consistent. - Remove outdated "Only single integration test" comment. - Don't use setup() as function name as it's used by busted. --- test/functional/terminal/tui_spec.lua | 205 ++++++++++++++++------------------ 1 file changed, 99 insertions(+), 106 deletions(-) (limited to 'test/functional/terminal') diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index f8d2c01771..53ee4c51f4 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -29,7 +29,7 @@ local spawn_argv = helpers.spawn_argv local set_session = helpers.set_session local write_file = helpers.write_file -if helpers.skip(helpers.is_os('win')) then return end +if helpers.skip(is_os('win')) then return end describe('TUI', function() local screen @@ -67,8 +67,7 @@ describe('TUI', function() local function expect_child_buf_lines(expected) assert(type({}) == type(expected)) retry(nil, nil, function() - local _, buflines = child_session:request( - 'nvim_buf_get_lines', 0, 0, -1, false) + local _, buflines = child_session:request('nvim_buf_get_lines', 0, 0, -1, false) eq(expected, buflines) end) end @@ -319,13 +318,13 @@ describe('TUI', function() local attrs = screen:get_default_attr_ids() attrs[11] = {foreground = 81} screen:expect([[ - {11:^G^V^M}{1: } | - {4:~ }| - {4:~ }| - {4:~ }| - {5:[No Name] [+] }| - {3:-- INSERT --} | - {3:-- TERMINAL --} | + {11:^G^V^M}{1: } | + {4:~ }| + {4:~ }| + {4:~ }| + {5:[No Name] [+] }| + {3:-- INSERT --} | + {3:-- TERMINAL --} | ]], attrs) end) @@ -949,8 +948,7 @@ describe('TUI', function() ]]) -- Dot-repeat/redo. feed_data('2.') - expect_child_buf_lines( - {'"pasted from terminapasted from terminalpasted from terminall"'}) + expect_child_buf_lines({'"pasted from terminapasted from terminalpasted from terminall"'}) screen:expect([[ "pasted from terminapasted from terminalpasted fro| m termina{1:l}l" | @@ -1003,13 +1001,13 @@ describe('TUI', function() 'this is line 2', 'line 3 is here', '', - } + } -- Redo. feed_data('\18') -- expect_child_buf_lines{ 'thisjust paste it™3 is here', '', - } + } end) it('paste: terminal mode', function() @@ -1071,17 +1069,15 @@ describe('TUI', function() screen:expect{grid=expected_grid1, attr_ids=expected_attr} -- Dot-repeat/redo. feed_data('.') - screen:expect{ - grid=[[ - ESC:{11:^[} / CR: | - xline 1 | - ESC:{11:^[} / CR: | - {1:x} | - {5:[No Name] [+] 5,1 Bot}| - | - {3:-- TERMINAL --} | - ]], - attr_ids=expected_attr} + screen:expect{grid=[[ + ESC:{11:^[} / CR: | + xline 1 | + ESC:{11:^[} / CR: | + {1:x} | + {5:[No Name] [+] 5,1 Bot}| + | + {3:-- TERMINAL --} | + ]], attr_ids=expected_attr} -- Undo. feed_data('u') expect_child_buf_lines(expected_crlf) @@ -1368,8 +1364,7 @@ describe('TUI', function() {5:[No Name] [+] }| {3:-- INSERT --} | {3:-- TERMINAL --} | - ]], - attr_ids={ + ]], attr_ids={ [1] = {reverse = true}, [2] = {background = tonumber('0x00000b')}, [3] = {bold = true}, @@ -1548,7 +1543,7 @@ describe('TUI', function() it('forwards :term palette colors with termguicolors', function() if is_ci('github') then - pending("tty-test complains about not owning the terminal -- actions/runner#241") + pending("tty-test complains about not owning the terminal -- actions/runner#241") end screen:set_rgb_cterm(true) screen:set_default_attr_ids({ @@ -1599,26 +1594,26 @@ describe('TUI', function() local exp_term = is_os('bsd') and 'builtin_xterm' or 'xterm-256color' local expected = { { - chan = 1, - ext_cmdline = false, - ext_hlstate = false, - ext_linegrid = true, - ext_messages = false, - ext_multigrid = false, - ext_popupmenu = false, - ext_tabline = false, - ext_termcolors = true, - ext_wildmenu = false, - height = 6, - override = false, - rgb = false, - stdin_tty = true, - stdout_tty = true, - term_background = '', - term_colors = 256, - term_name = exp_term, - width = 50 - }, + chan = 1, + ext_cmdline = false, + ext_hlstate = false, + ext_linegrid = true, + ext_messages = false, + ext_multigrid = false, + ext_popupmenu = false, + ext_tabline = false, + ext_termcolors = true, + ext_wildmenu = false, + height = 6, + override = false, + rgb = false, + stdin_tty = true, + stdout_tty = true, + term_background = '', + term_colors = 256, + term_name = exp_term, + width = 50 + }, } local _, rv = child_session:request('nvim_list_uis') eq(expected, rv) @@ -1639,8 +1634,8 @@ describe('TUI', function() | {3:-- TERMINAL --} | ]] - -- When grid assumes "℃" to be double-width but host terminal assumes it to be single-width, the - -- second cell of "℃" is a space and the attributes of the "℃" are applied to it. + -- When grid assumes "℃" to be double-width but host terminal assumes it to be single-width, + -- the second cell of "℃" is a space and the attributes of the "℃" are applied to it. local doublewidth_screen = [[ {13:℃}{12: ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ }| {12:℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ }| @@ -1662,7 +1657,7 @@ describe('TUI', function() end) it('draws correctly when cursor_address overflows #21643', function() - helpers.skip(helpers.is_os('mac'), 'FIXME: crashes/errors on macOS') + helpers.skip(is_os('mac'), 'FIXME: crashes/errors on macOS') screen:try_resize(77, 855) retry(nil, nil, function() eq({true, 852}, {child_session:request('nvim_win_get_height', 0)}) @@ -2173,7 +2168,7 @@ describe("TUI 't_Co' (terminal colors)", function() local screen local function assert_term_colors(term, colorterm, maxcolors) - helpers.clear({env={TERM=term}, args={}}) + clear({env={TERM=term}, args={}}) -- This is ugly because :term/termopen() forces TERM=xterm-256color. -- TODO: Revisit this after jobstart/termopen accept `env` dict. screen = thelpers.screen_setup(0, string.format( @@ -2538,29 +2533,28 @@ describe("TUI", function() end) +-- See test/unit/tui_spec.lua for unit tests. describe('TUI bg color', function() local screen - local function setup() - -- Only single integration test. - -- See test/unit/tui_spec.lua for unit tests. + local function setup_bg_test() clear() screen = thelpers.screen_setup(0, '["'..nvim_prog ..'", "-u", "NONE", "-i", "NONE", "--cmd", "set noswapfile", ' ..'"-c", "autocmd OptionSet background echo \\"did OptionSet, yay!\\""]') end - before_each(setup) + before_each(setup_bg_test) it('triggers OptionSet event on unsplit terminal-response', function() screen:expect([[ - {1: } | - {4:~ }| - {4:~ }| - {4:~ }| - {5:[No Name] 0,0-1 All}| - | - {3:-- TERMINAL --} | + {1: } | + {4:~ }| + {4:~ }| + {4:~ }| + {5:[No Name] 0,0-1 All}| + | + {3:-- TERMINAL --} | ]]) feed_data('\027]11;rgb:ffff/ffff/ffff\007') screen:expect{any='did OptionSet, yay!'} @@ -2568,15 +2562,15 @@ describe('TUI bg color', function() feed_data(':echo "new_bg=".&background\n') screen:expect{any='new_bg=light'} - setup() + setup_bg_test() screen:expect([[ - {1: } | - {4:~ }| - {4:~ }| - {4:~ }| - {5:[No Name] 0,0-1 All}| - | - {3:-- TERMINAL --} | + {1: } | + {4:~ }| + {4:~ }| + {4:~ }| + {5:[No Name] 0,0-1 All}| + | + {3:-- TERMINAL --} | ]]) feed_data('\027]11;rgba:ffff/ffff/ffff/8000\027\\') screen:expect{any='did OptionSet, yay!'} @@ -2587,13 +2581,13 @@ describe('TUI bg color', function() it('triggers OptionSet event with split terminal-response', function() screen:expect([[ - {1: } | - {4:~ }| - {4:~ }| - {4:~ }| - {5:[No Name] 0,0-1 All}| - | - {3:-- TERMINAL --} | + {1: } | + {4:~ }| + {4:~ }| + {4:~ }| + {5:[No Name] 0,0-1 All}| + | + {3:-- TERMINAL --} | ]]) -- Send a background response with the OSC command part split. feed_data('\027]11;rgb') @@ -2603,15 +2597,15 @@ describe('TUI bg color', function() feed_data(':echo "new_bg=".&background\n') screen:expect{any='new_bg=light'} - setup() + setup_bg_test() screen:expect([[ - {1: } | - {4:~ }| - {4:~ }| - {4:~ }| - {5:[No Name] 0,0-1 All}| - | - {3:-- TERMINAL --} | + {1: } | + {4:~ }| + {4:~ }| + {4:~ }| + {5:[No Name] 0,0-1 All}| + | + {3:-- TERMINAL --} | ]]) -- Send a background response with the Pt portion split. feed_data('\027]11;rgba:ffff/fff') @@ -2624,13 +2618,13 @@ describe('TUI bg color', function() it('not triggers OptionSet event with invalid terminal-response', function() screen:expect([[ - {1: } | - {4:~ }| - {4:~ }| - {4:~ }| - {5:[No Name] 0,0-1 All}| - | - {3:-- TERMINAL --} | + {1: } | + {4:~ }| + {4:~ }| + {4:~ }| + {5:[No Name] 0,0-1 All}| + | + {3:-- TERMINAL --} | ]]) feed_data('\027]11;rgb:ffff/ffff/ffff/8000\027\\') screen:expect_unchanged() @@ -2638,15 +2632,15 @@ describe('TUI bg color', function() feed_data(':echo "new_bg=".&background\n') screen:expect{any='new_bg=dark'} - setup() + setup_bg_test() screen:expect([[ - {1: } | - {4:~ }| - {4:~ }| - {4:~ }| - {5:[No Name] 0,0-1 All}| - | - {3:-- TERMINAL --} | + {1: } | + {4:~ }| + {4:~ }| + {4:~ }| + {5:[No Name] 0,0-1 All}| + | + {3:-- TERMINAL --} | ]]) feed_data('\027]11;rgba:ffff/foo/ffff/8000\007') screen:expect_unchanged() @@ -2726,7 +2720,7 @@ describe("TUI as a client", function() end) it("connects to remote instance (--headless)", function() - local server = helpers.spawn_argv(false) -- equivalent to clear() + local server = spawn_argv(false) -- equivalent to clear() local client_super = spawn_argv(true) set_session(server) @@ -2734,11 +2728,11 @@ describe("TUI as a client", function() server:request('nvim_input', 'iHalloj!') set_session(client_super) - local screen = thelpers.screen_setup(0, + local screen_client = thelpers.screen_setup(0, string.format([=[["%s", "--server", "%s", "--remote-ui"]]=], nvim_prog, server_pipe)) - screen:expect{grid=[[ + screen_client:expect{grid=[[ Halloj{1:!} | {4:~ }| {4:~ }| @@ -2751,7 +2745,7 @@ describe("TUI as a client", function() -- No heap-use-after-free when receiving UI events after deadly signal #22184 server:request('nvim_input', ('a'):rep(1000)) exec_lua([[vim.uv.kill(vim.fn.jobpid(vim.bo.channel), 'sigterm')]]) - screen:expect{grid=[[ + screen_client:expect{grid=[[ Vim: Caught deadly signal 'SIGTERM' | | | @@ -2866,7 +2860,6 @@ describe("TUI as a client", function() {3:-- TERMINAL --} | ]]} - server_super:close() client_super:close() end -- cgit From ed0d6536e34af2a2a74894e52da5734c9c8d6e17 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 24 Sep 2023 22:03:54 +0800 Subject: test: only trim trailing spaces in swapfile tests (#25341) --- test/functional/terminal/scrollback_spec.lua | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'test/functional/terminal') diff --git a/test/functional/terminal/scrollback_spec.lua b/test/functional/terminal/scrollback_spec.lua index 4a3005e082..1e278e4cff 100644 --- a/test/functional/terminal/scrollback_spec.lua +++ b/test/functional/terminal/scrollback_spec.lua @@ -5,7 +5,6 @@ local clear, eq, curbuf = helpers.clear, helpers.eq, helpers.curbuf local feed, testprg = helpers.feed, helpers.testprg local eval = helpers.eval local command = helpers.command -local matches = helpers.matches local poke_eventloop = helpers.poke_eventloop local retry = helpers.retry local meths = helpers.meths @@ -457,8 +456,8 @@ describe("'scrollback' option", function() expect_lines(58) -- Verify off-screen state - matches((is_os('win') and '^36: line[ ]*$' or '^35: line[ ]*$'), eval("getline(line('w0') - 1)")) - matches((is_os('win') and '^27: line[ ]*$' or '^26: line[ ]*$'), eval("getline(line('w0') - 10)")) + eq((is_os('win') and '36: line' or '35: line'), eval("getline(line('w0') - 1)->trim(' ', 2)")) + eq((is_os('win') and '27: line' or '26: line'), eval("getline(line('w0') - 10)->trim(' ', 2)")) end) it('deletes extra lines immediately', function() -- cgit From af7d317f3ff31d5ac5d8724b5057a422e1451b54 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Tue, 26 Sep 2023 22:36:08 +0200 Subject: refactor: remove long long is 32-bits even on 64-bit windows which makes the type suboptimal for a codebase meant to be cross-platform. --- test/functional/terminal/tui_spec.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'test/functional/terminal') diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index 53ee4c51f4..955a871d10 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -73,6 +73,7 @@ describe('TUI', function() end it('rapid resize #7572 #7628', function() + helpers.skip(helpers.is_asan(), 'Test extra unstable with ASAN. See #23762') -- Need buffer rows to provoke the behavior. feed_data(":edit test/functional/fixtures/bigfile.txt\n") screen:expect([[ -- cgit From e1157324657907fab37de8dea71442802d222dd3 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 3 Oct 2023 10:23:03 +0800 Subject: fix(terminal): check terminal size at end of screen update (#25480) --- test/functional/terminal/window_spec.lua | 41 ++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) (limited to 'test/functional/terminal') diff --git a/test/functional/terminal/window_spec.lua b/test/functional/terminal/window_spec.lua index f90e4f7e9d..39fc2c2562 100644 --- a/test/functional/terminal/window_spec.lua +++ b/test/functional/terminal/window_spec.lua @@ -44,7 +44,7 @@ describe(':terminal window', function() {7:6 } | {3:-- TERMINAL --} | ]]) - feed_data({'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'}) + feed_data('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') screen:expect([[ {7:1 }tty ready | {7:2 }rows: 6, cols: 48 | @@ -55,8 +55,6 @@ describe(':terminal window', function() {3:-- TERMINAL --} | ]]) - skip(is_os('win'), 'win: :terminal resize is unreliable #7007') - -- numberwidth=9 feed([[]]) feed([[:set numberwidth=9 numberi]]) @@ -69,7 +67,7 @@ describe(':terminal window', function() {7: 6 } | {3:-- TERMINAL --} | ]]) - feed_data({' abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'}) + feed_data(' abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') screen:expect([[ {7: 1 }tty ready | {7: 2 }rows: 6, cols: 48 | @@ -82,6 +80,41 @@ describe(':terminal window', function() end) end) + describe("with 'statuscolumn'", function() + it('wraps text', function() + command([[set number statuscolumn=++%l\ \ ]]) + screen:expect([[ + {7:++1 }tty ready | + {7:++2 }rows: 6, cols: 45 | + {7:++3 }{1: } | + {7:++4 } | + {7:++5 } | + {7:++6 } | + {3:-- TERMINAL --} | + ]]) + feed_data('\n\n\n\n\nabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') + screen:expect([[ + {7:++4 } | + {7:++5 } | + {7:++6 } | + {7:++7 } | + {7:++8 }abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRS| + {7:++9 }TUVWXYZ{1: } | + {3:-- TERMINAL --} | + ]]) + feed_data('\nabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') + screen:expect([[ + {7:++7 } | + {7:++8 }abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQR| + {7:++9 }STUVWXYZ | + {7:++10 }abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQR| + {7:++11 }STUVWXYZrows: 6, cols: 44 | + {7:++12 }{1: } | + {3:-- TERMINAL --} | + ]]) + end) + end) + describe("with 'colorcolumn'", function() before_each(function() feed([[]]) -- cgit From ddef39299f357d3131644647379e88a69749bf40 Mon Sep 17 00:00:00 2001 From: bfredl Date: Tue, 19 Sep 2023 14:30:02 +0200 Subject: refactor(grid): do arabic shaping in one place The 'arabicshape' feature of vim is a transformation of unicode text to make arabic and some related scripts look better at display time. In particular the content of a cell will be adjusted depending on the (original) content of the cells just before and after it. This is implemented by the arabic_shape() function in nvim. Before this commit, shaping was invoked in four different contexts: - when rendering buffer text in win_line() - in line_putchar() for rendering virtual text - as part of grid_line_puts, used by messages and statuslines and similar - as part of draw_cmdline() for drawing the cmdline This replaces all these with a post-processing step in grid_put_linebuf(), which has become the entry point for all text rendering after recent refactors. An aim of this is to make the handling of multibyte text yet simpler. One of the main reasons multibyte chars needs to be "parsed" into codepoint arrays of composing chars is so that these could be inspected for the purpose of shaping. This can likely be vastly simplified in many contexts where only the total length (in bytes) and width of composed char is needed. --- test/functional/terminal/tui_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/terminal') diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index 955a871d10..682eb48a27 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -1641,7 +1641,7 @@ describe('TUI', function() {13:℃}{12: ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ }| {12:℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ }| {12:℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ }{15:$}{12: }| - ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ >{4:@@@}| + ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ {4:@@@@}| {5:[No Name] [+] }| | {3:-- TERMINAL --} | -- cgit From 85ddd0074b71d006746cb298e73e6ba2f5a52541 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 15 Oct 2023 06:38:43 +0800 Subject: test(terminal/channel_spec): fix flakiness (#25649) --- test/functional/terminal/channel_spec.lua | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'test/functional/terminal') diff --git a/test/functional/terminal/channel_spec.lua b/test/functional/terminal/channel_spec.lua index 2cd02be321..51bf611860 100644 --- a/test/functional/terminal/channel_spec.lua +++ b/test/functional/terminal/channel_spec.lua @@ -24,6 +24,7 @@ describe('terminal channel is closed and later released if', function() -- channel hasn't been released yet eq("Vim(call):Can't send data to closed stream", pcall_err(command, [[bdelete! | call chansend(id, 'test')]])) + feed('') -- add input to separate two RPC requests -- channel has been released after one main loop iteration eq(chans - 1, eval('len(nvim_list_chans())')) end) @@ -40,6 +41,7 @@ describe('terminal channel is closed and later released if', function() feed('i') -- need to first process input poke_eventloop() + feed('') -- add input to separate two RPC requests -- channel has been released after another main loop iteration eq(chans - 1, eval('len(nvim_list_chans())')) end) @@ -55,6 +57,7 @@ describe('terminal channel is closed and later released if', function() -- channel still hasn't been released yet eq("Vim(call):Can't send data to closed stream", pcall_err(command, [[bdelete | call chansend(id, 'test')]])) + feed('') -- add input to separate two RPC requests -- channel has been released after one main loop iteration eq(chans - 1, eval('len(nvim_list_chans())')) end) @@ -72,6 +75,7 @@ describe('terminal channel is closed and later released if', function() feed('i') -- need to first process input poke_eventloop() + feed('') -- add input to separate two RPC requests -- channel has been released after another main loop iteration eq(chans - 1, eval('len(nvim_list_chans())')) end) @@ -89,6 +93,7 @@ describe('terminal channel is closed and later released if', function() -- channel still hasn't been released yet eq("Vim(call):Can't send data to closed stream", pcall_err(command, [[bdelete | call chansend(id, 'test')]])) + feed('') -- add input to separate two RPC requests -- channel has been released after one main loop iteration eq(chans - 1, eval('len(nvim_list_chans())')) end) -- cgit From 684e93054b82c6b5b215db7d3ecbad803eb81f0e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 25 Oct 2023 09:59:02 +0800 Subject: fix(terminal): assign channel to terminal earlier (#25771) --- test/functional/terminal/channel_spec.lua | 83 +++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) (limited to 'test/functional/terminal') diff --git a/test/functional/terminal/channel_spec.lua b/test/functional/terminal/channel_spec.lua index 51bf611860..8510df5347 100644 --- a/test/functional/terminal/channel_spec.lua +++ b/test/functional/terminal/channel_spec.lua @@ -8,6 +8,10 @@ local pcall_err = helpers.pcall_err local feed = helpers.feed local poke_eventloop = helpers.poke_eventloop local is_os = helpers.is_os +local meths = helpers.meths +local async_meths = helpers.async_meths +local testprg = helpers.testprg +local assert_alive = helpers.assert_alive describe('terminal channel is closed and later released if', function() local screen @@ -116,3 +120,82 @@ it('chansend sends lines to terminal channel in proper order', function() } end end) + +describe('no crash when TermOpen autocommand', function() + local screen + + before_each(function() + clear() + meths.set_option_value('shell', testprg('shell-test'), {}) + command('set shellcmdflag=EXE shellredir= shellpipe= shellquote= shellxquote=') + screen = Screen.new(60, 4) + screen:set_default_attr_ids({ + [0] = {bold = true, foreground = Screen.colors.Blue}; + }) + screen:attach() + end) + + it('processes job exit event when using termopen()', function() + command([[autocmd TermOpen * call input('')]]) + async_meths.command('terminal foobar') + screen:expect{grid=[[ + | + {0:~ }| + {0:~ }| + ^ | + ]]} + feed('') + screen:expect{grid=[[ + ^ready $ foobar | + | + [Process exited 0] | + | + ]]} + feed('i') + screen:expect{grid=[[ + ^ | + {0:~ }| + {0:~ }| + | + ]]} + assert_alive() + end) + + it('wipes buffer and processes events when using termopen()', function() + command([[autocmd TermOpen * bwipe! | call input('')]]) + async_meths.command('terminal foobar') + screen:expect{grid=[[ + | + {0:~ }| + {0:~ }| + ^ | + ]]} + feed('') + screen:expect{grid=[[ + ^ | + {0:~ }| + {0:~ }| + | + ]]} + assert_alive() + end) + + it('wipes buffer and processes events when using nvim_open_term()', function() + command([[autocmd TermOpen * bwipe! | call input('')]]) + async_meths.open_term(0, {}) + screen:expect{grid=[[ + | + {0:~ }| + {0:~ }| + ^ | + ]]} + feed('') + screen:expect{grid=[[ + ^ | + {0:~ }| + {0:~ }| + | + ]]} + assert_alive() + end) +end) -- cgit From 82b1a389ba98f5f8e8d6c9d7485386be272a22df Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 29 Oct 2023 09:32:03 +0800 Subject: fix(terminal): avoid Insert mode in Terminal buffer (#25820) --- test/functional/terminal/ex_terminal_spec.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test/functional/terminal') diff --git a/test/functional/terminal/ex_terminal_spec.lua b/test/functional/terminal/ex_terminal_spec.lua index 6020a12ddb..f628e261a2 100644 --- a/test/functional/terminal/ex_terminal_spec.lua +++ b/test/functional/terminal/ex_terminal_spec.lua @@ -125,6 +125,20 @@ describe(':terminal', function() feed('a') eq({ blocking=false, mode='t' }, nvim('get_mode')) end) + + it('switching to terminal buffer in Insert mode goes to Terminal mode #7164', function() + command('terminal') + command('vnew') + feed('i') + command('let g:events = []') + command('autocmd InsertLeave * let g:events += ["InsertLeave"]') + command('autocmd TermEnter * let g:events += ["TermEnter"]') + command('inoremap wincmd p') + eq({ blocking=false, mode='i' }, nvim('get_mode')) + feed('') + eq({ blocking=false, mode='t' }, nvim('get_mode')) + eq({'InsertLeave', 'TermEnter'}, eval('g:events')) + end) end) describe(':terminal (with fake shell)', function() -- cgit From c881092ffe9d6760d08efcd4dfb02efcb60cc706 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 31 Oct 2023 12:05:37 +0800 Subject: fix(terminal): don't lose focus on (#25845) --- test/functional/terminal/mouse_spec.lua | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'test/functional/terminal') diff --git a/test/functional/terminal/mouse_spec.lua b/test/functional/terminal/mouse_spec.lua index 6dccd14994..92d9b03b45 100644 --- a/test/functional/terminal/mouse_spec.lua +++ b/test/functional/terminal/mouse_spec.lua @@ -67,8 +67,23 @@ describe(':terminal mouse', function() eq('nt', eval('mode(1)')) end) - it('does not leave terminal mode on left-release', function() - feed('') + it('will not exit focus on left-release', function() + eq('t', eval('mode(1)')) + feed('<0,0>') + eq('t', eval('mode(1)')) + command('setlocal number') + eq('t', eval('mode(1)')) + feed('<0,0>') + eq('t', eval('mode(1)')) + end) + + it('will not exit focus on mouse movement', function() + eq('t', eval('mode(1)')) + feed('<0,0>') + eq('t', eval('mode(1)')) + command('setlocal number') + eq('t', eval('mode(1)')) + feed('<0,0>') eq('t', eval('mode(1)')) end) -- cgit From d4c2fc6ff6c579b2588f0e3ba02e5cbe58308c6a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 31 Oct 2023 15:23:20 +0800 Subject: fix(terminal): keep focus when scrolling number column of another window (#25848) --- test/functional/terminal/mouse_spec.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/functional/terminal') diff --git a/test/functional/terminal/mouse_spec.lua b/test/functional/terminal/mouse_spec.lua index 92d9b03b45..3291a38e03 100644 --- a/test/functional/terminal/mouse_spec.lua +++ b/test/functional/terminal/mouse_spec.lua @@ -324,7 +324,7 @@ describe(':terminal mouse', function() {3:-- TERMINAL --} | ]]) command('set mousescroll=ver:10') - feed('<4,0>') + feed('<0,0>') screen:expect([[ {7: 16 }line │line30 | {7: 17 }line │rows: 5, cols: 25 | @@ -335,7 +335,7 @@ describe(':terminal mouse', function() {3:-- TERMINAL --} | ]]) command('set mousescroll=ver:0') - feed('<4,0>') + feed('<0,0>') screen:expect_unchanged() feed([[w]]) command('setlocal nowrap') -- cgit From e7c46438ab118c138a7370a9976e45854c356a89 Mon Sep 17 00:00:00 2001 From: Gregory Anders Date: Sun, 12 Nov 2023 14:46:03 -0500 Subject: test: use ST terminator instead of BEL in OSC sequences libtermkey does not interpret OSC sequences that end with a BEL (0x07) instead of an ST (0x1b 0x5c) terminator. This causes these tests to fail since the OSC response is now parsed via libtermkey. Change the tests to use the ST terminator to appease libtermkey. --- test/functional/terminal/tui_spec.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test/functional/terminal') diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index 682eb48a27..960870fb46 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -2557,7 +2557,7 @@ describe('TUI bg color', function() | {3:-- TERMINAL --} | ]]) - feed_data('\027]11;rgb:ffff/ffff/ffff\007') + feed_data('\027]11;rgb:ffff/ffff/ffff\027\\') screen:expect{any='did OptionSet, yay!'} feed_data(':echo "new_bg=".&background\n') @@ -2610,7 +2610,7 @@ describe('TUI bg color', function() ]]) -- Send a background response with the Pt portion split. feed_data('\027]11;rgba:ffff/fff') - feed_data('f/ffff/8000\007') + feed_data('f/ffff/8000\027\\') screen:expect{any='did OptionSet, yay!'} feed_data(':echo "new_bg=".&background\n') @@ -2643,7 +2643,7 @@ describe('TUI bg color', function() | {3:-- TERMINAL --} | ]]) - feed_data('\027]11;rgba:ffff/foo/ffff/8000\007') + feed_data('\027]11;rgba:ffff/foo/ffff/8000\027\\') screen:expect_unchanged() feed_data(':echo "new_bg=".&background\n') -- cgit From ad867fee26c8124d23693823b56f849e4487b828 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 17 Nov 2023 22:13:30 +0800 Subject: fix(tui): handle cursor visibility properly (#26091) The test is for the case without 'termsync' because libvterm doesn't support synchronized output, and it passes without this PR. --- test/functional/terminal/tui_spec.lua | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'test/functional/terminal') diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index 960870fb46..b17eed00f9 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -1785,6 +1785,31 @@ describe('TUI', function() {3:-- TERMINAL --} | ]]) end) + + it('supports hiding cursor', function() + child_session:request('nvim_command', + "let g:id = jobstart([v:progpath, '--clean', '--headless'])") + feed_data(':call jobwait([g:id])\n') + screen:expect([[ + | + {4:~ }| + {4:~ }| + {4:~ }| + {5:[No Name] }| + :call jobwait([g:id]) | + {3:-- TERMINAL --} | + ]]) + feed_data('\003') + screen:expect([[ + {1: } | + {4:~ }| + {4:~ }| + {4:~ }| + {5:[No Name] }| + Type :qa and press to exit Nvim | + {3:-- TERMINAL --} | + ]]) + end) end) describe('TUI', function() -- cgit