fix(tests): needing two calls to setup a screen is cringe

Before calling "attach" a screen object is just a dummy container for
(row, col) values whose purpose is to be sent as part of the "attach"
function call anyway.

Just create the screen in an attached state directly. Keep the complete
(row, col, options) config together. It is still completely valid to
later detach and re-attach as needed, including to another session.
This commit is contained in:
bfredl
2024-11-11 22:15:19 +01:00
parent 40dee8a2dc
commit e61228a214
161 changed files with 128 additions and 606 deletions

View File

@@ -129,8 +129,6 @@ describe('eval-API', function()
end)
it('use buffer numbers and windows ids as handles', function()
local screen = Screen.new(40, 8)
screen:attach()
local bnr = eval("bufnr('')")
local bhnd = eval('nvim_get_current_buf()')
local wid = eval('win_getid()')
@@ -192,7 +190,6 @@ describe('eval-API', function()
it('are highlighted by vim.vim syntax file', function()
local screen = Screen.new(40, 8)
screen:attach()
command('set ft=vim')
command('set rtp^=build/runtime/')

View File

@@ -189,7 +189,6 @@ describe('uncaught exception', function()
it('multiline exception remains multiline #25350', function()
local screen = Screen.new(80, 11)
screen:attach()
exec_lua([[
function _G.Oops()
error("oops")
@@ -230,8 +229,7 @@ describe('listing functions using :function', function()
end)
it('does not crash if another function is deleted while listing', function()
local screen = Screen.new(80, 24)
screen:attach()
local _ = Screen.new(80, 24)
matches(
'Vim%(function%):E454: Function list was modified$',
pcall_err(
@@ -264,8 +262,7 @@ describe('listing functions using :function', function()
end)
it('does not crash if the same function is deleted while listing', function()
local screen = Screen.new(80, 24)
screen:attach()
local _ = Screen.new(80, 24)
matches(
'Vim%(function%):E454: Function list was modified$',
pcall_err(

View File

@@ -114,7 +114,6 @@ describe('execute()', function()
it('does not corrupt the command display #5422', function()
local screen = Screen.new(70, 7)
screen:attach()
feed(':echo execute("hi ErrorMsg")<CR>')
screen:expect(
[[
@@ -136,7 +135,6 @@ describe('execute()', function()
it('places cursor correctly #6035', function()
local screen = Screen.new(40, 6)
screen:attach()
source([=[
" test 1: non-silenced output goes as usual
function! Test1()
@@ -263,7 +261,6 @@ describe('execute()', function()
describe('{silent} argument', function()
it('captures & displays output for ""', function()
local screen = Screen.new(40, 5)
screen:attach()
command('let g:mes = execute("echon 42", "")')
screen:expect([[
^ |
@@ -287,7 +284,6 @@ describe('execute()', function()
it('captures but does not display output for "silent"', function()
local screen = Screen.new(40, 5)
screen:attach()
command('let g:mes = execute("echon 42")')
screen:expect([[
^ |

View File

@@ -4,6 +4,7 @@ local Screen = require('test.functional.ui.screen')
local clear = n.clear
local connect = n.connect
local get_session = n.get_session
local eq = t.eq
local fn = n.fn
local is_os = t.is_os
@@ -74,12 +75,12 @@ describe('has()', function()
it('"gui_running"', function()
eq(0, fn.has('gui_running'))
local tui = Screen.new(50, 15)
local tui_session = get_session()
local gui_session = connect(fn.serverstart())
local gui = Screen.new(50, 15)
eq(0, fn.has('gui_running'))
tui:attach({ ext_linegrid = true, rgb = true, stdin_tty = true, stdout_tty = true })
gui:attach({ ext_multigrid = true, rgb = true }, gui_session)
local tui = Screen.new(50, 5, { rgb = true, stdin_tty = true, stdout_tty = true }, tui_session)
eq(0, fn.has('gui_running'))
local gui = Screen.new(50, 15, { ext_multigrid = true, rgb = true }, gui_session)
eq(1, fn.has('gui_running'))
tui:detach()
eq(1, fn.has('gui_running'))

View File

@@ -17,7 +17,6 @@ local screen
before_each(function()
clear()
screen = Screen.new(25, 5)
screen:attach()
source([[
hi Test ctermfg=Red guifg=Red term=bold
function CustomCompl(...)

View File

@@ -174,7 +174,6 @@ describe('matchaddpos()', function()
end)
it('works with zero length', function()
local screen = Screen.new(40, 5)
screen:attach()
fn.setline(1, 'abcdef')
command('hi PreProc guifg=Red')
eq(4, fn.matchaddpos('PreProc', { { 1, 2, 0 } }, 3, 4))

View File

@@ -132,7 +132,6 @@ describe('system()', function()
before_each(function()
screen = Screen.new()
screen:attach()
end)
if is_os('win') then
@@ -430,11 +429,6 @@ describe('systemlist()', function()
before_each(function()
screen = Screen.new()
screen:attach()
end)
after_each(function()
screen:detach()
end)
it('`echo` and waits for its return', function()
@@ -567,7 +561,6 @@ describe('shell :!', function()
it(':{range}! with powershell filter/redirect #16271 #19250', function()
local screen = Screen.new(500, 8)
screen:attach()
local found = n.set_shell_powershell(true)
insert([[
3
@@ -598,7 +591,6 @@ describe('shell :!', function()
it(':{range}! without redirecting to buffer', function()
local screen = Screen.new(500, 10)
screen:attach()
insert([[
3
1

View File

@@ -108,7 +108,6 @@ describe('timers', function()
it('can invoke redraw in blocking getchar() call', function()
local screen = Screen.new(40, 6)
screen:attach()
api.nvim_buf_set_lines(0, 0, -1, true, { 'ITEM 1', 'ITEM 2' })
source([[
@@ -225,7 +224,6 @@ describe('timers', function()
it("doesn't mess up the cmdline", function()
local screen = Screen.new(40, 6)
screen:attach()
source([[
let g:val = 0
func! MyHandler(timer)
@@ -263,7 +261,6 @@ describe('timers', function()
it('can be triggered after an empty string <expr> mapping #17257', function()
local screen = Screen.new(40, 6)
screen:attach()
command([=[imap <expr> <F2> [timer_start(0, { _ -> execute("throw 'x'", "") }), ''][-1]]=])
feed('i<F2>')
screen:expect({ any = 'E605: Exception not caught: x' })