Travis: run luacheck on unit tests (#3059)

* Travis: run luacheck on unit tests
pull/3066/head
Frans de Jonge 7 years ago committed by Hzj_jie
parent 1bfad22af0
commit e3c17aa6d0

@ -10,7 +10,7 @@ travis_retry make fetchthirdparty
"${CI_DIR}/helper_shellchecks.sh" "${CI_DIR}/helper_shellchecks.sh"
echo -e "\n${ANSI_GREEN}Luacheck results" echo -e "\n${ANSI_GREEN}Luacheck results"
luajit "$(which luacheck)" --no-color -q {reader,setupkoenv,datastorage}.lua frontend plugins luajit "$(which luacheck)" --no-color -q {reader,setupkoenv,datastorage}.lua frontend plugins spec
echo -e "\n${ANSI_GREEN}make all" echo -e "\n${ANSI_GREEN}make all"
make all make all

@ -102,5 +102,15 @@ exclude_files = {
"plugins/newsdownloader.koplugin/lib/xml.lua", "plugins/newsdownloader.koplugin/lib/xml.lua",
} }
-- don't balk on busted stuff in spec
files["spec/unit/*"].std = "+busted"
files["spec/unit/*"].globals = {
"package",
"assertAlmostEquals",
"assertNotAlmostEquals",
"requireBackgroundRunner",
"stopBackgroundRunner",
}
-- TODO: clean up and enforce max line width (631) -- TODO: clean up and enforce max line width (631)
ignore = {"631"} ignore = {"631"}

