aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZyX <kp-pav@yandex.ru>2017-01-03 16:25:04 +0300
committerZyX <kp-pav@yandex.ru>2017-01-03 22:54:54 +0300
commit2151ddbd73a78fcecc992f58f036b8f765a9113e (patch)
tree47d08b3d9ce20546c8789888d1a151311352d041
parent0d7b779cab198c89b70bf9d1e6d42cffc3f28f50 (diff)
downloadrneovim-2151ddbd73a78fcecc992f58f036b8f765a9113e.tar.gz
rneovim-2151ddbd73a78fcecc992f58f036b8f765a9113e.tar.bz2
rneovim-2151ddbd73a78fcecc992f58f036b8f765a9113e.zip
unittest: Move nil checks to Gcc:preprocess
-rw-r--r--test/unit/formatc.lua4
-rw-r--r--test/unit/helpers.lua9
-rw-r--r--test/unit/preprocess.lua39
3 files changed, 24 insertions, 28 deletions
diff --git a/test/unit/formatc.lua b/test/unit/formatc.lua
index e5ac87032a..e288081960 100644
--- a/test/unit/formatc.lua
+++ b/test/unit/formatc.lua
@@ -221,10 +221,6 @@ local function standalone(...) -- luacheck: ignore
local raw = Preprocess.preprocess('', arg[1])
- if raw == nil then
- print("ERROR: Preprocess.preprocess() returned empty")
- end
-
local formatted
if #arg == 2 and arg[2] == 'no' then
formatted = raw
diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua
index abbdecacc9..1e97fc9793 100644
--- a/test/unit/helpers.lua
+++ b/test/unit/helpers.lua
@@ -69,14 +69,7 @@ local function cimport(...)
end
local body = nil
- for _ = 1, 10 do
- body, previous_defines = Preprocess.preprocess(previous_defines, unpack(paths))
- if body ~= nil then break end
- end
-
- if body == nil then
- print("ERROR: helpers.lua: Preprocess.preprocess() returned empty")
- end
+ body, previous_defines = Preprocess.preprocess(previous_defines, unpack(paths))
-- format it (so that the lines are "unique" statements), also filter out
-- Objective-C blocks
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