From 04f2f864e270e772c6326cefdf24947f0130e492 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Wed, 3 Jan 2024 02:09:18 +0100 Subject: refactor: format test/* --- test/functional/api/server_requests_spec.lua | 121 +++++++++++++++------------ 1 file changed, 66 insertions(+), 55 deletions(-) (limited to 'test/functional/api/server_requests_spec.lua') 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) -- cgit From c30f2e3182e3b50e7c03932027ac55edfc8ada4a Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 12 Jan 2024 12:44:54 +0000 Subject: test: typing for helpers.meths --- test/functional/api/server_requests_spec.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'test/functional/api/server_requests_spec.lua') diff --git a/test/functional/api/server_requests_spec.lua b/test/functional/api/server_requests_spec.lua index 421e0b5c9a..6878ac0218 100644 --- a/test/functional/api/server_requests_spec.lua +++ b/test/functional/api/server_requests_spec.lua @@ -244,7 +244,7 @@ describe('server -> client', function() \ 'rpc': v:true \ } ]]) - meths.set_var('args', { + meths.nvim_set_var('args', { nvim_prog, '-ll', 'test/functional/api/rpc_fixture.lua', @@ -296,7 +296,7 @@ describe('server -> client', function() set_session(server) eq(serverpid, funcs.getpid()) - eq('hello', meths.get_current_line()) + eq('hello', meths.nvim_get_current_line()) -- method calls work both ways funcs.rpcrequest(client_id, 'nvim_set_current_line', 'howdy!') @@ -304,7 +304,7 @@ describe('server -> client', function() set_session(client) eq(clientpid, funcs.getpid()) - eq('howdy!', meths.get_current_line()) + eq('howdy!', meths.nvim_get_current_line()) server:close() client:close() @@ -375,7 +375,7 @@ describe('server -> client', function() local id = funcs.sockconnect('pipe', address, { rpc = true }) funcs.rpcrequest(id, 'nvim_set_current_line', 'hello') - eq('hello', meths.get_current_line()) + eq('hello', meths.nvim_get_current_line()) eq(serverpid, funcs.rpcrequest(id, 'nvim_eval', 'getpid()')) eq(id, funcs.rpcrequest(id, 'nvim_get_api_info')[1]) -- cgit From 4f81f506f96f8b5bfcf00e952ceb492d3ce9dc6e Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 12 Jan 2024 13:11:28 +0000 Subject: test: normalise nvim bridge functions - remove helpers.cur*meths - remove helpers.nvim --- test/functional/api/server_requests_spec.lua | 36 ++++++++++++++-------------- 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'test/functional/api/server_requests_spec.lua') diff --git a/test/functional/api/server_requests_spec.lua b/test/functional/api/server_requests_spec.lua index 6878ac0218..e06d32f656 100644 --- a/test/functional/api/server_requests_spec.lua +++ b/test/functional/api/server_requests_spec.lua @@ -2,7 +2,7 @@ -- `rpcrequest` calls we need the client event loop to be running. local helpers = require('test.functional.helpers')(after_each) -local clear, nvim, eval = helpers.clear, helpers.nvim, helpers.eval +local clear, eval = helpers.clear, helpers.eval local eq, neq, run, stop = helpers.eq, helpers.neq, helpers.run, helpers.stop local nvim_prog, command, funcs = helpers.nvim_prog, helpers.command, helpers.funcs local source, next_msg = helpers.source, helpers.next_msg @@ -18,7 +18,7 @@ describe('server -> client', function() before_each(function() clear() - cid = nvim('get_api_info')[1] + cid = meths.nvim_get_api_info()[1] end) it('handles unexpected closed stream while preparing RPC response', function() @@ -47,7 +47,7 @@ describe('server -> client', function() local function on_request(method, args) eq('scall', method) eq({ 1, 2, 3 }, args) - nvim('command', 'let g:result = [4, 5, 6]') + command('let g:result = [4, 5, 6]') return eval('g:result') end run(on_request, nil, on_setup) @@ -77,15 +77,15 @@ describe('server -> client', function() describe('recursive call', function() it('works', function() local function on_setup() - nvim('set_var', 'result1', 0) - nvim('set_var', 'result2', 0) - nvim('set_var', 'result3', 0) - nvim('set_var', 'result4', 0) - 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')) - eq(32, nvim('get_var', 'result4')) + meths.nvim_set_var('result1', 0) + meths.nvim_set_var('result2', 0) + meths.nvim_set_var('result3', 0) + meths.nvim_set_var('result4', 0) + command('let g:result1 = rpcrequest(' .. cid .. ', "rcall", 2)') + eq(4, meths.nvim_get_var('result1')) + eq(8, meths.nvim_get_var('result2')) + eq(16, meths.nvim_get_var('result3')) + eq(32, meths.nvim_get_var('result4')) stop() end @@ -101,7 +101,7 @@ describe('server -> client', function() elseif n == 16 then cmd = 'let g:result4 = rpcrequest(' .. cid .. ', "rcall", ' .. n .. ')' end - nvim('command', cmd) + command(cmd) end return n end @@ -195,10 +195,10 @@ describe('server -> client', function() end) it('can send/receive notifications and make requests', function() - nvim('command', "call rpcnotify(vim, 'vim_set_current_line', 'SOME TEXT')") + command("call rpcnotify(vim, 'vim_set_current_line', 'SOME TEXT')") -- Wait for the notification to complete. - nvim('command', "call rpcrequest(vim, 'vim_eval', '0')") + command("call rpcrequest(vim, 'vim_eval', '0')") eq('SOME TEXT', eval("rpcrequest(vim, 'vim_get_current_line')")) end) @@ -212,7 +212,7 @@ describe('server -> client', function() eq(1, buf) eval("rpcnotify(vim, 'buffer_set_line', " .. buf .. ", 0, 'SOME TEXT')") - nvim('command', "call rpcrequest(vim, 'vim_eval', '0')") -- wait + command("call rpcrequest(vim, 'vim_eval', '0')") -- wait eq('SOME TEXT', eval("rpcrequest(vim, 'buffer_get_line', " .. buf .. ', 0)')) @@ -231,8 +231,8 @@ describe('server -> client', function() describe('jobstart()', function() local jobid before_each(function() - local channel = nvim('get_api_info')[1] - nvim('set_var', 'channel', channel) + local channel = meths.nvim_get_api_info()[1] + meths.nvim_set_var('channel', channel) source([[ function! s:OnEvent(id, data, event) call rpcnotify(g:channel, a:event, 0, a:data) -- cgit From 795f896a5772d5e0795f86642bdf90c82efac45c Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 12 Jan 2024 17:59:57 +0000 Subject: test: rename (meths, funcs) -> (api, fn) --- test/functional/api/server_requests_spec.lua | 92 ++++++++++++++-------------- 1 file changed, 46 insertions(+), 46 deletions(-) (limited to 'test/functional/api/server_requests_spec.lua') diff --git a/test/functional/api/server_requests_spec.lua b/test/functional/api/server_requests_spec.lua index e06d32f656..5e508e7513 100644 --- a/test/functional/api/server_requests_spec.lua +++ b/test/functional/api/server_requests_spec.lua @@ -4,10 +4,10 @@ local helpers = require('test.functional.helpers')(after_each) local clear, eval = helpers.clear, helpers.eval local eq, neq, run, stop = helpers.eq, helpers.neq, helpers.run, helpers.stop -local nvim_prog, command, funcs = helpers.nvim_prog, helpers.command, helpers.funcs +local nvim_prog, command, fn = helpers.nvim_prog, helpers.command, helpers.fn local source, next_msg = helpers.source, helpers.next_msg local ok = helpers.ok -local meths = helpers.meths +local api = helpers.api local spawn, merge_args = helpers.spawn, helpers.merge_args local set_session = helpers.set_session local pcall_err = helpers.pcall_err @@ -18,7 +18,7 @@ describe('server -> client', function() before_each(function() clear() - cid = meths.nvim_get_api_info()[1] + cid = api.nvim_get_api_info()[1] end) it('handles unexpected closed stream while preparing RPC response', function() @@ -77,15 +77,15 @@ describe('server -> client', function() describe('recursive call', function() it('works', function() local function on_setup() - meths.nvim_set_var('result1', 0) - meths.nvim_set_var('result2', 0) - meths.nvim_set_var('result3', 0) - meths.nvim_set_var('result4', 0) + api.nvim_set_var('result1', 0) + api.nvim_set_var('result2', 0) + api.nvim_set_var('result3', 0) + api.nvim_set_var('result4', 0) command('let g:result1 = rpcrequest(' .. cid .. ', "rcall", 2)') - eq(4, meths.nvim_get_var('result1')) - eq(8, meths.nvim_get_var('result2')) - eq(16, meths.nvim_get_var('result3')) - eq(32, meths.nvim_get_var('result4')) + eq(4, api.nvim_get_var('result1')) + eq(8, api.nvim_get_var('result2')) + eq(16, api.nvim_get_var('result3')) + eq(32, api.nvim_get_var('result4')) stop() end @@ -113,12 +113,12 @@ 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', fn.rpcrequest(cid, 'doit')) stop() end local function on_request(method) if method == 'doit' then - funcs.rpcnotify(cid, 'headsup') + fn.rpcnotify(cid, 'headsup') eq(true, received) return 'retval' end @@ -231,8 +231,8 @@ describe('server -> client', function() describe('jobstart()', function() local jobid before_each(function() - local channel = meths.nvim_get_api_info()[1] - meths.nvim_set_var('channel', channel) + local channel = api.nvim_get_api_info()[1] + api.nvim_set_var('channel', channel) source([[ function! s:OnEvent(id, data, event) call rpcnotify(g:channel, a:event, 0, a:data) @@ -244,7 +244,7 @@ describe('server -> client', function() \ 'rpc': v:true \ } ]]) - meths.nvim_set_var('args', { + api.nvim_set_var('args', { nvim_prog, '-ll', 'test/functional/api/rpc_fixture.lua', @@ -256,7 +256,7 @@ describe('server -> client', function() end) after_each(function() - pcall(funcs.jobstop, jobid) + pcall(fn.jobstop, jobid) end) if helpers.skip(helpers.is_os('win')) then @@ -264,16 +264,16 @@ describe('server -> client', function() end it('rpc and text stderr can be combined', function() - local status, rv = pcall(funcs.rpcrequest, jobid, 'poll') + local status, rv = pcall(fn.rpcrequest, jobid, 'poll') if not status then error(string.format('missing nvim Lua module? (%s)', rv)) end eq('ok', rv) - funcs.rpcnotify(jobid, 'ping') + fn.rpcnotify(jobid, 'ping') eq({ 'notification', 'pong', {} }, next_msg()) - eq('done!', funcs.rpcrequest(jobid, 'write_stderr', 'fluff\n')) + eq('done!', fn.rpcrequest(jobid, 'write_stderr', 'fluff\n')) eq({ 'notification', 'stderr', { 0, { 'fluff', '' } } }, next_msg()) - pcall(funcs.rpcrequest, jobid, 'exit') + pcall(fn.rpcrequest, jobid, 'exit') eq({ 'notification', 'stderr', { 0, { '' } } }, next_msg()) eq({ 'notification', 'exit', { 0, 0 } }, next_msg()) end) @@ -282,29 +282,29 @@ describe('server -> client', function() describe('connecting to another (peer) nvim', function() local nvim_argv = merge_args(helpers.nvim_argv, { '--headless' }) local function connect_test(server, mode, address) - local serverpid = funcs.getpid() + local serverpid = fn.getpid() local client = spawn(nvim_argv, false, nil, true) set_session(client) - local clientpid = funcs.getpid() + local clientpid = fn.getpid() neq(serverpid, clientpid) - local id = funcs.sockconnect(mode, address, { rpc = true }) + local id = fn.sockconnect(mode, address, { rpc = true }) ok(id > 0) - funcs.rpcrequest(id, 'nvim_set_current_line', 'hello') - local client_id = funcs.rpcrequest(id, 'nvim_get_api_info')[1] + fn.rpcrequest(id, 'nvim_set_current_line', 'hello') + local client_id = fn.rpcrequest(id, 'nvim_get_api_info')[1] set_session(server) - eq(serverpid, funcs.getpid()) - eq('hello', meths.nvim_get_current_line()) + eq(serverpid, fn.getpid()) + eq('hello', api.nvim_get_current_line()) -- method calls work both ways - funcs.rpcrequest(client_id, 'nvim_set_current_line', 'howdy!') - eq(id, funcs.rpcrequest(client_id, 'nvim_get_api_info')[1]) + fn.rpcrequest(client_id, 'nvim_set_current_line', 'howdy!') + eq(id, fn.rpcrequest(client_id, 'nvim_get_api_info')[1]) set_session(client) - eq(clientpid, funcs.getpid()) - eq('howdy!', meths.nvim_get_current_line()) + eq(clientpid, fn.getpid()) + eq('howdy!', api.nvim_get_current_line()) server:close() client:close() @@ -313,7 +313,7 @@ describe('server -> client', function() it('via named pipe', function() local server = spawn(nvim_argv) set_session(server) - local address = funcs.serverlist()[1] + local address = fn.serverlist()[1] local first = string.sub(address, 1, 1) ok(first == '/' or first == '\\') connect_test(server, 'pipe', address) @@ -322,7 +322,7 @@ 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(fn.serverstart, '127.0.0.1:') if not status then pending('no ipv4 stack') end @@ -333,7 +333,7 @@ describe('server -> client', function() it('via ipv6 address', function() local server = spawn(nvim_argv) set_session(server) - local status, address = pcall(funcs.serverstart, '::1:') + local status, address = pcall(fn.serverstart, '::1:') if not status then pending('no ipv6 stack') end @@ -344,7 +344,7 @@ describe('server -> client', function() it('via hostname', function() local server = spawn(nvim_argv) set_session(server) - local address = funcs.serverstart('localhost:') + local address = fn.serverstart('localhost:') eq('localhost:', string.sub(address, 1, 10)) connect_test(server, 'tcp', address) end) @@ -352,12 +352,12 @@ describe('server -> client', function() it('does not crash on receiving UI events', function() local server = spawn(nvim_argv) set_session(server) - local address = funcs.serverlist()[1] + local address = fn.serverlist()[1] local client = spawn(nvim_argv, false, nil, true) set_session(client) - local id = funcs.sockconnect('pipe', address, { rpc = true }) - funcs.rpcrequest(id, 'nvim_ui_attach', 80, 24, {}) + local id = fn.sockconnect('pipe', address, { rpc = true }) + fn.rpcrequest(id, 'nvim_ui_attach', 80, 24, {}) assert_alive() server:close() @@ -367,18 +367,18 @@ describe('server -> client', function() describe('connecting to its own pipe address', function() it('does not deadlock', function() - local address = funcs.serverlist()[1] + local address = fn.serverlist()[1] local first = string.sub(address, 1, 1) ok(first == '/' or first == '\\') - local serverpid = funcs.getpid() + local serverpid = fn.getpid() - local id = funcs.sockconnect('pipe', address, { rpc = true }) + local id = fn.sockconnect('pipe', address, { rpc = true }) - funcs.rpcrequest(id, 'nvim_set_current_line', 'hello') - eq('hello', meths.nvim_get_current_line()) - eq(serverpid, funcs.rpcrequest(id, 'nvim_eval', 'getpid()')) + fn.rpcrequest(id, 'nvim_set_current_line', 'hello') + eq('hello', api.nvim_get_current_line()) + eq(serverpid, fn.rpcrequest(id, 'nvim_eval', 'getpid()')) - eq(id, funcs.rpcrequest(id, 'nvim_get_api_info')[1]) + eq(id, fn.rpcrequest(id, 'nvim_get_api_info')[1]) end) end) end) -- cgit From 0185152802d4a84258a9a04c1d86a7e27d37d721 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 12 Feb 2024 05:50:39 -0800 Subject: refactor(tests): get channel id via nvim_get_chan_info #27441 Minor "best practices" nudge. --- test/functional/api/server_requests_spec.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'test/functional/api/server_requests_spec.lua') diff --git a/test/functional/api/server_requests_spec.lua b/test/functional/api/server_requests_spec.lua index 5e508e7513..298dbac217 100644 --- a/test/functional/api/server_requests_spec.lua +++ b/test/functional/api/server_requests_spec.lua @@ -18,18 +18,18 @@ describe('server -> client', function() before_each(function() clear() - cid = api.nvim_get_api_info()[1] + cid = api.nvim_get_chan_info(0).id end) it('handles unexpected closed stream while preparing RPC response', function() source([[ let g:_nvim_args = [v:progpath, '--embed', '--headless', '-n', '-u', 'NONE', '-i', 'NONE', ] let ch1 = jobstart(g:_nvim_args, {'rpc': v:true}) - let child1_ch = rpcrequest(ch1, "nvim_get_api_info")[0] + let child1_ch = rpcrequest(ch1, "nvim_get_chan_info", 0).id call rpcnotify(ch1, 'nvim_eval', 'rpcrequest('.child1_ch.', "nvim_get_api_info")') let ch2 = jobstart(g:_nvim_args, {'rpc': v:true}) - let child2_ch = rpcrequest(ch2, "nvim_get_api_info")[0] + let child2_ch = rpcrequest(ch2, "nvim_get_chan_info", 0).id call rpcnotify(ch2, 'nvim_eval', 'rpcrequest('.child2_ch.', "nvim_get_api_info")') call jobstop(ch1) @@ -231,7 +231,7 @@ describe('server -> client', function() describe('jobstart()', function() local jobid before_each(function() - local channel = api.nvim_get_api_info()[1] + local channel = api.nvim_get_chan_info(0).id api.nvim_set_var('channel', channel) source([[ function! s:OnEvent(id, data, event) @@ -292,7 +292,7 @@ describe('server -> client', function() ok(id > 0) fn.rpcrequest(id, 'nvim_set_current_line', 'hello') - local client_id = fn.rpcrequest(id, 'nvim_get_api_info')[1] + local client_id = fn.rpcrequest(id, 'nvim_get_chan_info', 0).id set_session(server) eq(serverpid, fn.getpid()) @@ -300,7 +300,7 @@ describe('server -> client', function() -- method calls work both ways fn.rpcrequest(client_id, 'nvim_set_current_line', 'howdy!') - eq(id, fn.rpcrequest(client_id, 'nvim_get_api_info')[1]) + eq(id, fn.rpcrequest(client_id, 'nvim_get_chan_info', 0).id) set_session(client) eq(clientpid, fn.getpid()) @@ -378,7 +378,7 @@ describe('server -> client', function() eq('hello', api.nvim_get_current_line()) eq(serverpid, fn.rpcrequest(id, 'nvim_eval', 'getpid()')) - eq(id, fn.rpcrequest(id, 'nvim_get_api_info')[1]) + eq(id, fn.rpcrequest(id, 'nvim_get_chan_info', 0).id) end) end) end) -- cgit