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.lua62
1 files changed, 33 insertions, 29 deletions
diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua
index 1fba15c2c3..a382641cff 100644
--- a/test/functional/helpers.lua
+++ b/test/functional/helpers.lua
@@ -1,10 +1,8 @@
require('coxpcall')
-local ffi = require('ffi')
+NIL = require('mpack').NIL
local lfs = require('lfs')
local assert = require('luassert')
-local Loop = require('nvim.loop')
-local MsgpackStream = require('nvim.msgpack_stream')
-local AsyncSession = require('nvim.async_session')
+local ChildProcessStream = require('nvim.child_process_stream')
local Session = require('nvim.session')
local nvim_prog = os.getenv('NVIM_PROG') or 'build/bin/nvim'
@@ -60,6 +58,9 @@ end
local session, loop_running, last_error
local function set_session(s)
+ if session then
+ session:close()
+ end
session = s
end
@@ -133,6 +134,22 @@ local function nvim_eval(expr)
return request('vim_eval', expr)
end
+local os_name = (function()
+ local name = nil
+ return (function()
+ if not name then
+ if nvim_eval('has("win32")') == 1 then
+ name = 'windows'
+ elseif nvim_eval('has("macunix")') == 1 then
+ name = 'osx'
+ else
+ name = 'unix'
+ end
+ end
+ return name
+ end)
+end)()
+
local function nvim_call(name, ...)
return request('vim_call_function', name, {...})
end
@@ -194,24 +211,17 @@ local function merge_args(...)
end
local function spawn(argv, merge)
- local loop = Loop.new()
- local msgpack_stream = MsgpackStream.new(loop)
- local async_session = AsyncSession.new(msgpack_stream)
- local sess = Session.new(async_session)
- loop:spawn(merge and merge_args(prepend_argv, argv) or argv)
- return sess
+ local child_stream = ChildProcessStream.spawn(merge and merge_args(prepend_argv, argv) or argv)
+ return Session.new(child_stream)
end
local function clear(extra_cmd)
- if session then
- session:exit(0)
- end
local args = {unpack(nvim_argv)}
if extra_cmd ~= nil then
table.insert(args, '--cmd')
table.insert(args, extra_cmd)
end
- session = spawn(args)
+ set_session(spawn(args))
end
local function insert(...)
@@ -247,7 +257,7 @@ end
local function source(code)
local tmpname = os.tmpname()
- if ffi.os == 'OSX' and string.match(tmpname, '^/tmp') then
+ if os_name() == 'osx' and string.match(tmpname, '^/tmp') then
tmpname = '/private'..tmpname
end
write_file(tmpname, code)
@@ -305,7 +315,7 @@ local function curbuf_contents()
-- previously sent keys are processed(vim_eval is a deferred function, and
-- only processed after all input)
wait()
- return table.concat(curbuf('get_line_slice', 0, -1, true, true), '\n')
+ return table.concat(curbuf('get_lines', 0, -1, true), '\n')
end
local function curwin(method, ...)
@@ -328,24 +338,18 @@ local function expect(contents)
return eq(dedent(contents), curbuf_contents())
end
-local function os_is_windows()
- return nvim_eval('has("win32")') == 1
-end
-
local function rmdir(path)
if lfs.attributes(path, 'mode') ~= 'directory' then
return nil
end
for file in lfs.dir(path) do
- if file == '.' or file == '..' then
- goto continue
- end
- local ret, err = os.remove(path..'/'..file)
- if not ret then
- error('os.remove: '..err)
- return nil
+ if file ~= '.' and file ~= '..' then
+ local ret, err = os.remove(path..'/'..file)
+ if not ret then
+ error('os.remove: '..err)
+ return nil
+ end
end
- ::continue::
end
local ret, err = os.remove(path)
if not ret then
@@ -434,7 +438,7 @@ return {
wait = wait,
set_session = set_session,
write_file = write_file,
- os_is_windows = os_is_windows,
+ os_name = os_name,
rmdir = rmdir,
mkdir = lfs.mkdir,
exc_exec = exc_exec,