diff options
author | Rui Abreu Ferreira <raf-ep@gmx.com> | 2015-12-29 19:18:16 +0000 |
---|---|---|
committer | Rui Abreu Ferreira <raf-ep@gmx.com> | 2016-08-31 11:32:28 +0100 |
commit | 9ce81f7b2b90846063f6bd4a5ce8efc61e437983 (patch) | |
tree | 15a95c9f6f0b0138b9a2f7f3cab087bbe3f6b0f8 /test/functional/helpers.lua | |
parent | 39c628d031b89e9048340f6c95b9c3a97c2a0089 (diff) | |
download | rneovim-9ce81f7b2b90846063f6bd4a5ce8efc61e437983.tar.gz rneovim-9ce81f7b2b90846063f6bd4a5ce8efc61e437983.tar.bz2 rneovim-9ce81f7b2b90846063f6bd4a5ce8efc61e437983.zip |
functionaltest: Create lua helper for os.tmpname()
In Windows Lua's os.tmpname() returns relative paths starting with \s,
prepend them with $TEMP to generate a valid path.
In OS X os.tmpname() returns paths in '/tmp' but they should be in
'/private/tmp'. We cannot use os_name() for platform detection because
some tests use tempname() before nvim is spawned, instead use one of the
following:
1. Set SYSTEM_NAME environment variable before calling the tests, it
is set from CMAKE_SYSTEM_NAME(i.e. uname -s or 'Windows')
2. Call uname -s
3. Assume windows
Diffstat (limited to 'test/functional/helpers.lua')
-rw-r--r-- | test/functional/helpers.lua | 57 |
1 files changed, 47 insertions, 10 deletions
diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 74625eb7fa..f20ca69967 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, ...) @@ -431,10 +467,10 @@ local function create_callindex(func) end -- Helper to skip tests. Returns true in Windows systems. --- pending_func is the pending() from busted +-- pending_func is pending() from busted local function pending_win32(pending_func) clear() - if os_name() == 'windows' then + if uname() == 'Windows' then if pending_func ~= nil then pending_func('FIXME: Windows', function() end) end @@ -508,6 +544,7 @@ return function(after_each) curwinmeths = curwinmeths, curtabmeths = curtabmeths, pending_win32 = pending_win32, + tmpname = tmpname, NIL = mpack.NIL, } end |