From 26db87652ed2a344ab5e59ebc562caf33ec40f32 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 5 Jan 2026 13:58:47 +0800 Subject: [PATCH] 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 d42fa1753adc18c4b22577724a804d556a16d736) --- test/functional/autocmd/termxx_spec.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/functional/autocmd/termxx_spec.lua b/test/functional/autocmd/termxx_spec.lua index 6841344aa4..d3d7e02fbe 100644 --- a/test/functional/autocmd/termxx_spec.lua +++ b/test/functional/autocmd/termxx_spec.lua @@ -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)