From e68181541d8dd6d0ca43d8cba7692997cbc26b6a Mon Sep 17 00:00:00 2001 From: Romain Forlot Date: Fri, 24 Aug 2018 15:59:18 +0200 Subject: Don't crash if lua test files aren't found This protect the file read to avoid crashing if no file has been found and display an error. Protect with double-quote the path to avoid 'find' error if space are part of the path. Change-Id: I3a27ca9d2566edd5f1b9cd301153e0ab735a177a Signed-off-by: Romain Forlot --- conf.d/controller/lua.d/aft.lua | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'conf.d') diff --git a/conf.d/controller/lua.d/aft.lua b/conf.d/controller/lua.d/aft.lua index 8f03e28..876af80 100644 --- a/conf.d/controller/lua.d/aft.lua +++ b/conf.d/controller/lua.d/aft.lua @@ -545,10 +545,20 @@ local function call_tests() --end end +local function readOneFile(f) + local cmdHandle = io.popen('find "'.. _AFT.bindingRootDir..'" -name "'..f..'"') + local filehandle = cmdHandle:read() + if filehandle then + dofile(filehandle) + else + print('Error: file not found ', f) + end + cmdHandle:close() +end + function _launch_test(context, args) _AFT.context = context _AFT.bindingRootDir = AFB:getrootdir(_AFT.context) - local loadedfile = nil -- Prepare the tests execution configuring the monitoring and loading -- lua test files to execute in the Framework. @@ -565,14 +575,10 @@ function _launch_test(context, args) if args.files and type(args.files) == 'table' then for _,f in pairs(args.files) do - local cmdHandle = io.popen('find '.. _AFT.bindingRootDir..' -name '..f) - loadedfile = dofile(cmdHandle:read()) - cmdHandle:close() + readOneFile(f) end elseif type(args.files) == 'string' then - local cmdHandle = io.popen('find '.._AFT.bindingRootDir..' -name '..args.files) - loadedfile = dofile(cmdHandle:read()) - cmdHandle:close() + readOneFile(args.files) end -- Execute the test within a context if given. We assume that the before -- cgit 1.2.3-korg