test: retry(): Report number of retries. (#6475)

tui_spec.lua: Retry the terminal-mode test.
This commit is contained in:
Justin M. Keyes 2017-04-09 02:11:08 +02:00 committed by GitHub
parent cd0a436622
commit a34408ef7f
2 changed files with 61 additions and 52 deletions

View File

@ -246,12 +246,13 @@ local function retry(max, max_ms, fn)
return result return result
end end
if (max and tries >= max) or (luv.now() - start_time > timeout) then if (max and tries >= max) or (luv.now() - start_time > timeout) then
break if type(result) == "string" then
result = "\nretry() attempts: "..tostring(tries).."\n"..result
end
error(result)
end end
tries = tries + 1 tries = tries + 1
end end
-- Do not use pcall() for the final attempt, let the failure bubble up.
return fn()
end end
local function clear(...) local function clear(...)

View File

@ -2,9 +2,10 @@
-- as a simple way to send keys and assert screen state. -- as a simple way to send keys and assert screen state.
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 feed = thelpers.feed_data local feed_data = thelpers.feed_data
local execute = helpers.execute local execute = helpers.execute
local nvim_dir = helpers.nvim_dir local nvim_dir = helpers.nvim_dir
local retry = helpers.retry
if helpers.pending_win32(pending) then return end if helpers.pending_win32(pending) then return end
@ -34,7 +35,7 @@ describe('tui', function()
end) end)
it('accepts basic utf-8 input', function() it('accepts basic utf-8 input', function()
feed('iabc\ntest1\ntest2') feed_data('iabc\ntest1\ntest2')
screen:expect([[ screen:expect([[
abc | abc |
test1 | test1 |
@ -44,7 +45,7 @@ describe('tui', function()
{3:-- INSERT --} | {3:-- INSERT --} |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
feed('\027') feed_data('\027')
screen:expect([[ screen:expect([[
abc | abc |
test1 | test1 |
@ -60,7 +61,7 @@ describe('tui', function()
local keys = 'dfghjkl' local keys = 'dfghjkl'
for c in keys:gmatch('.') do for c in keys:gmatch('.') do
execute('nnoremap <a-'..c..'> ialt-'..c..'<cr><esc>') execute('nnoremap <a-'..c..'> ialt-'..c..'<cr><esc>')
feed('\027'..c) feed_data('\027'..c)
end end
screen:expect([[ screen:expect([[
alt-j | alt-j |
@ -71,7 +72,7 @@ describe('tui', function()
| |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
feed('gg') feed_data('gg')
screen:expect([[ screen:expect([[
{1:a}lt-d | {1:a}lt-d |
alt-f | alt-f |
@ -90,7 +91,7 @@ describe('tui', function()
-- Example: for input ALT+j: -- Example: for input ALT+j:
-- * Vim (Nvim prior to #3982) sets high-bit, inserts "ê". -- * Vim (Nvim prior to #3982) sets high-bit, inserts "ê".
-- * Nvim (after #3982) inserts "j". -- * Nvim (after #3982) inserts "j".
feed('i\027j') feed_data('i\027j')
screen:expect([[ screen:expect([[
j{1: } | j{1: } |
{4:~ }| {4:~ }|
@ -103,10 +104,10 @@ describe('tui', function()
end) end)
it('accepts ascii control sequences', function() it('accepts ascii control sequences', function()
feed('i') feed_data('i')
feed('\022\007') -- ctrl+g feed_data('\022\007') -- ctrl+g
feed('\022\022') -- ctrl+v feed_data('\022\022') -- ctrl+v
feed('\022\013') -- ctrl+m feed_data('\022\013') -- ctrl+m
screen:expect([[ screen:expect([[
{9:^G^V^M}{1: } | {9:^G^V^M}{1: } |
{4:~ }| {4:~ }|
@ -119,7 +120,7 @@ describe('tui', function()
end) end)
it('automatically sends <Paste> for bracketed paste sequences', function() it('automatically sends <Paste> for bracketed paste sequences', function()
feed('i\027[200~') feed_data('i\027[200~')
screen:expect([[ screen:expect([[
{1: } | {1: } |
{4:~ }| {4:~ }|
@ -129,7 +130,7 @@ describe('tui', function()
{3:-- INSERT (paste) --} | {3:-- INSERT (paste) --} |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
feed('pasted from terminal') feed_data('pasted from terminal')
screen:expect([[ screen:expect([[
pasted from terminal{1: } | pasted from terminal{1: } |
{4:~ }| {4:~ }|
@ -139,7 +140,7 @@ describe('tui', function()
{3:-- INSERT (paste) --} | {3:-- INSERT (paste) --} |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
feed('\027[201~') feed_data('\027[201~')
screen:expect([[ screen:expect([[
pasted from terminal{1: } | pasted from terminal{1: } |
{4:~ }| {4:~ }|
@ -157,7 +158,7 @@ describe('tui', function()
for i = 1, 3000 do for i = 1, 3000 do
t[i] = 'item ' .. tostring(i) t[i] = 'item ' .. tostring(i)
end end
feed('i\027[200~'..table.concat(t, '\n')..'\027[201~') feed_data('i\027[200~'..table.concat(t, '\n')..'\027[201~')
screen:expect([[ screen:expect([[
item 2997 | item 2997 |
item 2998 | item 2998 |
@ -180,7 +181,7 @@ describe('tui with non-tty file descriptors', function()
it('can handle pipes as stdout and stderr', function() it('can handle pipes as stdout and stderr', function()
local screen = thelpers.screen_setup(0, '"'..helpers.nvim_prog local screen = thelpers.screen_setup(0, '"'..helpers.nvim_prog
..' -u NONE -i NONE --cmd \'set noswapfile noshowcmd noruler\' --cmd \'normal iabc\' > /dev/null 2>&1 && cat testF && rm testF"') ..' -u NONE -i NONE --cmd \'set noswapfile noshowcmd noruler\' --cmd \'normal iabc\' > /dev/null 2>&1 && cat testF && rm testF"')
feed(':w testF\n:q\n') feed_data(':w testF\n:q\n')
screen:expect([[ screen:expect([[
:w testF | :w testF |
:q | :q |
@ -200,12 +201,13 @@ describe('tui focus event handling', function()
helpers.clear() helpers.clear()
screen = thelpers.screen_setup(0, '["'..helpers.nvim_prog screen = thelpers.screen_setup(0, '["'..helpers.nvim_prog
..'", "-u", "NONE", "-i", "NONE", "--cmd", "set noswapfile noshowcmd noruler"]') ..'", "-u", "NONE", "-i", "NONE", "--cmd", "set noswapfile noshowcmd noruler"]')
execute('autocmd FocusGained * echo "gained"') feed_data(":autocmd FocusGained * echo 'gained'\n")
execute('autocmd FocusLost * echo "lost"') feed_data(":autocmd FocusLost * echo 'lost'\n")
feed_data("\034\016") -- CTRL-\ CTRL-N
end) end)
it('can handle focus events in normal mode', function() it('can handle focus events in normal mode', function()
feed('\027[I') feed_data('\027[I')
screen:expect([[ screen:expect([[
{1: } | {1: } |
{4:~ }| {4:~ }|
@ -216,7 +218,7 @@ describe('tui focus event handling', function()
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
feed('\027[O') feed_data('\027[O')
screen:expect([[ screen:expect([[
{1: } | {1: } |
{4:~ }| {4:~ }|
@ -230,8 +232,8 @@ describe('tui focus event handling', function()
it('can handle focus events in insert mode', function() it('can handle focus events in insert mode', function()
execute('set noshowmode') execute('set noshowmode')
feed('i') feed_data('i')
feed('\027[I') feed_data('\027[I')
screen:expect([[ screen:expect([[
{1: } | {1: } |
{4:~ }| {4:~ }|
@ -241,7 +243,7 @@ describe('tui focus event handling', function()
gained | gained |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
feed('\027[O') feed_data('\027[O')
screen:expect([[ screen:expect([[
{1: } | {1: } |
{4:~ }| {4:~ }|
@ -254,8 +256,8 @@ describe('tui focus event handling', function()
end) end)
it('can handle focus events in cmdline mode', function() it('can handle focus events in cmdline mode', function()
feed(':') feed_data(':')
feed('\027[I') feed_data('\027[I')
screen:expect([[ screen:expect([[
| |
{4:~ }| {4:~ }|
@ -265,7 +267,7 @@ describe('tui focus event handling', function()
g{1:a}ined | g{1:a}ined |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
feed('\027[O') feed_data('\027[O')
screen:expect([[ screen:expect([[
| |
{4:~ }| {4:~ }|
@ -278,30 +280,36 @@ describe('tui focus event handling', function()
end) end)
it('can handle focus events in terminal mode', function() it('can handle focus events in terminal mode', function()
execute('set shell='..nvim_dir..'/shell-test') feed_data(':set shell='..nvim_dir..'/shell-test\n')
execute('set laststatus=0') feed_data(':set noshowmode laststatus=0\n')
execute('set noshowmode')
execute('terminal') retry(2, 3 * screen.timeout, function()
feed('\027[I') feed_data(':terminal\n')
screen:expect([[ feed_data('\027[I')
ready $ | screen:expect([[
[Process exited 0]{1: } | ready $ |
| [Process exited 0]{1: } |
| |
| |
gained | |
{3:-- TERMINAL --} | gained |
]]) {3:-- TERMINAL --} |
feed('\027[O') ]])
screen:expect([[ feed_data('\027[O')
ready $ | screen:expect([[
[Process exited 0]{1: } | ready $ |
| [Process exited 0]{1: } |
| |
| |
lost | |
{3:-- TERMINAL --} | lost |
]]) {3:-- TERMINAL --} |
]])
-- If retry is needed...
feed_data("\034\016") -- CTRL-\ CTRL-N
feed_data(':bwipeout!\n')
end)
end) end)
end) end)