mirror of
https://github.com/neovim/neovim.git
synced 2025-12-07 07:02:46 +00:00
test: add tests for freeing channel opened by termopen()
This indirectly covers #16264
This commit is contained in:
@@ -3,8 +3,6 @@ local uname = helpers.uname
|
|||||||
local clear, eq, eval, next_msg, ok, source = helpers.clear, helpers.eq,
|
local clear, eq, eval, next_msg, ok, source = helpers.clear, helpers.eq,
|
||||||
helpers.eval, helpers.next_msg, helpers.ok, helpers.source
|
helpers.eval, helpers.next_msg, helpers.ok, helpers.source
|
||||||
local command, funcs, meths = helpers.command, helpers.funcs, helpers.meths
|
local command, funcs, meths = helpers.command, helpers.funcs, helpers.meths
|
||||||
local exc_exec = helpers.exc_exec
|
|
||||||
local poke_eventloop = helpers.poke_eventloop
|
|
||||||
local sleep = helpers.sleep
|
local sleep = helpers.sleep
|
||||||
local spawn, nvim_argv = helpers.spawn, helpers.nvim_argv
|
local spawn, nvim_argv = helpers.spawn, helpers.nvim_argv
|
||||||
local set_session = helpers.set_session
|
local set_session = helpers.set_session
|
||||||
@@ -283,16 +281,4 @@ describe('channels', function()
|
|||||||
-- works correctly with no output
|
-- works correctly with no output
|
||||||
eq({"notification", "exit", {id, 1, {''}}}, next_msg())
|
eq({"notification", "exit", {id, 1, {''}}}, next_msg())
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('should throw error when writing to a channel associated with a deleted terminal', function()
|
|
||||||
command('let id = nvim_open_term(0, {})')
|
|
||||||
local err = exc_exec([[bdelete! | call chansend(id, 'test')]])
|
|
||||||
-- channel hasn't been freed yet
|
|
||||||
eq("Vim(call):Can't send data to closed stream", err)
|
|
||||||
-- process free_channel_event
|
|
||||||
poke_eventloop()
|
|
||||||
err = exc_exec([[call chansend(id, 'test')]])
|
|
||||||
-- channel has ben freed
|
|
||||||
eq("Vim(call):E900: Invalid channel id", err)
|
|
||||||
end)
|
|
||||||
end)
|
end)
|
||||||
|
|||||||
49
test/functional/terminal/channel_spec.lua
Normal file
49
test/functional/terminal/channel_spec.lua
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
local helpers = require('test.functional.helpers')(after_each)
|
||||||
|
local clear = helpers.clear
|
||||||
|
local eq = helpers.eq
|
||||||
|
local command = helpers.command
|
||||||
|
local exc_exec = helpers.exc_exec
|
||||||
|
local feed = helpers.feed
|
||||||
|
local sleep = helpers.sleep
|
||||||
|
local poke_eventloop = helpers.poke_eventloop
|
||||||
|
|
||||||
|
describe('associated channel is closed and later freed for terminal', function()
|
||||||
|
before_each(clear)
|
||||||
|
|
||||||
|
it('opened by nvim_open_term() and deleted by :bdelete!', function()
|
||||||
|
command([[let id = nvim_open_term(0, {})]])
|
||||||
|
-- channel hasn't been freed yet
|
||||||
|
eq("Vim(call):Can't send data to closed stream", exc_exec([[bdelete! | call chansend(id, 'test')]]))
|
||||||
|
-- process free_channel_event
|
||||||
|
poke_eventloop()
|
||||||
|
-- channel has been freed
|
||||||
|
eq("Vim(call):E900: Invalid channel id", exc_exec([[call chansend(id, 'test')]]))
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('opened by termopen(), exited, and deleted by pressing a key', function()
|
||||||
|
command([[let id = termopen('echo')]])
|
||||||
|
sleep(500)
|
||||||
|
-- process has exited
|
||||||
|
eq("Vim(call):Can't send data to closed stream", exc_exec([[call chansend(id, 'test')]]))
|
||||||
|
-- delete terminal
|
||||||
|
feed('i<CR>')
|
||||||
|
-- process term_delayed_free and free_channel_event
|
||||||
|
poke_eventloop()
|
||||||
|
-- channel has been freed
|
||||||
|
eq("Vim(call):E900: Invalid channel id", exc_exec([[call chansend(id, 'test')]]))
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- This indirectly covers #16264
|
||||||
|
it('opened by termopen(), exited, and deleted by :bdelete', function()
|
||||||
|
command([[let id = termopen('echo')]])
|
||||||
|
sleep(500)
|
||||||
|
-- process has exited
|
||||||
|
eq("Vim(call):Can't send data to closed stream", exc_exec([[call chansend(id, 'test')]]))
|
||||||
|
-- channel hasn't been freed yet
|
||||||
|
eq("Vim(call):Can't send data to closed stream", exc_exec([[bdelete | call chansend(id, 'test')]]))
|
||||||
|
-- process term_delayed_free and free_channel_event
|
||||||
|
poke_eventloop()
|
||||||
|
-- channel has been freed
|
||||||
|
eq("Vim(call):E900: Invalid channel id", exc_exec([[call chansend(id, 'test')]]))
|
||||||
|
end)
|
||||||
|
end)
|
||||||
Reference in New Issue
Block a user