mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Merge pull request #6680 from mhinz/listen/localhost
Use uv_getaddrinfo() for servers
This commit is contained in:
@@ -1,20 +1,27 @@
|
||||
|
||||
local helpers = require('test.functional.helpers')(after_each)
|
||||
local nvim, eq, neq, eval = helpers.nvim, helpers.eq, helpers.neq, helpers.eval
|
||||
local eq, neq, eval = helpers.eq, helpers.neq, helpers.eval
|
||||
local command = helpers.command
|
||||
local clear, funcs, meths = helpers.clear, helpers.funcs, helpers.meths
|
||||
local os_name = helpers.os_name
|
||||
|
||||
local function clear_serverlist()
|
||||
for _, server in pairs(funcs.serverlist()) do
|
||||
funcs.serverstop(server)
|
||||
end
|
||||
end
|
||||
|
||||
describe('serverstart(), serverstop()', function()
|
||||
before_each(clear)
|
||||
|
||||
it('sets $NVIM_LISTEN_ADDRESS on first invocation', function()
|
||||
-- Unset $NVIM_LISTEN_ADDRESS
|
||||
nvim('command', 'let $NVIM_LISTEN_ADDRESS = ""')
|
||||
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.."')")
|
||||
command("call serverstop('"..s.."')")
|
||||
eq('', eval('$NVIM_LISTEN_ADDRESS'))
|
||||
end)
|
||||
|
||||
@@ -47,10 +54,38 @@ describe('serverstart(), serverstop()', function()
|
||||
end)
|
||||
|
||||
it('serverstop() ignores invalid input', function()
|
||||
nvim('command', "call serverstop('')")
|
||||
nvim('command', "call serverstop('bogus-socket-name')")
|
||||
command("call serverstop('')")
|
||||
command("call serverstop('bogus-socket-name')")
|
||||
end)
|
||||
|
||||
it('parses endpoints correctly', function()
|
||||
clear_serverlist()
|
||||
eq({}, funcs.serverlist())
|
||||
|
||||
local s = funcs.serverstart('127.0.0.1:0') -- assign random port
|
||||
assert(string.match(s, '127.0.0.1:%d+'))
|
||||
eq(s, funcs.serverlist()[1])
|
||||
clear_serverlist()
|
||||
|
||||
s = funcs.serverstart('127.0.0.1:') -- assign random port
|
||||
assert(string.match(s, '127.0.0.1:%d+'))
|
||||
eq(s, funcs.serverlist()[1])
|
||||
clear_serverlist()
|
||||
|
||||
funcs.serverstart('127.0.0.1:12345')
|
||||
funcs.serverstart('127.0.0.1:12345') -- exists already; ignore
|
||||
funcs.serverstart('::1:12345')
|
||||
funcs.serverstart('::1:12345') -- exists already; ignore
|
||||
local expected = {
|
||||
'127.0.0.1:12345',
|
||||
'::1:12345',
|
||||
}
|
||||
eq(expected, funcs.serverlist())
|
||||
clear_serverlist()
|
||||
|
||||
funcs.serverstart('127.0.0.1:65536') -- invalid port
|
||||
eq({}, funcs.serverlist())
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('serverlist()', function()
|
||||
@@ -75,7 +110,7 @@ describe('serverlist()', function()
|
||||
-- The new servers should be at the end of the list.
|
||||
for i = 1, #servs do
|
||||
eq(servs[i], new_servs[i + n])
|
||||
nvim('command', "call serverstop('"..servs[i].."')")
|
||||
command("call serverstop('"..servs[i].."')")
|
||||
end
|
||||
-- After serverstop() the servers should NOT be in the list.
|
||||
eq(n, eval('len(serverlist())'))
|
||||
|
||||
Reference in New Issue
Block a user