summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2017-03-04 16:08:27 +0000
committerDaniel Silverstone <dsilvers@digital-scurf.org>2017-03-04 17:35:18 +0000
commitb609d07be3b37f81f5c05ae56bd427d16bb6f5c9 (patch)
treec38a7b0c0bd126e989cb7582a1f9fbd30333adb5 /utils
parentf2f5b4e6229532f3ba69e9f32bc3305e37b20f4c (diff)
downloadgitano-b609d07be3b37f81f5c05ae56bd427d16bb6f5c9.tar.gz
adds support for coverage testing
Diffstat (limited to 'utils')
-rw-r--r--utils/install-lua-bin38
-rw-r--r--utils/merge-luacov-stats66
2 files changed, 99 insertions, 5 deletions
diff --git a/utils/install-lua-bin b/utils/install-lua-bin
index 41a7bd2..1f27a49 100644
--- a/utils/install-lua-bin
+++ b/utils/install-lua-bin
@@ -27,7 +27,9 @@
-- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-- SUCH DAMAGE.
-local lua_bin, inst_share_path, inst_bin_path, inst_mod_path, inst_plugin_path, input_name, output_name = ...
+local lua_bin, inst_share_path, inst_bin_path, inst_mod_path, inst_plugin_path, input_name, output_name, coverage_path, report_path = ...
+
+local luxio = require("luxio")
local input_fh = assert(io.open(input_name, "r"))
local output_fh = assert(io.open(output_name, "w"))
@@ -39,6 +41,22 @@ if not inst_mod_path:match("%?") then
inst_mod_path = inst_mod_path:gsub("/+", "/")
end
+if coverage_path and coverage_path == "" then
+ coverage_path = nil
+end
+
+if coverage_path and not coverage_path:match("%?") then
+ coverage_path = coverage_path .. "/?.lua"
+ coverage_path = coverage_path:gsub("/+", "/")
+end
+
+local coverage_part
+if coverage_path then
+ -- We are generating coverage, the part is the leafname of the
+ -- output binary
+ coverage_part = output_name:gsub("^.+/", "")
+end
+
local mod_path_present = false
for path_elem in package.path:gmatch("([^;]+)") do
if path_elem == inst_mod_path then
@@ -65,12 +83,20 @@ while line do
elseif token == "GITANO_LUA_PATH" then
if not mod_path_present then
output_fh:write(("package.path = ('%%s;%%s'):" ..
- "format(%q, package.path)" ..
- "\n"):format(inst_mod_path))
+ "format(%q, package.path)"
+ ):format(inst_mod_path))
else
- output_fh:write("-- Gitano modules installed into " ..
- inst_mod_path .. "\n")
+ output_fh:write("--[[Gitano modules installed into " ..
+ inst_mod_path .. "]]")
+ end
+ if coverage_path then
+ output_fh:write((" package.path = ('%%s;%%s'):" ..
+ "format(%q, package.path)"
+ ):format(coverage_path))
+ output_fh:write((" require('gitano.coverage').begin(%q, %q)"
+ ):format(report_path, coverage_part))
end
+ output_fh:write("\n")
elseif token == "GITANO_BIN_PATH" then
output_fh:write(("gitano.config.lib_bin_path(%q)\n"):format(inst_bin_path))
elseif token == "GITANO_SHARE_PATH" then
@@ -82,6 +108,8 @@ while line do
else
output_fh:write("-- Unknown token: " .. token .. "\n")
end
+ elseif line:match("@@%.luacov@@") then
+ output_fh:write(line:gsub("@@%.luacov@@", luxio.getcwd() .. "/.luacov") .. "\n")
else
output_fh:write(line .. "\n")
end
diff --git a/utils/merge-luacov-stats b/utils/merge-luacov-stats
new file mode 100644
index 0000000..f4b28ae
--- /dev/null
+++ b/utils/merge-luacov-stats
@@ -0,0 +1,66 @@
+-- Run this explicitly through -*- Lua -*-
+
+-- Copyright 2017 Daniel Silverstone <dsilvers@digital-scurf.org>
+-- All rights reserved.
+--
+-- Redistribution and use in source and binary forms, with or without
+-- modification, are permitted provided that the following conditions
+-- are met:
+-- 1. Redistributions of source code must retain the above copyright
+-- notice, this list of conditions and the following disclaimer.
+-- 2. Redistributions in binary form must reproduce the above copyright
+-- notice, this list of conditions and the following disclaimer in the
+-- documentation and/or other materials provided with the distribution.
+-- 3. Neither the name of the author nor the names of their contributors
+-- may be used to endorse or promote products derived from this software
+-- without specific prior written permission.
+--
+-- THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+-- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+-- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+-- ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+-- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+-- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+-- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+-- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+-- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+-- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+-- SUCH DAMAGE.
+
+local infiles = {...}
+
+local stats = require("luacov.stats")
+
+-- Step 1, merge all the coverage files together into a single one...
+
+local merged = {}
+
+function merge_data(fname)
+ local subdata = stats.load(fname)
+ for fname, fdat in pairs(subdata) do
+ if not merged[fname] then
+ merged[fname] = fdat
+ else
+ for i = 1, fdat.max do
+ merged[fname][i] = (merged[fname][i] or 0) + (fdat[i] or 0)
+ end
+ end
+ end
+end
+
+local percent = 0
+for i = 1, #infiles do
+ merge_data(infiles[i])
+ local newpercent = math.floor((i*100) / #infiles)
+ if (newpercent - percent > 0) or (newpercent == 100) then
+ io.stdout:write(("COVERAGE: %3d%% merged.\r"):format(newpercent))
+ percent = newpercent
+ io.stdout:flush();
+ end
+end
+io.stdout:write("\n");
+
+-- Step 2, write it all out
+
+print("Saving merged stats")
+stats.save("luacov.stats.out", merged)