@ -26,7 +26,7 @@ describe("AutoSuspend widget tests", function()
it("should be able to execute suspend when timing out", function() it("should be able to execute suspend when timing out", function()
local mock_time = require("mock_time") local mock_time = require("mock_time")
local widget_class = dofile("plugins/autosuspend.koplugin/main.lua") local widget_class = dofile("plugins/autosuspend.koplugin/main.lua")
local widget = widget_class:new() local widget = widget_class:new() --luacheck: ignore
local UIManager = require("ui/uimanager") local UIManager = require("ui/uimanager")
mock_time:increase(5) mock_time:increase(5)
UIManager:handleInput() UIManager:handleInput()
@ -41,10 +41,10 @@ describe("AutoSuspend widget tests", function()
local mock_time = require("mock_time") local mock_time = require("mock_time")
-- AutoSuspend plugin set the last_action_sec each time it is initialized. -- AutoSuspend plugin set the last_action_sec each time it is initialized.
local widget_class = dofile("plugins/autosuspend.koplugin/main.lua") local widget_class = dofile("plugins/autosuspend.koplugin/main.lua")
local widget1 = widget_class:new() local widget1 = widget_class:new() --luacheck: ignore
-- So if one more initialization happens, it won't sleep after another 5 seconds. -- So if one more initialization happens, it won't sleep after another 5 seconds.
mock_time:increase(5) mock_time:increase(5)
local widget2 = widget_class:new() local widget2 = widget_class:new() --luacheck: ignore
local UIManager = require("ui/uimanager") local UIManager = require("ui/uimanager")
mock_time:increase(6) mock_time:increase(6)
UIManager:handleInput() UIManager:handleInput()

@ -217,7 +217,6 @@ describe("BackgroundRunner widget tests", function()
end) end)
it("should block long binary job", function() it("should block long binary job", function()
local executed = 0
local job = { local job = {
when = 1, when = 1,
repeated = true, repeated = true,

@ -1,7 +1,7 @@
describe("BatteryState plugin tests", function() describe("BatteryState plugin tests", function()
local MockTime, module local MockTime, module
local stat = function() local stat = function() --luacheck: ignore
return module:new():stat() return module:new():stat()
end, end,

@ -2,7 +2,7 @@ require("commonrequire")
local DocumentRegistry = require("document/documentregistry") local DocumentRegistry = require("document/documentregistry")
local util = require("ffi/util") local util = require("ffi/util")
function logDuration(filename, pageno, dur) local function logDuration(filename, pageno, dur)
local file = io.open(filename, "a+") local file = io.open(filename, "a+")
if file then if file then
if file:seek("end") == 0 then -- write the header only once if file:seek("end") == 0 then -- write the header only once

@ -1,12 +1,11 @@
describe("Cache module", function() describe("Cache module", function()
local DocumentRegistry, Cache, DEBUG local DocumentRegistry, Cache
local doc local doc
local max_page = 1 local max_page = 1
setup(function() setup(function()
require("commonrequire") require("commonrequire")
DocumentRegistry = require("document/documentregistry") DocumentRegistry = require("document/documentregistry")
Cache = require("cache") Cache = require("cache")
DEBUG = require("dbg")
local sample_pdf = "spec/front/unit/data/sample.pdf" local sample_pdf = "spec/front/unit/data/sample.pdf"
doc = DocumentRegistry:openDocument(sample_pdf) doc = DocumentRegistry:openDocument(sample_pdf)

@ -10,12 +10,11 @@ logger:setLevel(logger.levels.warn)
-- global reader settings -- global reader settings
local DataStorage = require("datastorage") local DataStorage = require("datastorage")
os.remove(DataStorage:getDataDir().."/settings.reader.lua") os.remove(DataStorage:getDataDir().."/settings.reader.lua")
local DocSettings = require("docsettings")
G_reader_settings = require("luasettings"):open(".reader") G_reader_settings = require("luasettings"):open(".reader")
-- global einkfb for Screen (do not show SDL window) -- global einkfb for Screen (do not show SDL window)
einkfb = require("ffi/framebuffer") einkfb = require("ffi/framebuffer") --luacheck: ignore
einkfb.dummy = true einkfb.dummy = true --luacheck: ignore
-- init output device -- init output device
local Screen = require("device").screen local Screen = require("device").screen

@ -54,7 +54,8 @@ describe("Dbg module", function()
end) end)
it("should return all values returned by the guarded function", function() it("should return all values returned by the guarded function", function()
local called = false, re local called = false
local re
local foo = {} local foo = {}
function foo:bar() return 1 end function foo:bar() return 1 end
assert.is.falsy(called) assert.is.falsy(called)

@ -1,8 +1,7 @@
describe("DepGraph module", function() describe("DepGraph module", function()
local DepGraph, logger local DepGraph
setup(function() setup(function()
require("commonrequire") require("commonrequire")
logger = require("logger")
DepGraph = require("depgraph") DepGraph = require("depgraph")
end) end)

@ -1,4 +1,5 @@
describe("device module", function() describe("device module", function()
-- luacheck: push ignore
local mock_fb, mock_input local mock_fb, mock_input
local iopen = io.open local iopen = io.open
local osgetenv = os.getenv local osgetenv = os.getenv
@ -286,4 +287,5 @@ describe("device module", function()
UIManager.onRotation:revert() UIManager.onRotation:revert()
end) end)
end) end)
-- luacheck: pop
end) end)

@ -1,5 +1,6 @@
describe("Frontlight function in PowerD", function() describe("Frontlight function in PowerD", function()
local PowerD, device local PowerD
local param, test_when_on, test_when_off
setup(function() setup(function()
require("commonrequire") require("commonrequire")
@ -17,7 +18,6 @@ describe("Frontlight function in PowerD", function()
end) end)
before_each(function() before_each(function()
frontlight = param.fl_min
stub(PowerD, "init") stub(PowerD, "init")
stub(PowerD, "frontlightIntensityHW") stub(PowerD, "frontlightIntensityHW")
stub(PowerD, "setIntensityHW") stub(PowerD, "setIntensityHW")

@ -1,5 +1,5 @@
-- set true to test httpclient -- set true to test httpclient
DUSE_TURBO_LIB = false DUSE_TURBO_LIB = false --luacheck: ignore
describe("HTTP client module #notest #nocov", function() describe("HTTP client module #notest #nocov", function()
local UIManager local UIManager

@ -76,14 +76,14 @@ describe("Koptinterface module", function()
end) end)
it("should get native text boxes", function() it("should get native text boxes", function()
local kc = Koptinterface:getCachedContext(doc, 1) Koptinterface:getCachedContext(doc, 1)
local boxes = Koptinterface:getNativeTextBoxes(doc, 1) local boxes = Koptinterface:getNativeTextBoxes(doc, 1)
local lines_in_native_page = #boxes local lines_in_native_page = #boxes
assert.truthy(lines_in_native_page == 60) assert.truthy(lines_in_native_page == 60)
end) end)
it("should get native text boxes from scratch", function() it("should get native text boxes from scratch", function()
local kc = Koptinterface:getCachedContext(doc, 1) Koptinterface:getCachedContext(doc, 1)
local boxes = Koptinterface:getNativeTextBoxesFromScratch(doc, 1) local boxes = Koptinterface:getNativeTextBoxesFromScratch(doc, 1)
local lines_in_native_page = #boxes local lines_in_native_page = #boxes
assert.truthy(lines_in_native_page == 60) assert.truthy(lines_in_native_page == 60)
@ -91,7 +91,7 @@ describe("Koptinterface module", function()
it("should get reflow text boxes", function() it("should get reflow text boxes", function()
doc.configurable.text_wrap = 1 doc.configurable.text_wrap = 1
local kc = Koptinterface:getCachedContext(doc, 1) Koptinterface:getCachedContext(doc, 1)
local boxes = Koptinterface:getReflowedTextBoxes(doc, 1) local boxes = Koptinterface:getReflowedTextBoxes(doc, 1)
local lines_in_reflowed_page = #boxes local lines_in_reflowed_page = #boxes
assert.truthy(lines_in_reflowed_page > 60) assert.truthy(lines_in_reflowed_page > 60)
@ -99,7 +99,7 @@ describe("Koptinterface module", function()
it("should get reflow text boxes from scratch", function() it("should get reflow text boxes from scratch", function()
doc.configurable.text_wrap = 1 doc.configurable.text_wrap = 1
local kc = Koptinterface:getCachedContext(doc, 1) Koptinterface:getCachedContext(doc, 1)
local boxes = Koptinterface:getReflowedTextBoxesFromScratch(doc, 1) local boxes = Koptinterface:getReflowedTextBoxesFromScratch(doc, 1)
local lines_in_reflowed_page = #boxes local lines_in_reflowed_page = #boxes
assert.truthy(lines_in_reflowed_page > 60) assert.truthy(lines_in_reflowed_page > 60)
@ -123,7 +123,7 @@ describe("Koptinterface module", function()
it("should get word from reflow position", function() it("should get word from reflow position", function()
complex_doc.configurable.text_wrap = 1 complex_doc.configurable.text_wrap = 1
local kc = Koptinterface:getCachedContext(complex_doc, 19) Koptinterface:getCachedContext(complex_doc, 19)
local word_boxes = Koptinterface:getWordFromPosition(complex_doc, { local word_boxes = Koptinterface:getWordFromPosition(complex_doc, {
page = 19, x = 320, y = 730, page = 19, x = 320, y = 730,
}) })

@ -51,15 +51,13 @@ local service = [[
]] ]]
describe("KOSync modules #notest #nocov", function() describe("KOSync modules #notest #nocov", function()
local UIManager, logger, md5, client local logger, md5, client
local username, password, doc, percentage, progress, device local username, password, doc, percentage, progress, device
setup(function() setup(function()
require("commonrequire") require("commonrequire")
UIManager = require("ui/uimanager")
logger = require("logger") logger = require("logger")
md5 = require("ffi/MD5") md5 = require("ffi/MD5")
local HTTPClient = require("httpclient")
local Spore = require("Spore") local Spore = require("Spore")
client = Spore.new_from_string(service) client = Spore.new_from_string(service)
package.loaded['Spore.Middleware.GinClient'] = {} package.loaded['Spore.Middleware.GinClient'] = {}
@ -188,13 +186,13 @@ describe("KOSync modules #notest #nocov", function()
} }
-- TODO: Test kosync module -- TODO: Test kosync module
local function mockKOSyncClient() local function mockKOSyncClient() --luacheck: ignore
package.loaded["KOSyncClient"] = nil package.loaded["KOSyncClient"] = nil
local c = require("KOSyncClient") local c = require("KOSyncClient")
c.new = function(o) c.new = function(o)
local o = o or {} o = o or {}
setmetatable(o, self) setmetatable(o, self) --luacheck: ignore
self.__index = self self.__index = self --luacheck: ignore
return o return o
end end
@ -208,11 +206,11 @@ describe("KOSync modules #notest #nocov", function()
return res.result, res.body return res.result, res.body
end end
c.update_progress = function(name, passwd, doc, prog, percent, device, device_id, cb) c.update_progress = function(name, passwd, doc, prog, percent, device, device_id, cb) --luacheck: ignore
cb(res.result, res.body) cb(res.result, res.body)
end end
c.get_progress = function(name, passwd, doc, cb) c.get_progress = function(name, passwd, doc, cb) --luacheck: ignore
cb(res.result, res.body) cb(res.result, res.body)
end end
end end

@ -13,7 +13,7 @@ function MockTime:install()
self.original_util_time = util.gettime self.original_util_time = util.gettime
assert(self.original_util_time ~= nil) assert(self.original_util_time ~= nil)
end end
os.time = function() os.time = function() --luacheck: ignore
logger.dbg("MockTime:os.time: ", self.value) logger.dbg("MockTime:os.time: ", self.value)
return self.value return self.value
end end
@ -26,7 +26,7 @@ end
function MockTime:uninstall() function MockTime:uninstall()
assert(self ~= nil) assert(self ~= nil)
local util = require("ffi/util") local util = require("ffi/util")
os.time = self.original_os_time os.time = self.original_os_time --luacheck: ignore
if self.original_util_time ~= nil then if self.original_util_time ~= nil then
util.gettime = self.original_util_time util.gettime = self.original_util_time
end end

@ -41,7 +41,6 @@ describe("MockTime tests", function()
it("should increase time", function() it("should increase time", function()
local mock_time = require("mock_time") local mock_time = require("mock_time")
local current_time = os.time()
mock_time:install() mock_time:install()
assert.is.truthy(mock_time:set(10.1)) assert.is.truthy(mock_time:set(10.1))
assert.are.equal(os.time(), 10) assert.are.equal(os.time(), 10)

@ -51,7 +51,7 @@ describe("network_manager module", function()
package.loaded["ui/network/manager"] = nil package.loaded["ui/network/manager"] = nil
clearState() clearState()
G_reader_settings:saveSetting("wifi_was_on", true) G_reader_settings:saveSetting("wifi_was_on", true)
local network_manager = require("ui/network/manager") local network_manager = require("ui/network/manager") --luacheck: ignore
assert.is.same(turn_on_wifi_called, 1) assert.is.same(turn_on_wifi_called, 1)
assert.is.same(turn_off_wifi_called, 0) assert.is.same(turn_off_wifi_called, 0)
assert.is.same(obtain_ip_called, 1) assert.is.same(obtain_ip_called, 1)
@ -62,7 +62,7 @@ describe("network_manager module", function()
package.loaded["ui/network/manager"] = nil package.loaded["ui/network/manager"] = nil
clearState() clearState()
G_reader_settings:saveSetting("wifi_was_on", false) G_reader_settings:saveSetting("wifi_was_on", false)
local network_manager = require("ui/network/manager") local network_manager = require("ui/network/manager") --luacheck: ignore
assert.is.same(turn_on_wifi_called, 0) assert.is.same(turn_on_wifi_called, 0)
assert.is.same(turn_off_wifi_called, 0) assert.is.same(turn_off_wifi_called, 0)
assert.is.same(obtain_ip_called, 0) assert.is.same(obtain_ip_called, 0)

@ -166,6 +166,7 @@ bar=baz
end) end)
it("should create config file", function() it("should create config file", function()
local fd
local fn = "/tmp/abcfoobarbaz449" local fn = "/tmp/abcfoobarbaz449"
assert.is_not.Equals(lfs.attributes(fn, "mode"), "file") assert.is_not.Equals(lfs.attributes(fn, "mode"), "file")
finally(function() os.remove(fn) end) finally(function() os.remove(fn) end)

@ -1,4 +1,5 @@
describe("Math module", function() describe("Math module", function()
local Math
setup(function() setup(function()
require("commonrequire") require("commonrequire")

@ -1,5 +1,5 @@
describe("ReaderBookmark module", function() describe("ReaderBookmark module", function()
local DocumentRegistry, ReaderUI, UIManager, Screen, Geom, dbg, DocSettings local DocumentRegistry, ReaderUI, UIManager, Screen, Geom, DocSettings
local sample_epub, sample_pdf local sample_epub, sample_pdf
setup(function() setup(function()
@ -10,7 +10,6 @@ describe("ReaderBookmark module", function()
UIManager = require("ui/uimanager") UIManager = require("ui/uimanager")
Screen = require("device").screen Screen = require("device").screen
Geom = require("ui/geometry") Geom = require("ui/geometry")
dbg = require("dbg")
sample_epub = "spec/front/unit/data/juliet.epub" sample_epub = "spec/front/unit/data/juliet.epub"
sample_pdf = "spec/front/unit/data/sample.pdf" sample_pdf = "spec/front/unit/data/sample.pdf"
@ -45,7 +44,6 @@ describe("ReaderBookmark module", function()
end end
describe("bookmark for EPUB document", function() describe("bookmark for EPUB document", function()
local page = 10
local readerui local readerui
setup(function() setup(function()
DocSettings:open(sample_epub):purge() DocSettings:open(sample_epub):purge()

@ -1,15 +1,12 @@
describe("Readerdictionary module", function() describe("Readerdictionary module", function()
local DocumentRegistry, ReaderUI, lfs, UIManager, Screen, Event, DEBUG local DocumentRegistry, ReaderUI, UIManager, Screen
setup(function() setup(function()
require("commonrequire") require("commonrequire")
DocumentRegistry = require("document/documentregistry") DocumentRegistry = require("document/documentregistry")
ReaderUI = require("apps/reader/readerui") ReaderUI = require("apps/reader/readerui")
lfs = require("libs/libkoreader-lfs")
UIManager = require("ui/uimanager") UIManager = require("ui/uimanager")
Screen = require("device").screen Screen = require("device").screen
Event = require("ui/event")
DEBUG = require("dbg")
end) end)
local readerui, rolling, dictionary local readerui, rolling, dictionary

@ -1,14 +1,13 @@
describe("Readerfooter module", function() describe("Readerfooter module", function()
local DocumentRegistry, ReaderUI, MenuSorter, DocSettings, UIManager, DEBUG local DocumentRegistry, ReaderUI, DocSettings, UIManager
local purgeDir, Screen local purgeDir, Screen
local tapFooterMenu
setup(function() setup(function()
require("commonrequire") require("commonrequire")
package.unloadAll() package.unloadAll()
DEBUG = require("dbg")
DocumentRegistry = require("document/documentregistry") DocumentRegistry = require("document/documentregistry")
DocSettings = require("docsettings") DocSettings = require("docsettings")
MenuSorter = require("ui/menusorter")
ReaderUI = require("apps/reader/readerui") ReaderUI = require("apps/reader/readerui")
UIManager = require("ui/uimanager") UIManager = require("ui/uimanager")
purgeDir = require("ffi/util").purgeDir purgeDir = require("ffi/util").purgeDir
@ -432,8 +431,8 @@ describe("Readerfooter module", function()
it("should support toggle footer through menu if tap zone is disabled", function() it("should support toggle footer through menu if tap zone is disabled", function()
local saved_tap_zone_minibar = DTAP_ZONE_MINIBAR local saved_tap_zone_minibar = DTAP_ZONE_MINIBAR
DTAP_ZONE_MINIBAR.w = 0 DTAP_ZONE_MINIBAR.w = 0 --luacheck: ignore
DTAP_ZONE_MINIBAR.h = 0 DTAP_ZONE_MINIBAR.h = 0 --luacheck: ignore
local sample_pdf = "spec/front/unit/data/2col.pdf" local sample_pdf = "spec/front/unit/data/2col.pdf"
purgeDir(DocSettings:getSidecarDir(sample_pdf)) purgeDir(DocSettings:getSidecarDir(sample_pdf))
@ -471,7 +470,7 @@ describe("Readerfooter module", function()
tapFooterMenu(fake_menu, "Toggle mode") tapFooterMenu(fake_menu, "Toggle mode")
assert.is.same(2, footer.mode) assert.is.same(2, footer.mode)
DTAP_ZONE_MINIBAR = saved_tap_zone_minibar DTAP_ZONE_MINIBAR = saved_tap_zone_minibar --luacheck: ignore
end) end)
it("should remove and add modes to footer text in all_at_once mode", function() it("should remove and add modes to footer text in all_at_once mode", function()

@ -1,5 +1,5 @@
describe("Readerhighlight module", function() describe("Readerhighlight module", function()
local DocumentRegistry, ReaderUI, UIManager, Screen, Geom, dbg, Event local DocumentRegistry, ReaderUI, UIManager, Screen, Geom, Event
setup(function() setup(function()
require("commonrequire") require("commonrequire")
package.unloadAll() package.unloadAll()
@ -9,7 +9,6 @@ describe("Readerhighlight module", function()
ReaderUI = require("apps/reader/readerui") ReaderUI = require("apps/reader/readerui")
Screen = require("device").screen Screen = require("device").screen
UIManager = require("ui/uimanager") UIManager = require("ui/uimanager")
dbg = require("dbg")
end) end)
local function highlight_single_word(readerui, pos0) local function highlight_single_word(readerui, pos0)

@ -84,7 +84,7 @@ describe("Readerpaging module", function()
local tmp_readerui = ReaderUI:new{ local tmp_readerui = ReaderUI:new{
document = DocumentRegistry:openDocument(sample_djvu), document = DocumentRegistry:openDocument(sample_djvu),
} }
local paging = tmp_readerui.paging paging = tmp_readerui.paging
paging:onGotoPage(tmp_readerui.document:getPageCount()) paging:onGotoPage(tmp_readerui.document:getPageCount())
paging:onScrollPanRel(120) paging:onScrollPanRel(120)
paging:onScrollPanRel(-1) paging:onScrollPanRel(-1)

@ -1,5 +1,5 @@
describe("Readerrolling module", function() describe("Readerrolling module", function()
local DocumentRegistry, ReaderUI, Event, DEBUG local DocumentRegistry, ReaderUI, Event
local readerui, rolling local readerui, rolling
setup(function() setup(function()
@ -7,7 +7,6 @@ describe("Readerrolling module", function()
DocumentRegistry = require("document/documentregistry") DocumentRegistry = require("document/documentregistry")
ReaderUI = require("apps/reader/readerui") ReaderUI = require("apps/reader/readerui")
Event = require("ui/event") Event = require("ui/event")
DEBUG = require("dbg")
local sample_epub = "spec/front/unit/data/juliet.epub" local sample_epub = "spec/front/unit/data/juliet.epub"
readerui = ReaderUI:new{ readerui = ReaderUI:new{

@ -1,6 +1,6 @@
describe("Readertoc module", function() describe("Readertoc module", function()
local DocumentRegistry, ReaderUI, DEBUG local DocumentRegistry, ReaderUI, DEBUG
local readerui, toc, toc_max_depth local readerui, toc, toc_max_depth, title
setup(function() setup(function()
require("commonrequire") require("commonrequire")
@ -22,10 +22,10 @@ describe("Readertoc module", function()
assert.are.same(2, toc_max_depth) assert.are.same(2, toc_max_depth)
end) end)
it("should get toc title from page", function() it("should get toc title from page", function()
local title = toc:getTocTitleByPage(51) title = toc:getTocTitleByPage(51)
DEBUG("toc", toc.toc) DEBUG("toc", toc.toc)
assert(title == "SCENE V. A hall in Capulet's house.") assert(title == "SCENE V. A hall in Capulet's house.")
local title = toc:getTocTitleByPage(155) title = toc:getTocTitleByPage(155)
assert(title == "SCENE I. Friar Laurence's cell.") assert(title == "SCENE I. Friar Laurence's cell.")
end) end)
describe("getTocTicks API", function() describe("getTocTicks API", function()

@ -23,16 +23,16 @@ describe("ReadHistory module", function()
return DocSettings:getHistoryPath(realpath(test_file(name))) return DocSettings:getHistoryPath(realpath(test_file(name)))
end end
local function rm(file) local function rm(filename)
os.remove(file) os.remove(filename)
end end
local function mv(source, target) local function mv(source, target)
os.rename(source, target) os.rename(source, target)
end end
local function touch(file) local function touch(filename)
local f = io.open(file, "w") local f = io.open(filename, "w")
f:close() f:close()
end end

@ -1,5 +1,5 @@
describe("ReaderScreenshot module", function() describe("ReaderScreenshot module", function()
local DocumentRegistry, ReaderUI, lfs, UIManager, Screen, Event local DocumentRegistry, ReaderUI, lfs, UIManager, Event
local sample_epub = "spec/front/unit/data/leaves.epub" local sample_epub = "spec/front/unit/data/leaves.epub"
local readerui local readerui
setup(function() setup(function()
@ -8,7 +8,6 @@ describe("ReaderScreenshot module", function()
ReaderUI = require("apps/reader/readerui") ReaderUI = require("apps/reader/readerui")
lfs = require("libs/libkoreader-lfs") lfs = require("libs/libkoreader-lfs")
UIManager = require("ui/uimanager") UIManager = require("ui/uimanager")
Screen = require("device").screen
Event = require("ui/event") Event = require("ui/event")
readerui = ReaderUI:new{ readerui = ReaderUI:new{

@ -1,4 +1,5 @@
describe("touch probe module", function() describe("touch probe module", function()
local x, y
setup(function() setup(function()
require("commonrequire") require("commonrequire")
end) end)
@ -12,7 +13,7 @@ describe("touch probe module", function()
end end
-- for kobo touch, we have mirror_x, then switch_xy -- for kobo touch, we have mirror_x, then switch_xy
-- tap lower right corner -- tap lower right corner
local x, y = Device.screen:getWidth()-40, Device.screen:getHeight()-40 x, y = Device.screen:getWidth()-40, Device.screen:getHeight()-40
need_to_switch_xy = nil need_to_switch_xy = nil
TouchProbe:onTapProbe(nil, { TouchProbe:onTapProbe(nil, {
pos = { pos = {
@ -25,7 +26,7 @@ describe("touch probe module", function()
-- now only test mirror_x -- now only test mirror_x
-- tap lower right corner -- tap lower right corner
local x, y = Device.screen:getWidth()-40, Device.screen:getHeight()-40 x, y = Device.screen:getWidth()-40, Device.screen:getHeight()-40
need_to_switch_xy = nil need_to_switch_xy = nil
TouchProbe:onTapProbe(nil, { TouchProbe:onTapProbe(nil, {
pos = { pos = {
@ -38,7 +39,7 @@ describe("touch probe module", function()
-- now only test switch_xy -- now only test switch_xy
-- tap lower right corner -- tap lower right corner
local x, y = Device.screen:getWidth()-40, Device.screen:getHeight()-40 x, y = Device.screen:getWidth()-40, Device.screen:getHeight()-40
need_to_switch_xy = nil need_to_switch_xy = nil
TouchProbe:onTapProbe(nil, { TouchProbe:onTapProbe(nil, {
pos = { pos = {
@ -49,7 +50,7 @@ describe("touch probe module", function()
assert.is.same(TouchProbe.curr_probe_step, 2) assert.is.same(TouchProbe.curr_probe_step, 2)
assert.falsy(need_to_switch_xy) assert.falsy(need_to_switch_xy)
-- tap upper right corner -- tap upper right corner
local x, y = Device.screen:getWidth()-40, 40 x, y = Device.screen:getWidth()-40, 40
TouchProbe:onTapProbe(nil, { TouchProbe:onTapProbe(nil, {
pos = { pos = {
x = y, x = y,

@ -1,4 +1,5 @@
local dutch_wikipedia_text = "Wikipedia is een meertalige encyclopedie, waarvan de inhoud vrij beschikbaar is. Iedereen kan hier kennis toevoegen!" local dutch_wikipedia_text = "Wikipedia is een meertalige encyclopedie, waarvan de inhoud vrij beschikbaar is. Iedereen kan hier kennis toevoegen!"
local Translator
describe("Translator module", function() describe("Translator module", function()
setup(function() setup(function()

@ -6,6 +6,7 @@ local noop = function() end
describe("UIManager checkTasks benchmark", function() describe("UIManager checkTasks benchmark", function()
local now = { util.gettime() } local now = { util.gettime() }
local wait_until -- luacheck: no unused
UIManager:quit() UIManager:quit()
UIManager._task_queue = {} UIManager._task_queue = {}
@ -17,7 +18,7 @@ describe("UIManager checkTasks benchmark", function()
end end
-- for i=1,1000 do -- for i=1,1000 do
wait_until, now = UIManager:_checkTasks() wait_until, now = UIManager:_checkTasks() -- luacheck: no unused
-- end -- end
end) end)

@ -1,16 +1,16 @@
describe("UIManager spec", function() describe("UIManager spec", function()
local Device, UIManager, util local UIManager, util
local now, wait_until
local noop = function() end local noop = function() end
setup(function() setup(function()
require("commonrequire") require("commonrequire")
util = require("ffi/util") util = require("ffi/util")
UIManager = require("ui/uimanager") UIManager = require("ui/uimanager")
Device = require("device")
end) end)
it("should consume due tasks", function() it("should consume due tasks", function()
local now = { util.gettime() } now = { util.gettime() }
local future = { now[1] + 60000, now[2] } local future = { now[1] + 60000, now[2] }
local future2 = {future[1] + 5, future[2]} local future2 = {future[1] + 5, future[2]}
UIManager:quit() UIManager:quit()
@ -28,7 +28,7 @@ describe("UIManager spec", function()
end) end)
it("should calcualte wait_until properly in checkTasks routine", function() it("should calcualte wait_until properly in checkTasks routine", function()
local now = { util.gettime() } now = { util.gettime() }
local future = { now[1] + 60000, now[2] } local future = { now[1] + 60000, now[2] }
UIManager:quit() UIManager:quit()
UIManager._task_queue = { UIManager._task_queue = {
@ -43,7 +43,7 @@ describe("UIManager spec", function()
end) end)
it("should return nil wait_until properly in checkTasks routine", function() it("should return nil wait_until properly in checkTasks routine", function()
local now = { util.gettime() } now = { util.gettime() }
UIManager:quit() UIManager:quit()
UIManager._task_queue = { UIManager._task_queue = {
{ time = {now[1] - 10, now[2] }, action = noop }, { time = {now[1] - 10, now[2] }, action = noop },
@ -55,7 +55,7 @@ describe("UIManager spec", function()
end) end)
it("should insert new task properly in empty task queue", function() it("should insert new task properly in empty task queue", function()
local now = { util.gettime() } now = { util.gettime() }
UIManager:quit() UIManager:quit()
UIManager._task_queue = {} UIManager._task_queue = {}
assert.are.same(0, #UIManager._task_queue) assert.are.same(0, #UIManager._task_queue)
@ -65,7 +65,7 @@ describe("UIManager spec", function()
end) end)
it("should insert new task properly in single task queue", function() it("should insert new task properly in single task queue", function()
local now = { util.gettime() } now = { util.gettime() }
local future = { now[1]+10000, now[2] } local future = { now[1]+10000, now[2] }
UIManager:quit() UIManager:quit()
UIManager._task_queue = { UIManager._task_queue = {
@ -90,8 +90,7 @@ describe("UIManager spec", function()
end) end)
it("should insert new task in ascendant order", function() it("should insert new task in ascendant order", function()
local now = { util.gettime() } now = { util.gettime() }
local noop1 = function() end
UIManager:quit() UIManager:quit()
UIManager._task_queue = { UIManager._task_queue = {
{ time = {now[1] - 10, now[2] }, action = '1' }, { time = {now[1] - 10, now[2] }, action = '1' },
@ -116,8 +115,7 @@ describe("UIManager spec", function()
end) end)
it("should unschedule all the tasks with the same action", function() it("should unschedule all the tasks with the same action", function()
local now = { util.gettime() } now = { util.gettime() }
local noop1 = function() end
UIManager:quit() UIManager:quit()
UIManager._task_queue = { UIManager._task_queue = {
{ time = {now[1] - 15, now[2] }, action = '3' }, { time = {now[1] - 15, now[2] }, action = '3' },
@ -135,7 +133,7 @@ describe("UIManager spec", function()
end) end)
it("should not have race between unschedule and _checkTasks", function() it("should not have race between unschedule and _checkTasks", function()
local now = { util.gettime() } now = { util.gettime() }
local run_count = 0 local run_count = 0
local task_to_remove = function() local task_to_remove = function()
run_count = run_count + 1 run_count = run_count + 1

@ -146,7 +146,7 @@ describe("util module", function()
local text = "Ce test : 1) est très simple ; 2 ) simple comme ( 2/2 ) > 50 % ? ok." local text = "Ce test : 1) est très simple ; 2 ) simple comme ( 2/2 ) > 50 % ? ok."
local word = "" local word = ""
local table_of_words = {} local table_of_words = {}
local c local c, next_c
local table_chars = util.splitToChars(text) local table_chars = util.splitToChars(text)
for i = 1, #table_chars do for i = 1, #table_chars do
c = table_chars[i] c = table_chars[i]
@ -179,7 +179,7 @@ describe("util module", function()
local text = "Ce test : 1) est « très simple » ; 2 ) simple comme ( 2/2 ) > 50 % ? ok." local text = "Ce test : 1) est « très simple » ; 2 ) simple comme ( 2/2 ) > 50 % ? ok."
local word = "" local word = ""
local table_of_words = {} local table_of_words = {}
local c local c, next_c, prev_c
local table_chars = util.splitToChars(text) local table_chars = util.splitToChars(text)
for i = 1, #table_chars do for i = 1, #table_chars do
c = table_chars[i] c = table_chars[i]

@ -1,15 +1,14 @@
describe("Menu widget", function() describe("Menu widget", function()
local Menu, dbg local Menu
setup(function() setup(function()
require("commonrequire") require("commonrequire")
Menu = require("ui/widget/menu") Menu = require("ui/widget/menu")
dbg = require("dbg")
end) end)
it("should convert item table from touch menu properly", function() it("should convert item table from touch menu properly", function()
local cb1 = function() end local cb1 = function() end
local cb2 = function() end local cb2 = function() end
re = Menu.itemTableFromTouchMenu({ local re = Menu.itemTableFromTouchMenu({
navi = { navi = {
icon = 'foo/bar.png', icon = 'foo/bar.png',
{ text = 'foo', callback = cb1 }, { text = 'foo', callback = cb1 },

@ -1,5 +1,5 @@
describe("Wikipedia module", function() describe("Wikipedia module", function()
local util local Wikipedia
setup(function() setup(function()
require("commonrequire") require("commonrequire")
Wikipedia = require("ui/wikipedia") Wikipedia = require("ui/wikipedia")

Loading…
Cancel
Save