From 7a9c2d5e88e7e8ab9e4355776dd0b8263851de04 Mon Sep 17 00:00:00 2001 From: elsid Date: Wed, 26 Feb 2025 23:18:07 +0100 Subject: [PATCH] Split local and global event handlers --- .../integration_tests/test_lua_api/player.lua | 2 +- .../integration_tests/test_lua_api/test.lua | 2 +- .../testing_util/testing_util.lua | 23 +++++++++++-------- scripts/data/morrowind_tests/global.lua | 2 +- scripts/data/morrowind_tests/player.lua | 2 +- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/scripts/data/integration_tests/test_lua_api/player.lua b/scripts/data/integration_tests/test_lua_api/player.lua index 16f0f2eea3..9620866e6e 100644 --- a/scripts/data/integration_tests/test_lua_api/player.lua +++ b/scripts/data/integration_tests/test_lua_api/player.lua @@ -346,5 +346,5 @@ return { engineHandlers = { onFrame = testing.updateLocal, }, - eventHandlers = testing.eventHandlers + eventHandlers = testing.localEventHandlers, } diff --git a/scripts/data/integration_tests/test_lua_api/test.lua b/scripts/data/integration_tests/test_lua_api/test.lua index f55c44df63..2f336de8d9 100644 --- a/scripts/data/integration_tests/test_lua_api/test.lua +++ b/scripts/data/integration_tests/test_lua_api/test.lua @@ -330,5 +330,5 @@ return { engineHandlers = { onUpdate = testing.makeUpdateGlobal(), }, - eventHandlers = testing.eventHandlers, + eventHandlers = testing.globalEventHandlers, } diff --git a/scripts/data/integration_tests/testing_util/testing_util.lua b/scripts/data/integration_tests/testing_util/testing_util.lua index 2d67c6ca8a..f5de16fb2d 100644 --- a/scripts/data/integration_tests/testing_util/testing_util.lua +++ b/scripts/data/integration_tests/testing_util/testing_util.lua @@ -208,8 +208,20 @@ function M.formatActualExpected(actual, expected) return string.format('actual: %s, expected: %s', actual, expected) end -M.eventHandlers = { - runLocalTest = function(name) -- used only in local scripts +-- used only in global scripts +M.globalEventHandlers = { + localTestFinished = function(data) + if data.name ~= currentLocalTest then + error(string.format('localTestFinished with incorrect name %s, expected %s', data.name, currentLocalTest)) + end + currentLocalTest = nil + currentLocalTestError = data.errMsg + end, +} + +-- used only in local scripts +M.localEventHandlers = { + runLocalTest = function(name) fn = localTests[name] if not fn then core.sendGlobalEvent('localTestFinished', {name=name, errMsg='Local test is not found'}) @@ -223,13 +235,6 @@ M.eventHandlers = { core.sendGlobalEvent('localTestFinished', {name=name, errMsg=err}) end) end, - localTestFinished = function(data) -- used only in global scripts - if data.name ~= currentLocalTest then - error(string.format('localTestFinished with incorrect name %s, expected %s', data.name, currentLocalTest)) - end - currentLocalTest = nil - currentLocalTestError = data.errMsg - end, } return M diff --git a/scripts/data/morrowind_tests/global.lua b/scripts/data/morrowind_tests/global.lua index a78d90e408..f17e72cda9 100644 --- a/scripts/data/morrowind_tests/global.lua +++ b/scripts/data/morrowind_tests/global.lua @@ -16,5 +16,5 @@ return { engineHandlers = { onUpdate = testing.makeUpdateGlobal(), }, - eventHandlers = testing.eventHandlers, + eventHandlers = testing.globalEventHandlers, } diff --git a/scripts/data/morrowind_tests/player.lua b/scripts/data/morrowind_tests/player.lua index 7435b49553..226d9754f0 100644 --- a/scripts/data/morrowind_tests/player.lua +++ b/scripts/data/morrowind_tests/player.lua @@ -80,5 +80,5 @@ return { engineHandlers = { onFrame = testing.updateLocal, }, - eventHandlers = testing.eventHandlers + eventHandlers = testing.localEventHandlers, }