Skip to content

Commit

Permalink
Add test on error in event callback
Browse files Browse the repository at this point in the history
  • Loading branch information
Insality committed Jun 22, 2024
1 parent 0cc3351 commit 66739e0
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions test/test_event_logger.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,27 @@ return function()
assert(event.logger == logger)
end)

it("Subscribe and Unsubscribe", function()
it("Should handle error in callback", function()
local called = false

local EMPTY_FUNCTION = function(_, message, context) end
local logger = {
trace = EMPTY_FUNCTION,
debug = EMPTY_FUNCTION,
info = EMPTY_FUNCTION,
warn = EMPTY_FUNCTION,
error = function() called = true end,
}
event.set_logger(logger)
assert(event.logger == logger)

local test_event = event.create()
local f = function() end
local f = function() error("error") end

test_event:subscribe(f)
assert(#test_event.callbacks == 1)
test_event:trigger()

test_event:unsubscribe(f)
assert(#test_event.callbacks == 0)
assert(called == true)
end)
end)
end

0 comments on commit 66739e0

Please sign in to comment.