aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRui Abreu Ferreira <raf-ep@gmx.com>2015-12-29 19:18:16 +0000
committerRui Abreu Ferreira <raf-ep@gmx.com>2016-08-31 11:32:28 +0100
commit9ce81f7b2b90846063f6bd4a5ce8efc61e437983 (patch)
tree15a95c9f6f0b0138b9a2f7f3cab087bbe3f6b0f8
parent39c628d031b89e9048340f6c95b9c3a97c2a0089 (diff)
downloadrneovim-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
-rw-r--r--CMakeLists.txt5
-rw-r--r--cmake/RunTests.cmake1
-rw-r--r--test/functional/api/vim_spec.lua2
-rw-r--r--test/functional/core/job_spec.lua2
-rw-r--r--test/functional/ex_cmds/profile_spec.lua4
-rw-r--r--test/functional/helpers.lua57
-rw-r--r--test/functional/legacy/036_regexp_character_classes_spec.lua12
-rw-r--r--test/functional/legacy/file_perm_spec.lua2
-rw-r--r--test/functional/shada/helpers.lua2
9 files changed, 63 insertions, 24 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e91a7e67e9..01015fe270 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -498,6 +498,7 @@ if(BUSTED_PRG)
-DTEST_DIR=${CMAKE_CURRENT_SOURCE_DIR}/test
-DBUILD_DIR=${CMAKE_BINARY_DIR}
-DTEST_TYPE=unit
+ -DSYSTEM_NAME=${CMAKE_SYSTEM_NAME}
-P ${PROJECT_SOURCE_DIR}/cmake/RunTests.cmake
DEPENDS ${UNITTEST_PREREQS}
${TEST_TARGET_ARGS})
@@ -516,6 +517,7 @@ if(BUSTED_PRG)
-DTEST_DIR=${CMAKE_CURRENT_SOURCE_DIR}/test
-DBUILD_DIR=${CMAKE_BINARY_DIR}
-DTEST_TYPE=functional
+ -DSYSTEM_NAME=${CMAKE_SYSTEM_NAME}
-P ${PROJECT_SOURCE_DIR}/cmake/RunTests.cmake
DEPENDS ${FUNCTIONALTEST_PREREQS}
${TEST_TARGET_ARGS})
@@ -530,6 +532,7 @@ if(BUSTED_PRG)
-DTEST_DIR=${CMAKE_CURRENT_SOURCE_DIR}/test
-DBUILD_DIR=${CMAKE_BINARY_DIR}
-DTEST_TYPE=benchmark
+ -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}
-P ${PROJECT_SOURCE_DIR}/cmake/RunTests.cmake
DEPENDS ${BENCHMARK_PREREQS}
${TEST_TARGET_ARGS})
@@ -546,6 +549,7 @@ if(BUSTED_LUA_PRG)
-DTEST_DIR=${CMAKE_CURRENT_SOURCE_DIR}/test
-DBUILD_DIR=${CMAKE_BINARY_DIR}
-DTEST_TYPE=functional
+ -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}
-P ${PROJECT_SOURCE_DIR}/cmake/RunTests.cmake
DEPENDS ${FUNCTIONALTEST_PREREQS}
${TEST_TARGET_ARGS})
@@ -556,6 +560,7 @@ if(LUACHECK_PRG)
COMMAND ${CMAKE_COMMAND}
-DLUACHECK_PRG=${LUACHECK_PRG}
-DTEST_DIR=${CMAKE_CURRENT_SOURCE_DIR}/test
+ -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}
-P ${PROJECT_SOURCE_DIR}/cmake/RunTestsLint.cmake)
endif()
diff --git a/cmake/RunTests.cmake b/cmake/RunTests.cmake
index a045f9f982..58f19b6fa5 100644
--- a/cmake/RunTests.cmake
+++ b/cmake/RunTests.cmake
@@ -28,6 +28,7 @@ if(DEFINED ENV{TEST_FILTER})
set(TEST_TAG "--filter=$ENV{TEST_FILTER}")
endif()
+set(ENV{SYSTEM_NAME} ${SYSTEM_NAME})
execute_process(
COMMAND ${BUSTED_PRG} ${TEST_TAG} ${TEST_FILTER} -v -o ${BUSTED_OUTPUT_TYPE}
--lua=${LUA_PRG} --lazy --helper=${TEST_DIR}/${TEST_TYPE}/preload.lua
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua
index eb2b06edcb..848935fc0f 100644
--- a/test/functional/api/vim_spec.lua
+++ b/test/functional/api/vim_spec.lua
@@ -13,7 +13,7 @@ describe('vim_* functions', function()
describe('command', function()
it('works', function()
- local fname = os.tmpname()
+ local fname = helpers.tmpname()
nvim('command', 'new')
nvim('command', 'edit '..fname)
nvim('command', 'normal itesting\napi')
diff --git a/test/functional/core/job_spec.lua b/test/functional/core/job_spec.lua
index 157b8abb00..f764898f72 100644
--- a/test/functional/core/job_spec.lua
+++ b/test/functional/core/job_spec.lua
@@ -91,7 +91,7 @@ describe('jobs', function()
it('preserves NULs', function()
-- Make a file with NULs in it.
- local filename = os.tmpname()
+ local filename = helpers.tmpname()
write_file(filename, "abc\0def\n")
nvim('command', "let j = jobstart(['cat', '"..filename.."'], g:job_opts)")
diff --git a/test/functional/ex_cmds/profile_spec.lua b/test/functional/ex_cmds/profile_spec.lua
index d390806679..f185db192a 100644
--- a/test/functional/ex_cmds/profile_spec.lua
+++ b/test/functional/ex_cmds/profile_spec.lua
@@ -5,9 +5,9 @@ local helpers = require('test.functional.helpers')(after_each)
local eval = helpers.eval
local command = helpers.command
local eq, neq = helpers.eq, helpers.neq
-local tempfile = os.tmpname()
+local tempfile = helpers.tmpname()
--- os.tmpname() also creates the file on POSIX systems. Remove it again.
+-- tmpname() also creates the file on POSIX systems. Remove it again.
-- We just need the name, ignoring any race conditions.
if lfs.attributes(tempfile, 'uid') then
os.remove(tempfile)
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
diff --git a/test/functional/legacy/036_regexp_character_classes_spec.lua b/test/functional/legacy/036_regexp_character_classes_spec.lua
index 9e67bb9429..15287b9901 100644
--- a/test/functional/legacy/036_regexp_character_classes_spec.lua
+++ b/test/functional/legacy/036_regexp_character_classes_spec.lua
@@ -3,7 +3,6 @@
local helpers = require('test.functional.helpers')(after_each)
local clear, execute, expect = helpers.clear, helpers.execute, helpers.expect
local source, write_file = helpers.source, helpers.write_file
-local os_name = helpers.os_name
local function sixlines(text)
local result = ''
@@ -14,19 +13,16 @@ local function sixlines(text)
end
local function diff(text, nodedent)
- local tmpname = os.tmpname()
- if os_name() == 'osx' and string.match(tmpname, '^/tmp') then
- tmpname = '/private'..tmpname
- end
- execute('w! '..tmpname)
+ local fname = helpers.tmpname()
+ execute('w! '..fname)
helpers.wait()
- local data = io.open(tmpname):read('*all')
+ local data = io.open(fname):read('*all')
if nodedent then
helpers.eq(text, data)
else
helpers.eq(helpers.dedent(text), data)
end
- os.remove(tmpname)
+ os.remove(fname)
end
describe('character classes in regexp', function()
diff --git a/test/functional/legacy/file_perm_spec.lua b/test/functional/legacy/file_perm_spec.lua
index 9ebbfd25e4..77e82352c5 100644
--- a/test/functional/legacy/file_perm_spec.lua
+++ b/test/functional/legacy/file_perm_spec.lua
@@ -6,7 +6,7 @@ local clear, call, eq = helpers.clear, helpers.call, helpers.eq
local neq, exc_exec = helpers.neq, helpers.exc_exec
describe('Test getting and setting file permissions', function()
- local tempfile = os.tmpname()
+ local tempfile = helpers.tmpname()
before_each(function()
os.remove(tempfile)
diff --git a/test/functional/shada/helpers.lua b/test/functional/shada/helpers.lua
index bb2919d4fb..cde555f0a7 100644
--- a/test/functional/shada/helpers.lua
+++ b/test/functional/shada/helpers.lua
@@ -5,7 +5,7 @@ local write_file, merge_args = helpers.write_file, helpers.merge_args
local mpack = require('mpack')
-local tmpname = os.tmpname()
+local tmpname = helpers.tmpname()
local additional_cmd = ''
local function nvim_argv()