2
0
mirror of https://github.com/koreader/koreader synced 2024-10-31 21:20:20 +00:00
koreader/spec/unit/dbg_spec.lua
chrox 9ab005a1d3 fix unit test of readerlink and readerpaging
and have more confidence with the unit testing framework.

Now `make testfront` won't retry on failure and testing files are
ordered in each run so that it's possible to reproduce testing failure.

And this patch also fix flush settings not working before suspend issue:
at some point the `FlushSettings` event is sent to `UIManager` instead
of `ReaderUI`, but `UIManager` only delegated events to active widgets
and `ReaderUI` is actually not an active widgets thus will miss the event.

This patch also add a verbose debug mode with "-v" as a switch to turn
on this mode. With verbose mode on, event handling will be logged.
2016-08-12 17:05:07 +08:00

76 lines
2.0 KiB
Lua

describe("Dbg module", function()
local dbg, dbg_on
setup(function()
package.path = "?.lua;common/?.lua;rocks/share/lua/5.1/?.lua;frontend/?.lua;" .. package.path
dbg = require("dbg")
dbg_on = dbg.is_on
end)
after_each(function()
if dbg_on then
dbg:turnOn()
else
dbg:turnOff()
end
end)
it("setup mt.__call and guard after tunrnOn is called", function()
dbg:turnOff()
local old_call = getmetatable(dbg).__call
local old_guard = dbg.guard
dbg:turnOn()
assert.is_not.same(old_call, getmetatable(dbg).__call)
assert.is_not.same(old_guard, dbg.guard)
end)
it("should call pre_gard callback", function()
local called = false
local foo = {}
function foo:bar() end
assert.is.falsy(called)
dbg:turnOff()
assert.is.falsy(called)
dbg:turnOn()
dbg:guard(foo, 'bar', function() called = true end)
foo:bar()
assert.is.truthy(called)
end)
it("should call post_gard callback", function()
local called = false
local foo = {}
function foo:bar() end
assert.is.falsy(called)
dbg:turnOff()
assert.is.falsy(called)
dbg:turnOn()
dbg:guard(foo, 'bar', nil, function() called = true end)
foo:bar()
assert.is.truthy(called)
end)
it("should return all values returned by the guarded function", function()
local called = false, re
local foo = {}
function foo:bar() return 1 end
assert.is.falsy(called)
dbg:turnOn()
dbg:guard(foo, 'bar', function() called = true end)
re = {foo:bar()}
assert.is.truthy(called)
assert.is.same(re, {1})
called = false
function foo:bar() return 1, 2, 3 end
dbg:guard(foo, 'bar', function() called = true end)
assert.is.falsy(called)
re = {foo:bar()}
assert.is.same(re, {1, 2, 3})
end)
end)