aboutsummaryrefslogtreecommitdiff
path: root/test/functional/terminal/channel_spec.lua
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2023-11-29 22:40:31 +0000
committerJosh Rahm <joshuarahm@gmail.com>2023-11-29 22:40:31 +0000
commit339e2d15cc26fe86988ea06468d912a46c8d6f29 (patch)
treea6167fc8fcfc6ae2dc102f57b2473858eac34063 /test/functional/terminal/channel_spec.lua
parent067dc73729267c0262438a6fdd66e586f8496946 (diff)
parent4a8bf24ac690004aedf5540fa440e788459e5e34 (diff)
downloadrneovim-339e2d15cc26fe86988ea06468d912a46c8d6f29.tar.gz
rneovim-339e2d15cc26fe86988ea06468d912a46c8d6f29.tar.bz2
rneovim-339e2d15cc26fe86988ea06468d912a46c8d6f29.zip
Merge remote-tracking branch 'upstream/master' into fix_repeatcmdline
Diffstat (limited to 'test/functional/terminal/channel_spec.lua')
-rw-r--r--test/functional/terminal/channel_spec.lua96
1 files changed, 94 insertions, 2 deletions
diff --git a/test/functional/terminal/channel_spec.lua b/test/functional/terminal/channel_spec.lua
index 2ca7cdb0a2..8510df5347 100644
--- a/test/functional/terminal/channel_spec.lua
+++ b/test/functional/terminal/channel_spec.lua
@@ -8,6 +8,10 @@ local pcall_err = helpers.pcall_err
local feed = helpers.feed
local poke_eventloop = helpers.poke_eventloop
local is_os = helpers.is_os
+local meths = helpers.meths
+local async_meths = helpers.async_meths
+local testprg = helpers.testprg
+local assert_alive = helpers.assert_alive
describe('terminal channel is closed and later released if', function()
local screen
@@ -24,6 +28,7 @@ describe('terminal channel is closed and later released if', function()
-- channel hasn't been released yet
eq("Vim(call):Can't send data to closed stream",
pcall_err(command, [[bdelete! | call chansend(id, 'test')]]))
+ feed('<Ignore>') -- add input to separate two RPC requests
-- channel has been released after one main loop iteration
eq(chans - 1, eval('len(nvim_list_chans())'))
end)
@@ -40,6 +45,7 @@ describe('terminal channel is closed and later released if', function()
feed('i<CR>')
-- need to first process input
poke_eventloop()
+ feed('<Ignore>') -- add input to separate two RPC requests
-- channel has been released after another main loop iteration
eq(chans - 1, eval('len(nvim_list_chans())'))
end)
@@ -55,6 +61,7 @@ describe('terminal channel is closed and later released if', function()
-- 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')]]))
+ feed('<Ignore>') -- add input to separate two RPC requests
-- channel has been released after one main loop iteration
eq(chans - 1, eval('len(nvim_list_chans())'))
end)
@@ -72,6 +79,7 @@ describe('terminal channel is closed and later released if', function()
feed('i<CR>')
-- need to first process input
poke_eventloop()
+ feed('<Ignore>') -- add input to separate two RPC requests
-- channel has been released after another main loop iteration
eq(chans - 1, eval('len(nvim_list_chans())'))
end)
@@ -89,21 +97,105 @@ describe('terminal channel is closed and later released if', function()
-- 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')]]))
+ feed('<Ignore>') -- add input to separate two RPC requests
-- channel has been released after one main loop iteration
eq(chans - 1, eval('len(nvim_list_chans())'))
end)
end)
it('chansend sends lines to terminal channel in proper order', function()
- clear()
+ clear({args = {'--cmd', 'set laststatus=2'}})
local screen = Screen.new(100, 20)
screen:attach()
local shells = is_os('win') and {'cmd.exe', 'pwsh.exe -nop', 'powershell.exe -nop'} or {'sh'}
for _, sh in ipairs(shells) do
- command([[bdelete! | let id = termopen(']] .. sh .. [[')]])
+ command([[let id = termopen(']] .. sh .. [[')]])
command([[call chansend(id, ['echo "hello"', 'echo "world"', ''])]])
screen:expect{
any=[[echo "hello".*echo "world"]]
}
+ command('bdelete!')
+ screen:expect{
+ any='%[No Name%]'
+ }
end
end)
+
+describe('no crash when TermOpen autocommand', function()
+ local screen
+
+ before_each(function()
+ clear()
+ meths.set_option_value('shell', testprg('shell-test'), {})
+ command('set shellcmdflag=EXE shellredir= shellpipe= shellquote= shellxquote=')
+ screen = Screen.new(60, 4)
+ screen:set_default_attr_ids({
+ [0] = {bold = true, foreground = Screen.colors.Blue};
+ })
+ screen:attach()
+ end)
+
+ it('processes job exit event when using termopen()', function()
+ command([[autocmd TermOpen * call input('')]])
+ async_meths.command('terminal foobar')
+ screen:expect{grid=[[
+ |
+ {0:~ }|
+ {0:~ }|
+ ^ |
+ ]]}
+ feed('<CR>')
+ screen:expect{grid=[[
+ ^ready $ foobar |
+ |
+ [Process exited 0] |
+ |
+ ]]}
+ feed('i<CR>')
+ screen:expect{grid=[[
+ ^ |
+ {0:~ }|
+ {0:~ }|
+ |
+ ]]}
+ assert_alive()
+ end)
+
+ it('wipes buffer and processes events when using termopen()', function()
+ command([[autocmd TermOpen * bwipe! | call input('')]])
+ async_meths.command('terminal foobar')
+ screen:expect{grid=[[
+ |
+ {0:~ }|
+ {0:~ }|
+ ^ |
+ ]]}
+ feed('<CR>')
+ screen:expect{grid=[[
+ ^ |
+ {0:~ }|
+ {0:~ }|
+ |
+ ]]}
+ assert_alive()
+ end)
+
+ it('wipes buffer and processes events when using nvim_open_term()', function()
+ command([[autocmd TermOpen * bwipe! | call input('')]])
+ async_meths.open_term(0, {})
+ screen:expect{grid=[[
+ |
+ {0:~ }|
+ {0:~ }|
+ ^ |
+ ]]}
+ feed('<CR>')
+ screen:expect{grid=[[
+ ^ |
+ {0:~ }|
+ {0:~ }|
+ |
+ ]]}
+ assert_alive()
+ end)
+end)