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.
This commit is contained in:
zeertzjq 2023-07-23 12:46:56 +08:00 committed by GitHub
parent f56c184809
commit ce56ad2ba7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 45 additions and 45 deletions

View File

@ -24,8 +24,7 @@ describe(':terminal buffer', function()
before_each(function() before_each(function()
clear() clear()
feed_command('set modifiable swapfile undolevels=20') command('set modifiable swapfile undolevels=20')
poke_eventloop()
screen = thelpers.screen_setup() screen = thelpers.screen_setup()
end) end)
@ -199,7 +198,6 @@ describe(':terminal buffer', function()
it('handles loss of focus gracefully', function() it('handles loss of focus gracefully', function()
-- Change the statusline to avoid printing the file name, which varies. -- Change the statusline to avoid printing the file name, which varies.
nvim('set_option_value', 'statusline', '==========', {}) nvim('set_option_value', 'statusline', '==========', {})
feed_command('set laststatus=0')
-- Save the buffer number of the terminal for later testing. -- Save the buffer number of the terminal for later testing.
local tbuf = eval('bufnr("%")') local tbuf = eval('bufnr("%")')
@ -232,8 +230,6 @@ describe(':terminal buffer', function()
neq(tbuf, eval('bufnr("%")')) neq(tbuf, eval('bufnr("%")'))
feed_command('quit!') -- Should exit the new window, not the terminal. feed_command('quit!') -- Should exit the new window, not the terminal.
eq(tbuf, eval('bufnr("%")')) eq(tbuf, eval('bufnr("%")'))
feed_command('set laststatus=1') -- Restore laststatus to the default.
end) end)
it('term_close() use-after-free #4393', function() it('term_close() use-after-free #4393', function()
@ -433,7 +429,7 @@ describe('terminal input', function()
_G.input_data = _G.input_data .. data _G.input_data = _G.input_data .. data
end }) end })
]]) ]])
command('startinsert') feed('i')
poke_eventloop() poke_eventloop()
end) end)

View File

