diff options
author | ZyX <kp-pav@yandex.ru> | 2017-01-03 16:25:04 +0300 |
---|---|---|
committer | ZyX <kp-pav@yandex.ru> | 2017-01-03 22:54:54 +0300 |
commit | 2151ddbd73a78fcecc992f58f036b8f765a9113e (patch) | |
tree | 47d08b3d9ce20546c8789888d1a151311352d041 /test/unit/preprocess.lua | |
parent | 0d7b779cab198c89b70bf9d1e6d42cffc3f28f50 (diff) | |
download | rneovim-2151ddbd73a78fcecc992f58f036b8f765a9113e.tar.gz rneovim-2151ddbd73a78fcecc992f58f036b8f765a9113e.tar.bz2 rneovim-2151ddbd73a78fcecc992f58f036b8f765a9113e.zip |
unittest: Move nil checks to Gcc:preprocess
Diffstat (limited to 'test/unit/preprocess.lua')
-rw-r--r-- | test/unit/preprocess.lua | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/test/unit/preprocess.lua b/test/unit/preprocess.lua index 062432323f..236cc58192 100644 --- a/test/unit/preprocess.lua +++ b/test/unit/preprocess.lua @@ -146,6 +146,19 @@ function Gcc:dependencies(hdr) end end +local function repeated_call(cmd) + for _ = 1, 10 do + local stream = io.popen(cmd) + local ret = stream:read('*a') + stream:close() + if ret then + return ret + end + end + print('ERROR: preprocess.lua: Failed to execute ' .. cmd .. ': nil return after 10 attempts') + return nil +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(previous_defines, ...) @@ -159,28 +172,22 @@ function Gcc:preprocess(previous_defines, ...) pseudoheader_file:flush() pseudoheader_file:close() local defines = table.concat(self.preprocessor_extra_flags, ' ') - local cmd = ("echo $hdr | " .. - tostring(self.path) .. - " " .. - tostring(defines) .. - " -std=c99 -P -E " .. shell_quote(pseudoheader_fname)) - local def_cmd = ("echo $hdr | " .. - tostring(self.path) .. - " " .. - tostring(defines) .. - " -std=c99 -dM -E " .. shell_quote(pseudoheader_fname)) - local def_stream = io.popen(def_cmd) - local defines = def_stream:read('*a') - def_stream:close() + local cmd_base = self.path .. " " .. defines .. " -std=c99" + + local def_cmd = (cmd_base .. " -dM -E " .. shell_quote(pseudoheader_fname)) + local defines = repeated_call(def_cmd) + -- lfs = require("lfs") -- print("CWD: #{lfs.currentdir!}") -- print("CMD: #{cmd}") -- io.stderr\write("CWD: #{lfs.currentdir!}\n") -- io.stderr\write("CMD: #{cmd}\n") - local stream = io.popen(cmd) - local declarations = stream:read('*a') - stream:close() + local decl_cmd = (cmd_base .. " -P -E " .. shell_quote(pseudoheader_fname)) + local declarations = repeated_call(decl_cmd) + os.remove(pseudoheader_fname) + + assert(declarations and defines) return declarations, defines end |