From 4f35834b2ecddc8a78f424f2b0a0de4cf0034627 Mon Sep 17 00:00:00 2001 From: chrox Date: Wed, 3 Dec 2014 11:01:07 +0800 Subject: [PATCH] wrap computation intensive functions in hook free env when makeing coverage test so that Travis CI job won't fail because of timeout. --- .luacov | 4 ++++ spec/unit/commonrequire.lua | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/.luacov b/.luacov index a6b55357a..41ee69a79 100644 --- a/.luacov +++ b/.luacov @@ -2,6 +2,10 @@ -- project folder as '.luacov' for project specific configuration -- @class module -- @name luacov.defaults + +-- global flag to indicate coverage test +LUACOV = true + return { -- default filename to load for config options if not provided diff --git a/spec/unit/commonrequire.lua b/spec/unit/commonrequire.lua index e9aedbf65..67c8ef4a4 100644 --- a/spec/unit/commonrequire.lua +++ b/spec/unit/commonrequire.lua @@ -21,3 +21,25 @@ Input.dummy = true -- turn on debug local DEBUG = require("dbg") --DEBUG:turnOn() + +-- remove debug hooks in wrapped function for better luacov performance +if LUACOV then + local function hook_free_call(callback) + local hook, mask, count = debug.gethook() + debug.sethook() + local res = callback() + debug.sethook(hook, mask) + return res + end + + local UIManager = require("ui/uimanager") + local uimanager_run = UIManager.run + function UIManager:run() + hook_free_call(function() return uimanager_run(UIManager) end) + end + + local screen_shot = Screen.shot + function Screen:shot(filename) + hook_free_call(function() return screen_shot(Screen, filename) end) + end +end