Split local and global event handlers

This commit is contained in:
elsid 2025-02-26 23:18:07 +01:00
parent 981ca957c1
commit 7a9c2d5e88
No known key found for this signature in database
GPG Key ID: B845CB9FEE18AB40
5 changed files with 18 additions and 13 deletions

View File

@ -346,5 +346,5 @@ return {
engineHandlers = {
onFrame = testing.updateLocal,
},
eventHandlers = testing.eventHandlers
eventHandlers = testing.localEventHandlers,
}

View File

@ -330,5 +330,5 @@ return {
engineHandlers = {
onUpdate = testing.makeUpdateGlobal(),
},
eventHandlers = testing.eventHandlers,
eventHandlers = testing.globalEventHandlers,
}

View File

@ -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

View File

@ -16,5 +16,5 @@ return {
engineHandlers = {
onUpdate = testing.makeUpdateGlobal(),
},
eventHandlers = testing.eventHandlers,
eventHandlers = testing.globalEventHandlers,
}

View File

@ -80,5 +80,5 @@ return {
engineHandlers = {
onFrame = testing.updateLocal,
},
eventHandlers = testing.eventHandlers
eventHandlers = testing.localEventHandlers,
}