summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2018-08-30 16:44:01 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2018-08-30 17:23:05 +0200
commit2f768efe099087fedb56102c737353fccbfea4ed (patch)
tree3a0537f2ed2e1d3ab665056f3b0465a2c6e62efc
parent3c1dab4cb0457a97d71365e58c5ea033c1f0a42c (diff)
Reset context functions between test files
This reset the contextual functions that trigger before and after tests between each files loaded. Then context is set by file and not by the API's verb of the test binding. This is more an intuitive behavior. Change-Id: I76716dd19d23b715690b74d9b67253dffd01c12d Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
-rw-r--r--conf.d/controller/lua.d/aft.lua48
1 files changed, 28 insertions, 20 deletions
diff --git a/conf.d/controller/lua.d/aft.lua b/conf.d/controller/lua.d/aft.lua
index 876af80..afe9691 100644
--- a/conf.d/controller/lua.d/aft.lua
+++ b/conf.d/controller/lua.d/aft.lua
@@ -545,6 +545,28 @@ local function call_tests()
--end
end
+local function process_tests()
+ -- Execute the test within a context if given. We assume that the before
+ -- function success returning '0' else we abort the whole test procedure
+ if _AFT.beforeAll then
+ if _AFT.beforeAll() == 0 then
+ call_tests()
+ else
+ AFB:fail(_AFT.context, { info = "Can't set the context to execute the tests correctly. Look at the log and retry."})
+ end
+ else
+ call_tests()
+ end
+
+ -- Keep the context unset function to be executed after all no matter if
+ -- tests have been executed or not.
+ if _AFT.afterAll then
+ if _AFT.afterAll() ~= 0 then
+ print('Unsetting the tests context failed.')
+ end
+ end
+end
+
local function readOneFile(f)
local cmdHandle = io.popen('find "'.. _AFT.bindingRootDir..'" -name "'..f..'"')
local filehandle = cmdHandle:read()
@@ -576,29 +598,15 @@ function _launch_test(context, args)
if args.files and type(args.files) == 'table' then
for _,f in pairs(args.files) do
readOneFile(f)
+ process_tests()
+ _AFT.beforeEach = nil
+ _AFT.afterEach = nil
+ _AFT.beforeAll = nil
+ _AFT.afterAll = nil
end
elseif type(args.files) == 'string' then
readOneFile(args.files)
- end
-
- -- Execute the test within a context if given. We assume that the before
- -- function success returning '0' else we abort the whole test procedure
- if _AFT.beforeAll then
- if _AFT.beforeAll() == 0 then
- call_tests()
- else
- AFB:fail(_AFT.context, { info = "Can't set the context to execute the tests correctly. Look at the log and retry."})
- end
- else
- call_tests()
- end
-
- -- Keep the context unset function to be executed after all no matter if
- -- tests have been executed or not.
- if _AFT.afterAll then
- if _AFT.afterAll() ~= 0 then
- print('Unsetting the tests context failed.')
- end
+ process_tests()
end
if _AFT.exit[1] == 1 then os.exit(_AFT.exit[2]) end