2021-11-10 18:34:23 -07:00
|
|
|
local helpers = require('test.functional.helpers')(after_each)
|
2022-03-12 00:22:55 -07:00
|
|
|
local Screen = require('test.functional.ui.screen')
|
2021-11-10 18:34:23 -07:00
|
|
|
local clear = helpers.clear
|
|
|
|
local eq = helpers.eq
|
2022-03-12 00:22:55 -07:00
|
|
|
local eval = helpers.eval
|
2021-11-10 18:34:23 -07:00
|
|
|
local command = helpers.command
|
2021-11-11 19:27:11 -07:00
|
|
|
local pcall_err = helpers.pcall_err
|
2021-11-10 18:34:23 -07:00
|
|
|
local feed = helpers.feed
|
|
|
|
local poke_eventloop = helpers.poke_eventloop
|
|
|
|
|
2022-03-12 00:22:55 -07:00
|
|
|
describe('terminal channel is closed and later released if', function()
|
|
|
|
local screen
|
|
|
|
|
|
|
|
before_each(function()
|
|
|
|
clear()
|
|
|
|
screen = Screen.new()
|
|
|
|
screen:attach()
|
|
|
|
end)
|
2021-11-10 18:34:23 -07:00
|
|
|
|
|
|
|
it('opened by nvim_open_term() and deleted by :bdelete!', function()
|
|
|
|
command([[let id = nvim_open_term(0, {})]])
|
2022-03-12 00:22:55 -07:00
|
|
|
local chans = eval('len(nvim_list_chans())')
|
|
|
|
-- channel hasn't been released yet
|
|
|
|
eq("Vim(call):Can't send data to closed stream",
|
|
|
|
pcall_err(command, [[bdelete! | call chansend(id, 'test')]]))
|
|
|
|
-- channel has been released after one main loop iteration
|
|
|
|
eq(chans - 1, eval('len(nvim_list_chans())'))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('opened by nvim_open_term(), closed by chanclose(), and deleted by pressing a key', function()
|
|
|
|
command('let id = nvim_open_term(0, {})')
|
|
|
|
local chans = eval('len(nvim_list_chans())')
|
|
|
|
-- channel has been closed but not released
|
|
|
|
eq("Vim(call):Can't send data to closed stream",
|
|
|
|
pcall_err(command, [[call chanclose(id) | call chansend(id, 'test')]]))
|
|
|
|
screen:expect({any='%[Terminal closed%]'})
|
|
|
|
eq(chans, eval('len(nvim_list_chans())'))
|
|
|
|
-- delete terminal
|
|
|
|
feed('i<CR>')
|
|
|
|
-- need to first process input
|
|
|
|
poke_eventloop()
|
|
|
|
-- channel has been released after another main loop iteration
|
|
|
|
eq(chans - 1, eval('len(nvim_list_chans())'))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('opened by nvim_open_term(), closed by chanclose(), and deleted by :bdelete', function()
|
|
|
|
command('let id = nvim_open_term(0, {})')
|
|
|
|
local chans = eval('len(nvim_list_chans())')
|
|
|
|
-- channel has been closed but not released
|
|
|
|
eq("Vim(call):Can't send data to closed stream",
|
|
|
|
pcall_err(command, [[call chanclose(id) | call chansend(id, 'test')]]))
|
|
|
|
screen:expect({any='%[Terminal closed%]'})
|
|
|
|
eq(chans, eval('len(nvim_list_chans())'))
|
|
|
|
-- channel still hasn't been released yet
|
|
|
|
eq("Vim(call):Can't send data to closed stream",
|
|
|
|
pcall_err(command, [[bdelete | call chansend(id, 'test')]]))
|
|
|
|
-- channel has been released after one main loop iteration
|
|
|
|
eq(chans - 1, eval('len(nvim_list_chans())'))
|
2021-11-10 18:34:23 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('opened by termopen(), exited, and deleted by pressing a key', function()
|
|
|
|
command([[let id = termopen('echo')]])
|
2022-03-12 00:22:55 -07:00
|
|
|
local chans = eval('len(nvim_list_chans())')
|
|
|
|
-- wait for process to exit
|
|
|
|
screen:expect({any='%[Process exited 0%]'})
|
|
|
|
-- process has exited but channel has't been released
|
|
|
|
eq("Vim(call):Can't send data to closed stream",
|
|
|
|
pcall_err(command, [[call chansend(id, 'test')]]))
|
|
|
|
eq(chans, eval('len(nvim_list_chans())'))
|
2021-11-10 18:34:23 -07:00
|
|
|
-- delete terminal
|
|
|
|
feed('i<CR>')
|
2021-11-11 19:27:11 -07:00
|
|
|
-- need to first process input
|
2021-11-10 18:34:23 -07:00
|
|
|
poke_eventloop()
|
2022-03-12 00:22:55 -07:00
|
|
|
-- channel has been released after another main loop iteration
|
|
|
|
eq(chans - 1, eval('len(nvim_list_chans())'))
|
2021-11-10 18:34:23 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
-- This indirectly covers #16264
|
|
|
|
it('opened by termopen(), exited, and deleted by :bdelete', function()
|
|
|
|
command([[let id = termopen('echo')]])
|
2022-03-12 00:22:55 -07:00
|
|
|
local chans = eval('len(nvim_list_chans())')
|
|
|
|
-- wait for process to exit
|
|
|
|
screen:expect({any='%[Process exited 0%]'})
|
|
|
|
-- process has exited but channel hasn't been released
|
2021-11-11 08:07:03 -07:00
|
|
|
eq("Vim(call):Can't send data to closed stream",
|
2022-03-12 00:22:55 -07:00
|
|
|
pcall_err(command, [[call chansend(id, 'test')]]))
|
|
|
|
eq(chans, eval('len(nvim_list_chans())'))
|
|
|
|
-- channel still hasn't been released yet
|
|
|
|
eq("Vim(call):Can't send data to closed stream",
|
|
|
|
pcall_err(command, [[bdelete | call chansend(id, 'test')]]))
|
|
|
|
-- channel has been released after one main loop iteration
|
|
|
|
eq(chans - 1, eval('len(nvim_list_chans())'))
|
2021-11-11 08:07:03 -07:00
|
|
|
end)
|
|
|
|
end)
|