aboutsummaryrefslogtreecommitdiff
path: root/test/functional/helpers.lua
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/helpers.lua')
-rw-r--r--test/functional/helpers.lua102
1 files changed, 56 insertions, 46 deletions
diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua
index 6400db9f87..dcaaa664b9 100644
--- a/test/functional/helpers.lua
+++ b/test/functional/helpers.lua
@@ -1,14 +1,10 @@
-require('coxpcall')
local luv = require('luv')
-local lfs = require('lfs')
-local mpack = require('mpack')
local global_helpers = require('test.helpers')
--- nvim client: Found in .deps/usr/share/lua/<version>/nvim/ if "bundled".
-local Session = require('nvim.session')
-local TcpStream = require('nvim.tcp_stream')
-local SocketStream = require('nvim.socket_stream')
-local ChildProcessStream = require('nvim.child_process_stream')
+local Session = require('test.client.session')
+local uv_stream = require('test.client.uv_stream')
+local SocketStream = uv_stream.SocketStream
+local ChildProcessStream = uv_stream.ChildProcessStream
local check_cores = global_helpers.check_cores
local check_logs = global_helpers.check_logs
@@ -22,12 +18,9 @@ local sleep = global_helpers.sleep
local tbl_contains = global_helpers.tbl_contains
local fail = global_helpers.fail
-local module = {
- NIL = mpack.NIL,
- mkdir = lfs.mkdir,
-}
+local module = {}
-local start_dir = lfs.currentdir()
+local start_dir = luv.cwd()
local runtime_set = 'set runtimepath^=./build/lib/nvim/'
module.nvim_prog = (
os.getenv('NVIM_PRG')
@@ -89,6 +82,13 @@ end
local session, loop_running, last_error, method_error
+if not is_os('win') then
+ local sigpipe_handler = luv.new_signal()
+ luv.signal_start(sigpipe_handler, "sigpipe", function()
+ print("warning: got SIGPIPE signal. Likely related to a crash in nvim")
+ end)
+end
+
function module.get_session()
return session
end
@@ -202,7 +202,7 @@ function module.expect_msg_seq(...)
end
local function call_and_stop_on_error(lsession, ...)
- local status, result = copcall(...) -- luacheck: ignore
+ local status, result = Session.safe_pcall(...) -- luacheck: ignore
if not status then
lsession:stop()
last_error = result
@@ -271,7 +271,7 @@ function module.nvim_prog_abs()
end
end
--- Executes an ex-command. VimL errors manifest as client (lua) errors, but
+-- Executes an ex-command. Vimscript errors manifest as client (lua) errors, but
-- v:errmsg will not be updated.
function module.command(cmd)
module.request('nvim_command', cmd)
@@ -295,26 +295,26 @@ function module.expect_exit(fn_or_timeout, ...)
end
end
--- Evaluates a VimL expression.
--- Fails on VimL error, but does not update v:errmsg.
+-- 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 VimL function via RPC.
--- Fails on VimL error, but does not update v:errmsg.
+-- 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 VimL function via Lua.
--- Fails on VimL error, but does not update v:errmsg.
+-- Executes a Vimscript function via Lua.
+-- Fails on Vimscript error, but does not update v:errmsg.
function module.call_lua(name, ...)
return module.exec_lua([[return vim.call(...)]], name, ...)
end
-- Sends user input to Nvim.
--- Does not fail on VimL error, but v:errmsg will be updated.
+-- Does not fail on Vimscript error, but v:errmsg will be updated.
local function nvim_feed(input)
while #input > 0 do
local written = module.request('nvim_input', input)
@@ -428,7 +428,7 @@ end
-- Creates a new Session connected by domain socket (named pipe) or TCP.
function module.connect(file_or_address)
local addr, port = string.match(file_or_address, "(.*):(%d+)")
- local stream = (addr and port) and TcpStream.open(addr, port) or
+ local stream = (addr and port) and SocketStream.connect(addr, port) or
SocketStream.open(file_or_address)
return Session.new(stream)
end
@@ -524,7 +524,7 @@ function module.insert(...)
nvim_feed('<ESC>')
end
--- Executes an ex-command by user input. Because nvim_input() is used, VimL
+-- 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.
function module.feed_command(...)
for _, v in ipairs({...}) do
@@ -537,7 +537,7 @@ function module.feed_command(...)
end
end
--- @deprecated use nvim_exec()
+-- @deprecated use nvim_exec2()
function module.source(code)
module.exec(dedent(code))
end
@@ -557,16 +557,18 @@ function module.set_shell_powershell(fake)
assert(found)
end
local shell = found and (is_os('win') and 'powershell' or 'pwsh') or module.testprg('pwsh-test')
- local set_encoding = '[Console]::InputEncoding=[Console]::OutputEncoding=[System.Text.UTF8Encoding]::new();'
- local cmd = set_encoding..'Remove-Item -Force '..table.concat(is_os('win')
- and {'alias:cat', 'alias:echo', 'alias:sleep', 'alias:sort'}
+ local cmd = 'Remove-Item -Force '..table.concat(is_os('win')
+ and {'alias:cat', 'alias:echo', 'alias:sleep', 'alias:sort', 'alias:tee'}
or {'alias:echo'}, ',')..';'
module.exec([[
let &shell = ']]..shell..[['
set shellquote= shellxquote=
- let &shellcmdflag = '-NoLogo -NoProfile -ExecutionPolicy RemoteSigned -Command ]]..cmd..[['
- let &shellpipe = '2>&1 | Out-File -Encoding UTF8 %s; exit $LastExitCode'
- let &shellredir = '2>&1 | Out-File -Encoding UTF8 %s; exit $LastExitCode'
+ let &shellcmdflag = '-NoLogo -NoProfile -ExecutionPolicy RemoteSigned -Command '
+ let &shellcmdflag .= '[Console]::InputEncoding=[Console]::OutputEncoding=[System.Text.UTF8Encoding]::new();'
+ let &shellcmdflag .= '$PSDefaultParameterValues[''Out-File:Encoding'']=''utf8'';'
+ let &shellcmdflag .= ']]..cmd..[['
+ let &shellredir = '2>&1 | %%{ "$_" } | Out-File %s; exit $LastExitCode'
+ let &shellpipe = '2>&1 | %%{ "$_" } | tee %s; exit $LastExitCode'
]])
return found
end
@@ -732,21 +734,17 @@ function module.assert_visible(bufnr, visible)
end
local function do_rmdir(path)
- local mode, errmsg, errcode = lfs.attributes(path, 'mode')
- if mode == nil then
- if errcode == 2 then
- -- "No such file or directory", don't complain.
- return
- end
- error(string.format('rmdir: %s (%d)', errmsg, errcode))
+ local stat = luv.fs_stat(path)
+ if stat == nil then
+ return
end
- if mode ~= 'directory' then
+ if stat.type ~= 'directory' then
error(string.format('rmdir: not a directory: %s', path))
end
- for file in lfs.dir(path) do
+ for file in vim.fs.dir(path) do
if file ~= '.' and file ~= '..' then
local abspath = path..'/'..file
- if lfs.attributes(abspath, 'mode') == 'directory' then
+ if global_helpers.isdir(abspath) then
do_rmdir(abspath) -- recurse
else
local ret, err = os.remove(abspath)
@@ -766,9 +764,9 @@ local function do_rmdir(path)
end
end
end
- local ret, err = lfs.rmdir(path)
+ local ret, err = luv.fs_rmdir(path)
if not ret then
- error('lfs.rmdir('..path..'): '..err)
+ error('luv.fs_rmdir('..path..'): '..err)
end
end
@@ -828,13 +826,15 @@ function module.skip_fragile(pending_fn, cond)
end
function module.exec(code)
- return module.meths.exec(code, false)
+ module.meths.exec2(code, {})
end
function module.exec_capture(code)
- return module.meths.exec(code, true)
+ return module.meths.exec2(code, { output = true }).output
end
+--- @param code string
+--- @return any
function module.exec_lua(code, ...)
return module.meths.exec_lua(code, {...})
end
@@ -858,12 +858,20 @@ function module.testprg(name)
return ('%s/%s%s'):format(module.nvim_dir, name, ext)
end
+function module.is_asan()
+ local version = module.eval('execute("verbose version")')
+ return version:match('-fsanitize=[a-z,]*address')
+end
+
-- Returns a valid, platform-independent Nvim listen address.
-- Useful for communicating with child instances.
function module.new_pipename()
-- HACK: Start a server temporarily, get the name, then stop it.
local pipename = module.eval('serverstart()')
module.funcs.serverstop(pipename)
+ -- Remove the pipe so that trying to connect to it without a server listening
+ -- will be an error instead of a hang.
+ os.remove(pipename)
return pipename
end
@@ -902,7 +910,7 @@ local load_factor = 1
if global_helpers.is_ci() then
-- Compute load factor only once (but outside of any tests).
module.clear()
- module.request('nvim_command', 'source src/nvim/testdir/load.vim')
+ module.request('nvim_command', 'source test/old/testdir/load.vim')
load_factor = module.request('nvim_eval', 'g:test_load_factor')
end
function module.load_adjust(num)
@@ -944,8 +952,10 @@ function module.mkdir_p(path)
or 'mkdir -p '..path))
end
+--- @class test.functional.helpers: test.helpers
module = global_helpers.tbl_extend('error', module, global_helpers)
+--- @return test.functional.helpers
return function(after_each)
if after_each then
after_each(function()