mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
test: clear(): args_rm
parameter
This commit is contained in:
parent
f0a7e3fc9a
commit
17291642bd
@ -13,9 +13,7 @@ local nvim_set = helpers.nvim_set
|
|||||||
local read_file = helpers.read_file
|
local read_file = helpers.read_file
|
||||||
local retry = helpers.retry
|
local retry = helpers.retry
|
||||||
local rmdir = helpers.rmdir
|
local rmdir = helpers.rmdir
|
||||||
local set_session = helpers.set_session
|
|
||||||
local sleep = helpers.sleep
|
local sleep = helpers.sleep
|
||||||
local spawn = helpers.spawn
|
|
||||||
local iswin = helpers.iswin
|
local iswin = helpers.iswin
|
||||||
local write_file = helpers.write_file
|
local write_file = helpers.write_file
|
||||||
|
|
||||||
@ -228,10 +226,6 @@ describe('sysinit', function()
|
|||||||
local vimdir = 'Xvim'
|
local vimdir = 'Xvim'
|
||||||
local xhome = 'Xhome'
|
local xhome = 'Xhome'
|
||||||
local pathsep = helpers.get_pathsep()
|
local pathsep = helpers.get_pathsep()
|
||||||
local argv = {
|
|
||||||
nvim_prog, '--headless', '--embed', '-i', 'NONE', '-n',
|
|
||||||
'--cmd', 'set nomore undodir=. directory=. belloff='
|
|
||||||
}
|
|
||||||
|
|
||||||
before_each(function()
|
before_each(function()
|
||||||
rmdir(xdgdir)
|
rmdir(xdgdir)
|
||||||
@ -260,19 +254,21 @@ describe('sysinit', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
it('prefers XDG_CONFIG_DIRS over VIM', function()
|
it('prefers XDG_CONFIG_DIRS over VIM', function()
|
||||||
set_session(spawn(argv, nil,
|
clear{args={'--cmd', 'set nomore undodir=. directory=. belloff='},
|
||||||
{ 'HOME='..xhome,
|
args_rm={'-u', '--cmd'},
|
||||||
'XDG_CONFIG_DIRS='..xdgdir,
|
env={ HOME=xhome,
|
||||||
'VIM='..vimdir }))
|
XDG_CONFIG_DIRS=xdgdir,
|
||||||
|
VIM=vimdir }}
|
||||||
eq('loaded 1 xdg 1 vim 0',
|
eq('loaded 1 xdg 1 vim 0',
|
||||||
eval('printf("loaded %d xdg %d vim %d", g:loaded, get(g:, "xdg", 0), get(g:, "vim", 0))'))
|
eval('printf("loaded %d xdg %d vim %d", g:loaded, get(g:, "xdg", 0), get(g:, "vim", 0))'))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('uses VIM if XDG_CONFIG_DIRS unset', function()
|
it('uses VIM if XDG_CONFIG_DIRS unset', function()
|
||||||
set_session(spawn(argv, nil,
|
clear{args={'--cmd', 'set nomore undodir=. directory=. belloff='},
|
||||||
{ 'HOME='..xhome,
|
args_rm={'-u', '--cmd'},
|
||||||
'XDG_CONFIG_DIRS=',
|
env={ HOME=xhome,
|
||||||
'VIM='..vimdir }))
|
XDG_CONFIG_DIRS='',
|
||||||
|
VIM=vimdir }}
|
||||||
eq('loaded 1 xdg 0 vim 1',
|
eq('loaded 1 xdg 0 vim 1',
|
||||||
eval('printf("loaded %d xdg %d vim %d", g:loaded, get(g:, "xdg", 0), get(g:, "vim", 0))'))
|
eval('printf("loaded %d xdg %d vim %d", g:loaded, get(g:, "xdg", 0), get(g:, "vim", 0))'))
|
||||||
end)
|
end)
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
local Screen = require('test.functional.ui.screen')
|
local Screen = require('test.functional.ui.screen')
|
||||||
local helpers = require('test.functional.helpers')(after_each)
|
local helpers = require('test.functional.helpers')(after_each)
|
||||||
|
|
||||||
|
local clear = helpers.clear
|
||||||
local buf, eq, feed_command = helpers.curbufmeths, helpers.eq, helpers.feed_command
|
local buf, eq, feed_command = helpers.curbufmeths, helpers.eq, helpers.feed_command
|
||||||
local feed, nvim_prog, wait = helpers.feed, helpers.nvim_prog, helpers.wait
|
local feed, wait = helpers.feed, helpers.wait
|
||||||
local ok, set_session, spawn = helpers.ok, helpers.set_session, helpers.spawn
|
local ok = helpers.ok
|
||||||
local eval = helpers.eval
|
local eval = helpers.eval
|
||||||
|
|
||||||
local shada_file = 'Xtest.shada'
|
local shada_file = 'Xtest.shada'
|
||||||
|
|
||||||
local function _clear()
|
local function _clear()
|
||||||
set_session(spawn({nvim_prog, '--embed', '--headless', '-u', 'NONE',
|
clear{args={'-i', shada_file, -- Need shada for these tests.
|
||||||
-- Need shada for these tests.
|
'--cmd', 'set noswapfile undodir=. directory=. viewdir=. backupdir=. belloff= noshowcmd noruler'},
|
||||||
'-i', shada_file,
|
args_rm={'-i', '--cmd'}}
|
||||||
'--cmd', 'set noswapfile undodir=. directory=. viewdir=. backupdir=. belloff= noshowcmd noruler'}))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe(':oldfiles', function()
|
describe(':oldfiles', function()
|
||||||
|
@ -1,23 +1,21 @@
|
|||||||
local helpers = require('test.functional.helpers')(after_each)
|
local helpers = require('test.functional.helpers')(after_each)
|
||||||
local lfs = require('lfs')
|
local lfs = require('lfs')
|
||||||
local command, eq, neq, spawn, nvim_prog, set_session, write_file =
|
local clear = helpers.clear
|
||||||
helpers.command, helpers.eq, helpers.neq, helpers.spawn,
|
local command, eq, neq, write_file =
|
||||||
helpers.nvim_prog, helpers.set_session, helpers.write_file
|
helpers.command, helpers.eq, helpers.neq, helpers.write_file
|
||||||
local iswin = helpers.iswin
|
local iswin = helpers.iswin
|
||||||
local read_file = helpers.read_file
|
local read_file = helpers.read_file
|
||||||
|
|
||||||
describe(':wshada', function()
|
describe(':wshada', function()
|
||||||
local shada_file = 'wshada_test'
|
local shada_file = 'wshada_test'
|
||||||
local session
|
|
||||||
|
|
||||||
before_each(function()
|
before_each(function()
|
||||||
-- Override the default session because we need 'swapfile' for these tests.
|
clear{args={'-i', iswin() and 'nul' or '/dev/null',
|
||||||
session = spawn({nvim_prog, '-u', 'NONE', '-i', iswin() and 'nul' or '/dev/null', '--embed',
|
-- Need 'swapfile' for these tests.
|
||||||
'--cmd', 'set swapfile'})
|
'--cmd', 'set swapfile undodir=. directory=. viewdir=. backupdir=. belloff= noshowcmd noruler'},
|
||||||
set_session(session)
|
args_rm={'-n', '-i', '--cmd'}}
|
||||||
end)
|
end)
|
||||||
after_each(function ()
|
after_each(function ()
|
||||||
session:close()
|
|
||||||
os.remove(shada_file)
|
os.remove(shada_file)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ local nvim_prog = (
|
|||||||
local nvim_set = 'set shortmess+=I background=light noswapfile noautoindent'
|
local nvim_set = 'set shortmess+=I background=light noswapfile noautoindent'
|
||||||
..' laststatus=1 undodir=. directory=. viewdir=. backupdir=.'
|
..' laststatus=1 undodir=. directory=. viewdir=. backupdir=.'
|
||||||
..' belloff= noshowcmd noruler nomore'
|
..' 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'}
|
'--cmd', nvim_set, '--embed'}
|
||||||
-- Directory containing nvim.
|
-- Directory containing nvim.
|
||||||
local nvim_dir = nvim_prog:gsub("[/\\][^/\\]+$", "")
|
local nvim_dir = nvim_prog:gsub("[/\\][^/\\]+$", "")
|
||||||
@ -312,6 +312,43 @@ local function merge_args(...)
|
|||||||
return argv
|
return argv
|
||||||
end
|
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 function spawn(argv, merge, env)
|
||||||
local child_stream = ChildProcessStream.spawn(
|
local child_stream = ChildProcessStream.spawn(
|
||||||
merge and merge_args(prepend_argv, argv) or argv,
|
merge and merge_args(prepend_argv, argv) or argv,
|
||||||
@ -350,14 +387,18 @@ local function retry(max, max_ms, fn)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Starts a new global Nvim session.
|
-- Starts a new global Nvim session.
|
||||||
|
--
|
||||||
-- Parameters are interpreted as startup args, OR a map with these keys:
|
-- Parameters are interpreted as startup args, OR a map with these keys:
|
||||||
-- args: Appended to the default `nvim_argv` set.
|
-- args: List: Args appended to the default `nvim_argv` set.
|
||||||
-- env : Defines the environment of the new session.
|
-- args_rm: List: Args removed from the default set. All cases are
|
||||||
-- headless: Append --headless arg.
|
-- 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:
|
-- Example:
|
||||||
-- clear('-e')
|
-- clear('-e')
|
||||||
-- clear{args={'-e'}, env={TERM=term}}
|
-- clear{args={'-e'}, args_rm={'-i'}, env={TERM=term}}
|
||||||
local function clear(...)
|
local function clear(...)
|
||||||
local args = {unpack(nvim_argv)}
|
local args = {unpack(nvim_argv)}
|
||||||
local new_args
|
local new_args
|
||||||
@ -365,6 +406,7 @@ local function clear(...)
|
|||||||
local opts = select(1, ...)
|
local opts = select(1, ...)
|
||||||
local headless = true
|
local headless = true
|
||||||
if type(opts) == 'table' then
|
if type(opts) == 'table' then
|
||||||
|
args = remove_args(args, opts.args_rm)
|
||||||
if opts.env then
|
if opts.env then
|
||||||
local env_tbl = {}
|
local env_tbl = {}
|
||||||
for k, v in pairs(opts.env) do
|
for k, v in pairs(opts.env) do
|
||||||
@ -375,7 +417,8 @@ local function clear(...)
|
|||||||
for _, k in ipairs({
|
for _, k in ipairs({
|
||||||
'HOME',
|
'HOME',
|
||||||
'ASAN_OPTIONS',
|
'ASAN_OPTIONS',
|
||||||
'LD_LIBRARY_PATH', 'PATH',
|
'LD_LIBRARY_PATH',
|
||||||
|
'PATH',
|
||||||
'NVIM_LOG_FILE',
|
'NVIM_LOG_FILE',
|
||||||
'NVIM_RPLUGIN_MANIFEST',
|
'NVIM_RPLUGIN_MANIFEST',
|
||||||
}) do
|
}) do
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
local helpers = require('test.functional.helpers')(after_each)
|
local helpers = require('test.functional.helpers')(after_each)
|
||||||
local lfs = require('lfs')
|
local lfs = require('lfs')
|
||||||
local clear, command, eq, neq, eval, wait, spawn =
|
local clear, command, eq, neq, eval, wait =
|
||||||
helpers.clear, helpers.command, helpers.eq, helpers.neq, helpers.eval,
|
helpers.clear, helpers.command, helpers.eq, helpers.neq, helpers.eval,
|
||||||
helpers.wait, helpers.spawn
|
helpers.wait
|
||||||
|
|
||||||
describe('storing global variables in ShaDa files', function()
|
describe('storing global variables in ShaDa files', function()
|
||||||
local tempname = 'Xtest-functional-legacy-074'
|
local tempname = 'Xtest-functional-legacy-074'
|
||||||
@ -14,9 +14,7 @@ describe('storing global variables in ShaDa files', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
it('is working', function()
|
it('is working', function()
|
||||||
local nvim2 = spawn({helpers.nvim_prog, '-u', 'NONE',
|
clear{args_rm={'-i'}, args={'-i', 'Xviminfo'}}
|
||||||
'-i', 'Xviminfo', '--embed'})
|
|
||||||
helpers.set_session(nvim2)
|
|
||||||
|
|
||||||
local test_dict = {foo = 1, bar = 0, longvarible = 1000}
|
local test_dict = {foo = 1, bar = 0, longvarible = 1000}
|
||||||
local test_list = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
|
local test_list = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
|
||||||
|
@ -15,9 +15,6 @@ local neq = helpers.neq
|
|||||||
local mkdir = helpers.mkdir
|
local mkdir = helpers.mkdir
|
||||||
local rmdir = helpers.rmdir
|
local rmdir = helpers.rmdir
|
||||||
local alter_slashes = helpers.alter_slashes
|
local alter_slashes = helpers.alter_slashes
|
||||||
local spawn = helpers.spawn
|
|
||||||
local nvim_prog = helpers.nvim_prog
|
|
||||||
local set_session = helpers.set_session
|
|
||||||
|
|
||||||
describe('startup defaults', function()
|
describe('startup defaults', function()
|
||||||
describe(':filetype', function()
|
describe(':filetype', function()
|
||||||
@ -164,26 +161,22 @@ describe('startup defaults', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
it("'shadafile' ('viminfofile')", function()
|
it("'shadafile' ('viminfofile')", function()
|
||||||
-- Cannot use clear() because we do not want "-i NONE".
|
local env = {XDG_DATA_HOME='Xtest-userdata', XDG_CONFIG_HOME='Xtest-userconfig'}
|
||||||
local function clear_use_default_shada()
|
clear{args={}, args_rm={'-i'}, env=env}
|
||||||
set_session(spawn({nvim_prog, '-u', 'NONE', '--embed', '--headless'},
|
|
||||||
false,
|
|
||||||
{XDG_DATA_HOME='Xtest-userdata',
|
|
||||||
XDG_CONFIG_HOME='Xtest-userconfig'}))
|
|
||||||
end
|
|
||||||
clear_use_default_shada()
|
|
||||||
-- Default 'shadafile' is empty.
|
-- Default 'shadafile' is empty.
|
||||||
-- This means use the default location. :help shada-file-name
|
-- This means use the default location. :help shada-file-name
|
||||||
eq('', meths.get_option('shadafile'))
|
eq('', meths.get_option('shadafile'))
|
||||||
eq('', meths.get_option('viminfofile'))
|
eq('', meths.get_option('viminfofile'))
|
||||||
-- Check that shada data (such as v:oldfiles) is saved/restored.
|
-- Check that shada data (such as v:oldfiles) is saved/restored.
|
||||||
command('edit foo')
|
command('edit Xtest-foo')
|
||||||
command('write')
|
command('write')
|
||||||
local f = eval('fnamemodify(@%,":p")')
|
local f = eval('fnamemodify(@%,":p")')
|
||||||
assert(string.len(f) > 3)
|
assert(string.len(f) > 3)
|
||||||
command('qall')
|
command('qall')
|
||||||
clear_use_default_shada()
|
clear{args={}, args_rm={'-i'}, env=env}
|
||||||
eq({ f }, eval('v:oldfiles'))
|
eq({ f }, eval('v:oldfiles'))
|
||||||
|
os.remove('Xtest-foo')
|
||||||
|
rmdir('Xtest-userdata')
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("'packpath'", function()
|
it("'packpath'", function()
|
||||||
|
Loading…
Reference in New Issue
Block a user