aboutsummaryrefslogtreecommitdiff
path: root/test/functional/terminal/channel_spec.lua
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2021-11-11 09:34:23 +0800
committerzeertzjq <zeertzjq@outlook.com>2021-11-11 09:34:23 +0800
commit8b5c32c8cd9b76aaefa0977a69789fa9bd43f2fd (patch)
tree9074a2641f22b0733d91d2fee90fe33c9c64cde1 /test/functional/terminal/channel_spec.lua
parenta502a7a7311657564065c9d2cd1a64292550722c (diff)
downloadrneovim-8b5c32c8cd9b76aaefa0977a69789fa9bd43f2fd.tar.gz
rneovim-8b5c32c8cd9b76aaefa0977a69789fa9bd43f2fd.tar.bz2
rneovim-8b5c32c8cd9b76aaefa0977a69789fa9bd43f2fd.zip
test: add tests for freeing channel opened by termopen()
This indirectly covers #16264
Diffstat (limited to 'test/functional/terminal/channel_spec.lua')
-rw-r--r--test/functional/terminal/channel_spec.lua49
1 files changed, 49 insertions, 0 deletions
diff --git a/test/functional/terminal/channel_spec.lua b/test/functional/terminal/channel_spec.lua
new file mode 100644
index 0000000000..7d37dcccc8
--- /dev/null
+++ b/test/functional/terminal/channel_spec.lua
@@ -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)