diff options
author | Matthew Wild <mwild1@gmail.com> | 2020-09-03 12:59:43 +0100 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2020-09-03 12:59:43 +0100 |
commit | c909bca762b655dd798b9f0f5c937feced7aa655 (patch) | |
tree | 4153e8bfdc225c44323fd205b47301d966339e7e /spec | |
parent | 1cec1146460848a60dca8ebc85c97d7c45544c65 (diff) | |
download | prosody-c909bca762b655dd798b9f0f5c937feced7aa655.tar.gz prosody-c909bca762b655dd798b9f0f5c937feced7aa655.zip |
util.events: Add set_debug_hook() method
Hook signature:
ret = debug_hook(handler, event_name, event_data)
Diffstat (limited to 'spec')
-rw-r--r-- | spec/util_events_spec.lua | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/spec/util_events_spec.lua b/spec/util_events_spec.lua index fee60f8f..95303cce 100644 --- a/spec/util_events_spec.lua +++ b/spec/util_events_spec.lua @@ -208,5 +208,43 @@ describe("util.events", function () assert.spy(h).was_called(2); end); end); + + describe("debug hooks", function () + it("should get called", function () + local d = spy.new(function (handler, event_name, event_data) + return handler(event_data); + end); + + e.add_handler("myevent", h); + e.fire_event("myevent"); + + assert.spy(h).was_called(1); + assert.spy(d).was_called(0); + + assert.is_nil(e.set_debug_hook(d)); + + e.fire_event("myevent", { mydata = true }); + + assert.spy(h).was_called(2); + assert.spy(d).was_called(1); + assert.spy(d).was_called_with(h, "myevent", { mydata = true }); + + assert.equal(d, e.set_debug_hook(nil)); + + e.fire_event("myevent", { mydata = false }); + + assert.spy(h).was_called(3); + assert.spy(d).was_called(1); + end); + it("setting should return any existing debug hook", function () + local function f() end + local function g() end + assert.is_nil(e.set_debug_hook(f)); + assert.is_equal(f, e.set_debug_hook(g)); + assert.is_equal(g, e.set_debug_hook(f)); + assert.is_equal(f, e.set_debug_hook(nil)); + assert.is_nil(e.set_debug_hook(f)); + end); + end); end); end); |