[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [ANN] LuaCov 0.2 - coverage analysis tool
- From: Geoff Leyland <geoff_leyland@...>
- Date: Fri, 1 May 2009 09:02:58 +1200
On 1/05/2009, at 3:19 AM, Hisham wrote:
Hello,
I released a minor update to LuaCov (a tiny tool for coverage analysis
written using the debug library) including a fix to a bug reported by
Guilherme Lopes. Version 0.2 is now available at:
http://luacov.luaforge.net/
It's written in pure Lua 5.1 and has no dependencies. More info at
its homepage.
You can also fetch and install it using LuaRocks, of course. :)
Cheers,
-- Hisham
Thanks Hisham, that's really handy!
I made a few changes to luacov to suit me, some or none of which might
be of interest.
- added some exclusion patterns
- "do" and "repeat"
- "local a, b" "local function(a, b)" "local function f(a, b)" and
"local a, b ="
- all the excluded lines ending with comments:
else -- that wasn't the case, so do this instead
- changed the count format to "% 6d", and put asterisks in front of
zeros.
The big exclusion if in luacov started to get a bit mucky, so I tidied
it up. The result is below, if it's of any use.
Cheers,
Geoff
luacov:
...
table.sort(names)
local exclusions =
{
{ false, "^#!" }, -- Unix hash-bang magic line
{ true, "" }, -- Empty line
{ true, "end,?" }, -- Single "end"
{ true, "else" }, -- Single "else"
{ true, "repeat" }, -- Single "repeat"
{ true, "do" }, -- Single "do"
{ true, "local%s+[%w_,%s]+" }, -- "local var1, ..., varN"
{ true, "local%s+[%w_,%s]+%s*=" }, -- "local var1, ..., varN ="
{ true, "local%s+function%s*%([%w_,%s]*%)" }, -- "local
function(arg1, ..., argN)"
{ true, "local%s+function%s+[%w_]*%s*%([%w_,%s]*%)" }, -- "local
function f (arg1, ..., argN)"
}
local function excluded(line)
for _, e in ipairs(exclusions) do
if e[1] then
if line:match("^%s*"..e[2].."%s*$") or line:match("^
%s*"..e[2].."%s*%-%-") then return true end
else
if line:match(e[2]) then return true end
end
end
return false
end
for _, filename in ipairs(names) do
local filedata = data[filename]
local file = io.open(filename, "r")
if file then
report:write("\n")
report:write
("=
=
=
=
=
=
=
=======================================================================
\n")
report:write(filename, "\n")
report:write
("=
=
=
=
=
=
=
=======================================================================
\n")
local line_nr = 1
while true do
local line = file:read("*l")
if not line then break end
if excluded(line) then
report:write(" ", "\t", line, "\n")
else
local hits = filedata[line_nr]
if not hits then hits = 0 end
if hits == 0 then
report:write("*****0", "\t", line, "\n")
else
report:write(("% 6d"):format(hits), "\t", line, "\n")
end
end
line_nr = line_nr + 1
end
end
end