aboutsummaryrefslogtreecommitdiff
path: root/test/functional/api/server_requests_spec.lua
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/api/server_requests_spec.lua')
-rw-r--r--test/functional/api/server_requests_spec.lua121
1 files changed, 66 insertions, 55 deletions
diff --git a/test/functional/api/server_requests_spec.lua b/test/functional/api/server_requests_spec.lua
index 1ad4ad3a02..421e0b5c9a 100644
--- a/test/functional/api/server_requests_spec.lua
+++ b/test/functional/api/server_requests_spec.lua
@@ -40,13 +40,13 @@ describe('server -> client', function()
describe('simple call', function()
it('works', function()
local function on_setup()
- eq({4, 5, 6}, eval('rpcrequest('..cid..', "scall", 1, 2, 3)'))
+ eq({ 4, 5, 6 }, eval('rpcrequest(' .. cid .. ', "scall", 1, 2, 3)'))
stop()
end
local function on_request(method, args)
eq('scall', method)
- eq({1, 2, 3}, args)
+ eq({ 1, 2, 3 }, args)
nvim('command', 'let g:result = [4, 5, 6]')
return eval('g:result')
end
@@ -61,14 +61,14 @@ describe('server -> client', function()
-- elements following the empty string.
it('works', function()
local function on_setup()
- eq({1, 2, '', 3, 'asdf'}, eval('rpcrequest('..cid..', "nstring")'))
+ eq({ 1, 2, '', 3, 'asdf' }, eval('rpcrequest(' .. cid .. ', "nstring")'))
stop()
end
local function on_request()
-- No need to evaluate the args, we are only interested in
-- a response that contains an array with an empty string.
- return {1, 2, '', 3, 'asdf'}
+ return { 1, 2, '', 3, 'asdf' }
end
run(on_request, nil, on_setup)
end)
@@ -81,7 +81,7 @@ describe('server -> client', function()
nvim('set_var', 'result2', 0)
nvim('set_var', 'result3', 0)
nvim('set_var', 'result4', 0)
- nvim('command', 'let g:result1 = rpcrequest('..cid..', "rcall", 2)')
+ nvim('command', 'let g:result1 = rpcrequest(' .. cid .. ', "rcall", 2)')
eq(4, nvim('get_var', 'result1'))
eq(8, nvim('get_var', 'result2'))
eq(16, nvim('get_var', 'result3'))
@@ -95,11 +95,11 @@ describe('server -> client', function()
if n <= 16 then
local cmd
if n == 4 then
- cmd = 'let g:result2 = rpcrequest('..cid..', "rcall", '..n..')'
+ cmd = 'let g:result2 = rpcrequest(' .. cid .. ', "rcall", ' .. n .. ')'
elseif n == 8 then
- cmd = 'let g:result3 = rpcrequest('..cid..', "rcall", '..n..')'
+ cmd = 'let g:result3 = rpcrequest(' .. cid .. ', "rcall", ' .. n .. ')'
elseif n == 16 then
- cmd = 'let g:result4 = rpcrequest('..cid..', "rcall", '..n..')'
+ cmd = 'let g:result4 = rpcrequest(' .. cid .. ', "rcall", ' .. n .. ')'
end
nvim('command', cmd)
end
@@ -113,18 +113,18 @@ describe('server -> client', function()
it('does not delay notifications during pending request', function()
local received = false
local function on_setup()
- eq("retval", funcs.rpcrequest(cid, "doit"))
+ eq('retval', funcs.rpcrequest(cid, 'doit'))
stop()
end
local function on_request(method)
- if method == "doit" then
- funcs.rpcnotify(cid, "headsup")
- eq(true,received)
- return "retval"
+ if method == 'doit' then
+ funcs.rpcnotify(cid, 'headsup')
+ eq(true, received)
+ return 'retval'
end
end
local function on_notification(method)
- if method == "headsup" then
+ if method == 'headsup' then
received = true
end
end
@@ -148,28 +148,28 @@ describe('server -> client', function()
-- of nvim's request stack).
pending('will close connection if not properly synchronized', function()
local function on_setup()
- eq('notified!', eval('rpcrequest('..cid..', "notify")'))
+ eq('notified!', eval('rpcrequest(' .. cid .. ', "notify")'))
end
local function on_request(method)
- if method == "notify" then
- eq(1, eval('rpcnotify('..cid..', "notification")'))
+ if method == 'notify' then
+ eq(1, eval('rpcnotify(' .. cid .. ', "notification")'))
return 'notified!'
- elseif method == "nested" then
+ elseif method == 'nested' then
-- do some busywork, so the first request will return
-- before this one
for _ = 1, 5 do
assert_alive()
end
- eq(1, eval('rpcnotify('..cid..', "nested_done")'))
+ eq(1, eval('rpcnotify(' .. cid .. ', "nested_done")'))
return 'done!'
end
end
local function on_notification(method)
- if method == "notification" then
- eq('done!', eval('rpcrequest('..cid..', "nested")'))
- elseif method == "nested_done" then
+ if method == 'notification' then
+ eq('done!', eval('rpcrequest(' .. cid .. ', "nested")'))
+ elseif method == 'nested_done' then
ok(false, 'never sent', 'sent')
end
end
@@ -182,11 +182,17 @@ describe('server -> client', function()
describe('recursive (child) nvim client', function()
before_each(function()
- command("let vim = rpcstart('"..nvim_prog.."', ['-u', 'NONE', '-i', 'NONE', '--cmd', 'set noswapfile', '--embed', '--headless'])")
+ command(
+ "let vim = rpcstart('"
+ .. nvim_prog
+ .. "', ['-u', 'NONE', '-i', 'NONE', '--cmd', 'set noswapfile', '--embed', '--headless'])"
+ )
neq(0, eval('vim'))
end)
- after_each(function() command('call rpcstop(vim)') end)
+ after_each(function()
+ command('call rpcstop(vim)')
+ end)
it('can send/receive notifications and make requests', function()
nvim('command', "call rpcnotify(vim, 'vim_set_current_line', 'SOME TEXT')")
@@ -198,25 +204,27 @@ describe('server -> client', function()
end)
it('can communicate buffers, tabpages, and windows', function()
- eq({1}, eval("rpcrequest(vim, 'nvim_list_tabpages')"))
+ eq({ 1 }, eval("rpcrequest(vim, 'nvim_list_tabpages')"))
-- Window IDs start at 1000 (LOWEST_WIN_ID in window.h)
- eq({1000}, eval("rpcrequest(vim, 'nvim_list_wins')"))
+ eq({ 1000 }, eval("rpcrequest(vim, 'nvim_list_wins')"))
local buf = eval("rpcrequest(vim, 'nvim_list_bufs')")[1]
eq(1, buf)
- eval("rpcnotify(vim, 'buffer_set_line', "..buf..", 0, 'SOME TEXT')")
- nvim('command', "call rpcrequest(vim, 'vim_eval', '0')") -- wait
+ eval("rpcnotify(vim, 'buffer_set_line', " .. buf .. ", 0, 'SOME TEXT')")
+ nvim('command', "call rpcrequest(vim, 'vim_eval', '0')") -- wait
- eq('SOME TEXT', eval("rpcrequest(vim, 'buffer_get_line', "..buf..", 0)"))
+ eq('SOME TEXT', eval("rpcrequest(vim, 'buffer_get_line', " .. buf .. ', 0)'))
-- Call get_lines(buf, range [0,0], strict_indexing)
- eq({'SOME TEXT'}, eval("rpcrequest(vim, 'buffer_get_lines', "..buf..", 0, 1, 1)"))
+ eq({ 'SOME TEXT' }, eval("rpcrequest(vim, 'buffer_get_lines', " .. buf .. ', 0, 1, 1)'))
end)
it('returns an error if the request failed', function()
- eq("Vim:Error invoking 'does-not-exist' on channel 3:\nInvalid method: does-not-exist",
- pcall_err(eval, "rpcrequest(vim, 'does-not-exist')"))
+ eq(
+ "Vim:Error invoking 'does-not-exist' on channel 3:\nInvalid method: does-not-exist",
+ pcall_err(eval, "rpcrequest(vim, 'does-not-exist')")
+ )
end)
end)
@@ -236,13 +244,14 @@ describe('server -> client', function()
\ 'rpc': v:true
\ }
]])
- meths.set_var("args", {
- nvim_prog, '-ll',
+ meths.set_var('args', {
+ nvim_prog,
+ '-ll',
'test/functional/api/rpc_fixture.lua',
package.path,
package.cpath,
})
- jobid = eval("jobstart(g:args, g:job_opts)")
+ jobid = eval('jobstart(g:args, g:job_opts)')
neq(0, jobid)
end)
@@ -250,7 +259,9 @@ describe('server -> client', function()
pcall(funcs.jobstop, jobid)
end)
- if helpers.skip(helpers.is_os('win')) then return end
+ if helpers.skip(helpers.is_os('win')) then
+ return
+ end
it('rpc and text stderr can be combined', function()
local status, rv = pcall(funcs.rpcrequest, jobid, 'poll')
@@ -258,18 +269,18 @@ describe('server -> client', function()
error(string.format('missing nvim Lua module? (%s)', rv))
end
eq('ok', rv)
- funcs.rpcnotify(jobid, "ping")
- eq({'notification', 'pong', {}}, next_msg())
- eq("done!",funcs.rpcrequest(jobid, "write_stderr", "fluff\n"))
- eq({'notification', 'stderr', {0, {'fluff', ''}}}, next_msg())
- pcall(funcs.rpcrequest, jobid, "exit")
- eq({'notification', 'stderr', {0, {''}}}, next_msg())
- eq({'notification', 'exit', {0, 0}}, next_msg())
+ funcs.rpcnotify(jobid, 'ping')
+ eq({ 'notification', 'pong', {} }, next_msg())
+ eq('done!', funcs.rpcrequest(jobid, 'write_stderr', 'fluff\n'))
+ eq({ 'notification', 'stderr', { 0, { 'fluff', '' } } }, next_msg())
+ pcall(funcs.rpcrequest, jobid, 'exit')
+ eq({ 'notification', 'stderr', { 0, { '' } } }, next_msg())
+ eq({ 'notification', 'exit', { 0, 0 } }, next_msg())
end)
end)
describe('connecting to another (peer) nvim', function()
- local nvim_argv = merge_args(helpers.nvim_argv, {'--headless'})
+ local nvim_argv = merge_args(helpers.nvim_argv, { '--headless' })
local function connect_test(server, mode, address)
local serverpid = funcs.getpid()
local client = spawn(nvim_argv, false, nil, true)
@@ -277,7 +288,7 @@ describe('server -> client', function()
local clientpid = funcs.getpid()
neq(serverpid, clientpid)
- local id = funcs.sockconnect(mode, address, {rpc=true})
+ local id = funcs.sockconnect(mode, address, { rpc = true })
ok(id > 0)
funcs.rpcrequest(id, 'nvim_set_current_line', 'hello')
@@ -303,7 +314,7 @@ describe('server -> client', function()
local server = spawn(nvim_argv)
set_session(server)
local address = funcs.serverlist()[1]
- local first = string.sub(address,1,1)
+ local first = string.sub(address, 1, 1)
ok(first == '/' or first == '\\')
connect_test(server, 'pipe', address)
end)
@@ -311,11 +322,11 @@ describe('server -> client', function()
it('via ipv4 address', function()
local server = spawn(nvim_argv)
set_session(server)
- local status, address = pcall(funcs.serverstart, "127.0.0.1:")
+ local status, address = pcall(funcs.serverstart, '127.0.0.1:')
if not status then
pending('no ipv4 stack')
end
- eq('127.0.0.1:', string.sub(address,1,10))
+ eq('127.0.0.1:', string.sub(address, 1, 10))
connect_test(server, 'tcp', address)
end)
@@ -326,15 +337,15 @@ describe('server -> client', function()
if not status then
pending('no ipv6 stack')
end
- eq('::1:', string.sub(address,1,4))
+ eq('::1:', string.sub(address, 1, 4))
connect_test(server, 'tcp', address)
end)
it('via hostname', function()
local server = spawn(nvim_argv)
set_session(server)
- local address = funcs.serverstart("localhost:")
- eq('localhost:', string.sub(address,1,10))
+ local address = funcs.serverstart('localhost:')
+ eq('localhost:', string.sub(address, 1, 10))
connect_test(server, 'tcp', address)
end)
@@ -345,7 +356,7 @@ describe('server -> client', function()
local client = spawn(nvim_argv, false, nil, true)
set_session(client)
- local id = funcs.sockconnect('pipe', address, {rpc=true})
+ local id = funcs.sockconnect('pipe', address, { rpc = true })
funcs.rpcrequest(id, 'nvim_ui_attach', 80, 24, {})
assert_alive()
@@ -357,15 +368,15 @@ describe('server -> client', function()
describe('connecting to its own pipe address', function()
it('does not deadlock', function()
local address = funcs.serverlist()[1]
- local first = string.sub(address,1,1)
+ local first = string.sub(address, 1, 1)
ok(first == '/' or first == '\\')
local serverpid = funcs.getpid()
- local id = funcs.sockconnect('pipe', address, {rpc=true})
+ local id = funcs.sockconnect('pipe', address, { rpc = true })
funcs.rpcrequest(id, 'nvim_set_current_line', 'hello')
eq('hello', meths.get_current_line())
- eq(serverpid, funcs.rpcrequest(id, "nvim_eval", "getpid()"))
+ eq(serverpid, funcs.rpcrequest(id, 'nvim_eval', 'getpid()'))
eq(id, funcs.rpcrequest(id, 'nvim_get_api_info')[1])
end)