neovim/test/functional/eval/server_spec.lua

84 lines
2.8 KiB
Lua
Raw Normal View History

2015-04-02 08:49:22 -07:00
local helpers = require('test.functional.helpers')(after_each)
local nvim, eq, neq, eval = helpers.nvim, helpers.eq, helpers.neq, helpers.eval
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
describe('serverstart(), serverstop()', function()
2015-04-02 08:49:22 -07:00
before_each(clear)
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 = ""')
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)
it('sets v:servername _only_ on nvim startup unless all servers are stopped',
function()
local initial_server = meths.get_vvar('servername')
assert(initial_server ~= nil and initial_server:len() > 0,
'v:servername was not initialized')
-- v:servername is readonly so we cannot unset it--but we can test that it
-- does not get set again thereafter.
local s = funcs.serverstart()
assert(s ~= nil and s:len() > 0, "serverstart() returned empty")
neq(initial_server, s)
-- serverstop() does _not_ modify v:servername...
funcs.serverstop(s)
eq(initial_server, meths.get_vvar('servername'))
-- ...unless we stop _all_ servers.
funcs.serverstop(funcs.serverlist()[1])
eq('', meths.get_vvar('servername'))
-- 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')
funcs.serverstart(servername)
eq(servername, meths.get_vvar('servername'))
2015-04-02 08:49:22 -07:00
end)
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)