commit 5eb1c4df54e296579f86f675d7efe04a66106799
parent 5d6846c389a0ec3ba236537d82853277269268a6
Author: glepnir <glephunter@gmail.com>
Date: Tue, 24 Feb 2026 20:15:24 +0800
refactor(test): avoid deprecated functions #37017
Problem:
Tests are using some deprecated functions.
Solution:
Replace with command, pcall_err, etc.
Diffstat:
2 files changed, 63 insertions(+), 80 deletions(-)
diff --git a/test/functional/plugin/lsp/completion_spec.lua b/test/functional/plugin/lsp/completion_spec.lua
@@ -1351,6 +1351,24 @@ describe('vim.lsp.completion: integration', function()
end)
end)
+ local assert_cleanup_after_detach = function(client_id)
+ exec_lua(function()
+ vim.lsp.buf_detach_client(0, client_id)
+ end)
+ -- After detach, trigger and verify this client no longer contributes
+ exec_lua(function()
+ vim.lsp.completion.get()
+ end)
+ retry(nil, nil, function()
+ eq(
+ 0,
+ exec_lua(function()
+ return vim.fn.pumvisible()
+ end)
+ )
+ end)
+ end
+
it('puts cursor at the end of completed word', function()
local completion_list = {
isIncomplete = false,
@@ -1365,7 +1383,7 @@ describe('vim.lsp.completion: integration', function()
exec_lua(function()
vim.o.completeopt = 'menuone,noselect'
end)
- create_server('dummy', completion_list)
+ local client_id = create_server('dummy', completion_list)
feed('i world<esc>0ih<c-x><c-o>')
retry(nil, nil, function()
eq(
@@ -1394,9 +1412,10 @@ describe('vim.lsp.completion: integration', function()
return vim.api.nvim_win_get_cursor(0)[2]
end)
)
+ assert_cleanup_after_detach(client_id)
end)
- it('#clear multiple-lines word', function()
+ it('clear multiple-lines word', function()
local completion_list = {
isIncomplete = false,
items = {
@@ -1412,7 +1431,7 @@ describe('vim.lsp.completion: integration', function()
exec_lua(function()
vim.o.completeopt = 'menuone,noselect'
end)
- create_server('dummy', completion_list)
+ local client_id = create_server('dummy', completion_list)
feed('Sif true <C-X><C-O>')
retry(nil, nil, function()
eq(
@@ -1432,6 +1451,7 @@ describe('vim.lsp.completion: integration', function()
}
end)
)
+ assert_cleanup_after_detach(client_id)
end)
it('prepends prefix for items with different start positions', function()
@@ -1451,7 +1471,7 @@ describe('vim.lsp.completion: integration', function()
exec_lua(function()
vim.o.completeopt = 'menu,menuone,noinsert'
end)
- create_server('dummy', completion_list)
+ local client_id = create_server('dummy', completion_list)
feed('Adiv.foo<C-x><C-O>')
retry(nil, nil, function()
eq(
@@ -1464,6 +1484,7 @@ describe('vim.lsp.completion: integration', function()
feed('<C-Y>')
eq('<div class="foo"></div>', n.api.nvim_get_current_line())
eq({ 1, 17 }, n.api.nvim_win_get_cursor(0))
+ assert_cleanup_after_detach(client_id)
end)
it('does not empty server start boundary', function()
@@ -1567,45 +1588,6 @@ describe('vim.lsp.completion: integration', function()
feed('<C-y>')
eq('w-1/2', n.api.nvim_get_current_line())
end)
- it('removes client from triggers and clients table on LspDetach', function()
- local list1 = {
- isIncomplete = false,
- items = { { label = 'foo' } },
- }
- local list2 = {
- isIncomplete = false,
- items = { { label = 'bar' } },
- }
- local id1 = create_server('dummy1', list1, { trigger_chars = { '.' } })
- local id2 = create_server('dummy2', list2, { trigger_chars = { '.' } })
- n.command('set cot=menuone,menu')
- local function assert_matches(expected)
- retry(nil, nil, function()
- eq(
- 1,
- exec_lua(function()
- return vim.fn.pumvisible()
- end)
- )
- end)
- eq(expected, n.api.nvim_get_current_line())
- end
- feed('Sw.')
- assert_matches('w.foo')
- exec_lua('vim.lsp.buf_detach_client(0, ' .. id1 .. ')')
- feed('<ESC>Sw.')
- assert_matches('w.bar')
- exec_lua('vim.lsp.buf_detach_client(0, ' .. id2 .. ')')
- feed('<ESC>Sw.')
- retry(nil, nil, function()
- eq(
- 0,
- exec_lua(function()
- return vim.fn.pumvisible()
- end)
- )
- end)
- end)
end)
describe("vim.lsp.completion: omnifunc + 'autocomplete'", function()
diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua
@@ -7,7 +7,7 @@ local assert_alive = n.assert_alive
local feed, clear = n.feed, n.clear
local poke_eventloop = n.poke_eventloop
local nvim_prog = n.nvim_prog
-local eval, feed_command, source = n.eval, n.feed_command, n.source
+local eval, source = n.eval, n.source
local pcall_err = t.pcall_err
local eq, neq = t.eq, t.neq
local api = n.api
@@ -15,7 +15,6 @@ local retry = t.retry
local testprg = n.testprg
local write_file = t.write_file
local command = n.command
-local exc_exec = n.exc_exec
local matches = t.matches
local exec_lua = n.exec_lua
local sleep = vim.uv.sleep
@@ -110,28 +109,28 @@ describe(':terminal buffer', function()
it('sends data to the terminal when the "put" operator is used', function()
feed('<c-\\><c-n>gg"ayj')
- feed_command('let @a = "appended " . @a')
+ fn.setreg('a', 'appended ' .. fn.getreg('a'))
feed('"ap"ap')
screen:expect([[
^tty ready |
appended tty ready |*2
|
|*2
- :let @a = "appended " . @a |
+ |
]])
-- operator count is also taken into consideration
feed('3"ap')
screen:expect([[
^tty ready |
appended tty ready |*5
- :let @a = "appended " . @a |
+ |
]])
end)
it('sends data to the terminal when the ":put" command is used', function()
feed('<c-\\><c-n>gg"ayj')
- feed_command('let @a = "appended " . @a')
- feed_command('put a')
+ fn.setreg('a', 'appended ' .. fn.getreg('a'))
+ feed(':put a<CR>')
screen:expect([[
^tty ready |
appended tty ready |
@@ -140,7 +139,7 @@ describe(':terminal buffer', function()
:put a |
]])
-- line argument is only used to move the cursor
- feed_command('6put a')
+ feed(':6put a<CR>')
screen:expect([[
tty ready |
appended tty ready |*2
@@ -158,7 +157,7 @@ describe(':terminal buffer', function()
{100:~ }|*5
:bd! |
]])
- feed_command('bnext')
+ feed(':bnext<CR>')
screen:expect([[
^ |
{100:~ }|*5
@@ -197,24 +196,24 @@ describe(':terminal buffer', function()
]])
neq(tbuf, eval('bufnr("%")'))
- feed_command('quit!') -- Should exit the new window, not the terminal.
+ command('quit!') -- Should exit the new window, not the terminal.
eq(tbuf, eval('bufnr("%")'))
end)
describe('handles confirmations', function()
it('with :confirm', function()
feed('<c-\\><c-n>')
- feed_command('confirm bdelete')
+ feed(':confirm bdelete<CR>')
screen:expect { any = 'Close "term://' }
end)
it('with &confirm', function()
feed('<c-\\><c-n>')
- feed_command('bdelete')
+ feed(':bdelete<CR>')
screen:expect { any = 'E89' }
feed('<cr>')
eq('terminal', eval('&buftype'))
- feed_command('set confirm | bdelete')
+ feed(':set confirm | bdelete<CR>')
screen:expect { any = 'Close "term://' }
feed('y')
neq('terminal', eval('&buftype'))
@@ -235,13 +234,13 @@ describe(':terminal buffer', function()
end)
it('requires bang (!) to close a running job #15402', function()
- eq('Vim(wqall):E948: Job still running (add ! to end the job)', exc_exec('wqall'))
+ eq('Vim(wqall):E948: Job still running (add ! to end the job)', pcall_err(command, 'wqall'))
for _, cmd in ipairs({ 'bdelete', '%bdelete', 'bwipeout', 'bunload' }) do
matches(
'^Vim%('
.. cmd:gsub('%%', '')
.. '%):E89: term://.*tty%-test.* will be killed %(add %! to override%)$',
- exc_exec(cmd)
+ pcall_err(command, cmd)
)
end
command('call jobstop(&channel)')
@@ -263,7 +262,7 @@ describe(':terminal buffer', function()
it('does not segfault when pasting empty register #13955', function()
feed('<c-\\><c-n>')
- feed_command('put a') -- register a is empty
+ command('put a') -- register a is empty
n.assert_alive()
end)
@@ -931,19 +930,18 @@ describe(':terminal buffer', function()
finally(function()
os.remove(testfilename)
end)
- feed_command('edit ' .. testfilename)
+ feed(':edit ' .. testfilename .. '<CR>')
-- Move cursor away from the beginning of the line
feed('$')
-- Let jobstart(…,{term=true}) modify the buffer
- feed_command([[call jobstart("echo", {'term':v:true})]])
+ fn.jobstart('echo', { term = true })
assert_alive()
- feed_command('bdelete!')
+ command('bdelete!')
end)
it('no heap-buffer-overflow when sending long line with nowrap #11548', function()
- feed_command('set nowrap')
- feed_command('autocmd TermOpen * startinsert')
- feed_command('call feedkeys("4000ai\\<esc>:terminal!\\<cr>")')
+ command('set nowrap | autocmd TermOpen * startinsert')
+ feed(':call feedkeys("4000ai\\<esc>:terminal!\\<cr>")<CR>')
assert_alive()
end)
@@ -1432,18 +1430,21 @@ describe('on_lines does not emit out-of-bounds line indexes when', function()
end)
it('creating a terminal buffer #16394', function()
- feed_command('autocmd TermOpen * ++once call v:lua.register_callback(str2nr(expand("<abuf>")))')
- feed_command('terminal')
+ command('autocmd TermOpen * ++once call v:lua.register_callback(str2nr(expand("<abuf>")))')
+ command('terminal')
sleep(500)
eq('', exec_lua([[return _G.cb_error]]))
end)
it('deleting a terminal buffer #16394', function()
- feed_command('terminal')
+ command('terminal')
sleep(500)
- feed_command('lua _G.register_callback(0)')
- feed_command('bdelete!')
- eq('', exec_lua([[return _G.cb_error]]))
+ local cb_error = exec_lua([[
+ _G.register_callback(0)
+ vim.cmd('bdelete!')
+ return _G.cb_error
+ ]])
+ eq('', cb_error)
end)
end)
@@ -1621,7 +1622,7 @@ if is_os('win') then
before_each(function()
clear()
- feed_command('set modifiable swapfile undolevels=20')
+ command('set modifiable swapfile undolevels=20')
poke_eventloop()
local cmd = { 'cmd.exe', '/K', 'PROMPT=$g$s' }
screen = tt.setup_screen(nil, cmd)
@@ -1629,8 +1630,8 @@ if is_os('win') then
it('"put" operator sends data normally', function()
feed('<c-\\><c-n>G')
- feed_command('let @a = ":: tty ready"')
- feed_command('let @a = @a . "\\n:: appended " . @a . "\\n\\n"')
+ local s = ':: tty ready'
+ fn.setreg('a', s .. '\n:: appended ' .. s .. '\n\n')
feed('"ap"ap')
screen:expect([[
|
@@ -1639,7 +1640,7 @@ if is_os('win') then
> :: tty ready |
> :: appended :: tty ready |
^> |
- :let @a = @a . "\n:: appended " . @a . "\n\n" |
+ |
]])
-- operator count is also taken into consideration
feed('3"ap')
@@ -1650,15 +1651,15 @@ if is_os('win') then
> :: tty ready |
> :: appended :: tty ready |
^> |
- :let @a = @a . "\n:: appended " . @a . "\n\n" |
+ |
]])
end)
it('":put" command sends data normally', function()
feed('<c-\\><c-n>G')
- feed_command('let @a = ":: tty ready"')
- feed_command('let @a = @a . "\\n:: appended " . @a . "\\n\\n"')
- feed_command('put a')
+ local s = ':: tty ready'
+ fn.setreg('a', s .. '\n:: appended ' .. s .. '\n\n')
+ feed(':put a<CR>')
screen:expect([[
|
> :: tty ready |
@@ -1669,7 +1670,7 @@ if is_os('win') then
:put a |
]])
-- line argument is only used to move the cursor
- feed_command('6put a')
+ feed(':6put a<CR>')
screen:expect([[
|
> :: tty ready |