tests/ui: remove unnecessary screen:detach()

It is perfectly fine and expected to detach from the screen just by
the UI disconnecting from nvim or exiting nvim. Just keep detach() in
screen_basic_spec, to get some coverage of the detach method itself.

This avoids hang on failure in many situations (though one could argue
that detach() should be "fast", or at least "as fast as resize",
which works in press-return already).

Never use detach() just to change the size of the screen, try_resize()
method exists for that specifically.
This commit is contained in:
Björn Linse
2019-10-13 20:18:22 +02:00
parent a330129a28
commit 4987311fb5
28 changed files with 14 additions and 171 deletions

View File

@@ -15,10 +15,6 @@ describe("update_menu notification", function()
screen:attach() screen:attach()
end) end)
after_each(function()
screen:detach()
end)
local function expect_sent(expected) local function expect_sent(expected)
screen:expect{condition=function() screen:expect{condition=function()
if screen.update_menu ~= expected then if screen.update_menu ~= expected then

View File

@@ -963,9 +963,6 @@ describe("pty process teardown", function()
| |
]]) ]])
end) end)
after_each(function()
screen:detach()
end)
it("does not prevent/delay exit. #4798 #4900", function() it("does not prevent/delay exit. #4798 #4900", function()
if helpers.pending_win32(pending) then return end if helpers.pending_win32(pending) then return end

View File

@@ -144,7 +144,6 @@ describe('eval-API', function()
{5:~ }| {5:~ }|
| |
]]) ]])
screen:detach()
end) end)
it('cannot be called from sandbox', function() it('cannot be called from sandbox', function()

View File

@@ -121,10 +121,6 @@ describe('system()', function()
screen:attach() screen:attach()
end) end)
after_each(function()
screen:detach()
end)
if iswin() then if iswin() then
local function test_more() local function test_more()
eq('root = true', eval([[get(split(system('"more" ".editorconfig"'), "\n"), 0, '')]])) eq('root = true', eval([[get(split(system('"more" ".editorconfig"'), "\n"), 0, '')]]))

View File

@@ -19,10 +19,6 @@ describe(":drop", function()
command("set laststatus=2 shortmess-=F") command("set laststatus=2 shortmess-=F")
end) end)
after_each(function()
screen:detach()
end)
it("works like :e when called with only one window open", function() it("works like :e when called with only one window open", function()
feed_command("drop tmp1.vim") feed_command("drop tmp1.vim")
screen:expect([[ screen:expect([[

View File

@@ -13,10 +13,6 @@ describe(':highlight', function()
screen:attach() screen:attach()
end) end)
after_each(function()
screen:detach()
end)
it('invalid color name', function() it('invalid color name', function()
eq('Vim(highlight):E421: Color name or number not recognized: ctermfg=#181818', eq('Vim(highlight):E421: Color name or number not recognized: ctermfg=#181818',
exc_exec("highlight normal ctermfg=#181818")) exc_exec("highlight normal ctermfg=#181818"))

View File

@@ -14,9 +14,6 @@ describe('folding', function()
screen = Screen.new(20, 8) screen = Screen.new(20, 8)
screen:attach() screen:attach()
end) end)
after_each(function()
screen:detach()
end)
it('creation, opening, moving (to the end) and closing', function() it('creation, opening, moving (to the end) and closing', function()
insert([[ insert([[

View File

@@ -17,7 +17,10 @@ describe('search cmdline', function()
screen = Screen.new(20, 3) screen = Screen.new(20, 3)
screen:attach() screen:attach()
screen:set_default_attr_ids({ screen:set_default_attr_ids({
inc = {reverse = true} inc = {reverse = true},
err = { foreground = Screen.colors.Grey100, background = Screen.colors.Red },
more = { bold = true, foreground = Screen.colors.SeaGreen4 },
tilde = { bold = true, foreground = Screen.colors.Blue1 },
}) })
end) end)
@@ -404,12 +407,7 @@ describe('search cmdline', function()
end) end)
it('keeps the view after deleting a char from the search', function() it('keeps the view after deleting a char from the search', function()
screen:detach() screen:try_resize(20, 6)
screen = Screen.new(20, 6)
screen:attach()
screen:set_default_attr_ids({
inc = {reverse = true},
})
tenlines() tenlines()
feed('/foo') feed('/foo')
@@ -445,14 +443,7 @@ describe('search cmdline', function()
end) end)
it('restores original view after failed search', function() it('restores original view after failed search', function()
screen:detach() screen:try_resize(40, 3)
screen = Screen.new(40, 3)
screen:attach()
screen:set_default_attr_ids({
inc = {reverse = true},
err = { foreground = Screen.colors.Grey100, background = Screen.colors.Red },
more = { bold = true, foreground = Screen.colors.SeaGreen4 },
})
tenlines() tenlines()
feed('0') feed('0')
feed('/foo') feed('/foo')
@@ -481,15 +472,7 @@ describe('search cmdline', function()
it("CTRL-G with 'incsearch' and ? goes in the right direction", function() it("CTRL-G with 'incsearch' and ? goes in the right direction", function()
-- oldtest: Test_search_cmdline4(). -- oldtest: Test_search_cmdline4().
screen:detach() screen:try_resize(40, 4)
screen = Screen.new(40, 4)
screen:attach()
screen:set_default_attr_ids({
inc = {reverse = true},
err = { foreground = Screen.colors.Grey100, background = Screen.colors.Red },
more = { bold = true, foreground = Screen.colors.SeaGreen4 },
tilde = { bold = true, foreground = Screen.colors.Blue1 },
})
command('enew!') command('enew!')
funcs.setline(1, {' 1 the first', ' 2 the second', ' 3 the third'}) funcs.setline(1, {' 1 the first', ' 2 the second', ' 3 the third'})
command('set laststatus=0 shortmess+=s') command('set laststatus=0 shortmess+=s')

View File

@@ -16,10 +16,6 @@ describe("'fillchars'", function()
screen:attach() screen:attach()
end) end)
after_each(function()
screen:detach()
end)
local function shouldfail(val,errval) local function shouldfail(val,errval)
errval = errval or val errval = errval or val
eq('Vim(set):E474: Invalid argument: fillchars='..errval, eq('Vim(set):E474: Invalid argument: fillchars='..errval,
@@ -100,10 +96,6 @@ describe("'listchars'", function()
screen:attach() screen:attach()
end) end)
after_each(function()
screen:detach()
end)
it('is local to window', function() it('is local to window', function()
feed('i<tab><tab><tab><esc>') feed('i<tab><tab><tab><esc>')
command('set laststatus=0') command('set laststatus=0')

View File

@@ -25,10 +25,6 @@ describe(':Man', function()
screen:attach() screen:attach()
end) end)
after_each(function()
screen:detach()
end)
it('clears backspaces from text and adds highlights', function() it('clears backspaces from text and adds highlights', function()
rawfeed([[ rawfeed([[
ithis i<C-v><C-h>is<C-v><C-h>s a<C-v><C-h>a test ithis i<C-v><C-h>is<C-v><C-h>s a<C-v><C-h>a test

View File

@@ -31,10 +31,6 @@ describe(':terminal mouse', function()
]]) ]])
end) end)
after_each(function()
screen:detach()
end)
describe('when the terminal has focus', function() describe('when the terminal has focus', function()
it('will exit focus on mouse-scroll', function() it('will exit focus on mouse-scroll', function()
eq('t', eval('mode()')) eq('t', eval('mode()'))

View File

@@ -21,10 +21,6 @@ describe(':terminal scrollback', function()
screen = thelpers.screen_setup(nil, nil, 30) screen = thelpers.screen_setup(nil, nil, 30)
end) end)
after_each(function()
screen:detach()
end)
describe('when the limit is exceeded', function() describe('when the limit is exceeded', function()
before_each(function() before_each(function()
local lines = {} local lines = {}
@@ -406,8 +402,6 @@ describe("'scrollback' option", function()
feed_data(nvim_dir..'/shell-test REP 31 line'..(iswin() and '\r' or '\n')) feed_data(nvim_dir..'/shell-test REP 31 line'..(iswin() and '\r' or '\n'))
screen:expect{any='30: line '} screen:expect{any='30: line '}
retry(nil, nil, function() expect_lines(7) end) retry(nil, nil, function() expect_lines(7) end)
screen:detach()
end) end)
it('deletes lines (only) if necessary', function() it('deletes lines (only) if necessary', function()
@@ -464,8 +458,6 @@ describe("'scrollback' option", function()
-- Verify off-screen state -- Verify off-screen state
eq((iswin() and '36: line' or '35: line'), eval("getline(line('w0') - 1)")) eq((iswin() and '36: line' or '35: line'), eval("getline(line('w0') - 1)"))
eq((iswin() and '27: line' or '26: line'), eval("getline(line('w0') - 10)")) eq((iswin() and '27: line' or '26: line'), eval("getline(line('w0') - 10)"))
screen:detach()
end) end)
it('defaults to 10000 in :terminal buffers', function() it('defaults to 10000 in :terminal buffers', function()

View File

@@ -45,10 +45,6 @@ describe('TUI', function()
child_session = helpers.connect(child_server) child_session = helpers.connect(child_server)
end) end)
after_each(function()
screen:detach()
end)
-- Wait for mode in the child Nvim (avoid "typeahead race" #10826). -- Wait for mode in the child Nvim (avoid "typeahead race" #10826).
local function wait_for_mode(mode) local function wait_for_mode(mode)
retry(nil, nil, function() retry(nil, nil, function()

View File

@@ -37,10 +37,6 @@ describe('Buffer highlighting', function()
}) })
end) end)
after_each(function()
screen:detach()
end)
local add_highlight = curbufmeths.add_highlight local add_highlight = curbufmeths.add_highlight
local clear_namespace = curbufmeths.clear_namespace local clear_namespace = curbufmeths.clear_namespace

View File

@@ -25,10 +25,6 @@ local function test_cmdline(linegrid)
screen = new_screen({rgb=true, ext_cmdline=true, ext_linegrid=linegrid}) screen = new_screen({rgb=true, ext_cmdline=true, ext_linegrid=linegrid})
end) end)
after_each(function()
screen:detach()
end)
it('works', function() it('works', function()
feed(':') feed(':')
screen:expect{grid=[[ screen:expect{grid=[[
@@ -804,10 +800,6 @@ describe('cmdline redraw', function()
screen = new_screen({rgb=true}) screen = new_screen({rgb=true})
end) end)
after_each(function()
screen:detach()
end)
it('with timer', function() it('with timer', function()
feed(':012345678901234567890123456789') feed(':012345678901234567890123456789')
screen:expect{grid=[[ screen:expect{grid=[[

View File

@@ -13,10 +13,6 @@ describe('ui/cursor', function()
screen:attach() screen:attach()
end) end)
after_each(function()
screen:detach()
end)
it("'guicursor' is published as a UI event", function() it("'guicursor' is published as a UI event", function()
local expected_mode_info = { local expected_mode_info = {
[1] = { [1] = {

View File

@@ -24,10 +24,6 @@ describe("folded lines", function()
}) })
end) end)
after_each(function()
screen:detach()
end)
it("work with more than one signcolumn", function() it("work with more than one signcolumn", function()
command("set signcolumn=yes:9") command("set signcolumn=yes:9")
feed("i<cr><esc>") feed("i<cr><esc>")

View File

@@ -35,7 +35,6 @@ describe('highlight: `:syntax manual`', function()
end) end)
after_each(function() after_each(function()
screen:detach()
os.remove('Xtest-functional-ui-highlight.tmp.vim') os.remove('Xtest-functional-ui-highlight.tmp.vim')
end) end)
@@ -97,10 +96,6 @@ describe('highlight defaults', function()
command("set display-=msgsep") command("set display-=msgsep")
end) end)
after_each(function()
screen:detach()
end)
it('window status bar', function() it('window status bar', function()
screen:set_default_attr_ids({ screen:set_default_attr_ids({
[0] = {bold=true, foreground=Screen.colors.Blue}, [0] = {bold=true, foreground=Screen.colors.Blue},
@@ -346,17 +341,10 @@ describe('highlight defaults', function()
end) end)
describe('highlight', function() describe('highlight', function()
local screen before_each(clear)
before_each(function()
clear()
screen = Screen.new(25,10)
screen:attach()
end)
it('visual', function() it('visual', function()
screen:detach() local screen = Screen.new(20,4)
screen = Screen.new(20,4)
screen:attach() screen:attach()
screen:set_default_attr_ids({ screen:set_default_attr_ids({
[1] = {background = Screen.colors.LightGrey}, [1] = {background = Screen.colors.LightGrey},
@@ -389,8 +377,7 @@ describe('highlight', function()
end) end)
it('cterm=standout gui=standout', function() it('cterm=standout gui=standout', function()
screen:detach() local screen = Screen.new(20,5)
screen = Screen.new(20,5)
screen:attach() screen:attach()
screen:set_default_attr_ids({ screen:set_default_attr_ids({
[1] = {bold = true, foreground = Screen.colors.Blue1}, [1] = {bold = true, foreground = Screen.colors.Blue1},
@@ -413,8 +400,7 @@ describe('highlight', function()
end) end)
it('strikethrough', function() it('strikethrough', function()
screen:detach() local screen = Screen.new(25,6)
screen = Screen.new(25,6)
screen:attach() screen:attach()
feed_command('syntax on') feed_command('syntax on')
feed_command('syn keyword TmpKeyword foo') feed_command('syn keyword TmpKeyword foo')
@@ -439,8 +425,7 @@ describe('highlight', function()
end) end)
it('nocombine', function() it('nocombine', function()
screen:detach() local screen = Screen.new(25,6)
screen = Screen.new(25,6)
screen:set_default_attr_ids{ screen:set_default_attr_ids{
[1] = {foreground = Screen.colors.SlateBlue, underline = true}, [1] = {foreground = Screen.colors.SlateBlue, underline = true},
[2] = {bold = true, foreground = Screen.colors.Blue1}, [2] = {bold = true, foreground = Screen.colors.Blue1},
@@ -487,6 +472,8 @@ describe('highlight', function()
end) end)
it('guisp (special/undercurl)', function() it('guisp (special/undercurl)', function()
local screen = Screen.new(25,10)
screen:attach()
feed_command('syntax on') feed_command('syntax on')
feed_command('syn keyword TmpKeyword neovim') feed_command('syn keyword TmpKeyword neovim')
feed_command('syn keyword TmpKeyword1 special') feed_command('syn keyword TmpKeyword1 special')
@@ -542,10 +529,6 @@ describe("'listchars' highlight", function()
screen:attach() screen:attach()
end) end)
after_each(function()
screen:detach()
end)
it("'cursorline' and 'cursorcolumn'", function() it("'cursorline' and 'cursorcolumn'", function()
screen:set_default_attr_ids({ screen:set_default_attr_ids({
[0] = {bold=true, foreground=Screen.colors.Blue}, [0] = {bold=true, foreground=Screen.colors.Blue},

View File

@@ -556,7 +556,6 @@ describe(":substitute, 'inccommand' preserves undo", function()
]]) ]])
end end
end end
screen:detach()
end) end)
it('with undolevels=2', function() it('with undolevels=2', function()
@@ -647,7 +646,6 @@ describe(":substitute, 'inccommand' preserves undo", function()
Already ...t change | Already ...t change |
]]) ]])
end end
screen:detach()
end end
end) end)
@@ -713,7 +711,6 @@ describe(":substitute, 'inccommand' preserves undo", function()
Already ...t change | Already ...t change |
]]) ]])
end end
screen:detach()
end) end)
end) end)
@@ -726,10 +723,6 @@ describe(":substitute, inccommand=split", function()
common_setup(screen, "split", default_text .. default_text) common_setup(screen, "split", default_text .. default_text)
end) end)
after_each(function()
screen:detach()
end)
it("preserves 'modified' buffer flag", function() it("preserves 'modified' buffer flag", function()
feed_command("set nomodified") feed_command("set nomodified")
feed(":%s/tw") feed(":%s/tw")
@@ -1241,10 +1234,6 @@ describe("inccommand=nosplit", function()
common_setup(screen, "nosplit", default_text .. default_text) common_setup(screen, "nosplit", default_text .. default_text)
end) end)
after_each(function()
if screen then screen:detach() end
end)
it("works with :smagic, :snomagic", function() it("works with :smagic, :snomagic", function()
feed_command("set hlsearch") feed_command("set hlsearch")
insert("Line *.3.* here") insert("Line *.3.* here")
@@ -1719,10 +1708,6 @@ describe("'inccommand' split windows", function()
common_setup(screen, "split", default_text) common_setup(screen, "split", default_text)
end end
after_each(function()
screen:detach()
end)
it('work after more splits', function() it('work after more splits', function()
refresh() refresh()

View File

@@ -40,10 +40,6 @@ describe('ui/mouse/input', function()
]]) ]])
end) end)
after_each(function()
screen:detach()
end)
it('single left click moves cursor', function() it('single left click moves cursor', function()
feed('<LeftMouse><2,1>') feed('<LeftMouse><2,1>')
screen:expect([[ screen:expect([[

View File

@@ -21,10 +21,6 @@ describe("multibyte rendering", function()
}) })
end) end)
after_each(function()
screen:detach()
end)
it("works with composed char at start of line", function() it("works with composed char at start of line", function()
insert([[ insert([[
̊ ̊
@@ -131,10 +127,6 @@ describe('multibyte rendering: statusline', function()
command('set laststatus=2') command('set laststatus=2')
end) end)
after_each(function()
screen:detach()
end)
it('last char shows (multibyte)', function() it('last char shows (multibyte)', function()
command('set statusline=你好') command('set statusline=你好')
screen:expect([[ screen:expect([[

View File

@@ -37,10 +37,6 @@ describe('ext_multigrid', function()
}) })
end) end)
after_each(function()
screen:detach()
end)
it('default initial screen', function() it('default initial screen', function()
screen:expect{grid=[[ screen:expect{grid=[[
## grid 1 ## grid 1

View File

@@ -40,10 +40,6 @@ describe('ui receives option updates', function()
return defaults return defaults
end end
after_each(function()
screen:detach()
end)
it("for defaults", function() it("for defaults", function()
local expected = reset() local expected = reset()
screen:expect(function() screen:expect(function()

View File

@@ -31,7 +31,6 @@ describe("shell command :!", function()
after_each(function() after_each(function()
child_session.feed_data("\3") -- Ctrl-C child_session.feed_data("\3") -- Ctrl-C
screen:detach()
end) end)
it("displays output without LF/EOF. #4646 #4569 #3772", function() it("displays output without LF/EOF. #4646 #4569 #3772", function()

View File

@@ -26,10 +26,6 @@ describe('Signs', function()
} ) } )
end) end)
after_each(function()
screen:detach()
end)
describe(':sign place', function() describe(':sign place', function()
it('allows signs with combining characters', function() it('allows signs with combining characters', function()
feed('ia<cr>b<cr><esc>') feed('ia<cr>b<cr><esc>')

View File

@@ -20,10 +20,6 @@ describe("'spell'", function()
}) })
end) end)
after_each(function()
screen:detach()
end)
it('joins long lines #7937', function() it('joins long lines #7937', function()
feed_command('set spell') feed_command('set spell')
insert([[ insert([[

View File

@@ -22,10 +22,6 @@ describe('Screen', function()
} ) } )
end) end)
after_each(function()
screen:detach()
end)
describe("match and conceal", function() describe("match and conceal", function()
before_each(function() before_each(function()

View File

@@ -17,10 +17,6 @@ describe('ui/ext_tabline', function()
end) end)
end) end)
after_each(function()
screen:detach()
end)
it('publishes UI events', function() it('publishes UI events', function()
command("tabedit another-tab") command("tabedit another-tab")