mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 11:28:22 +00:00
test: Extend {unit,functional}.helpers with global helpers
Automatically include all "global helper" util functions in the unit.helpers and functional.helpers and modules. So tests don't need to expicitly do: local global_helpers = require('test.helpers')
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
-- Test server -> client RPC scenarios. Note: unlike `rpcnotify`, to evaluate
|
-- Test server -> client RPC scenarios. Note: unlike `rpcnotify`, to evaluate
|
||||||
-- `rpcrequest` calls we need the client event loop to be running.
|
-- `rpcrequest` calls we need the client event loop to be running.
|
||||||
local helpers = require('test.functional.helpers')(after_each)
|
local helpers = require('test.functional.helpers')(after_each)
|
||||||
local Paths = require('test.config.paths')
|
|
||||||
|
|
||||||
local clear, nvim, eval = helpers.clear, helpers.nvim, helpers.eval
|
local clear, nvim, eval = helpers.clear, helpers.nvim, helpers.eval
|
||||||
local eq, neq, run, stop = helpers.eq, helpers.neq, helpers.run, helpers.stop
|
local eq, neq, run, stop = helpers.eq, helpers.neq, helpers.run, helpers.stop
|
||||||
@@ -243,8 +242,8 @@ describe('server -> client', function()
|
|||||||
\ 'rpc': v:true
|
\ 'rpc': v:true
|
||||||
\ }
|
\ }
|
||||||
]])
|
]])
|
||||||
local lua_prog = Paths.test_lua_prg
|
meths.set_var("args", {helpers.test_lua_prg,
|
||||||
meths.set_var("args", {lua_prog, 'test/functional/api/rpc_fixture.lua'})
|
'test/functional/api/rpc_fixture.lua'})
|
||||||
jobid = eval("jobstart(g:args, g:job_opts)")
|
jobid = eval("jobstart(g:args, g:job_opts)")
|
||||||
neq(0, 'jobid')
|
neq(0, 'jobid')
|
||||||
end)
|
end)
|
||||||
|
@@ -8,20 +8,12 @@ local Session = require('nvim.session')
|
|||||||
local TcpStream = require('nvim.tcp_stream')
|
local TcpStream = require('nvim.tcp_stream')
|
||||||
local SocketStream = require('nvim.socket_stream')
|
local SocketStream = require('nvim.socket_stream')
|
||||||
local ChildProcessStream = require('nvim.child_process_stream')
|
local ChildProcessStream = require('nvim.child_process_stream')
|
||||||
local Paths = require('test.config.paths')
|
|
||||||
|
|
||||||
local check_cores = global_helpers.check_cores
|
local check_cores = global_helpers.check_cores
|
||||||
local check_logs = global_helpers.check_logs
|
local check_logs = global_helpers.check_logs
|
||||||
local dedent = global_helpers.dedent
|
local dedent = global_helpers.dedent
|
||||||
local eq = global_helpers.eq
|
local eq = global_helpers.eq
|
||||||
local expect_err = global_helpers.expect_err
|
|
||||||
local filter = global_helpers.filter
|
|
||||||
local map = global_helpers.map
|
|
||||||
local matches = global_helpers.matches
|
|
||||||
local near = global_helpers.near
|
|
||||||
local neq = global_helpers.neq
|
|
||||||
local ok = global_helpers.ok
|
local ok = global_helpers.ok
|
||||||
local read_file = global_helpers.read_file
|
|
||||||
local sleep = global_helpers.sleep
|
local sleep = global_helpers.sleep
|
||||||
local table_contains = global_helpers.table_contains
|
local table_contains = global_helpers.table_contains
|
||||||
local table_flatten = global_helpers.table_flatten
|
local table_flatten = global_helpers.table_flatten
|
||||||
@@ -32,7 +24,7 @@ local start_dir = lfs.currentdir()
|
|||||||
local nvim_prog = (
|
local nvim_prog = (
|
||||||
os.getenv('NVIM_PROG')
|
os.getenv('NVIM_PROG')
|
||||||
or os.getenv('NVIM_PRG')
|
or os.getenv('NVIM_PRG')
|
||||||
or Paths.test_build_dir .. '/bin/nvim'
|
or global_helpers.test_build_dir .. '/bin/nvim'
|
||||||
)
|
)
|
||||||
-- Default settings for the test session.
|
-- Default settings for the test session.
|
||||||
local nvim_set = 'set shortmess+=I background=light noswapfile noautoindent'
|
local nvim_set = 'set shortmess+=I background=light noswapfile noautoindent'
|
||||||
@@ -802,33 +794,25 @@ local module = {
|
|||||||
curtabmeths = curtabmeths,
|
curtabmeths = curtabmeths,
|
||||||
curwin = curwin,
|
curwin = curwin,
|
||||||
curwinmeths = curwinmeths,
|
curwinmeths = curwinmeths,
|
||||||
dedent = dedent,
|
|
||||||
eq = eq,
|
|
||||||
eval = nvim_eval,
|
eval = nvim_eval,
|
||||||
exc_exec = exc_exec,
|
exc_exec = exc_exec,
|
||||||
expect = expect,
|
expect = expect,
|
||||||
expect_any = expect_any,
|
expect_any = expect_any,
|
||||||
expect_err = expect_err,
|
|
||||||
expect_msg_seq = expect_msg_seq,
|
expect_msg_seq = expect_msg_seq,
|
||||||
expect_twostreams = expect_twostreams,
|
expect_twostreams = expect_twostreams,
|
||||||
feed = feed,
|
feed = feed,
|
||||||
feed_command = feed_command,
|
feed_command = feed_command,
|
||||||
filter = filter,
|
|
||||||
funcs = funcs,
|
funcs = funcs,
|
||||||
get_pathsep = get_pathsep,
|
get_pathsep = get_pathsep,
|
||||||
get_session = get_session,
|
get_session = get_session,
|
||||||
insert = insert,
|
insert = insert,
|
||||||
iswin = iswin,
|
iswin = iswin,
|
||||||
map = map,
|
|
||||||
matches = matches,
|
|
||||||
merge_args = merge_args,
|
merge_args = merge_args,
|
||||||
meth_pcall = meth_pcall,
|
meth_pcall = meth_pcall,
|
||||||
meths = meths,
|
meths = meths,
|
||||||
missing_provider = missing_provider,
|
missing_provider = missing_provider,
|
||||||
mkdir = lfs.mkdir,
|
mkdir = lfs.mkdir,
|
||||||
load_adjust = load_adjust,
|
load_adjust = load_adjust,
|
||||||
near = near,
|
|
||||||
neq = neq,
|
|
||||||
new_pipename = new_pipename,
|
new_pipename = new_pipename,
|
||||||
next_msg = next_msg,
|
next_msg = next_msg,
|
||||||
nvim = nvim,
|
nvim = nvim,
|
||||||
@@ -838,13 +822,11 @@ local module = {
|
|||||||
nvim_prog = nvim_prog,
|
nvim_prog = nvim_prog,
|
||||||
nvim_prog_abs = nvim_prog_abs,
|
nvim_prog_abs = nvim_prog_abs,
|
||||||
nvim_set = nvim_set,
|
nvim_set = nvim_set,
|
||||||
ok = ok,
|
|
||||||
os_name = os_name,
|
os_name = os_name,
|
||||||
pathroot = pathroot,
|
pathroot = pathroot,
|
||||||
pending_win32 = pending_win32,
|
pending_win32 = pending_win32,
|
||||||
prepend_argv = prepend_argv,
|
prepend_argv = prepend_argv,
|
||||||
rawfeed = rawfeed,
|
rawfeed = rawfeed,
|
||||||
read_file = read_file,
|
|
||||||
redir_exec = redir_exec,
|
redir_exec = redir_exec,
|
||||||
request = request,
|
request = request,
|
||||||
retry = retry,
|
retry = retry,
|
||||||
@@ -854,20 +836,17 @@ local module = {
|
|||||||
set_session = set_session,
|
set_session = set_session,
|
||||||
set_shell_powershell = set_shell_powershell,
|
set_shell_powershell = set_shell_powershell,
|
||||||
skip_fragile = skip_fragile,
|
skip_fragile = skip_fragile,
|
||||||
sleep = sleep,
|
|
||||||
source = source,
|
source = source,
|
||||||
spawn = spawn,
|
spawn = spawn,
|
||||||
stop = stop,
|
stop = stop,
|
||||||
table_flatten = table_flatten,
|
|
||||||
tabmeths = tabmeths,
|
tabmeths = tabmeths,
|
||||||
tabpage = tabpage,
|
tabpage = tabpage,
|
||||||
tmpname = tmpname,
|
|
||||||
uimeths = uimeths,
|
uimeths = uimeths,
|
||||||
wait = wait,
|
wait = wait,
|
||||||
window = window,
|
window = window,
|
||||||
winmeths = winmeths,
|
winmeths = winmeths,
|
||||||
write_file = write_file,
|
|
||||||
}
|
}
|
||||||
|
module = global_helpers.map_extend('error', module, global_helpers)
|
||||||
|
|
||||||
return function(after_each)
|
return function(after_each)
|
||||||
if after_each then
|
if after_each then
|
||||||
|
@@ -3,6 +3,7 @@ local assert = require('luassert')
|
|||||||
local luv = require('luv')
|
local luv = require('luv')
|
||||||
local lfs = require('lfs')
|
local lfs = require('lfs')
|
||||||
local relpath = require('pl.path').relpath
|
local relpath = require('pl.path').relpath
|
||||||
|
local Paths = require('test.config.paths')
|
||||||
|
|
||||||
local quote_me = '[^.%w%+%-%@%_%/]' -- complement (needn't quote)
|
local quote_me = '[^.%w%+%-%@%_%/]' -- complement (needn't quote)
|
||||||
local function shell_quote(str)
|
local function shell_quote(str)
|
||||||
@@ -420,6 +421,7 @@ local function updated(d, d2)
|
|||||||
return d
|
return d
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Concat list-like tables.
|
||||||
local function concat_tables(...)
|
local function concat_tables(...)
|
||||||
local ret = {}
|
local ret = {}
|
||||||
for i = 1, select('#', ...) do
|
for i = 1, select('#', ...) do
|
||||||
@@ -433,6 +435,34 @@ local function concat_tables(...)
|
|||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Concat map-like tables.
|
||||||
|
--
|
||||||
|
-- behavior: Decides what to do if a key is found in more than one map:
|
||||||
|
-- "error": raise an error
|
||||||
|
-- "keep": skip
|
||||||
|
-- "force": set the item again
|
||||||
|
local function map_extend(behavior, ...)
|
||||||
|
if (behavior ~= 'error' and behavior ~= 'keep' and behavior ~= 'force') then
|
||||||
|
error('invalid "behavior": '..tostring(behavior))
|
||||||
|
end
|
||||||
|
local ret = {}
|
||||||
|
for i = 1, select('#', ...) do
|
||||||
|
local tbl = select(i, ...)
|
||||||
|
if tbl then
|
||||||
|
for k, v in pairs(tbl) do
|
||||||
|
if behavior ~= 'force' and ret[k] ~= nil then
|
||||||
|
if behavior == 'error' then
|
||||||
|
error('key found in more than one map: '..k)
|
||||||
|
end -- Else behavior is "keep".
|
||||||
|
else
|
||||||
|
ret[k] = v
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return ret
|
||||||
|
end
|
||||||
|
|
||||||
local function dedent(str, leave_indent)
|
local function dedent(str, leave_indent)
|
||||||
-- find minimum common indent across lines
|
-- find minimum common indent across lines
|
||||||
local indent = nil
|
local indent = nil
|
||||||
@@ -771,6 +801,7 @@ local module = {
|
|||||||
intchar2lua = intchar2lua,
|
intchar2lua = intchar2lua,
|
||||||
isCI = isCI,
|
isCI = isCI,
|
||||||
map = map,
|
map = map,
|
||||||
|
map_extend = map_extend,
|
||||||
matches = matches,
|
matches = matches,
|
||||||
mergedicts_copy = mergedicts_copy,
|
mergedicts_copy = mergedicts_copy,
|
||||||
near = near,
|
near = near,
|
||||||
@@ -792,5 +823,6 @@ local module = {
|
|||||||
which = which,
|
which = which,
|
||||||
write_file = write_file,
|
write_file = write_file,
|
||||||
}
|
}
|
||||||
|
module = map_extend('error', module, Paths)
|
||||||
|
|
||||||
return module
|
return module
|
||||||
|
@@ -15,7 +15,6 @@ local dedent = global_helpers.dedent
|
|||||||
local neq = global_helpers.neq
|
local neq = global_helpers.neq
|
||||||
local map = global_helpers.map
|
local map = global_helpers.map
|
||||||
local eq = global_helpers.eq
|
local eq = global_helpers.eq
|
||||||
local ok = global_helpers.ok
|
|
||||||
|
|
||||||
-- C constants.
|
-- C constants.
|
||||||
local NULL = ffi.cast('void*', 0)
|
local NULL = ffi.cast('void*', 0)
|
||||||
@@ -842,9 +841,6 @@ local module = {
|
|||||||
cimport = cimport,
|
cimport = cimport,
|
||||||
cppimport = cppimport,
|
cppimport = cppimport,
|
||||||
internalize = internalize,
|
internalize = internalize,
|
||||||
ok = ok,
|
|
||||||
eq = eq,
|
|
||||||
neq = neq,
|
|
||||||
ffi = ffi,
|
ffi = ffi,
|
||||||
lib = lib,
|
lib = lib,
|
||||||
cstr = cstr,
|
cstr = cstr,
|
||||||
@@ -869,6 +865,7 @@ local module = {
|
|||||||
ptr2key = ptr2key,
|
ptr2key = ptr2key,
|
||||||
debug_log = debug_log,
|
debug_log = debug_log,
|
||||||
}
|
}
|
||||||
|
module = global_helpers.map_extend('error', module, global_helpers)
|
||||||
return function()
|
return function()
|
||||||
return module
|
return module
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user