mirror of
https://github.com/neovim/neovim.git
synced 2024-12-19 18:55:14 -07:00
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
This commit is contained in:
parent
39c628d031
commit
9ce81f7b2b
@ -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()
|
||||
|
||||
|
@ -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
|
||||
|
@ -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')
|
||||
|
@ -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)")
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
|
@ -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)
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user