diff options
author | ZyX <kp-pav@yandex.ru> | 2017-01-03 08:57:43 +0300 |
---|---|---|
committer | ZyX <kp-pav@yandex.ru> | 2017-01-03 22:54:54 +0300 |
commit | 0d7b779cab198c89b70bf9d1e6d42cffc3f28f50 (patch) | |
tree | 45324590a09ee5fc289b12195eed9d614975a6df /test | |
parent | 410d18ef5c24a325f4d63c9b01991015199194c2 (diff) | |
download | rneovim-0d7b779cab198c89b70bf9d1e6d42cffc3f28f50.tar.gz rneovim-0d7b779cab198c89b70bf9d1e6d42cffc3f28f50.tar.bz2 rneovim-0d7b779cab198c89b70bf9d1e6d42cffc3f28f50.zip |
unittest: Record previous defines in another place
Previous commit made preprocess.lua know how its output will be used. This moves
state to cimport, making only it know which is cleaner.
Diffstat (limited to 'test')
-rw-r--r-- | test/unit/formatc.lua | 2 | ||||
-rw-r--r-- | test/unit/helpers.lua | 4 | ||||
-rw-r--r-- | test/unit/preprocess.lua | 11 |
3 files changed, 9 insertions, 8 deletions
diff --git a/test/unit/formatc.lua b/test/unit/formatc.lua index 9b47a318f0..e5ac87032a 100644 --- a/test/unit/formatc.lua +++ b/test/unit/formatc.lua @@ -219,7 +219,7 @@ local function standalone(...) -- luacheck: ignore Preprocess.add_to_include_path('./../../build/include') Preprocess.add_to_include_path('./../../.deps/usr/include') - local raw = Preprocess.preprocess(arg[1]) + local raw = Preprocess.preprocess('', arg[1]) if raw == nil then print("ERROR: Preprocess.preprocess() returned empty") diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua index c9885f73d0..abbdecacc9 100644 --- a/test/unit/helpers.lua +++ b/test/unit/helpers.lua @@ -45,6 +45,8 @@ local function filter_complex_blocks(body) return table.concat(result, "\n") end +local previous_defines = '' + -- 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. local function cimport(...) @@ -68,7 +70,7 @@ local function cimport(...) local body = nil for _ = 1, 10 do - body = Preprocess.preprocess(unpack(paths)) + body, previous_defines = Preprocess.preprocess(previous_defines, unpack(paths)) if body ~= nil then break end end diff --git a/test/unit/preprocess.lua b/test/unit/preprocess.lua index 99537cd66a..062432323f 100644 --- a/test/unit/preprocess.lua +++ b/test/unit/preprocess.lua @@ -115,7 +115,6 @@ local Gcc = { '-D "_Nonnull="', '-U__BLOCKS__', }, - added_header_defines = '', } function Gcc:new(obj) @@ -149,12 +148,12 @@ end -- returns a stream representing a preprocessed form of the passed-in headers. -- Don't forget to close the stream by calling the close() method on it. -function Gcc:preprocess(...) +function Gcc:preprocess(previous_defines, ...) -- create pseudo-header local pseudoheader = headerize({...}, false) local pseudoheader_fname = 'tmp_pseudoheader.h' local pseudoheader_file = io.open(pseudoheader_fname, 'w') - pseudoheader_file:write(self.added_header_defines) + pseudoheader_file:write(previous_defines) pseudoheader_file:write("\n") pseudoheader_file:write(pseudoheader) pseudoheader_file:flush() @@ -171,7 +170,7 @@ function Gcc:preprocess(...) tostring(defines) .. " -std=c99 -dM -E " .. shell_quote(pseudoheader_fname)) local def_stream = io.popen(def_cmd) - self.added_header_defines = def_stream:read('*a') + local defines = def_stream:read('*a') def_stream:close() -- lfs = require("lfs") -- print("CWD: #{lfs.currentdir!}") @@ -179,10 +178,10 @@ function Gcc:preprocess(...) -- io.stderr\write("CWD: #{lfs.currentdir!}\n") -- io.stderr\write("CMD: #{cmd}\n") local stream = io.popen(cmd) - local ret = stream:read('*a') + local declarations = stream:read('*a') stream:close() os.remove(pseudoheader_fname) - return ret + return declarations, defines end local Clang = Gcc:new() |