diff options
Diffstat (limited to 'test/functional/core/channels_spec.lua')
-rw-r--r-- | test/functional/core/channels_spec.lua | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/test/functional/core/channels_spec.lua b/test/functional/core/channels_spec.lua index 93dec9fb35..ca52404d3b 100644 --- a/test/functional/core/channels_spec.lua +++ b/test/functional/core/channels_spec.lua @@ -10,6 +10,8 @@ local nvim_prog = helpers.nvim_prog local is_os = helpers.is_os local retry = helpers.retry local expect_twostreams = helpers.expect_twostreams +local assert_alive = helpers.assert_alive +local pcall_err = helpers.pcall_err describe('channels', function() local init = [[ @@ -100,6 +102,38 @@ describe('channels', function() eq({"notification", "exit", {3,0}}, next_msg()) end) + it('can use stdio channel and on_print callback', function() + source([[ + let g:job_opts = { + \ 'on_stdout': function('OnEvent'), + \ 'on_stderr': function('OnEvent'), + \ 'on_exit': function('OnEvent'), + \ } + ]]) + meths.set_var("nvim_prog", nvim_prog) + meths.set_var("code", [[ + function! OnStdin(id, data, event) dict + echo string([a:id, a:data, a:event]) + if a:data == [''] + quit + endif + endfunction + function! OnPrint(text) dict + call chansend(g:x, ['OnPrint:' .. a:text]) + endfunction + let g:x = stdioopen({'on_stdin': funcref('OnStdin'), 'on_print':'OnPrint'}) + call chansend(x, "hello") + ]]) + command("let g:id = jobstart([ g:nvim_prog, '-u', 'NONE', '-i', 'NONE', '--cmd', 'set noswapfile', '--headless', '--cmd', g:code], g:job_opts)") + local id = eval("g:id") + ok(id > 0) + + eq({ "notification", "stdout", {id, { "hello" } } }, next_msg()) + + command("call chansend(id, 'howdy')") + eq({"notification", "stdout", {id, {"OnPrint:[1, ['howdy'], 'stdin']"}}}, next_msg()) + end) + local function expect_twoline(id, stream, line1, line2, nobr) local msg = next_msg() local joined = nobr and {line1..line2} or {line1, line2} @@ -282,3 +316,22 @@ describe('channels', function() eq({"notification", "exit", {id, 1, {''}}}, next_msg()) end) end) + +describe('loopback', function() + before_each(function() + clear() + command("let chan = sockconnect('pipe', v:servername, {'rpc': v:true})") + end) + + it('does not crash when sending raw data', function() + eq("Vim(call):Can't send raw data to rpc channel", + pcall_err(command, "call chansend(chan, 'test')")) + assert_alive() + end) + + it('are released when closed', function() + local chans = eval('len(nvim_list_chans())') + command('call chanclose(chan)') + eq(chans - 1, eval('len(nvim_list_chans())')) + end) +end) |