diff options
author | Romain Forlot <romain.forlot@iot.bzh> | 2018-07-09 11:54:26 +0200 |
---|---|---|
committer | Romain Forlot <romain.forlot@iot.bzh> | 2018-07-10 17:12:30 +0200 |
commit | 34f32fcb7b1ea567c60c9ae1f46a235e0fba4bfe (patch) | |
tree | e869665ced034639c435e988b9b64a0ffcbfaf9e | |
parent | 5d43cc3428569c62ff1804a5d79afa27637c8479 (diff) |
Adds before and after function to set context
3 Cases are done:
- before and after all tests
- before and after each tests
- before and after specific tests
Change-Id: Ie222e6a3809a14d71a822b084a27ed93ec7bb286
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
-rw-r--r-- | conf.d/controller/lua.d/aft.lua | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/conf.d/controller/lua.d/aft.lua b/conf.d/controller/lua.d/aft.lua index bd0141f..d2587fe 100644 --- a/conf.d/controller/lua.d/aft.lua +++ b/conf.d/controller/lua.d/aft.lua @@ -252,22 +252,32 @@ function _AFT.testVerbError(testName, api, verb, args, cb) end}) end -function _AFT.describe(testName, testFunction) +function _AFT.describe(testName, testFunction, setUp, tearDown) sanitizedTestName = "test"..tostring(testName) if _AFT.beforeEach then local b = _AFT.beforeEach() end if _AFT.afterEach then local a = _AFT.afterEach() end local aTest = {} function aTest:sanitizedTestName() testFunction() end - function aTest:setUp() b() end - function aTest:tearDown() a() end + function aTest:setUp() + if type(setUp) == 'function' then setUp() end + b() + end + function aTest:tearDown() + a() + if type(tearDown) == 'function' then tearDown() end + end table.insert(_AFT.tests_list, {testName, function() - testFunction() + if type(testFunction) == 'function' then + testFunction() + else + print('# ERROR: Test '.. testName .. ' is note defined as a function.') + end end}) end -function _AFT.setbeforeEach(beforeEachTestFunction) +function _AFT.setBeforeEach(beforeEachTestFunction) if type(beforeEachTestFunction) == "function" then _AFT.beforeEach = beforeEachTestFunction else @@ -283,7 +293,7 @@ function _AFT.setAfterEach(afterEachTestFunction) end end -function _AFT.setBefore(beforeAllTestsFunctions) +function _AFT.setBeforeAll(beforeAllTestsFunctions) if type(beforeAllTestsFunctions) == "function" then _AFT.beforeAll = beforeAllTestsFunctions else @@ -291,7 +301,7 @@ function _AFT.setBefore(beforeAllTestsFunctions) end end -function _AFT.setAfter(afterAllTestsFunctions) +function _AFT.setAfterAll(afterAllTestsFunctions) if type(afterAllTestsFunctions) == "function" then _AFT.afterAll = afterAllTestsFunctions else @@ -440,7 +450,7 @@ function _launch_test(context, args) -- 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 + if _AFT.afterAll() ~= 0 then print('Unsetting the tests context failed.') end end |