2015-04-02 08:49:22 -07:00
|
|
|
|
2016-04-23 16:53:11 -07:00
|
|
|
local helpers = require('test.functional.helpers')(after_each)
|
2015-11-17 14:44:00 -07:00
|
|
|
local nvim, eq, neq, eval = helpers.nvim, helpers.eq, helpers.neq, helpers.eval
|
2015-12-29 12:23:51 -07:00
|
|
|
local clear, funcs, meths = helpers.clear, helpers.funcs, helpers.meths
|
2016-03-06 15:26:23 -07:00
|
|
|
local os_name = helpers.os_name
|
2015-04-02 08:49:22 -07:00
|
|
|
|
2015-05-09 01:25:19 -07:00
|
|
|
describe('serverstart(), serverstop()', function()
|
2015-04-02 08:49:22 -07:00
|
|
|
before_each(clear)
|
|
|
|
|
2015-05-09 01:25:19 -07:00
|
|
|
it('sets $NVIM_LISTEN_ADDRESS on first invocation', function()
|
|
|
|
-- Unset $NVIM_LISTEN_ADDRESS
|
2015-04-02 08:49:22 -07:00
|
|
|
nvim('command', 'let $NVIM_LISTEN_ADDRESS = ""')
|
2015-05-09 01:25:19 -07:00
|
|
|
|
|
|
|
local s = eval('serverstart()')
|
|
|
|
assert(s ~= nil and s:len() > 0, "serverstart() returned empty")
|
|
|
|
eq(s, eval('$NVIM_LISTEN_ADDRESS'))
|
|
|
|
nvim('command', "call serverstop('"..s.."')")
|
|
|
|
eq('', eval('$NVIM_LISTEN_ADDRESS'))
|
|
|
|
end)
|
|
|
|
|
2015-12-29 12:23:51 -07:00
|
|
|
it('sets v:servername _only_ on nvim startup unless all servers are stopped',
|
|
|
|
function()
|
|
|
|
local initial_server = meths.get_vvar('servername')
|
2015-05-09 01:25:19 -07:00
|
|
|
assert(initial_server ~= nil and initial_server:len() > 0,
|
2015-12-29 12:23:51 -07:00
|
|
|
'v:servername was not initialized')
|
2015-05-09 01:25:19 -07:00
|
|
|
|
|
|
|
-- v:servername is readonly so we cannot unset it--but we can test that it
|
|
|
|
-- does not get set again thereafter.
|
2015-12-29 12:23:51 -07:00
|
|
|
local s = funcs.serverstart()
|
2015-05-09 01:25:19 -07:00
|
|
|
assert(s ~= nil and s:len() > 0, "serverstart() returned empty")
|
|
|
|
neq(initial_server, s)
|
|
|
|
|
|
|
|
-- serverstop() does _not_ modify v:servername...
|
2015-12-29 12:23:51 -07:00
|
|
|
funcs.serverstop(s)
|
|
|
|
eq(initial_server, meths.get_vvar('servername'))
|
2015-05-09 01:25:19 -07:00
|
|
|
|
|
|
|
-- ...unless we stop _all_ servers.
|
2015-12-29 12:23:51 -07:00
|
|
|
funcs.serverstop(funcs.serverlist()[1])
|
|
|
|
eq('', meths.get_vvar('servername'))
|
2015-05-09 01:25:19 -07:00
|
|
|
|
|
|
|
-- v:servername will take the next available server.
|
2016-03-06 15:26:23 -07:00
|
|
|
local servername = (os_name() == 'windows'
|
2017-01-11 21:08:19 -07:00
|
|
|
and [[\\.\pipe\Xtest-functional-server-pipe]]
|
|
|
|
or 'Xtest-functional-server-socket')
|
2015-12-29 12:23:51 -07:00
|
|
|
funcs.serverstart(servername)
|
|
|
|
eq(servername, meths.get_vvar('servername'))
|
2015-04-02 08:49:22 -07:00
|
|
|
end)
|
|
|
|
|
2015-05-09 01:25:19 -07:00
|
|
|
it('serverstop() ignores invalid input', function()
|
|
|
|
nvim('command', "call serverstop('')")
|
|
|
|
nvim('command', "call serverstop('bogus-socket-name')")
|
|
|
|
end)
|
|
|
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
describe('serverlist()', function()
|
|
|
|
before_each(clear)
|
|
|
|
|
|
|
|
it('returns the list of servers', function()
|
2015-04-02 08:49:22 -07:00
|
|
|
-- There should already be at least one server.
|
|
|
|
local n = eval('len(serverlist())')
|
|
|
|
|
|
|
|
-- Add a few
|
2017-01-11 21:08:19 -07:00
|
|
|
local servs = (os_name() == 'windows'
|
|
|
|
and { [[\\.\pipe\Xtest-pipe0934]], [[\\.\pipe\Xtest-pipe4324]] }
|
|
|
|
or { [[Xtest-pipe0934]], [[Xtest-pipe4324]] })
|
2015-04-02 08:49:22 -07:00
|
|
|
for _, s in ipairs(servs) do
|
2017-01-11 21:08:19 -07:00
|
|
|
eq(s, eval("serverstart('"..s.."')"))
|
2015-04-02 08:49:22 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
local new_servs = eval('serverlist()')
|
|
|
|
|
|
|
|
-- Exactly #servs servers should be added.
|
|
|
|
eq(n + #servs, #new_servs)
|
|
|
|
-- The new servers should be at the end of the list.
|
|
|
|
for i = 1, #servs do
|
|
|
|
eq(servs[i], new_servs[i + n])
|
2017-01-11 21:08:19 -07:00
|
|
|
nvim('command', "call serverstop('"..servs[i].."')")
|
2015-04-02 08:49:22 -07:00
|
|
|
end
|
2017-01-11 21:08:19 -07:00
|
|
|
-- After serverstop() the servers should NOT be in the list.
|
2015-04-02 08:49:22 -07:00
|
|
|
eq(n, eval('len(serverlist())'))
|
|
|
|
end)
|
|
|
|
end)
|