make coverage target for code coverage for the unit test

so that we can easily find which module needs unit test

In order to run 'make coverage' `luacov` need to be installed
with 'sudo luarocks install luacov'.
pull/956/head
chrox 10 years ago
parent 330e5a2789
commit f1f8d8dc4f

@ -0,0 +1,58 @@
--- Global configuration file. Copy, customize and store in your
-- project folder as '.luacov' for project specific configuration
-- @class module
-- @name luacov.defaults
return {
-- default filename to load for config options if not provided
-- only has effect in 'luacov.defaults.lua'
['configfile'] = '.luacov',
-- filename to store stats collected
['statsfile'] = 'luacov.stats.out',
-- filename to store report
['reportfile'] = 'luacov.report.out',
-- Run reporter on completion? (won't work for ticks)
runreport = true,
-- Delete stats file after reporting?
deletestats = true,
-- Patterns for files to include when reporting
-- all will be included if nothing is listed
-- (exclude overrules include, do not include
-- the .lua extension)
['include'] = {
},
-- Patterns for files to exclude when reporting
-- all will be included if nothing is listed
-- (exclude overrules include, do not include
-- the .lua extension)
['exclude'] = {
'luacov$',
'luacov.reporter$',
'luacov.defaults$',
'luacov.runner$',
'luacov.stats$',
'luacov.tick$',
'ansicolors$',
'copas$',
'coxpcall$',
'mediator$',
'moonscript.*$',
'socket$',
'busted.*$',
'luassert.*$',
'pl/.*$',
'say.init$',
'ffi/.*_h$',
'common/.*$',
'JSON',
'MD5',
},
}

@ -16,8 +16,10 @@ install:
- sudo apt-get install libsdl1.2-dev luarocks
- git clone https://github.com/Olivine-Labs/busted/
- cd busted && git checkout v1.10.0 && sudo luarocks make && cd ..
- sudo luarocks install luacov
script:
- make fetchthirdparty
- make
- make testfront
- make coverage

@ -82,6 +82,10 @@ $(INSTALL_DIR)/koreader/.busted:
test -e $(INSTALL_DIR)/koreader/.busted || \
ln -sf ../../.busted $(INSTALL_DIR)/koreader
$(INSTALL_DIR)/koreader/.luacov:
test -e $(INSTALL_DIR)/koreader/.luacov || \
ln -sf ../../.luacov $(INSTALL_DIR)/koreader
testfront: $(INSTALL_DIR)/koreader/.busted
cd $(INSTALL_DIR)/koreader && busted -l ./luajit
@ -89,6 +93,13 @@ test:
$(MAKE) -C $(KOR_BASE) test
$(MAKE) testfront
coverage: $(INSTALL_DIR)/koreader/.luacov
cd $(INSTALL_DIR)/koreader && busted -c -l ./luajit --exclude-tags=nocov
# coverage report summary
cd $(INSTALL_DIR)/koreader && tail -n \
+$$(($$(grep -nm1 Summary luacov.report.out|cut -d: -f1)-1)) \
luacov.report.out
.PHONY: test
fetchthirdparty:

@ -1,6 +1,6 @@
require "defaults"
package.path = "?.lua;common/?.lua;frontend/?.lua"
package.cpath = "?.so;common/?.so;/usr/lib/lua/?.so"
package.path = "?.lua;common/?.lua;frontend/?.lua;" .. package.path
package.cpath = "?.so;common/?.so;/usr/lib/lua/?.so;" .. package.cpath
require "libs/libkoreader-lfs"
-- global einkfb for Screen
@ -26,22 +26,23 @@ describe("Cache module", function()
it("should clear cache", function()
Cache:clear()
end)
local max_page = 1
it("should serialize blitbuffer", function()
for pageno = 1, math.min(10, doc.info.number_of_pages) do
for pageno = 1, math.min(max_page, doc.info.number_of_pages) do
doc:renderPage(pageno, nil, 1, 0, 1.0, 0)
Cache:serialize()
end
Cache:clear()
end)
it("should deserialize blitbuffer", function()
for pageno = 1, math.min(10, doc.info.number_of_pages) do
for pageno = 1, math.min(max_page, doc.info.number_of_pages) do
doc:hintPage(pageno, 1, 0, 1.0, 0)
end
Cache:clear()
end)
it("should serialize koptcontext", function()
doc.configurable.text_wrap = 1
for pageno = 1, math.min(10, doc.info.number_of_pages) do
for pageno = 1, math.min(max_page, doc.info.number_of_pages) do
doc:renderPage(pageno, nil, 1, 0, 1.0, 0)
doc:getPageDimensions(pageno)
Cache:serialize()
@ -49,7 +50,7 @@ describe("Cache module", function()
Cache:clear()
end)
it("should deserialize koptcontext", function()
for pageno = 1, math.min(10, doc.info.number_of_pages) do
for pageno = 1, math.min(max_page, doc.info.number_of_pages) do
doc:renderPage(pageno, nil, 1, 0, 1.0, 0)
end
Cache:clear()

@ -1,6 +1,6 @@
require "defaults"
package.path = "?.lua;common/?.lua;frontend/?.lua"
package.cpath = "?.so;common/?.so;/usr/lib/lua/?.so"
package.path = "?.lua;common/?.lua;frontend/?.lua;" .. package.path
package.cpath = "?.so;common/?.so;/usr/lib/lua/?.so;" .. package.cpath
-- global einkfb for Screen
einkfb = require("ffi/framebuffer")

@ -155,13 +155,13 @@ Title:
</feed>
]]
package.path = "?.lua;common/?.lua;frontend/?.lua"
package.path = "?.lua;common/?.lua;frontend/?.lua;" .. package.path
local OPDSParser = require("ui/opdsparser")
local DEBUG = require("dbg")
DEBUG:turnOn()
describe("OPDS parser module", function()
describe("OPDS parser module #nocov", function()
it("should parse OPDS navigation catalog", function()
local catalog = OPDSParser:parse(navigation_sample)
local feed = catalog.feed

Loading…
Cancel
Save