@ -6,7 +6,7 @@ local testprg, command = helpers.testprg, helpers.command
local nvim_prog = helpers.nvim_prog local nvim_prog = helpers.nvim_prog
local eq, eval = helpers.eq, helpers.eval local eq, eval = helpers.eq, helpers.eval
local matches = helpers.matches local matches = helpers.matches
local feed_command = helpers.feed_command local poke_eventloop = helpers.poke_eventloop
local hide_cursor = thelpers.hide_cursor local hide_cursor = thelpers.hide_cursor
local show_cursor = thelpers.show_cursor local show_cursor = thelpers.show_cursor
local is_os = helpers.is_os local is_os = helpers.is_os
@ -153,7 +153,8 @@ describe('cursor with customized highlighting', function()
}) })
screen:attach({rgb=false}) screen:attach({rgb=false})
command('call termopen(["'..testprg('tty-test')..'"])') command('call termopen(["'..testprg('tty-test')..'"])')
feed_command('startinsert') feed('i')
poke_eventloop()
end) end)
it('overrides the default highlighting', function() it('overrides the default highlighting', function()

View File

@ -99,7 +99,7 @@ describe(':terminal', function()
end) end)
it('nvim_get_mode() in :terminal', function() it('nvim_get_mode() in :terminal', function()
command(':terminal') command('terminal')
eq({ blocking=false, mode='nt' }, nvim('get_mode')) eq({ blocking=false, mode='nt' }, nvim('get_mode'))
feed('i') feed('i')
eq({ blocking=false, mode='t' }, nvim('get_mode')) eq({ blocking=false, mode='t' }, nvim('get_mode'))
@ -108,17 +108,19 @@ describe(':terminal', function()
end) end)
it(':stopinsert RPC request exits terminal-mode #7807', function() it(':stopinsert RPC request exits terminal-mode #7807', function()
command(':terminal') command('terminal')
feed('i[tui] insert-mode') feed('i[tui] insert-mode')
eq({ blocking=false, mode='t' }, nvim('get_mode')) eq({ blocking=false, mode='t' }, nvim('get_mode'))
command('stopinsert') command('stopinsert')
feed('<Ignore>') -- Add input to separate two RPC requests
eq({ blocking=false, mode='nt' }, nvim('get_mode')) eq({ blocking=false, mode='nt' }, nvim('get_mode'))
end) end)
it(':stopinsert in normal mode doesn\'t break insert mode #9889', function() it(':stopinsert in normal mode doesn\'t break insert mode #9889', function()
command(':terminal') command('terminal')
eq({ blocking=false, mode='nt' }, nvim('get_mode')) eq({ blocking=false, mode='nt' }, nvim('get_mode'))
command(':stopinsert') command('stopinsert')
feed('<Ignore>') -- Add input to separate two RPC requests
eq({ blocking=false, mode='nt' }, nvim('get_mode')) eq({ blocking=false, mode='nt' }, nvim('get_mode'))
feed('a') feed('a')
eq({ blocking=false, mode='t' }, nvim('get_mode')) eq({ blocking=false, mode='t' }, nvim('get_mode'))

View File

@ -5,7 +5,7 @@ local helpers = require('test.functional.helpers')(nil)
local Screen = require('test.functional.ui.screen') local Screen = require('test.functional.ui.screen')
local testprg = helpers.testprg local testprg = helpers.testprg
local exec_lua = helpers.exec_lua local exec_lua = helpers.exec_lua
local feed_command, nvim = helpers.feed_command, helpers.nvim local nvim = helpers.nvim
local function feed_data(data) local function feed_data(data)
if type(data) == 'table' then if type(data) == 'table' then
@ -82,15 +82,16 @@ local function screen_setup(extra_rows, command, cols, opts)
screen:attach(opts or {rgb=false}) screen:attach(opts or {rgb=false})
feed_command('enew | call termopen('..command..')') nvim('command', 'enew | call termopen('..command..')')
nvim('input', '<CR>') nvim('input', '<CR>')
local vim_errmsg = nvim('eval', 'v:errmsg') local vim_errmsg = nvim('eval', 'v:errmsg')
if vim_errmsg and "" ~= vim_errmsg then if vim_errmsg and "" ~= vim_errmsg then
error(vim_errmsg) error(vim_errmsg)
end end
feed_command('setlocal scrollback=10') nvim('command', 'setlocal scrollback=10')
feed_command('startinsert') nvim('command', 'startinsert')
nvim('input', '<Ignore>') -- Add input to separate two RPC requests
-- tty-test puts the terminal into raw mode and echoes input. Tests work by -- 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. -- feeding termcodes to control the display and asserting by screen:expect.

View File

@ -2,7 +2,7 @@ local Screen = require('test.functional.ui.screen')
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local thelpers = require('test.functional.terminal.helpers') local thelpers = require('test.functional.terminal.helpers')
local clear, eq, curbuf = helpers.clear, helpers.eq, helpers.curbuf 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 eval = helpers.eval
local command = helpers.command local command = helpers.command
local matches = helpers.matches local matches = helpers.matches
@ -349,8 +349,7 @@ describe(':terminal prints more lines than the screen height and exits', functio
clear() clear()
local screen = Screen.new(30, 7) local screen = Screen.new(30, 7)
screen:attach({rgb=false}) screen:attach({rgb=false})
feed_command(("call termopen(['%s', '10']) | startinsert"):format(testprg('tty-test'))) command(("call termopen(['%s', '10']) | startinsert"):format(testprg('tty-test')))
poke_eventloop()
screen:expect([[ screen:expect([[
line6 | line6 |
line7 | line7 |

View File

@ -8,7 +8,6 @@ local helpers = require('test.functional.helpers')(after_each)
local thelpers = require('test.functional.terminal.helpers') local thelpers = require('test.functional.terminal.helpers')
local Screen = require('test.functional.ui.screen') local Screen = require('test.functional.ui.screen')
local eq = helpers.eq local eq = helpers.eq
local feed_command = helpers.feed_command
local feed_data = thelpers.feed_data local feed_data = thelpers.feed_data
local clear = helpers.clear local clear = helpers.clear
local command = helpers.command local command = helpers.command
@ -110,14 +109,14 @@ describe('TUI', function()
end) end)
it('accepts resize while pager is active', function() it('accepts resize while pager is active', function()
child_session:request("nvim_exec", [[ child_session:request('nvim_exec2', [[
set more set more
func! ManyErr() func! ManyErr()
for i in range(20) for i in range(20)
echoerr "FAIL ".i echoerr "FAIL ".i
endfor endfor
endfunc endfunc
]], false) ]], {})
feed_data(':call ManyErr()\r') feed_data(':call ManyErr()\r')
screen:expect{grid=[[ screen:expect{grid=[[
{8:Error detected while processing function ManyErr:} | {8:Error detected while processing function ManyErr:} |
@ -241,7 +240,7 @@ describe('TUI', function()
it('interprets leading <Esc> byte as ALT modifier in normal-mode', function() it('interprets leading <Esc> byte as ALT modifier in normal-mode', function()
local keys = 'dfghjkl' local keys = 'dfghjkl'
for c in keys:gmatch('.') do for c in keys:gmatch('.') do
feed_command('nnoremap <a-'..c..'> ialt-'..c..'<cr><esc>') feed_data(':nnoremap <a-'..c..'> ialt-'..c..'<cr><esc>\r')
feed_data('\027'..c) feed_data('\027'..c)
end end
screen:expect([[ screen:expect([[
@ -281,9 +280,11 @@ describe('TUI', function()
end) end)
it('interprets <Esc>[27u as <Esc>', function() it('interprets <Esc>[27u as <Esc>', function()
feed_command('nnoremap <M-;> <Nop>') child_session:request('nvim_exec2', [[
feed_command('nnoremap <Esc> AESC<Esc>') nnoremap <M-;> <Nop>
feed_command('nnoremap ; Asemicolon<Esc>') nnoremap <Esc> AESC<Esc>
nnoremap ; Asemicolon<Esc>
]], {})
feed_data('\027[27u;') feed_data('\027[27u;')
screen:expect([[ screen:expect([[
ESCsemicolo{1:n} | ESCsemicolo{1:n} |
@ -331,11 +332,11 @@ describe('TUI', function()
end) end)
it('accepts mouse wheel events #19992', function() 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 set number nostartofline nowrap mousescroll=hor:1,ver:1
call setline(1, repeat([join(range(10), '----')], 10)) call setline(1, repeat([join(range(10), '----')], 10))
vsplit vsplit
]], false) ]], {})
screen:expect([[ screen:expect([[
{11: 1 }{1:0}----1----2----3----4│{11: 1 }0----1----2----3----| {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----| {11: 2 }0----1----2----3----4│{11: 2 }0----1----2----3----|
@ -661,11 +662,11 @@ describe('TUI', function()
| |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
child_session:request('nvim_exec', [[ child_session:request('nvim_exec2', [[
tab split tab split
tabnew tabnew
highlight Tabline ctermbg=NONE ctermfg=NONE cterm=underline highlight Tabline ctermbg=NONE ctermfg=NONE cterm=underline
]], false) ]], {})
screen:expect([[ screen:expect([[
{12: + [No Name] + [No Name] }{3: [No Name] }{1: }{12:X}| {12: + [No Name] + [No Name] }{3: [No Name] }{1: }{12:X}|
{1: } | {1: } |
@ -720,7 +721,7 @@ describe('TUI', function()
end) end)
it('mouse events work with right-click menu', function() 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') call setline(1, 'popup menu test')
set mouse=a mousemodel=popup set mouse=a mousemodel=popup
@ -730,7 +731,7 @@ describe('TUI', function()
menu PopUp.baz :let g:menustr = 'baz'<CR> menu PopUp.baz :let g:menustr = 'baz'<CR>
highlight Pmenu ctermbg=NONE ctermfg=NONE cterm=underline,reverse highlight Pmenu ctermbg=NONE ctermfg=NONE cterm=underline,reverse
highlight PmenuSel ctermbg=NONE ctermfg=NONE cterm=underline,reverse,bold highlight PmenuSel ctermbg=NONE ctermfg=NONE cterm=underline,reverse,bold
]], false) ]], {})
meths.input_mouse('right', 'press', '', 0, 0, 4) meths.input_mouse('right', 'press', '', 0, 0, 4)
screen:expect([[ screen:expect([[
{1:p}opup menu test | {1:p}opup menu test |
@ -1584,11 +1585,11 @@ describe('TUI', function()
it('no stack-use-after-scope with cursor color #22432', function() it('no stack-use-after-scope with cursor color #22432', function()
screen:set_option('rgb', true) screen:set_option('rgb', true)
command('set termguicolors') command('set termguicolors')
child_session:request('nvim_exec', [[ child_session:request('nvim_exec2', [[
set tgc set tgc
hi Cursor guifg=Red guibg=Green hi Cursor guifg=Red guibg=Green
set guicursor=n:block-Cursor/lCursor set guicursor=n:block-Cursor/lCursor
]], false) ]], {})
screen:set_default_attr_ids({ screen:set_default_attr_ids({
[1] = {reverse = true}, [1] = {reverse = true},
[2] = {bold = true, foreground = Screen.colors.Blue}, [2] = {bold = true, foreground = Screen.colors.Blue},
@ -1808,10 +1809,10 @@ describe('TUI FocusGained/FocusLost', function()
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
child_session = helpers.connect(child_server) child_session = helpers.connect(child_server)
child_session:request('nvim_exec', [[ child_session:request('nvim_exec2', [[
autocmd FocusGained * echo 'gained' autocmd FocusGained * echo 'gained'
autocmd FocusLost * echo 'lost' autocmd FocusLost * echo 'lost'
]], false) ]], {})
feed_data("\034\016") -- CTRL-\ CTRL-N feed_data("\034\016") -- CTRL-\ CTRL-N
end) end)
@ -1842,7 +1843,7 @@ describe('TUI FocusGained/FocusLost', function()
end) end)
it('in insert-mode', function() it('in insert-mode', function()
feed_command('set noshowmode') feed_data(':set noshowmode\r')
feed_data('i') feed_data('i')
screen:expect{grid=[[ screen:expect{grid=[[
{1: } | {1: } |
@ -1907,11 +1908,11 @@ describe('TUI FocusGained/FocusLost', function()
-- Set up autocmds that modify the buffer, instead of just calling :echo. -- 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. -- This is how we can test handling of focus gained/lost during cmdline-mode.
-- See commit: 5cc87d4dabd02167117be7a978b5c8faaa975419. -- See commit: 5cc87d4dabd02167117be7a978b5c8faaa975419.
child_session:request('nvim_exec', [[ child_session:request('nvim_exec2', [[
autocmd! autocmd!
autocmd FocusLost * call append(line('$'), 'lost') autocmd FocusLost * call append(line('$'), 'lost')
autocmd FocusGained * call append(line('$'), 'gained') autocmd FocusGained * call append(line('$'), 'gained')
]], false) ]], {})
retry(2, 3 * screen.timeout, function() retry(2, 3 * screen.timeout, function()
-- Enter cmdline-mode. -- Enter cmdline-mode.
feed_data(':') feed_data(':')