diff options
author | ZyX <kp-pav@yandex.ru> | 2017-03-12 03:02:14 +0300 |
---|---|---|
committer | ZyX <kp-pav@yandex.ru> | 2017-03-12 03:02:14 +0300 |
commit | a7f64ba5171564e307de89f5b130528897887592 (patch) | |
tree | 1df266c006f086511315d3228689f36cb0044a35 | |
parent | bf68907778aba402ead678a6846f865d29e666d8 (diff) | |
download | rneovim-a7f64ba5171564e307de89f5b130528897887592.tar.gz rneovim-a7f64ba5171564e307de89f5b130528897887592.tar.bz2 rneovim-a7f64ba5171564e307de89f5b130528897887592.zip |
unittests: Move filtering cdefs to main process
-rw-r--r-- | test/unit/helpers.lua | 69 | ||||
-rw-r--r-- | test/unit/set.lua | 16 |
2 files changed, 52 insertions, 33 deletions
diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua index 17425e43e8..fa218ea2d9 100644 --- a/test/unit/helpers.lua +++ b/test/unit/helpers.lua @@ -124,7 +124,8 @@ local function trim(s) end -- a Set that keeps around the lines we've already seen -local cdefs = Set:new() +local cdefs_init = Set:new() +local cdefs_mod = nil local imported = Set:new() local pragma_pack_id = 1 @@ -164,9 +165,11 @@ cimport = function(...) if preprocess_cache_mod then preprocess_cache = preprocess_cache_mod previous_defines = previous_defines_mod + cdefs = cdefs_mod else preprocess_cache = preprocess_cache_init previous_defines = previous_defines_init + cdefs = cdefs_init end for _, path in ipairs({...}) do if not (path:sub(1, 1) == '/' or path:sub(1, 1) == '.' @@ -187,6 +190,35 @@ cimport = function(...) end body = formatc(body) body = filter_complex_blocks(body) + -- add the formatted lines to a set + local new_cdefs = Set:new() + for line in body:gmatch("[^\r\n]+") do + line = trim(line) + -- give each #pragma pack an unique id, so that they don't get removed + -- if they are inserted into the set + -- (they are needed in the right order with the struct definitions, + -- otherwise luajit has wrong memory layouts for the sturcts) + if line:match("#pragma%s+pack") then + line = line .. " // " .. pragma_pack_id + pragma_pack_id = pragma_pack_id + 1 + end + new_cdefs:add(line) + end + + -- subtract the lines we've already imported from the new lines, then add + -- the new unique lines to the old lines (so they won't be imported again) + new_cdefs:diff(cdefs) + cdefs:union(new_cdefs) + -- request a sorted version of the new lines (same relative order as the + -- original preprocessed file) and feed that to the LuaJIT ffi + local new_lines = new_cdefs:to_table() + if os.getenv('NVIM_TEST_PRINT_CDEF') == '1' then + for lnum, line in ipairs(new_lines) do + print(lnum, line) + end + end + body = table.concat(new_lines, '\n') + preprocess_cache[path] = body end cimportstr(preprocess_cache, path) @@ -213,40 +245,10 @@ cimportstr = child_call(function(preprocess_cache, path) return lib end local body = preprocess_cache[path] - -- add the formatted lines to a set - local new_cdefs = Set:new() - for line in body:gmatch("[^\r\n]+") do - line = trim(line) - -- give each #pragma pack an unique id, so that they don't get removed - -- if they are inserted into the set - -- (they are needed in the right order with the struct definitions, - -- otherwise luajit has wrong memory layouts for the sturcts) - if line:match("#pragma%s+pack") then - line = line .. " // " .. pragma_pack_id - pragma_pack_id = pragma_pack_id + 1 - end - new_cdefs:add(line) - end - - -- subtract the lines we've already imported from the new lines, then add - -- the new unique lines to the old lines (so they won't be imported again) - new_cdefs:diff(cdefs) - cdefs:union(new_cdefs) - - if new_cdefs:size() == 0 then - -- if there's no new lines, just return + if body == '' then return lib end - - -- request a sorted version of the new lines (same relative order as the - -- original preprocessed file) and feed that to the LuaJIT ffi - local new_lines = new_cdefs:to_table() - if os.getenv('NVIM_TEST_PRINT_CDEF') == '1' then - for lnum, line in ipairs(new_lines) do - print(lnum, line) - end - end - cdef(table.concat(new_lines, "\n")) + cdef(body) imported:add(path) return lib @@ -482,6 +484,7 @@ local function gen_itp(it) child_cleanups_mod_once = {} preprocess_cache_mod = map(function(v) return v end, preprocess_cache_init) previous_defines_mod = previous_defines_init + cdefs_mod = cdefs_init:copy() local function just_fail(_) return false end diff --git a/test/unit/set.lua b/test/unit/set.lua index 4e66546f32..f3d68c3042 100644 --- a/test/unit/set.lua +++ b/test/unit/set.lua @@ -26,6 +26,22 @@ function Set:new(items) return obj end +function Set:copy() + local obj = {} + obj.nelem = self.nelem + obj.tbl = {} + obj.items = {} + for k, v in pairs(self.tbl) do + obj.tbl[k] = v + end + for k, v in pairs(self.items) do + obj.items[k] = v + end + setmetatable(obj, Set) + obj.__index = Set + return obj +end + -- adds the argument Set to this Set function Set:union(other) for e in other:iterator() do |