aboutsummaryrefslogtreecommitdiff
path: root/test/functional/helpers.lua
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2019-04-17 01:08:48 +0200
committerJustin M. Keyes <justinkz@gmail.com>2019-04-27 16:19:40 +0200
commit17291642bd9a58c39fb4d61f6b6170829a47c73e (patch)
tree1f4189cd6608f6b9c62a48e180f389f0090b3225 /test/functional/helpers.lua
parentf0a7e3fc9a6057d7e3e060d2de37e4fda9239046 (diff)
downloadrneovim-17291642bd9a58c39fb4d61f6b6170829a47c73e.tar.gz
rneovim-17291642bd9a58c39fb4d61f6b6170829a47c73e.tar.bz2
rneovim-17291642bd9a58c39fb4d61f6b6170829a47c73e.zip
test: clear(): `args_rm` parameter
Diffstat (limited to 'test/functional/helpers.lua')
-rw-r--r--test/functional/helpers.lua55
1 files changed, 49 insertions, 6 deletions
diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua
index b518813f5d..7cb562a776 100644
--- a/test/functional/helpers.lua
+++ b/test/functional/helpers.lua
@@ -38,7 +38,7 @@ local nvim_prog = (
local nvim_set = 'set shortmess+=I background=light noswapfile noautoindent'
..' laststatus=1 undodir=. directory=. viewdir=. backupdir=.'
..' belloff= noshowcmd noruler nomore'
-local nvim_argv = {nvim_prog, '-u', 'NONE', '-i', 'NONE', '-N',
+local nvim_argv = {nvim_prog, '-u', 'NONE', '-i', 'NONE',
'--cmd', nvim_set, '--embed'}
-- Directory containing nvim.
local nvim_dir = nvim_prog:gsub("[/\\][^/\\]+$", "")
@@ -312,6 +312,43 @@ local function merge_args(...)
return argv
end
+-- Removes Nvim startup args from `args` matching items in `args_rm`.
+--
+-- "-u", "-i", "--cmd" are treated specially: their "values" are also removed.
+-- Example:
+-- args={'--headless', '-u', 'NONE'}
+-- args_rm={'--cmd', '-u'}
+-- Result:
+-- {'--headless'}
+--
+-- All cases are removed.
+-- Example:
+-- args={'--cmd', 'foo', '-N', '--cmd', 'bar'}
+-- args_rm={'--cmd', '-u'}
+-- Result:
+-- {'-N'}
+local function remove_args(args, args_rm)
+ local new_args = {}
+ local skip_following = {'-u', '-i', '-c', '--cmd', '-s', '--listen'}
+ if not args_rm or #args_rm == 0 then
+ return {unpack(args)}
+ end
+ for _, v in ipairs(args_rm) do
+ assert(type(v) == 'string')
+ end
+ local last = ''
+ for _, arg in ipairs(args) do
+ if table_contains(skip_following, last) then
+ last = ''
+ elseif table_contains(args_rm, arg) then
+ last = arg
+ else
+ table.insert(new_args, arg)
+ end
+ end
+ return new_args
+end
+
local function spawn(argv, merge, env)
local child_stream = ChildProcessStream.spawn(
merge and merge_args(prepend_argv, argv) or argv,
@@ -350,14 +387,18 @@ local function retry(max, max_ms, fn)
end
-- Starts a new global Nvim session.
+--
-- Parameters are interpreted as startup args, OR a map with these keys:
--- args: Appended to the default `nvim_argv` set.
--- env : Defines the environment of the new session.
--- headless: Append --headless arg.
+-- args: List: Args appended to the default `nvim_argv` set.
+-- args_rm: List: Args removed from the default set. All cases are
+-- removed, e.g. args_rm={'--cmd'} removes all cases of "--cmd"
+-- (and its value) from the default set.
+-- env: Map: Defines the environment of the new session.
+-- headless: Boolean (default=true): Append --headless arg.
--
-- Example:
-- clear('-e')
--- clear{args={'-e'}, env={TERM=term}}
+-- clear{args={'-e'}, args_rm={'-i'}, env={TERM=term}}
local function clear(...)
local args = {unpack(nvim_argv)}
local new_args
@@ -365,6 +406,7 @@ local function clear(...)
local opts = select(1, ...)
local headless = true
if type(opts) == 'table' then
+ args = remove_args(args, opts.args_rm)
if opts.env then
local env_tbl = {}
for k, v in pairs(opts.env) do
@@ -375,7 +417,8 @@ local function clear(...)
for _, k in ipairs({
'HOME',
'ASAN_OPTIONS',
- 'LD_LIBRARY_PATH', 'PATH',
+ 'LD_LIBRARY_PATH',
+ 'PATH',
'NVIM_LOG_FILE',
'NVIM_RPLUGIN_MANIFEST',
}) do