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"
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"
make all

@ -102,5 +102,15 @@ exclude_files = {
"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)
ignore = {"631"}

@ -26,7 +26,7 @@ describe("AutoSuspend widget tests", function()
it("should be able to execute suspend when timing out", function()
local mock_time = require("mock_time")
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")
mock_time:increase(5)
UIManager:handleInput()
@ -41,10 +41,10 @@ describe("AutoSuspend widget tests", function()
local mock_time = require("mock_time")
-- AutoSuspend plugin set the last_action_sec each time it is initialized.
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.
mock_time:increase(5)
local widget2 = widget_class:new()
local widget2 = widget_class:new() --luacheck: ignore
local UIManager = require("ui/uimanager")
mock_time:increase(6)
UIManager:handleInput()

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

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

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

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

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

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

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

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

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

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

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

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

@ -13,7 +13,7 @@ function MockTime:install()
self.original_util_time = util.gettime
assert(self.original_util_time ~= nil)
end
os.time = function()
os.time = function() --luacheck: ignore
logger.dbg("MockTime:os.time: ", self.value)
return self.value
end
@ -26,7 +26,7 @@ end
function MockTime:uninstall()
assert(self ~= nil)
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
util.gettime = self.original_util_time
end

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

@ -51,7 +51,7 @@ describe("network_manager module", function()
package.loaded["ui/network/manager"] = nil
clearState()
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_off_wifi_called, 0)
assert.is.same(obtain_ip_called, 1)
@ -62,7 +62,7 @@ describe("network_manager module", function()
package.loaded["ui/network/manager"] = nil
clearState()
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_off_wifi_called, 0)
assert.is.same(obtain_ip_called, 0)

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

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

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

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

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

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

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

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

@ -1,6 +1,6 @@
describe("Readertoc module", function()
local DocumentRegistry, ReaderUI, DEBUG
local readerui, toc, toc_max_depth
local readerui, toc, toc_max_depth, title
setup(function()
require("commonrequire")
@ -22,10 +22,10 @@ describe("Readertoc module", function()
assert.are.same(2, toc_max_depth)
end)
it("should get toc title from page", function()
local title = toc:getTocTitleByPage(51)
title = toc:getTocTitleByPage(51)
DEBUG("toc", toc.toc)
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.")
end)
describe("getTocTicks API", function()

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

@ -1,5 +1,5 @@
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 readerui
setup(function()
@ -8,7 +8,6 @@ describe("ReaderScreenshot module", function()
ReaderUI = require("apps/reader/readerui")
lfs = require("libs/libkoreader-lfs")
UIManager = require("ui/uimanager")
Screen = require("device").screen
Event = require("ui/event")
readerui = ReaderUI:new{

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

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

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

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

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

Loading…
Cancel
Save