test(terminal): fix incorrect TermClose test

The test may wipe the wrong buffer if :bdelete switches to another one.

Also remove the builtin TermClose autocommand. It doesn't affect the
tests for now, but still it's better to avoid its interference.

(cherry picked from commit d42fa1753a)
This commit is contained in:
zeertzjq
2026-01-05 13:58:47 +08:00
committed by github-actions[bot]
parent 77809f0d9c
commit 26db87652e

View File

@@ -20,13 +20,15 @@ describe('autocmd TermClose', function()
clear()
api.nvim_set_option_value('shell', testprg('shell-test'), {})
command('set shellcmdflag=EXE shellredir= shellpipe= shellquote= shellxquote=')
command('autocmd! nvim.terminal TermClose')
end)
local function test_termclose_delete_own_buf()
-- The terminal process needs to keep running so that TermClose isn't triggered immediately.
api.nvim_set_option_value('shell', string.format('"%s" INTERACT', testprg('shell-test')), {})
command('autocmd TermClose * bdelete!')
command('terminal')
local termbuf = api.nvim_get_current_buf()
command(('autocmd TermClose * bdelete! %d'):format(termbuf))
matches(
'^TermClose Autocommands for "%*": Vim%(bdelete%):E937: Attempt to delete a buffer that is in use: term://',
pcall_err(command, 'bdelete!')
@@ -34,8 +36,7 @@ describe('autocmd TermClose', function()
assert_alive()
end
-- TODO: fixed after merging patches for `can_unload_buffer`?
pending('TermClose deleting its own buffer, altbuf = buffer 1 #10386', function()
it('TermClose deleting its own buffer, altbuf = buffer 1 #10386', function()
test_termclose_delete_own_buf()
end)