mirror of
https://github.com/neovim/neovim.git
synced 2025-12-13 18:12:50 +00:00
test: use poke_eventloop() instead of sleep(10) where possible (#19794)
Using sleep(10) to wait for typeahead to finish is flaky, especially on macOS, where legacy/global_spec.lua has failed several times.
This commit is contained in:
@@ -2,6 +2,7 @@ local helpers = require('test.functional.helpers')(after_each)
|
|||||||
local Screen = require('test.functional.ui.screen')
|
local Screen = require('test.functional.ui.screen')
|
||||||
local clear, feed, source = helpers.clear, helpers.feed, helpers.source
|
local clear, feed, source = helpers.clear, helpers.feed, helpers.source
|
||||||
local command = helpers.command
|
local command = helpers.command
|
||||||
|
local poke_eventloop = helpers.poke_eventloop
|
||||||
local sleep = helpers.sleep
|
local sleep = helpers.sleep
|
||||||
|
|
||||||
describe("CTRL-C (mapped)", function()
|
describe("CTRL-C (mapped)", function()
|
||||||
@@ -57,11 +58,9 @@ describe("CTRL-C (mapped)", function()
|
|||||||
it('interrupts :sleep', function()
|
it('interrupts :sleep', function()
|
||||||
command('nnoremap <C-C> <Nop>')
|
command('nnoremap <C-C> <Nop>')
|
||||||
feed(':sleep 100<CR>')
|
feed(':sleep 100<CR>')
|
||||||
-- wait for :sleep to start
|
poke_eventloop() -- wait for :sleep to start
|
||||||
sleep(10)
|
|
||||||
feed('foo<C-C>')
|
feed('foo<C-C>')
|
||||||
-- wait for input buffer to be flushed
|
poke_eventloop() -- wait for input buffer to be flushed
|
||||||
sleep(10)
|
|
||||||
feed('i')
|
feed('i')
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
^ |
|
^ |
|
||||||
@@ -77,10 +76,9 @@ describe("CTRL-C (mapped)", function()
|
|||||||
command('nnoremap <C-C> <Nop>')
|
command('nnoremap <C-C> <Nop>')
|
||||||
command('nmap <F2> <Ignore><F2>')
|
command('nmap <F2> <Ignore><F2>')
|
||||||
feed('<F2>')
|
feed('<F2>')
|
||||||
sleep(10)
|
sleep(10) -- wait for the key to enter typeahead
|
||||||
feed('foo<C-C>')
|
feed('foo<C-C>')
|
||||||
-- wait for input buffer to be flushed
|
poke_eventloop() -- wait for input buffer to be flushed
|
||||||
sleep(10)
|
|
||||||
feed('i')
|
feed('i')
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
^ |
|
^ |
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ local eq = helpers.eq
|
|||||||
local eval = helpers.eval
|
local eval = helpers.eval
|
||||||
local feed = helpers.feed
|
local feed = helpers.feed
|
||||||
local meths = helpers.meths
|
local meths = helpers.meths
|
||||||
local sleep = helpers.sleep
|
local poke_eventloop = helpers.poke_eventloop
|
||||||
|
|
||||||
before_each(clear)
|
before_each(clear)
|
||||||
|
|
||||||
@@ -143,7 +143,7 @@ describe('Ex mode', function()
|
|||||||
^ |
|
^ |
|
||||||
]])
|
]])
|
||||||
feed('<C-C>')
|
feed('<C-C>')
|
||||||
sleep(10) -- Wait for input to be flushed
|
poke_eventloop() -- Wait for input to be flushed
|
||||||
feed('foo<CR>')
|
feed('foo<CR>')
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
Entering Ex mode. Type "visual" to go to Normal mode. |
|
Entering Ex mode. Type "visual" to go to Normal mode. |
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ local Screen = require('test.functional.ui.screen')
|
|||||||
local clear = helpers.clear
|
local clear = helpers.clear
|
||||||
local exec = helpers.exec
|
local exec = helpers.exec
|
||||||
local feed = helpers.feed
|
local feed = helpers.feed
|
||||||
local sleep = helpers.sleep
|
local poke_eventloop = helpers.poke_eventloop
|
||||||
|
|
||||||
before_each(clear)
|
before_each(clear)
|
||||||
|
|
||||||
@@ -24,7 +24,7 @@ describe(':global', function()
|
|||||||
]])
|
]])
|
||||||
|
|
||||||
feed(':g/foo/norm :<C-V>;<CR>')
|
feed(':g/foo/norm :<C-V>;<CR>')
|
||||||
sleep(10) -- Wait for :sleep to start
|
poke_eventloop() -- Wait for :sleep to start
|
||||||
feed('<C-C>')
|
feed('<C-C>')
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
^foo |
|
^foo |
|
||||||
@@ -37,7 +37,7 @@ describe(':global', function()
|
|||||||
|
|
||||||
-- Also test in Ex mode
|
-- Also test in Ex mode
|
||||||
feed('gQg/foo/norm :<C-V>;<CR>')
|
feed('gQg/foo/norm :<C-V>;<CR>')
|
||||||
sleep(10) -- Wait for :sleep to start
|
poke_eventloop() -- Wait for :sleep to start
|
||||||
feed('<C-C>')
|
feed('<C-C>')
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
{0: }|
|
{0: }|
|
||||||
|
|||||||
@@ -131,11 +131,11 @@ describe('mapping', function()
|
|||||||
command('set selectmode=mouse')
|
command('set selectmode=mouse')
|
||||||
|
|
||||||
command('nnoremap <LeftDrag> <LeftDrag><Cmd><CR>')
|
command('nnoremap <LeftDrag> <LeftDrag><Cmd><CR>')
|
||||||
sleep(10)
|
poke_eventloop()
|
||||||
meths.input_mouse('left', 'press', '', 0, 0, 0)
|
meths.input_mouse('left', 'press', '', 0, 0, 0)
|
||||||
sleep(10)
|
poke_eventloop()
|
||||||
meths.input_mouse('left', 'drag', '', 0, 0, 1)
|
meths.input_mouse('left', 'drag', '', 0, 0, 1)
|
||||||
sleep(10)
|
poke_eventloop()
|
||||||
eq('s', eval('mode()'))
|
eq('s', eval('mode()'))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@@ -144,22 +144,22 @@ describe('mapping', function()
|
|||||||
|
|
||||||
command('inoremap <LeftDrag> <LeftDrag><Cmd>let g:dragged = 1<CR>')
|
command('inoremap <LeftDrag> <LeftDrag><Cmd>let g:dragged = 1<CR>')
|
||||||
feed('i')
|
feed('i')
|
||||||
sleep(10)
|
poke_eventloop()
|
||||||
meths.input_mouse('left', 'press', '', 0, 0, 0)
|
meths.input_mouse('left', 'press', '', 0, 0, 0)
|
||||||
sleep(10)
|
poke_eventloop()
|
||||||
meths.input_mouse('left', 'drag', '', 0, 0, 1)
|
meths.input_mouse('left', 'drag', '', 0, 0, 1)
|
||||||
sleep(10)
|
poke_eventloop()
|
||||||
eq(1, eval('g:dragged'))
|
eq(1, eval('g:dragged'))
|
||||||
eq('v', eval('mode()'))
|
eq('v', eval('mode()'))
|
||||||
feed([[<C-\><C-N>]])
|
feed([[<C-\><C-N>]])
|
||||||
|
|
||||||
command([[inoremap <LeftDrag> <LeftDrag><C-\><C-N>]])
|
command([[inoremap <LeftDrag> <LeftDrag><C-\><C-N>]])
|
||||||
feed('i')
|
feed('i')
|
||||||
sleep(10)
|
poke_eventloop()
|
||||||
meths.input_mouse('left', 'press', '', 0, 0, 0)
|
meths.input_mouse('left', 'press', '', 0, 0, 0)
|
||||||
sleep(10)
|
poke_eventloop()
|
||||||
meths.input_mouse('left', 'drag', '', 0, 0, 1)
|
meths.input_mouse('left', 'drag', '', 0, 0, 1)
|
||||||
sleep(10)
|
poke_eventloop()
|
||||||
eq('n', eval('mode()'))
|
eq('n', eval('mode()'))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user