From c1df1ceff7e84016c9a31ae478d5668ea3aa10a3 Mon Sep 17 00:00:00 2001 From: myk002 Date: Wed, 30 Jun 2021 07:10:59 -0700 Subject: [PATCH] add support for custom test wrapper functions to support @BeforeEach and @AfterEach semantics. however, much of our code is scope-based (lambda-based?) so it seemed to make sense to use a single wrapper function instead of separate before_each and after_each functions. --- ci/test.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/ci/test.lua b/ci/test.lua index 5a606476f..fe1da3bb0 100644 --- a/ci/test.lua +++ b/ci/test.lua @@ -280,8 +280,21 @@ end local function build_test_env() local env = { test = utils.OrderedTable(), + -- config values can be overridden in the test file to define + -- requirements for the tests in that file config = { + -- override with the required game mode mode = 'none', + -- override with a test wrapper function with common setup and + -- teardown for every test, if needed. for example: + -- local function test_wrapper(test_fn) + -- mock.patch(dfhack.filesystem, + -- 'listdir_recursive', + -- mock.func({}), + -- test_fn) + -- end + -- config.wrapper = test_wrapper + wrapper = nil, }, expect = {}, mock = mock, @@ -351,6 +364,10 @@ local function load_tests(file, tests) return false end for name, test_func in pairs(env.test) do + if env.config.wrapper then + local fn = test_func + test_func = function() env.config.wrapper(fn) end + end local test_data = { full_name = short_filename .. ':' .. name, func = test_func,