From b11b681289582472340e3af72ea116c4ba354066 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Wed, 11 Apr 2018 01:43:15 +0200 Subject: test/util: matches() --- test/functional/helpers.lua | 2 ++ test/helpers.lua | 7 +++++++ 2 files changed, 9 insertions(+) (limited to 'test') diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index b8d912114d..84ba6b6853 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -16,6 +16,7 @@ local neq = global_helpers.neq local eq = global_helpers.eq local ok = global_helpers.ok local map = global_helpers.map +local matches = global_helpers.matches local filter = global_helpers.filter local dedent = global_helpers.dedent local table_flatten = global_helpers.table_flatten @@ -747,6 +748,7 @@ local module = { insert = insert, iswin = iswin, map = map, + matches = matches, merge_args = merge_args, meth_pcall = meth_pcall, meths = meths, diff --git a/test/helpers.lua b/test/helpers.lua index 7cce6d8c55..0b6a10a29a 100644 --- a/test/helpers.lua +++ b/test/helpers.lua @@ -16,6 +16,12 @@ end local function ok(res) return assert.is_true(res) end +local function matches(pat, actual) + if nil ~= string.match(actual, pat) then + return true + end + error(string.format('Pattern does not match.\nPattern:\n%s\nActual:\n%s', pat, actual)) +end -- initial_path: directory to recurse into -- re: include pattern (string) @@ -572,6 +578,7 @@ return { hasenv = hasenv, intchar2lua = intchar2lua, map = map, + matches = matches, mergedicts_copy = mergedicts_copy, neq = neq, ok = ok, -- cgit From 9f598e57656fe072114b9f1e73d3051423e13234 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 8 Apr 2018 13:06:26 +0200 Subject: serverstop(): return FALSE for invalid address --- test/functional/eval/server_spec.lua | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'test') diff --git a/test/functional/eval/server_spec.lua b/test/functional/eval/server_spec.lua index 393616838e..edd63fe83c 100644 --- a/test/functional/eval/server_spec.lua +++ b/test/functional/eval/server_spec.lua @@ -11,21 +11,21 @@ local function clear_serverlist() end end -describe('serverstart(), serverstop()', function() +describe('server', function() before_each(clear) - it('sets $NVIM_LISTEN_ADDRESS on first invocation', function() + it('serverstart() sets $NVIM_LISTEN_ADDRESS on first invocation', function() -- Unset $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')) - command("call serverstop('"..s.."')") + eq(1, eval("serverstop('"..s.."')")) eq('', eval('$NVIM_LISTEN_ADDRESS')) end) - it('sets v:servername _only_ on nvim startup unless all servers are stopped', + it('serverstart() sets v:servername at startup or if all servers were stopped', function() local initial_server = meths.get_vvar('servername') assert(initial_server ~= nil and initial_server:len() > 0, @@ -38,11 +38,11 @@ describe('serverstart(), serverstop()', function() neq(initial_server, s) -- serverstop() does _not_ modify v:servername... - funcs.serverstop(s) + eq(1, funcs.serverstop(s)) eq(initial_server, meths.get_vvar('servername')) -- ...unless we stop _all_ servers. - funcs.serverstop(funcs.serverlist()[1]) + eq(1, funcs.serverstop(funcs.serverlist()[1])) eq('', meths.get_vvar('servername')) -- v:servername will take the next available server. @@ -53,9 +53,9 @@ describe('serverstart(), serverstop()', function() eq(servername, meths.get_vvar('servername')) end) - it('serverstop() ignores invalid input', function() - command("call serverstop('')") - command("call serverstop('bogus-socket-name')") + it('serverstop() returns false for invalid input', function() + eq(0, eval("serverstop('')")) + eq(0, eval("serverstop('bogus-socket-name')")) end) it('parses endpoints correctly', function() @@ -120,7 +120,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]) - command("call serverstop('"..servs[i].."')") + eq(1, eval("serverstop('"..servs[i].."')")) end -- After serverstop() the servers should NOT be in the list. eq(n, eval('len(serverlist())')) -- cgit From 507bda1c95cdac2886f64e59aa6bbf85c3fac389 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 8 Apr 2018 17:20:25 +0200 Subject: server: introduce --listen, deprecate $NVIM_LISTEN_ADDRESS --- test/functional/eval/server_spec.lua | 38 ++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) (limited to 'test') diff --git a/test/functional/eval/server_spec.lua b/test/functional/eval/server_spec.lua index edd63fe83c..a2644498f2 100644 --- a/test/functional/eval/server_spec.lua +++ b/test/functional/eval/server_spec.lua @@ -1,14 +1,14 @@ - local helpers = require('test.functional.helpers')(after_each) 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 ok = helpers.ok local os_name = helpers.os_name local function clear_serverlist() - for _, server in pairs(funcs.serverlist()) do - funcs.serverstop(server) - end + for _, server in pairs(funcs.serverlist()) do + funcs.serverstop(server) + end end describe('server', function() @@ -96,16 +96,12 @@ describe('server', function() funcs.serverstart('127.0.0.1:65536') -- invalid port eq({}, funcs.serverlist()) end) -end) -describe('serverlist()', function() - before_each(clear) - - it('returns the list of servers', function() + it('serverlist() returns the list of servers', function() -- There should already be at least one server. local n = eval('len(serverlist())') - -- Add a few + -- Add some servers. local servs = (os_name() == 'windows' and { [[\\.\pipe\Xtest-pipe0934]], [[\\.\pipe\Xtest-pipe4324]] } or { [[Xtest-pipe0934]], [[Xtest-pipe4324]] }) @@ -126,3 +122,25 @@ describe('serverlist()', function() eq(n, eval('len(serverlist())')) end) end) + +describe('startup --listen', function() + it('validates', function() + clear() + + local cmd = { unpack(helpers.nvim_argv) } + table.insert(cmd, '--listen') + eq('nvim: Argument missing after: "--listen"', + string.match(funcs.system(cmd), '.-n"')) + + cmd = { unpack(helpers.nvim_argv) } + table.insert(cmd, '--listen2') + eq('nvim: Garbage after option argument: "--listen2"', + string.match(funcs.system(cmd), '.-2"')) + end) + + it('sets v:servername, overrides $NVIM_LISTEN_ADDRESS', function() + clear({ env={ NVIM_LISTEN_ADDRESS='Xtest-env-pipe' }, + args={ '--listen', 'Xtest-listen-pipe' } }) + eq('Xtest-listen-pipe', meths.get_vvar('servername')) + end) +end) -- cgit From 704ba4151e7f67999510ee0ac19fdabb595d530c Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Wed, 11 Apr 2018 00:01:43 +0200 Subject: server: init v:servername if $NVIM_LISTEN_ADDRESS is invalid Before this change, if $NVIM_LISTEN_ADDRESS was invalid, v:servername was left empty. --- test/functional/eval/server_spec.lua | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'test') diff --git a/test/functional/eval/server_spec.lua b/test/functional/eval/server_spec.lua index a2644498f2..4e4aed864b 100644 --- a/test/functional/eval/server_spec.lua +++ b/test/functional/eval/server_spec.lua @@ -2,8 +2,9 @@ local helpers = require('test.functional.helpers')(after_each) 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 iswin = helpers.iswin local ok = helpers.ok -local os_name = helpers.os_name +local matches = helpers.matches local function clear_serverlist() for _, server in pairs(funcs.serverlist()) do @@ -25,7 +26,15 @@ describe('server', function() eq('', eval('$NVIM_LISTEN_ADDRESS')) end) - it('serverstart() sets v:servername at startup or if all servers were stopped', + it('sets new v:servername if $NVIM_LISTEN_ADDRESS is invalid', function() + clear({env={NVIM_LISTEN_ADDRESS='.'}}) + eq('.', eval('$NVIM_LISTEN_ADDRESS')) + local servers = funcs.serverlist() + eq(1, #servers) + ok(string.len(servers[1]) > 4) -- Like /tmp/nvim…/… or \\.\pipe\… + end) + + it('sets v:servername at startup or if all servers were stopped', function() local initial_server = meths.get_vvar('servername') assert(initial_server ~= nil and initial_server:len() > 0, @@ -46,9 +55,8 @@ describe('server', function() eq('', meths.get_vvar('servername')) -- v:servername will take the next available server. - local servername = (os_name() == 'windows' - and [[\\.\pipe\Xtest-functional-server-pipe]] - or 'Xtest-functional-server-socket') + local servername = (iswin() and [[\\.\pipe\Xtest-functional-server-pipe]] + or 'Xtest-functional-server-socket') funcs.serverstart(servername) eq(servername, meths.get_vvar('servername')) end) @@ -102,7 +110,7 @@ describe('server', function() local n = eval('len(serverlist())') -- Add some servers. - local servs = (os_name() == 'windows' + local servs = (iswin() and { [[\\.\pipe\Xtest-pipe0934]], [[\\.\pipe\Xtest-pipe4324]] } or { [[Xtest-pipe0934]], [[Xtest-pipe4324]] }) for _, s in ipairs(servs) do @@ -129,18 +137,18 @@ describe('startup --listen', function() local cmd = { unpack(helpers.nvim_argv) } table.insert(cmd, '--listen') - eq('nvim: Argument missing after: "--listen"', - string.match(funcs.system(cmd), '.-n"')) + matches('nvim.*: Argument missing after: "%-%-listen"', funcs.system(cmd)) cmd = { unpack(helpers.nvim_argv) } table.insert(cmd, '--listen2') - eq('nvim: Garbage after option argument: "--listen2"', - string.match(funcs.system(cmd), '.-2"')) + matches('nvim.*: Garbage after option argument: "%-%-listen2"', funcs.system(cmd)) end) it('sets v:servername, overrides $NVIM_LISTEN_ADDRESS', function() + local addr = (iswin() and [[\\.\pipe\Xtest-listen-pipe]] + or 'Xtest-listen-pipe') clear({ env={ NVIM_LISTEN_ADDRESS='Xtest-env-pipe' }, - args={ '--listen', 'Xtest-listen-pipe' } }) - eq('Xtest-listen-pipe', meths.get_vvar('servername')) + args={ '--listen', addr } }) + eq(addr, meths.get_vvar('servername')) end) end) -- cgit