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.lua168
1 files changed, 132 insertions, 36 deletions
diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua
index 02109d0889..d5b7442b57 100644
--- a/test/functional/helpers.lua
+++ b/test/functional/helpers.lua
@@ -133,11 +133,11 @@ local function stop()
end
local function nvim_command(cmd)
- request('vim_command', cmd)
+ request('nvim_command', cmd)
end
local function nvim_eval(expr)
- return request('vim_eval', expr)
+ return request('nvim_eval', expr)
end
local os_name = (function()
@@ -157,12 +157,12 @@ local os_name = (function()
end)()
local function nvim_call(name, ...)
- return request('vim_call_function', name, {...})
+ return request('nvim_call_function', name, {...})
end
local function nvim_feed(input)
while #input > 0 do
- local written = request('vim_input', input)
+ local written = request('nvim_input', input)
input = input:sub(written + 1)
end
end
@@ -216,17 +216,48 @@ local function merge_args(...)
return argv
end
-local function spawn(argv, merge)
- local child_stream = ChildProcessStream.spawn(merge and merge_args(prepend_argv, argv) or argv)
+local function spawn(argv, merge, env)
+ local child_stream = ChildProcessStream.spawn(
+ merge and merge_args(prepend_argv, argv) or argv,
+ env)
return Session.new(child_stream)
end
local function clear(...)
local args = {unpack(nvim_argv)}
- for _, arg in ipairs({...}) do
+ local new_args
+ local env = nil
+ local opts = select(1, ...)
+ if type(opts) == 'table' then
+ if opts.env then
+ local env_tbl = {}
+ for k, v in pairs(opts.env) do
+ assert(type(k) == 'string')
+ assert(type(v) == 'string')
+ env_tbl[k] = v
+ end
+ for _, k in ipairs({
+ 'HOME',
+ 'ASAN_OPTIONS',
+ 'LD_LIBRARY_PATH', 'PATH',
+ 'NVIM_LOG_FILE',
+ 'NVIM_RPLUGIN_MANIFEST',
+ }) do
+ env_tbl[k] = os.getenv(k)
+ end
+ env = {}
+ for k, v in pairs(env_tbl) do
+ env[#env + 1] = k .. '=' .. v
+ end
+ end
+ new_args = opts.args or {}
+ else
+ new_args = {...}
+ end
+ for _, arg in ipairs(new_args) do
table.insert(args, arg)
end
- set_session(spawn(args))
+ set_session(spawn(args, nil, env))
end
local function insert(...)
@@ -260,43 +291,82 @@ local function write_file(name, text, dont_dedent)
file:close()
end
-local function source(code)
- local tmpname = os.tmpname()
- if os_name() == 'osx' and string.match(tmpname, '^/tmp') then
- tmpname = '/private'..tmpname
+-- Tries to get platform name, from $SYSTEM_NAME, uname,
+-- fallback is 'Windows'
+local uname = (function()
+ local platform = nil
+ return (function()
+ if platform then
+ return platform
+ end
+
+ platform = os.getenv("SYSTEM_NAME")
+ if platform then
+ return platform
+ end
+
+ local status, f = pcall(io.popen, "uname -s")
+ if status then
+ platform = f:read("*l")
+ else
+ platform = 'Windows'
+ end
+ return platform
+ end)
+end)()
+
+local function tmpname()
+ local fname = os.tmpname()
+ if uname() == 'Windows' and fname:sub(1, 2) == '\\s' then
+ -- In Windows tmpname() returns a filename starting with
+ -- special sequence \s, prepend $TEMP path
+ local tmpdir = os.getenv('TEMP')
+ return tmpdir..fname
+ elseif fname:match('^/tmp') and uname() == 'Darwin' then
+ -- In OS X /tmp links to /private/tmp
+ return '/private'..fname
+ else
+ return fname
end
- write_file(tmpname, code)
- nvim_command('source '..tmpname)
- os.remove(tmpname)
- return tmpname
+end
+
+local function source(code)
+ local fname = tmpname()
+ write_file(fname, code)
+ nvim_command('source '..fname)
+ os.remove(fname)
+ return fname
end
local function nvim(method, ...)
- return request('vim_'..method, ...)
+ return request('nvim_'..method, ...)
+end
+
+local function ui(method, ...)
+ return request('nvim_ui_'..method, ...)
end
local function nvim_async(method, ...)
- session:notify('vim_'..method, ...)
+ session:notify('nvim_'..method, ...)
end
local function buffer(method, ...)
- return request('buffer_'..method, ...)
+ return request('nvim_buf_'..method, ...)
end
local function window(method, ...)
- return request('window_'..method, ...)
+ return request('nvim_win_'..method, ...)
end
local function tabpage(method, ...)
- return request('tabpage_'..method, ...)
+ return request('nvim_tabpage_'..method, ...)
end
local function curbuf(method, ...)
- local buf = nvim('get_current_buffer')
if not method then
- return buf
+ return nvim('get_current_buf')
end
- return buffer(method, buf, ...)
+ return buffer(method, 0, ...)
end
local function wait()
@@ -306,8 +376,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()
@@ -316,26 +386,24 @@ local function curbuf_contents()
end
local function curwin(method, ...)
- local win = nvim('get_current_window')
if not method then
- return win
+ return nvim('get_current_win')
end
- return window(method, win, ...)
+ return window(method, 0, ...)
end
local function curtab(method, ...)
- local tab = nvim('get_current_tabpage')
if not method then
- return tab
+ return nvim('get_current_tabpage')
end
- return tabpage(method, tab, ...)
+ return tabpage(method, 0, ...)
end
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
@@ -343,7 +411,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
@@ -356,13 +424,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
@@ -399,8 +477,23 @@ local function create_callindex(func)
return table
end
+-- Helper to skip tests. Returns true in Windows systems.
+-- pending_func is pending() from busted
+local function pending_win32(pending_func)
+ clear()
+ if uname() == 'Windows' then
+ if pending_func ~= nil then
+ pending_func('FIXME: Windows', function() end)
+ end
+ return true
+ else
+ return false
+ end
+end
+
local funcs = create_callindex(nvim_call)
local meths = create_callindex(nvim)
+local uimeths = create_callindex(ui)
local bufmeths = create_callindex(buffer)
local winmeths = create_callindex(window)
local tabmeths = create_callindex(tabpage)
@@ -459,9 +552,12 @@ return function(after_each)
bufmeths = bufmeths,
winmeths = winmeths,
tabmeths = tabmeths,
+ uimeths = uimeths,
curbufmeths = curbufmeths,
curwinmeths = curwinmeths,
curtabmeths = curtabmeths,
+ pending_win32 = pending_win32,
+ tmpname = tmpname,
NIL = mpack.NIL,
}
end