2022-02-24 08:47:41 -07:00
|
|
|
local helpers = require('test.functional.helpers')(after_each)
|
|
|
|
|
|
|
|
local clear = helpers.clear
|
|
|
|
local command = helpers.command
|
|
|
|
local eq = helpers.eq
|
2023-03-25 19:49:32 -07:00
|
|
|
local exec_capture = helpers.exec_capture
|
2022-09-17 01:17:51 -07:00
|
|
|
local exec_lua = helpers.exec_lua
|
2022-02-24 08:47:41 -07:00
|
|
|
local expect = helpers.expect
|
2024-01-12 10:59:57 -07:00
|
|
|
local fn = helpers.fn
|
2022-02-24 08:47:41 -07:00
|
|
|
local insert = helpers.insert
|
2023-06-11 00:29:51 -07:00
|
|
|
local nvim_prog = helpers.nvim_prog
|
2022-02-24 08:47:41 -07:00
|
|
|
local new_argv = helpers.new_argv
|
|
|
|
local neq = helpers.neq
|
|
|
|
local set_session = helpers.set_session
|
|
|
|
local spawn = helpers.spawn
|
|
|
|
local tmpname = helpers.tmpname
|
|
|
|
local write_file = helpers.write_file
|
|
|
|
|
|
|
|
describe('Remote', function()
|
|
|
|
local fname, other_fname
|
|
|
|
local contents = 'The call is coming from outside the process'
|
|
|
|
local other_contents = "A second file's contents"
|
|
|
|
|
|
|
|
before_each(function()
|
|
|
|
fname = tmpname() .. ' with spaces in the filename'
|
|
|
|
other_fname = tmpname()
|
|
|
|
write_file(fname, contents)
|
|
|
|
write_file(other_fname, other_contents)
|
|
|
|
end)
|
|
|
|
|
|
|
|
describe('connect to server and', function()
|
|
|
|
local server
|
|
|
|
before_each(function()
|
|
|
|
server = spawn(new_argv(), true)
|
|
|
|
set_session(server)
|
|
|
|
end)
|
|
|
|
|
|
|
|
after_each(function()
|
|
|
|
server:close()
|
|
|
|
end)
|
|
|
|
|
2023-06-11 00:29:51 -07:00
|
|
|
-- Run a `nvim --remote*` command and return { stdout, stderr } of the process
|
2022-03-03 14:33:27 -07:00
|
|
|
local function run_remote(...)
|
2022-02-24 08:47:41 -07:00
|
|
|
set_session(server)
|
2024-01-12 10:59:57 -07:00
|
|
|
local addr = fn.serverlist()[1]
|
2022-02-24 08:47:41 -07:00
|
|
|
|
|
|
|
-- Create an nvim instance just to run the remote-invoking nvim. We want
|
|
|
|
-- to wait for the remote instance to exit and calling jobwait blocks
|
|
|
|
-- the event loop. If the server event loop is blocked, it can't process
|
|
|
|
-- our incoming --remote calls.
|
|
|
|
local client_starter = spawn(new_argv(), false, nil, true)
|
|
|
|
set_session(client_starter)
|
2022-09-17 01:17:51 -07:00
|
|
|
-- Call jobstart() and jobwait() in the same RPC request to reduce flakiness.
|
2024-01-02 18:09:18 -07:00
|
|
|
eq(
|
|
|
|
{ 0 },
|
|
|
|
exec_lua(
|
|
|
|
[[return vim.fn.jobwait({ vim.fn.jobstart({...}, {
|
2023-06-11 00:29:51 -07:00
|
|
|
stdout_buffered = true,
|
|
|
|
stderr_buffered = true,
|
|
|
|
on_stdout = function(_, data, _)
|
|
|
|
_G.Remote_stdout = table.concat(data, '\n')
|
|
|
|
end,
|
|
|
|
on_stderr = function(_, data, _)
|
|
|
|
_G.Remote_stderr = table.concat(data, '\n')
|
|
|
|
end,
|
2024-01-02 18:09:18 -07:00
|
|
|
}) })]],
|
|
|
|
nvim_prog,
|
|
|
|
'--clean',
|
|
|
|
'--headless',
|
|
|
|
'--server',
|
|
|
|
addr,
|
|
|
|
...
|
|
|
|
)
|
|
|
|
)
|
2023-06-11 00:29:51 -07:00
|
|
|
local res = exec_lua([[return { _G.Remote_stdout, _G.Remote_stderr }]])
|
2022-02-24 08:47:41 -07:00
|
|
|
client_starter:close()
|
|
|
|
set_session(server)
|
2023-06-11 00:29:51 -07:00
|
|
|
return res
|
2022-02-24 08:47:41 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
it('edit a single file', function()
|
2023-06-11 00:29:51 -07:00
|
|
|
eq({ '', '' }, run_remote('--remote', fname))
|
2022-02-24 08:47:41 -07:00
|
|
|
expect(contents)
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(2, #fn.getbufinfo())
|
2022-02-24 08:47:41 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('tab edit a single file with a non-changed buffer', function()
|
2023-06-11 00:29:51 -07:00
|
|
|
eq({ '', '' }, run_remote('--remote-tab', fname))
|
2022-02-24 08:47:41 -07:00
|
|
|
expect(contents)
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(1, #fn.gettabinfo())
|
2022-02-24 08:47:41 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('tab edit a single file with a changed buffer', function()
|
|
|
|
insert('hello')
|
2023-06-11 00:29:51 -07:00
|
|
|
eq({ '', '' }, run_remote('--remote-tab', fname))
|
2022-02-24 08:47:41 -07:00
|
|
|
expect(contents)
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(2, #fn.gettabinfo())
|
2022-02-24 08:47:41 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('edit multiple files', function()
|
2023-06-11 00:29:51 -07:00
|
|
|
eq({ '', '' }, run_remote('--remote', fname, other_fname))
|
2022-02-24 08:47:41 -07:00
|
|
|
expect(contents)
|
|
|
|
command('next')
|
|
|
|
expect(other_contents)
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(3, #fn.getbufinfo())
|
2022-02-24 08:47:41 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('send keys', function()
|
2024-01-02 18:09:18 -07:00
|
|
|
eq({ '', '' }, run_remote('--remote-send', ':edit ' .. fname .. '<CR><C-W>v'))
|
2022-02-24 08:47:41 -07:00
|
|
|
expect(contents)
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(2, #fn.getwininfo())
|
2022-02-24 08:47:41 -07:00
|
|
|
-- Only a single buffer as we're using edit and not drop like --remote does
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(1, #fn.getbufinfo())
|
2022-02-24 08:47:41 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('evaluate expressions', function()
|
2023-06-11 07:12:32 -07:00
|
|
|
eq({ '0', '' }, run_remote('--remote-expr', 'setline(1, "Yo")'))
|
|
|
|
eq({ 'Yo', '' }, run_remote('--remote-expr', 'getline(1)'))
|
2022-02-24 08:47:41 -07:00
|
|
|
expect('Yo')
|
2023-06-30 17:16:34 -07:00
|
|
|
eq({ ('k'):rep(1234), '' }, run_remote('--remote-expr', 'repeat("k", 1234)'))
|
2023-06-11 07:12:32 -07:00
|
|
|
eq({ '1.25', '' }, run_remote('--remote-expr', '1.25'))
|
|
|
|
eq({ 'no', '' }, run_remote('--remote-expr', '0z6E6F'))
|
|
|
|
eq({ '\t', '' }, run_remote('--remote-expr', '"\t"'))
|
2022-02-24 08:47:41 -07:00
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('creates server if not found', function()
|
|
|
|
clear('--remote', fname)
|
|
|
|
expect(contents)
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(1, #fn.getbufinfo())
|
2022-02-24 08:47:41 -07:00
|
|
|
-- Since we didn't pass silent, we should get a complaint
|
2023-03-25 19:49:32 -07:00
|
|
|
neq(nil, string.find(exec_capture('messages'), 'E247:'))
|
2022-02-24 08:47:41 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('creates server if not found with tabs', function()
|
|
|
|
clear('--remote-tab-silent', fname, other_fname)
|
|
|
|
expect(contents)
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(2, #fn.gettabinfo())
|
|
|
|
eq(2, #fn.getbufinfo())
|
2022-02-24 08:47:41 -07:00
|
|
|
-- We passed silent, so no message should be issued about the server not being found
|
2023-03-25 19:49:32 -07:00
|
|
|
eq(nil, string.find(exec_capture('messages'), 'E247:'))
|
2022-02-24 08:47:41 -07:00
|
|
|
end)
|
|
|
|
|
2023-06-11 00:29:51 -07:00
|
|
|
describe('exits with error on', function()
|
2022-02-24 08:47:41 -07:00
|
|
|
local function run_and_check_exit_code(...)
|
|
|
|
local bogus_argv = new_argv(...)
|
|
|
|
|
|
|
|
-- Create an nvim instance just to run the remote-invoking nvim. We want
|
|
|
|
-- to wait for the remote instance to exit and calling jobwait blocks
|
|
|
|
-- the event loop. If the server event loop is blocked, it can't process
|
|
|
|
-- our incoming --remote calls.
|
2022-03-03 14:33:27 -07:00
|
|
|
clear()
|
2022-09-17 01:17:51 -07:00
|
|
|
-- Call jobstart() and jobwait() in the same RPC request to reduce flakiness.
|
|
|
|
eq({ 2 }, exec_lua([[return vim.fn.jobwait({ vim.fn.jobstart(...) })]], bogus_argv))
|
2022-02-24 08:47:41 -07:00
|
|
|
end
|
|
|
|
it('bogus subcommand', function()
|
|
|
|
run_and_check_exit_code('--remote-bogus')
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('send without server', function()
|
|
|
|
run_and_check_exit_code('--remote-send', 'i')
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('expr without server', function()
|
|
|
|
run_and_check_exit_code('--remote-expr', 'setline(1, "Yo")')
|
|
|
|
end)
|
2022-03-03 14:33:27 -07:00
|
|
|
it('wait subcommand', function()
|
|
|
|
run_and_check_exit_code('--remote-wait', fname)
|
|
|
|
end)
|
2022-02-24 08:47:41 -07:00
|
|
|
end)
|
|
|
|
end)
|