From f1f8d8dc4f4caa0e2b18e2d150f2d45147ed541f Mon Sep 17 00:00:00 2001 From: chrox Date: Mon, 6 Oct 2014 21:31:04 +0800 Subject: [PATCH] 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'. --- .luacov | 58 +++++++++++++++++++++++++++++++++++ .travis.yml | 2 ++ Makefile | 11 +++++++ spec/unit/cache_spec.lua | 13 ++++---- spec/unit/document_spec.lua | 4 +-- spec/unit/opdsparser_spec.lua | 4 +-- 6 files changed, 82 insertions(+), 10 deletions(-) create mode 100644 .luacov diff --git a/.luacov b/.luacov new file mode 100644 index 000000000..a96959446 --- /dev/null +++ b/.luacov @@ -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', + }, + + +} diff --git a/.travis.yml b/.travis.yml index ca0ac94f4..7a0bf9fcf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/Makefile b/Makefile index 732fe99c8..d0247c0e7 100644 --- a/Makefile +++ b/Makefile @@ -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: diff --git a/spec/unit/cache_spec.lua b/spec/unit/cache_spec.lua index f32ff3f8e..d6f909173 100644 --- a/spec/unit/cache_spec.lua +++ b/spec/unit/cache_spec.lua @@ -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() diff --git a/spec/unit/document_spec.lua b/spec/unit/document_spec.lua index ca84cbeda..53c454de3 100644 --- a/spec/unit/document_spec.lua +++ b/spec/unit/document_spec.lua @@ -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") diff --git a/spec/unit/opdsparser_spec.lua b/spec/unit/opdsparser_spec.lua index 2e54cdcc6..ef4fca8f8 100644 --- a/spec/unit/opdsparser_spec.lua +++ b/spec/unit/opdsparser_spec.lua @@ -155,13 +155,13 @@ Title: ]] -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