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()
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)

View File

@ -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()

View File

@ -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('<Ignore>') -- 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('<Ignore>') -- 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'))

View File

@ -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', '<CR>')
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', '<Ignore>') -- 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.

View File

@ -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 |

View File

@ -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 <Esc> byte as ALT modifier in normal-mode', function()
local keys = 'dfghjkl'
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)
end
screen:expect([[
@ -281,9 +280,11 @@ describe('TUI', function()
end)
it('interprets <Esc>[27u as <Esc>', function()
feed_command('nnoremap <M-;> <Nop>')
feed_command('nnoremap <Esc> AESC<Esc>')
feed_command('nnoremap ; Asemicolon<Esc>')
child_session:request('nvim_exec2', [[
nnoremap <M-;> <Nop>
nnoremap <Esc> AESC<Esc>
nnoremap ; Asemicolon<Esc>
]], {})
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'<CR>
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(':')