diff options
Diffstat (limited to 'test/functional/helpers.lua')
-rw-r--r-- | test/functional/helpers.lua | 68 |
1 files changed, 60 insertions, 8 deletions
diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 140e78aeb5..8dca4c5bbe 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -291,15 +291,51 @@ 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, ...) @@ -434,6 +470,20 @@ 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) @@ -499,6 +549,8 @@ return function(after_each) curbufmeths = curbufmeths, curwinmeths = curwinmeths, curtabmeths = curtabmeths, + pending_win32 = pending_win32, + tmpname = tmpname, NIL = mpack.NIL, } end |