From 794baf4d8a5817c340cb3456a169df69eed0e5f0 Mon Sep 17 00:00:00 2001 From: chrox Date: Mon, 6 Oct 2014 21:22:38 +0800 Subject: [PATCH 1/6] benchmark has no specifications so won't be run by default --- spec/unit/{benchmark_spec.lua => benchmark.lua} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename spec/unit/{benchmark_spec.lua => benchmark.lua} (100%) diff --git a/spec/unit/benchmark_spec.lua b/spec/unit/benchmark.lua similarity index 100% rename from spec/unit/benchmark_spec.lua rename to spec/unit/benchmark.lua From 330e5a2789d59edda1b9d334bea30ca8585ee705 Mon Sep 17 00:00:00 2001 From: chrox Date: Mon, 6 Oct 2014 21:23:54 +0800 Subject: [PATCH 2/6] don't open SDL if input device is dummy --- frontend/ui/input.lua | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/frontend/ui/input.lua b/frontend/ui/input.lua index 5e0c457d4..5db69b84a 100644 --- a/frontend/ui/input.lua +++ b/frontend/ui/input.lua @@ -345,11 +345,8 @@ function Input:init() self.event_map[10021] = "NotCharging" if util.isEmulated() then - if not util.isWindows() then - os.remove("/tmp/emu_event") - os.execute("mkfifo /tmp/emu_event") - input.open("/tmp/emu_event") - end + -- open SDL if it's not dummy input device + if not self.dummy then input.open() end -- SDL key codes if not util.haveSDL2() then self.event_map = self.sdl_event_map From f1f8d8dc4f4caa0e2b18e2d150f2d45147ed541f Mon Sep 17 00:00:00 2001 From: chrox Date: Mon, 6 Oct 2014 21:31:04 +0800 Subject: [PATCH 3/6] 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 From 770245418ce10b60ac910e829e98f22e97a22435 Mon Sep 17 00:00:00 2001 From: chrox Date: Mon, 6 Oct 2014 22:28:55 +0800 Subject: [PATCH 4/6] install luajit for luacov in Travis --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7a0bf9fcf..d428edd72 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,7 +19,7 @@ install: - sudo luarocks install luacov script: - - make fetchthirdparty - - make + - make fetchthirdparty all + - sudo cp base/build/*/luajit /usr/bin/ - make testfront - make coverage From 3a98b4b0f76f2bc50ca51751f05cdc0334c4f9f3 Mon Sep 17 00:00:00 2001 From: chrox Date: Mon, 6 Oct 2014 23:36:13 +0800 Subject: [PATCH 5/6] add coveralls badge to show coverage number --- .luacov | 2 +- .travis.yml | 4 ++++ README.md | 7 +++++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.luacov b/.luacov index a96959446..656b1cef0 100644 --- a/.luacov +++ b/.luacov @@ -18,7 +18,7 @@ return { runreport = true, -- Delete stats file after reporting? - deletestats = true, + deletestats = false, -- Patterns for files to include when reporting -- all will be included if nothing is listed diff --git a/.travis.yml b/.travis.yml index d428edd72..61d8613e2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,9 +17,13 @@ install: - git clone https://github.com/Olivine-Labs/busted/ - cd busted && git checkout v1.10.0 && sudo luarocks make && cd .. - sudo luarocks install luacov + - sudo luarocks install luacov-coveralls --server=http://rocks.moonscript.org/dev script: - make fetchthirdparty all - sudo cp base/build/*/luajit /usr/bin/ - make testfront - make coverage + +after_success: + - cd koreader-*/koreader && luacov-coveralls -v diff --git a/README.md b/README.md index fea2fd372..5d34ac3ff 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ -KOReader [![Build Status][travis-icon]][travis-link] +KOReader +[![Build Status][travis-icon]][travis-link] +[![Coverage Status][coverage-icon]][coverage-link] ======== KOReader is a document viewer application, originally created for Kindle @@ -189,4 +191,5 @@ http://ccache.samba.org [linux-vm]:http://www.howtogeek.com/howto/11287/how-to-run-ubuntu-in-windows-7-with-vmware-player/ [l10n-readme]:https://github.com/koreader/koreader/blob/master/l10n/README.md [koreader-transifex]:https://www.transifex.com/projects/p/koreader/ - +[coverage-icon]:https://coveralls.io/repos/koreader/koreader/badge.png +[coverage-link]:https://coveralls.io/r/koreader/koreader From 5cf50c1401af2d7ffd9d661ea3e958be25da9177 Mon Sep 17 00:00:00 2001 From: Huang Xin Date: Mon, 6 Oct 2014 23:54:56 +0800 Subject: [PATCH 6/6] Update README.md --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index 5d34ac3ff..5bbbd20b7 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,4 @@ -KOReader -[![Build Status][travis-icon]][travis-link] -[![Coverage Status][coverage-icon]][coverage-link] +KOReader [![Build Status][travis-icon]][travis-link] [![Coverage Status][coverage-icon]][coverage-link] ======== KOReader is a document viewer application, originally created for Kindle