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.lua36
1 files changed, 28 insertions, 8 deletions
diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua
index f6d09e6139..325f41e506 100644
--- a/test/functional/helpers.lua
+++ b/test/functional/helpers.lua
@@ -1,6 +1,8 @@
require('coxpcall')
local lfs = require('lfs')
local ChildProcessStream = require('nvim.child_process_stream')
+local SocketStream = require('nvim.socket_stream')
+local TcpStream = require('nvim.tcp_stream')
local Session = require('nvim.session')
local global_helpers = require('test.helpers')
@@ -223,6 +225,14 @@ local function spawn(argv, merge, env)
return Session.new(child_stream)
end
+-- Creates a new Session connected by domain socket (named pipe) or TCP.
+local function connect(file_or_address)
+ local addr, port = string.match(file_or_address, "(.*):(%d+)")
+ local stream = (addr and port) and TcpStream.open(addr, port) or
+ SocketStream.open(file_or_address)
+ return Session.new(stream)
+end
+
local function clear(...)
local args = {unpack(nvim_argv)}
local new_args
@@ -291,8 +301,7 @@ local function write_file(name, text, dont_dedent)
file:close()
end
--- Tries to get platform name, from $SYSTEM_NAME, uname,
--- fallback is 'Windows'
+-- Tries to get platform name from $SYSTEM_NAME, uname; fallback is "Windows".
local uname = (function()
local platform = nil
return (function()
@@ -376,8 +385,8 @@ local function wait()
end
-- sleeps the test runner (_not_ the nvim instance)
-local function sleep(timeout)
- run(nil, nil, nil, timeout)
+local function sleep(ms)
+ run(nil, nil, nil, ms)
end
local function curbuf_contents()
@@ -403,7 +412,7 @@ local function expect(contents)
return eq(dedent(contents), curbuf_contents())
end
-local function rmdir(path)
+local function do_rmdir(path)
if lfs.attributes(path, 'mode') ~= 'directory' then
return nil
end
@@ -411,7 +420,7 @@ local function rmdir(path)
if file ~= '.' and file ~= '..' then
local abspath = path..'/'..file
if lfs.attributes(abspath, 'mode') == 'directory' then
- local ret = rmdir(abspath) -- recurse
+ local ret = do_rmdir(abspath) -- recurse
if not ret then
return nil
end
@@ -424,13 +433,23 @@ local function rmdir(path)
end
end
end
- local ret, err = os.remove(path)
+ local ret, err = lfs.rmdir(path)
if not ret then
- error('os.remove: '..err)
+ error('lfs.rmdir('..path..'): '..err)
end
return ret
end
+local function rmdir(path)
+ local ret, _ = pcall(do_rmdir, path)
+ -- During teardown, the nvim process may not exit quickly enough, then rmdir()
+ -- will fail (on Windows).
+ if not ret then -- Try again.
+ sleep(1000)
+ do_rmdir(path)
+ end
+end
+
local exc_exec = function(cmd)
nvim_command(([[
try
@@ -498,6 +517,7 @@ return function(after_each)
return {
prepend_argv = prepend_argv,
clear = clear,
+ connect = connect,
spawn = spawn,
dedent = dedent,
source = source,