aboutsummaryrefslogtreecommitdiff
path: root/test/functional
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2024-01-17 13:46:55 +0000
committerGitHub <noreply@github.com>2024-01-17 13:46:55 +0000
commite855a80c72ed89815255bb6ff38bff27e58e523f (patch)
treeecb2245caed90d99785df194199cf971284852ee /test/functional
parentd88814ef68b3f2ad3ed005ee0683eff063b017a6 (diff)
parent14b7ffcf89bc448b626df3d9e19f9f5a3682ae2b (diff)
downloadrneovim-e855a80c72ed89815255bb6ff38bff27e58e523f.tar.gz
rneovim-e855a80c72ed89815255bb6ff38bff27e58e523f.tar.bz2
rneovim-e855a80c72ed89815255bb6ff38bff27e58e523f.zip
Merge pull request #27024 from lewis6991/test_followup
test: big cleanup followup + typing
Diffstat (limited to 'test/functional')
-rw-r--r--test/functional/api/vim_spec.lua36
-rw-r--r--test/functional/ex_cmds/swapfile_preserve_recover_spec.lua2
-rw-r--r--test/functional/helpers.lua260
-rw-r--r--test/functional/lua/fs_spec.lua4
-rw-r--r--test/functional/lua/luaeval_spec.lua4
-rw-r--r--test/functional/shada/merging_spec.lua2
-rw-r--r--test/functional/shada/shada_spec.lua2
-rw-r--r--test/functional/terminal/channel_spec.lua6
-rw-r--r--test/functional/ui/messages_spec.lua10
-rw-r--r--test/functional/ui/popupmenu_spec.lua2
-rw-r--r--test/functional/vimscript/ctx_functions_spec.lua4
-rw-r--r--test/functional/vimscript/input_spec.lua20
-rw-r--r--test/functional/vimscript/timer_spec.lua18
13 files changed, 225 insertions, 145 deletions
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua
index 8d9789a3ce..91f61b5053 100644
--- a/test/functional/api/vim_spec.lua
+++ b/test/functional/api/vim_spec.lua
@@ -8,7 +8,7 @@ local assert_alive = helpers.assert_alive
local NIL = vim.NIL
local clear, eq, neq = helpers.clear, helpers.eq, helpers.neq
local command = helpers.command
-local command_output = helpers.api.command_output
+local command_output = helpers.api.nvim_command_output
local exec = helpers.exec
local exec_capture = helpers.exec_capture
local eval = helpers.eval
@@ -19,6 +19,7 @@ local matches = helpers.matches
local pesc = vim.pesc
local mkdir_p = helpers.mkdir_p
local ok, nvim_async, feed = helpers.ok, helpers.nvim_async, helpers.feed
+local async_meths = helpers.async_meths
local is_os = helpers.is_os
local parse_context = helpers.parse_context
local request = helpers.request
@@ -33,7 +34,7 @@ local insert = helpers.insert
local skip = helpers.skip
local pcall_err = helpers.pcall_err
-local format_string = helpers.format_string
+local format_string = require('test.format_string').format_string
local intchar2lua = helpers.intchar2lua
local mergedicts_copy = helpers.mergedicts_copy
local endswith = vim.endswith
@@ -76,7 +77,7 @@ describe('API', function()
eq({
'notification',
'nvim_error_event',
- { error_types.Exception.id, 'Invalid method: nvim_bogus' },
+ { error_types.Exception.id, 'Invalid method: bogus' },
}, next_msg())
-- error didn't close channel.
assert_alive()
@@ -84,7 +85,7 @@ describe('API', function()
it('failed async request emits nvim_error_event', function()
local error_types = api.nvim_get_api_info()[2].error_types
- nvim_async('command', 'bogus')
+ async_meths.nvim_command('bogus')
eq({
'notification',
'nvim_error_event',
@@ -2081,13 +2082,13 @@ describe('API', function()
{ ['rc'] = { 'hjkl' }, ['n'] = 97 },
},
- ['jumps'] = eval(([[
+ ['jumps'] = eval((([[
filter(map(add(
getjumplist()[0], { 'bufnr': bufnr('%'), 'lnum': getcurpos()[1] }),
'filter(
{ "f": expand("#".v:val.bufnr.":p"), "l": v:val.lnum },
{ k, v -> k != "l" || v != 1 })'), '!empty(v:val.f)')
- ]]):gsub('\n', '')),
+ ]]):gsub('\n', ''))),
['bufs'] = eval([[
filter(map(getbufinfo(), '{ "f": v:val.name }'), '!empty(v:val.f)')
@@ -2301,7 +2302,7 @@ describe('API', function()
end)
it('can show one line', function()
- nvim_async('err_write', 'has bork\n')
+ async_meths.nvim_err_write('has bork\n')
screen:expect([[
^ |
{0:~ }|*6
@@ -2310,7 +2311,7 @@ describe('API', function()
end)
it('shows return prompt when more than &cmdheight lines', function()
- nvim_async('err_write', 'something happened\nvery bad\n')
+ async_meths.nvim_err_write('something happened\nvery bad\n')
screen:expect([[
|
{0:~ }|*3
@@ -2322,7 +2323,7 @@ describe('API', function()
end)
it('shows return prompt after all lines are shown', function()
- nvim_async('err_write', 'FAILURE\nERROR\nEXCEPTION\nTRACEBACK\n')
+ async_meths.nvim_err_write('FAILURE\nERROR\nEXCEPTION\nTRACEBACK\n')
screen:expect([[
|
{0:~ }|
@@ -2337,8 +2338,8 @@ describe('API', function()
it('handles multiple calls', function()
-- without linebreak text is joined to one line
- nvim_async('err_write', 'very ')
- nvim_async('err_write', 'fail\n')
+ async_meths.nvim_err_write('very ')
+ async_meths.nvim_err_write('fail\n')
screen:expect([[
^ |
{0:~ }|*6
@@ -2347,7 +2348,7 @@ describe('API', function()
helpers.poke_eventloop()
-- shows up to &cmdheight lines
- nvim_async('err_write', 'more fail\ntoo fail\n')
+ async_meths.nvim_err_write('more fail\ntoo fail\n')
screen:expect([[
|
{0:~ }|*3
@@ -2360,7 +2361,7 @@ describe('API', function()
end)
it('NUL bytes in message', function()
- nvim_async('err_write', 'aaa\0bbb\0\0ccc\nddd\0\0\0eee\n')
+ async_meths.nvim_err_write('aaa\0bbb\0\0ccc\nddd\0\0\0eee\n')
screen:expect {
grid = [[
|
@@ -2389,7 +2390,7 @@ describe('API', function()
end)
it('shows only one return prompt after all lines are shown', function()
- nvim_async('err_writeln', 'FAILURE\nERROR\nEXCEPTION\nTRACEBACK')
+ async_meths.nvim_err_writeln('FAILURE\nERROR\nEXCEPTION\nTRACEBACK')
screen:expect([[
|
{0:~ }|
@@ -3394,8 +3395,7 @@ describe('API', function()
end)
it('can show highlighted line', function()
- nvim_async(
- 'echo',
+ async_meths.nvim_echo(
{ { 'msg_a' }, { 'msg_b', 'Statement' }, { 'msg_c', 'Special' } },
true,
{}
@@ -3410,7 +3410,7 @@ describe('API', function()
end)
it('can show highlighted multiline', function()
- nvim_async('echo', { { 'msg_a\nmsg_a', 'Statement' }, { 'msg_b', 'Special' } }, true, {})
+ async_meths.nvim_echo({ { 'msg_a\nmsg_a', 'Statement' }, { 'msg_b', 'Special' } }, true, {})
screen:expect {
grid = [[
|
@@ -3431,7 +3431,7 @@ describe('API', function()
it('can disable saving message history', function()
command('set cmdheight=2') -- suppress Press ENTER
- nvim_async('echo', { { 'msg\nmsg' }, { 'msg' } }, false, {})
+ async_meths.nvim_echo({ { 'msg\nmsg' }, { 'msg' } }, false, {})
eq('', exec_capture('messages'))
end)
end)
diff --git a/test/functional/ex_cmds/swapfile_preserve_recover_spec.lua b/test/functional/ex_cmds/swapfile_preserve_recover_spec.lua
index 4c2e54cc6b..a6fdb919c5 100644
--- a/test/functional/ex_cmds/swapfile_preserve_recover_spec.lua
+++ b/test/functional/ex_cmds/swapfile_preserve_recover_spec.lua
@@ -222,7 +222,7 @@ describe('swapfile detection', function()
screen2:expect(expected_no_dialog)
-- With API call and shortmess+=F
- async_meths.command('edit %')
+ async_meths.nvim_command('edit %')
screen2:expect {
any = [[Found a swap file by the name ".*]]
.. [[Xtest_swapdialog_dir[/\].*]]
diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua
index e9f8f30aa0..eddf336b6f 100644
--- a/test/functional/helpers.lua
+++ b/test/functional/helpers.lua
@@ -18,7 +18,7 @@ local fail = global_helpers.fail
local module = {}
local runtime_set = 'set runtimepath^=./build/lib/nvim/'
-module.nvim_prog = (os.getenv('NVIM_PRG') or global_helpers.test_build_dir .. '/bin/nvim')
+module.nvim_prog = (os.getenv('NVIM_PRG') or global_helpers.paths.test_build_dir .. '/bin/nvim')
-- Default settings for the test session.
module.nvim_set = (
'set shortmess+=IS background=light termguicolors noswapfile noautoindent startofline'
@@ -55,7 +55,7 @@ if module.nvim_dir == module.nvim_prog then
module.nvim_dir = '.'
end
-local prepend_argv
+local prepend_argv --- @type string[]?
if os.getenv('VALGRIND') then
local log_file = os.getenv('VALGRIND_LOG') or 'valgrind-%p.log'
@@ -79,7 +79,7 @@ elseif os.getenv('GDB') then
end
if prepend_argv then
- local new_nvim_argv = {}
+ local new_nvim_argv = {} --- @type string[]
local len = #prepend_argv
for i = 1, len do
new_nvim_argv[i] = prepend_argv[i]
@@ -91,10 +91,13 @@ if prepend_argv then
module.prepend_argv = prepend_argv
end
-local session, loop_running, last_error, method_error
+local session --- @type test.Session?
+local loop_running --- @type boolean?
+local last_error --- @type string?
+local method_error --- @type string?
if not is_os('win') then
- local sigpipe_handler = uv.new_signal()
+ local sigpipe_handler = assert(uv.new_signal())
uv.signal_start(sigpipe_handler, 'sigpipe', function()
print('warning: got SIGPIPE signal. Likely related to a crash in nvim')
end)
@@ -108,10 +111,15 @@ function module.set_session(s)
session = s
end
+--- @param method string
+--- @param ... any
+--- @return any
function module.request(method, ...)
+ assert(session)
local status, rv = session:request(method, ...)
if not status then
if loop_running then
+ --- @type string
last_error = rv[2]
session:stop()
else
@@ -121,12 +129,18 @@ function module.request(method, ...)
return rv
end
+--- @param method string
+--- @param ... any
+--- @return any
function module.request_lua(method, ...)
return module.exec_lua([[return vim.api[...](select(2, ...))]], method, ...)
end
+--- @param timeout? integer
+--- @return string?
function module.next_msg(timeout)
- return session:next_message(timeout and timeout or 10000)
+ assert(session)
+ return session:next_message(timeout or 10000)
end
function module.expect_twostreams(msgs1, msgs2)
@@ -164,6 +178,7 @@ function module.expect_msg_seq(...)
error('invalid args')
end
local ignore = arg1['ignore'] and arg1['ignore'] or {}
+ --- @type string[]
local seqs = arg1['seqs'] and arg1['seqs'] or { ... }
if type(ignore) ~= 'table' then
error("'ignore' arg must be a list of strings")
@@ -213,6 +228,7 @@ function module.expect_msg_seq(...)
local message = result
if type(result) == 'table' then
-- 'eq' returns several things
+ --- @type string
message = result.message
end
final_error = cat_err(final_error, message)
@@ -234,8 +250,16 @@ function module.set_method_error(err)
method_error = err
end
+--- @param lsession test.Session
+--- @param request_cb function
+--- @param notification_cb function
+--- @param setup_cb function
+--- @param timeout integer
+--- @return {[1]: integer, [2]: string}
function module.run_session(lsession, request_cb, notification_cb, setup_cb, timeout)
- local on_request, on_notification, on_setup
+ local on_request --- @type function?
+ local on_notification --- @type function?
+ local on_setup --- @type function?
if request_cb then
function on_request(method, args)
@@ -273,11 +297,12 @@ function module.run_session(lsession, request_cb, notification_cb, setup_cb, tim
end
function module.run(request_cb, notification_cb, setup_cb, timeout)
+ assert(session)
return module.run_session(session, request_cb, notification_cb, setup_cb, timeout)
end
function module.stop()
- session:stop()
+ assert(session):stop()
end
function module.nvim_prog_abs()
@@ -301,6 +326,7 @@ function module.expect_exit(fn_or_timeout, ...)
eof_err_msg,
module.pcall_err(function(timeout, fn, ...)
fn(...)
+ assert(session)
while session:next_message(timeout) do
end
if session.eof_err then
@@ -311,26 +337,18 @@ function module.expect_exit(fn_or_timeout, ...)
end
end
--- Evaluates a Vimscript expression.
--- Fails on Vimscript error, but does not update v:errmsg.
-function module.eval(expr)
- return module.request('nvim_eval', expr)
-end
-
--- Executes a Vimscript function via RPC.
--- Fails on Vimscript error, but does not update v:errmsg.
-function module.call(name, ...)
- return module.request('nvim_call_function', name, { ... })
-end
-
--- Executes a Vimscript function via Lua.
--- Fails on Vimscript error, but does not update v:errmsg.
+--- Executes a Vimscript function via Lua.
+--- Fails on Vimscript error, but does not update v:errmsg.
+--- @param name string
+--- @param ... any
+--- @return any
function module.call_lua(name, ...)
return module.exec_lua([[return vim.call(...)]], name, ...)
end
--- Sends user input to Nvim.
--- Does not fail on Vimscript error, but v:errmsg will be updated.
+--- Sends user input to Nvim.
+--- Does not fail on Vimscript error, but v:errmsg will be updated.
+--- @param input string
local function nvim_feed(input)
while #input > 0 do
local written = module.request('nvim_input', input)
@@ -342,22 +360,27 @@ local function nvim_feed(input)
end
end
+--- @param ... string
function module.feed(...)
for _, v in ipairs({ ... }) do
nvim_feed(dedent(v))
end
end
+--- @param ... string
function module.rawfeed(...)
for _, v in ipairs({ ... }) do
nvim_feed(dedent(v))
end
end
+---@param ... string[]?
+---@return string[]
function module.merge_args(...)
local i = 1
- local argv = {}
+ local argv = {} --- @type string[]
for anum = 1, select('#', ...) do
+ --- @type string[]?
local args = select(anum, ...)
if args then
for _, arg in ipairs(args) do
@@ -369,26 +392,29 @@ function module.merge_args(...)
return argv
end
--- Removes Nvim startup args from `args` matching items in `args_rm`.
---
--- - Special case: "-u", "-i", "--cmd" are treated specially: their "values" are also removed.
--- - Special case: "runtimepath" will remove only { '--cmd', 'set runtimepath^=…', }
---
--- Example:
--- args={'--headless', '-u', 'NONE'}
--- args_rm={'--cmd', '-u'}
--- Result:
--- {'--headless'}
---
--- All matching cases are removed.
---
--- Example:
--- args={'--cmd', 'foo', '-N', '--cmd', 'bar'}
--- args_rm={'--cmd', '-u'}
--- Result:
--- {'-N'}
+--- Removes Nvim startup args from `args` matching items in `args_rm`.
+---
+--- - Special case: "-u", "-i", "--cmd" are treated specially: their "values" are also removed.
+--- - Special case: "runtimepath" will remove only { '--cmd', 'set runtimepath^=…', }
+---
+--- Example:
+--- args={'--headless', '-u', 'NONE'}
+--- args_rm={'--cmd', '-u'}
+--- Result:
+--- {'--headless'}
+---
+--- All matching cases are removed.
+---
+--- Example:
+--- args={'--cmd', 'foo', '-N', '--cmd', 'bar'}
+--- args_rm={'--cmd', '-u'}
+--- Result:
+--- {'-N'}
+--- @param args string[]
+--- @param args_rm string[]
+--- @return string[]
local function remove_args(args, args_rm)
- local new_args = {}
+ local new_args = {} --- @type string[]
local skip_following = { '-u', '-i', '-c', '--cmd', '-s', '--listen' }
if not args_rm or #args_rm == 0 then
return { unpack(args) }
@@ -433,7 +459,12 @@ function module.check_close()
session = nil
end
---- @param io_extra used for stdin_fd, see :help ui-option
+--- @param argv string[]
+--- @param merge boolean?
+--- @param env string[]?
+--- @param keep boolean
+--- @param io_extra uv.uv_pipe_t? used for stdin_fd, see :help ui-option
+--- @return test.Session
function module.spawn(argv, merge, env, keep, io_extra)
if not keep then
module.check_close()
@@ -469,16 +500,27 @@ function module.clear(...)
return module.get_session()
end
--- same params as clear, but does returns the session instead
--- of replacing the default session
+--- same params as clear, but does returns the session instead
+--- of replacing the default session
+--- @return test.Session
function module.spawn_argv(keep, ...)
local argv, env, io_extra = module.new_argv(...)
return module.spawn(argv, nil, env, keep, io_extra)
end
--- Builds an argument list for use in clear().
---
----@see clear() for parameters.
+--- @class test.new_argv.Opts
+--- @field args? string[]
+--- @field args_rm? string[]
+--- @field env? table<string,string>
+--- @field io_extra? uv.uv_pipe_t
+
+--- Builds an argument list for use in clear().
+---
+--- @see clear() for parameters.
+--- @param ... string
+--- @return string[]
+--- @return string[]?
+--- @return uv.uv_pipe_t?
function module.new_argv(...)
local args = { unpack(module.nvim_argv) }
table.insert(args, '--headless')
@@ -487,16 +529,17 @@ function module.new_argv(...)
table.insert(args, '--listen')
table.insert(args, _G._nvim_test_id)
end
- local new_args
- local io_extra
- local env = nil
+ local new_args --- @type string[]
+ local io_extra --- @type uv.uv_pipe_t?
+ local env --- @type string[]?
+ --- @type test.new_argv.Opts|string
local opts = select(1, ...)
if type(opts) ~= 'table' then
new_args = { ... }
else
args = remove_args(args, opts.args_rm)
if opts.env then
- local env_opt = {}
+ local env_opt = {} --- @type table<string,string>
for k, v in pairs(opts.env) do
assert(type(k) == 'string')
assert(type(v) == 'string')
@@ -535,6 +578,7 @@ function module.new_argv(...)
return args, env, io_extra
end
+--- @param ... string
function module.insert(...)
nvim_feed('i')
for _, v in ipairs({ ... }) do
@@ -544,8 +588,9 @@ function module.insert(...)
nvim_feed('<ESC>')
end
--- Executes an ex-command by user input. Because nvim_input() is used, Vimscript
--- errors will not manifest as client (lua) errors. Use command() for that.
+--- Executes an ex-command by user input. Because nvim_input() is used, Vimscript
+--- errors will not manifest as client (lua) errors. Use command() for that.
+--- @param ... string
function module.feed_command(...)
for _, v in ipairs({ ... }) do
if v:sub(1, 1) ~= '/' then
@@ -598,8 +643,10 @@ function module.set_shell_powershell(fake)
end
function module.create_callindex(func)
- local table = {}
- setmetatable(table, {
+ return setmetatable({}, {
+ --- @param tbl table<any,function>
+ --- @param arg1 string
+ --- @return function
__index = function(tbl, arg1)
local ret = function(...)
return func(arg1, ...)
@@ -608,36 +655,34 @@ function module.create_callindex(func)
return ret
end,
})
- return table
end
-local function ui(method, ...)
- return module.request('nvim_ui_' .. method, ...)
+--- @param method string
+--- @param ... any
+function module.nvim_async(method, ...)
+ assert(session):notify(method, ...)
end
-function module.nvim_async(method, ...)
- session:notify('nvim_' .. method, ...)
+--- Executes a Vimscript function via RPC.
+--- Fails on Vimscript error, but does not update v:errmsg.
+--- @param name string
+--- @param ... any
+--- @return any
+function module.call(name, ...)
+ return module.request('nvim_call_function', name, { ... })
end
module.async_meths = module.create_callindex(module.nvim_async)
-module.uimeths = module.create_callindex(ui)
-
-local function create_bridge(request, call)
- local function nvim(method, ...)
- if vim.startswith(method, 'nvim_') then
- return request(method, ...)
- end
- return request('nvim_' .. method, ...)
- end
- return {
- fn = module.create_callindex(call),
- api = module.create_callindex(nvim),
- }
-end
+module.rpc = {
+ fn = module.create_callindex(module.call),
+ api = module.create_callindex(module.request),
+}
-module.rpc = create_bridge(module.request, module.call)
-module.lua = create_bridge(module.request_lua, module.call_lua)
+module.lua = {
+ fn = module.create_callindex(module.call_lua),
+ api = module.create_callindex(module.request_lua),
+}
module.describe_lua_and_rpc = function(describe)
return function(what, tests)
@@ -657,6 +702,7 @@ module.api = vim.api
module.fn = vim.fn
for name, fns in pairs(module.rpc) do
+ --- @diagnostic disable-next-line:no-unknown
module[name] = fns
end
@@ -664,10 +710,14 @@ end
-- v:errmsg will not be updated.
module.command = module.api.nvim_command
+-- Evaluates a Vimscript expression.
+-- Fails on Vimscript error, but does not update v:errmsg.
+module.eval = module.api.nvim_eval
+
function module.poke_eventloop()
-- Execute 'nvim_eval' (a deferred function) to
-- force at least one main_loop iteration
- session:request('nvim_eval', '1')
+ module.api.nvim_eval('1')
end
function module.buf_lines(bufnr)
@@ -689,6 +739,10 @@ function module.expect_any(contents)
return ok(nil ~= string.find(module.curbuf_contents(), contents, 1, true))
end
+--- @param expected any[]
+--- @param received any[]
+--- @param kind string
+--- @return any
function module.expect_events(expected, received, kind)
if not pcall(eq, expected, received) then
local msg = 'unexpected ' .. kind .. ' received.\n\n'
@@ -728,6 +782,7 @@ function module.assert_visible(bufnr, visible)
end
end
+--- @param path string
local function do_rmdir(path)
local stat = uv.fs_stat(path)
if stat == nil then
@@ -795,14 +850,17 @@ function module.exc_exec(cmd)
return ret
end
+--- @param cond boolean
+--- @param reason string
+--- @return boolean
function module.skip(cond, reason)
if cond then
+ --- @type fun(reason: string)
local pending = getfenv(2).pending
pending(reason or 'FIXME')
return true
- else
- return false
end
+ return false
end
-- Calls pending() and returns `true` if the system is too slow to
@@ -825,6 +883,8 @@ function module.exec(code)
module.api.nvim_exec2(code, {})
end
+--- @param code string
+--- @return string
function module.exec_capture(code)
return module.api.nvim_exec2(code, { output = true }).output
end
@@ -832,7 +892,7 @@ end
--- @param code string
--- @return any
function module.exec_lua(code, ...)
- return module.api.exec_lua(code, { ... })
+ return module.api.nvim_exec_lua(code, { ... })
end
function module.get_pathsep()
@@ -871,19 +931,24 @@ function module.new_pipename()
return pipename
end
+--- @param provider string
+--- @return string|false?
function module.missing_provider(provider)
if provider == 'ruby' or provider == 'node' or provider == 'perl' then
+ --- @type string?
local e = module.fn['provider#' .. provider .. '#Detect']()[2]
return e ~= '' and e or false
elseif provider == 'python' or provider == 'python3' then
local py_major_version = (provider == 'python3' and 3 or 2)
+ --- @type string?
local e = module.fn['provider#pythonx#Detect'](py_major_version)[2]
return e ~= '' and e or false
- else
- assert(false, 'Unknown provider: ' .. provider)
end
+ assert(false, 'Unknown provider: ' .. provider)
end
+--- @param obj string|table
+--- @return any
function module.alter_slashes(obj)
if not is_os('win') then
return obj
@@ -892,14 +957,14 @@ function module.alter_slashes(obj)
local ret = obj:gsub('/', '\\')
return ret
elseif type(obj) == 'table' then
- local ret = {}
+ --- @cast obj table<any,any>
+ local ret = {} --- @type table<any,any>
for k, v in pairs(obj) do
ret[k] = module.alter_slashes(v)
end
return ret
- else
- assert(false, 'expected string or table of strings, got ' .. type(obj))
end
+ assert(false, 'expected string or table of strings, got ' .. type(obj))
end
local load_factor = 1
@@ -909,18 +974,25 @@ if global_helpers.is_ci() then
module.request('nvim_command', 'source test/old/testdir/load.vim')
load_factor = module.request('nvim_eval', 'g:test_load_factor')
end
+
+--- @param num number
+--- @return number
function module.load_adjust(num)
return math.ceil(num * load_factor)
end
+--- @param ctx table<string,any>
+--- @return table
function module.parse_context(ctx)
- local parsed = {}
+ local parsed = {} --- @type table<string,any>
for _, item in ipairs({ 'regs', 'jumps', 'bufs', 'gvars' }) do
+ --- @param v any
parsed[item] = vim.tbl_filter(function(v)
return type(v) == 'table'
end, module.call('msgpackparse', ctx[item]))
end
parsed['bufs'] = parsed['bufs'][1]
+ --- @param v any
return vim.tbl_map(function(v)
if #v == 0 then
return nil
@@ -931,10 +1003,12 @@ end
function module.add_builddir_to_rtp()
-- Add runtime from build dir for doc/tags (used with :help).
- module.command(string.format([[set rtp+=%s/runtime]], module.test_build_dir))
+ module.command(string.format([[set rtp+=%s/runtime]], module.paths.test_build_dir))
end
--- Kill (reap) a process by PID.
+--- Kill (reap) a process by PID.
+--- @param pid string
+--- @return boolean?
function module.os_kill(pid)
return os.execute(
(
@@ -944,7 +1018,9 @@ function module.os_kill(pid)
)
end
--- Create folder with non existing parents
+--- Create folder with non existing parents
+--- @param path string
+--- @return boolean?
function module.mkdir_p(path)
return os.execute((is_os('win') and 'mkdir ' .. path or 'mkdir -p ' .. path))
end
diff --git a/test/functional/lua/fs_spec.lua b/test/functional/lua/fs_spec.lua
index 66ba0f71f2..6821fe3c5e 100644
--- a/test/functional/lua/fs_spec.lua
+++ b/test/functional/lua/fs_spec.lua
@@ -6,8 +6,8 @@ local eq = helpers.eq
local mkdir_p = helpers.mkdir_p
local rmdir = helpers.rmdir
local nvim_dir = helpers.nvim_dir
-local test_build_dir = helpers.test_build_dir
-local test_source_path = helpers.test_source_path
+local test_build_dir = helpers.paths.test_build_dir
+local test_source_path = helpers.paths.test_source_path
local nvim_prog = helpers.nvim_prog
local is_os = helpers.is_os
local mkdir = helpers.mkdir
diff --git a/test/functional/lua/luaeval_spec.lua b/test/functional/lua/luaeval_spec.lua
index 6ed7af6b6e..171d37ba55 100644
--- a/test/functional/lua/luaeval_spec.lua
+++ b/test/functional/lua/luaeval_spec.lua
@@ -162,7 +162,7 @@ describe('luaeval()', function()
return sp('map', '[' .. val .. ']')
end
local function luaevalarg(argexpr, expr)
- return eval(([=[
+ return eval((([=[
[
extend(g:, {'_ret': luaeval(%s, %s)})._ret,
type(g:_ret)==type({})&&has_key(g:_ret, '_TYPE')
@@ -172,7 +172,7 @@ describe('luaeval()', function()
get(g:_ret, '_VAL', g:_ret)
]
: [0, g:_ret]][1]
- ]=]):format(expr or '"_A"', argexpr):gsub('\n', ''))
+ ]=]):format(expr or '"_A"', argexpr):gsub('\n', '')))
end
it('correctly passes special dictionaries', function()
diff --git a/test/functional/shada/merging_spec.lua b/test/functional/shada/merging_spec.lua
index 94e0ee6e82..1b5c0eab5d 100644
--- a/test/functional/shada/merging_spec.lua
+++ b/test/functional/shada/merging_spec.lua
@@ -525,7 +525,7 @@ describe('ShaDa marks support code', function()
local found = 0
for _, v in ipairs(read_shada_file(shada_fname)) do
if v.type == 7 and v.value.f == mock_file_path .. '-' then
- print(require('test.helpers').format_luav(v))
+ print(require('test.format_string').format_luav(v))
found = found + 1
end
end
diff --git a/test/functional/shada/shada_spec.lua b/test/functional/shada/shada_spec.lua
index 2942beab2f..6eb318015d 100644
--- a/test/functional/shada/shada_spec.lua
+++ b/test/functional/shada/shada_spec.lua
@@ -7,7 +7,7 @@ local is_os = helpers.is_os
local skip = helpers.skip
local uv = vim.uv
-local paths = require('test.cmakeconfig.paths')
+local paths = helpers.paths
local shada_helpers = require('test.functional.shada.helpers')
local reset, clear, get_shada_rw =
diff --git a/test/functional/terminal/channel_spec.lua b/test/functional/terminal/channel_spec.lua
index 2b39c93f14..9615534c87 100644
--- a/test/functional/terminal/channel_spec.lua
+++ b/test/functional/terminal/channel_spec.lua
@@ -151,7 +151,7 @@ describe('no crash when TermOpen autocommand', function()
it('processes job exit event when using termopen()', function()
command([[autocmd TermOpen * call input('')]])
- async_meths.command('terminal foobar')
+ async_meths.nvim_command('terminal foobar')
screen:expect {
grid = [[
|
@@ -181,7 +181,7 @@ describe('no crash when TermOpen autocommand', function()
it('wipes buffer and processes events when using termopen()', function()
command([[autocmd TermOpen * bwipe! | call input('')]])
- async_meths.command('terminal foobar')
+ async_meths.nvim_command('terminal foobar')
screen:expect {
grid = [[
|
@@ -202,7 +202,7 @@ describe('no crash when TermOpen autocommand', function()
it('wipes buffer and processes events when using nvim_open_term()', function()
command([[autocmd TermOpen * bwipe! | call input('')]])
- async_meths.open_term(0, {})
+ async_meths.nvim_open_term(0, {})
screen:expect {
grid = [[
|
diff --git a/test/functional/ui/messages_spec.lua b/test/functional/ui/messages_spec.lua
index 4f95cd909c..9d1b6163d2 100644
--- a/test/functional/ui/messages_spec.lua
+++ b/test/functional/ui/messages_spec.lua
@@ -7,7 +7,7 @@ local command = helpers.command
local set_method_error = helpers.set_method_error
local api = helpers.api
local async_meths = helpers.async_meths
-local test_build_dir = helpers.test_build_dir
+local test_build_dir = helpers.paths.test_build_dir
local nvim_prog = helpers.nvim_prog
local exec = helpers.exec
local exec_capture = helpers.exec_capture
@@ -1039,7 +1039,7 @@ stack traceback:
end)
it('supports nvim_echo messages with multiple attrs', function()
- async_meths.echo(
+ async_meths.nvim_echo(
{ { 'wow, ', 'Search' }, { 'such\n\nvery ', 'ErrorMsg' }, { 'color', 'LineNr' } },
true,
{}
@@ -1403,7 +1403,7 @@ vimComment xxx match /\s"[^\-:.%#=*].*$/ms=s+1,lc=1 excludenl contains=@vim
end)
it('supports nvim_echo messages with multiple attrs', function()
- async_meths.echo(
+ async_meths.nvim_echo(
{ { 'wow, ', 'Search' }, { 'such\n\nvery ', 'ErrorMsg' }, { 'color', 'LineNr' } },
true,
{}
@@ -1521,7 +1521,7 @@ vimComment xxx match /\s"[^\-:.%#=*].*$/ms=s+1,lc=1 excludenl contains=@vim
end)
it('consecutive calls to win_move_statusline() work after multiline message #21014', function()
- async_meths.exec(
+ async_meths.nvim_exec(
[[
echo "\n"
call win_move_statusline(0, -4)
@@ -2196,7 +2196,7 @@ aliquip ex ea commodo consequat.]]
}
-- not processed while command is executing
- async_meths.ui_try_resize(35, 5)
+ async_meths.nvim_ui_try_resize(35, 5)
-- TODO(bfredl): ideally it should be processed just
-- before the "press ENTER" prompt though
diff --git a/test/functional/ui/popupmenu_spec.lua b/test/functional/ui/popupmenu_spec.lua
index b74a15d56f..1f7d187016 100644
--- a/test/functional/ui/popupmenu_spec.lua
+++ b/test/functional/ui/popupmenu_spec.lua
@@ -2527,7 +2527,7 @@ describe('builtin popupmenu', function()
]])
end
feed('<C-E>')
- async_meths.call_function('input', { '', '', 'sign' })
+ async_meths.nvim_call_function('input', { '', '', 'sign' })
if multigrid then
screen:expect {
grid = [[
diff --git a/test/functional/vimscript/ctx_functions_spec.lua b/test/functional/vimscript/ctx_functions_spec.lua
index b8f9bbc92d..dc60a474f3 100644
--- a/test/functional/vimscript/ctx_functions_spec.lua
+++ b/test/functional/vimscript/ctx_functions_spec.lua
@@ -314,13 +314,13 @@ describe('context functions', function()
}
local with_jumps = {
- ['jumps'] = eval(([[
+ ['jumps'] = eval((([[
filter(map(add(
getjumplist()[0], { 'bufnr': bufnr('%'), 'lnum': getcurpos()[1] }),
'filter(
{ "f": expand("#".v:val.bufnr.":p"), "l": v:val.lnum },
{ k, v -> k != "l" || v != 1 })'), '!empty(v:val.f)')
- ]]):gsub('\n', '')),
+ ]]):gsub('\n', ''))),
}
local with_bufs = {
diff --git a/test/functional/vimscript/input_spec.lua b/test/functional/vimscript/input_spec.lua
index 6dd22078d6..b749d5a7f0 100644
--- a/test/functional/vimscript/input_spec.lua
+++ b/test/functional/vimscript/input_spec.lua
@@ -414,19 +414,19 @@ describe('confirm()', function()
-- screen:expect() calls are needed to avoid feeding input too early
screen:expect({ any = '%[No Name%]' })
- async_meths.command([[let a = confirm('Press O to proceed')]])
+ async_meths.nvim_command([[let a = confirm('Press O to proceed')]])
screen:expect({ any = '{CONFIRM:.+: }' })
feed('o')
screen:expect({ any = '%[No Name%]' })
eq(1, api.nvim_get_var('a'))
- async_meths.command([[let a = 'Are you sure?'->confirm("&Yes\n&No")]])
+ async_meths.nvim_command([[let a = 'Are you sure?'->confirm("&Yes\n&No")]])
screen:expect({ any = '{CONFIRM:.+: }' })
feed('y')
screen:expect({ any = '%[No Name%]' })
eq(1, api.nvim_get_var('a'))
- async_meths.command([[let a = confirm('Are you sure?', "&Yes\n&No")]])
+ async_meths.nvim_command([[let a = confirm('Are you sure?', "&Yes\n&No")]])
screen:expect({ any = '{CONFIRM:.+: }' })
feed('n')
screen:expect({ any = '%[No Name%]' })
@@ -435,26 +435,26 @@ describe('confirm()', function()
-- Not possible to match Vim's CTRL-C test here as CTRL-C always sets got_int in Nvim.
-- confirm() should return 0 when pressing ESC.
- async_meths.command([[let a = confirm('Are you sure?', "&Yes\n&No")]])
+ async_meths.nvim_command([[let a = confirm('Are you sure?', "&Yes\n&No")]])
screen:expect({ any = '{CONFIRM:.+: }' })
feed('<Esc>')
screen:expect({ any = '%[No Name%]' })
eq(0, api.nvim_get_var('a'))
-- Default choice is returned when pressing <CR>.
- async_meths.command([[let a = confirm('Are you sure?', "&Yes\n&No")]])
+ async_meths.nvim_command([[let a = confirm('Are you sure?', "&Yes\n&No")]])
screen:expect({ any = '{CONFIRM:.+: }' })
feed('<CR>')
screen:expect({ any = '%[No Name%]' })
eq(1, api.nvim_get_var('a'))
- async_meths.command([[let a = confirm('Are you sure?', "&Yes\n&No", 2)]])
+ async_meths.nvim_command([[let a = confirm('Are you sure?', "&Yes\n&No", 2)]])
screen:expect({ any = '{CONFIRM:.+: }' })
feed('<CR>')
screen:expect({ any = '%[No Name%]' })
eq(2, api.nvim_get_var('a'))
- async_meths.command([[let a = confirm('Are you sure?', "&Yes\n&No", 0)]])
+ async_meths.nvim_command([[let a = confirm('Are you sure?', "&Yes\n&No", 0)]])
screen:expect({ any = '{CONFIRM:.+: }' })
feed('<CR>')
screen:expect({ any = '%[No Name%]' })
@@ -462,7 +462,9 @@ describe('confirm()', function()
-- Test with the {type} 4th argument
for _, type in ipairs({ 'Error', 'Question', 'Info', 'Warning', 'Generic' }) do
- async_meths.command(([[let a = confirm('Are you sure?', "&Yes\n&No", 1, '%s')]]):format(type))
+ async_meths.nvim_command(
+ ([[let a = confirm('Are you sure?', "&Yes\n&No", 1, '%s')]]):format(type)
+ )
screen:expect({ any = '{CONFIRM:.+: }' })
feed('y')
screen:expect({ any = '%[No Name%]' })
@@ -518,7 +520,7 @@ describe('confirm()', function()
feed(':call nvim_command("edit x")<cr>')
check_and_clear(':call nvim_command("edit |\n')
- async_meths.command('edit x')
+ async_meths.nvim_command('edit x')
check_and_clear(' |\n')
end)
end)
diff --git a/test/functional/vimscript/timer_spec.lua b/test/functional/vimscript/timer_spec.lua
index 3f53c21e7a..046d451888 100644
--- a/test/functional/vimscript/timer_spec.lua
+++ b/test/functional/vimscript/timer_spec.lua
@@ -1,7 +1,7 @@
local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen')
local feed, eq, eval, ok = helpers.feed, helpers.eq, helpers.eval, helpers.ok
-local source, nvim_async, run = helpers.source, helpers.nvim_async, helpers.run
+local source, async_meths, run = helpers.source, helpers.async_meths, helpers.run
local clear, command, fn = helpers.clear, helpers.command, helpers.fn
local exc_exec = helpers.exc_exec
local api = helpers.api
@@ -52,9 +52,9 @@ describe('timers', function()
endfunc
]])
eval("timer_start(10, 'MyHandler', {'repeat': -1})")
- nvim_async('command', 'sleep 10')
+ async_meths.nvim_command('sleep 10')
eq(-1, eval('g:val')) -- timer did nothing yet.
- nvim_async('command', 'let g:val = 0')
+ async_meths.nvim_command('let g:val = 0')
run(nil, nil, nil, load_adjust(20))
retry(nil, nil, function()
eq(2, eval('g:val'))
@@ -70,7 +70,7 @@ describe('timers', function()
end)
it('can be started during sleep', function()
- nvim_async('command', 'sleep 10')
+ async_meths.nvim_command('sleep 10')
-- this also tests that remote requests works during sleep
eq(0, eval("[timer_start(10, 'MyHandler', {'repeat': 2}), g:val][1]"))
run(nil, nil, nil, load_adjust(20))
@@ -94,7 +94,7 @@ describe('timers', function()
it('are triggered in blocking getchar() call', function()
command("call timer_start(5, 'MyHandler', {'repeat': -1})")
- nvim_async('command', 'let g:val = 0 | let g:c = getchar()')
+ async_meths.nvim_command('let g:val = 0 | let g:c = getchar()')
retry(nil, nil, function()
local val = eval('g:val')
ok(val >= 2, '>= 2', tostring(val))
@@ -128,8 +128,10 @@ describe('timers', function()
redraw
endfunc
]])
- nvim_async('command', 'let g:c2 = getchar()')
- nvim_async('command', 'call timer_start(' .. load_adjust(100) .. ", 'AddItem', {'repeat': -1})")
+ async_meths.nvim_command('let g:c2 = getchar()')
+ async_meths.nvim_command(
+ 'call timer_start(' .. load_adjust(100) .. ", 'AddItem', {'repeat': -1})"
+ )
screen:expect([[
^ITEM 1 |
@@ -137,7 +139,7 @@ describe('timers', function()
{1:~ }|*3
|
]])
- nvim_async('command', 'let g:cont = 1')
+ async_meths.nvim_command('let g:cont = 1')
screen:expect([[
^ITEM 1 |