aboutsummaryrefslogtreecommitdiff
path: root/test/unit/helpers.lua
diff options
context:
space:
mode:
authorZyX <kp-pav@yandex.ru>2017-03-12 03:14:34 +0300
committerZyX <kp-pav@yandex.ru>2017-03-12 03:14:34 +0300
commitd559fe6e936f19055c75e22eab54004782716117 (patch)
tree9dc9610ddc526f50995350bc2ce6abb7da7eb85f /test/unit/helpers.lua
parenta7f64ba5171564e307de89f5b130528897887592 (diff)
downloadrneovim-d559fe6e936f19055c75e22eab54004782716117.tar.gz
rneovim-d559fe6e936f19055c75e22eab54004782716117.tar.bz2
rneovim-d559fe6e936f19055c75e22eab54004782716117.zip
unittests: Allow running `ffi.cdef` in the main process
Diffstat (limited to 'test/unit/helpers.lua')
-rw-r--r--test/unit/helpers.lua16
1 files changed, 13 insertions, 3 deletions
diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua
index fa218ea2d9..91f48efef9 100644
--- a/test/unit/helpers.lua
+++ b/test/unit/helpers.lua
@@ -158,11 +158,15 @@ local preprocess_cache_init = {}
local previous_defines_mod = ''
local preprocess_cache_mod = nil
+local function is_child_cdefs()
+ return (os.getenv('NVIM_TEST_MAIN_CDEFS') ~= '1')
+end
+
-- use this helper to import C files, you can pass multiple paths at once,
-- this helper will return the C namespace of the nvim library.
cimport = function(...)
local previous_defines, preprocess_cache
- if preprocess_cache_mod then
+ if is_child_cdefs() and preprocess_cache_mod then
preprocess_cache = preprocess_cache_mod
previous_defines = previous_defines_mod
cdefs = cdefs_mod
@@ -240,7 +244,7 @@ local cimport_immediate = function(...)
end
end
-cimportstr = child_call(function(preprocess_cache, path)
+local function _cimportstr(preprocess_cache, path)
if imported:contains(path) then
return lib
end
@@ -252,7 +256,13 @@ cimportstr = child_call(function(preprocess_cache, path)
imported:add(path)
return lib
-end, lib)
+end
+
+if is_child_cdefs() then
+ cimportstr = child_call(_cimportstr, lib)
+else
+ cimportstr = _cimportstr
+end
local function alloc_log_new()
local log = {