This repository has been archived by the owner on Nov 20, 2020. It is now read-only.
forked from lunarmodules/luacov
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[luadist-git] add luacov-0.2-Darwin-x86_64 [ci skip]
- Loading branch information
0 parents
commit 6085f2b
Showing
25 changed files
with
3,505 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
depends = { | ||
[[lua >= 5.0]], | ||
} | ||
|
||
maintainer = "Peter Drahoš" | ||
type = "x86_64" | ||
version = "0.2" | ||
name = "luacov" | ||
url = "http://luacov.luaforge.net/" | ||
files = { | ||
Data = { | ||
[[share/luacov/README.md]], | ||
} | ||
, | ||
Documentation = { | ||
[[share/luacov/doc//doc/files/src/luacov/defaults.html]], | ||
[[share/luacov/doc//doc/files/src/luacov/init.html]], | ||
[[share/luacov/doc//doc/files/src/luacov/reporter.html]], | ||
[[share/luacov/doc//doc/files/src/luacov/runner.html]], | ||
[[share/luacov/doc//doc/files/src/luacov/stats.html]], | ||
[[share/luacov/doc//doc/files/src/luacov/tick.html]], | ||
[[share/luacov/doc//doc/index.html]], | ||
[[share/luacov/doc//doc/luadoc.css]], | ||
[[share/luacov/doc//doc/modules/luacov.defaults.html]], | ||
[[share/luacov/doc//doc/modules/luacov.html]], | ||
[[share/luacov/doc//doc/modules/luacov.reporter.html]], | ||
[[share/luacov/doc//doc/modules/luacov.runner.html]], | ||
[[share/luacov/doc//doc/modules/luacov.stats.html]], | ||
[[share/luacov/doc//doc/modules/luacov.tick.html]], | ||
[[share/luacov/doc//doc.css]], | ||
[[share/luacov/doc//index.html]], | ||
[[share/luacov/doc//license.html]], | ||
[[share/luacov/doc//luacov.png]], | ||
} | ||
, | ||
Other = { | ||
[[share/luacov/etc/luacov]], | ||
} | ||
, | ||
Runtime = { | ||
[[lib/lua/luacov.lua]], | ||
[[lib/lua/luacov/stats.lua]], | ||
[[lib/lua/luacov/tick.lua]], | ||
[[bin/luacov]], | ||
} | ||
, | ||
} | ||
|
||
arch = "Darwin" | ||
license = "MIT/X11" | ||
author = "Hisham Muhammad" | ||
desc = "LuaCov is a simple coverage analysis tool for Lua scripts." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- Loads <code>luacov.runner</code> and immediately starts it. | ||
-- Useful for launching scripts from the command-line. | ||
-- @class module | ||
-- @name luacov | ||
-- @example lua -lluacov sometest.lua | ||
local runner = require("luacov.runner") | ||
runner.init() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
----------------------------------------------------- | ||
-- Manages the file with statistics (being) collected. | ||
-- In general the module requires that its property <code>stats.statsfile</code> | ||
-- has been set to the filename of the statsfile to create, load, etc. | ||
-- @class module | ||
-- @name luacov.stats | ||
local M = {} | ||
|
||
----------------------------------------------------- | ||
-- Loads the stats file. | ||
-- @return table with data | ||
-- @return hitcount of the line with the most hits (to provide the widest number format for reporting) | ||
function M.load() | ||
local data, most_hits = {}, 0 | ||
local stats = io.open(M.statsfile, "r") | ||
if not stats then | ||
return nil | ||
end | ||
while true do | ||
local nlines = stats:read("*n") | ||
if not nlines then | ||
break | ||
end | ||
local skip = stats:read(1) | ||
if skip ~= ":" then | ||
break | ||
end | ||
local filename = stats:read("*l") | ||
if not filename then | ||
break | ||
end | ||
data[filename] = { | ||
max=nlines | ||
} | ||
for i = 1, nlines do | ||
local hits = stats:read("*n") | ||
if not hits then | ||
break | ||
end | ||
local skip = stats:read(1) | ||
if skip ~= " " then | ||
break | ||
end | ||
if hits > 0 then | ||
data[filename][i] = hits | ||
most_hits = math.max(most_hits, hits) | ||
end | ||
end | ||
end | ||
stats:close() | ||
return data, most_hits | ||
end | ||
|
||
-------------------------------- | ||
-- Opens the statfile | ||
-- @return filehandle | ||
function M.start() | ||
return io.open(M.statsfile, "w") | ||
end | ||
|
||
-------------------------------- | ||
-- Closes the statfile | ||
-- @param stats filehandle to the statsfile | ||
function M.stop(stats) | ||
stats:close() | ||
end | ||
|
||
-------------------------------- | ||
-- Saves data to the statfile | ||
-- @param data data to store | ||
-- @param stats filehandle where to store | ||
function M.save(data, stats) | ||
stats:seek("set") | ||
for filename, filedata in pairs(data) do | ||
local max = filedata.max | ||
stats:write(max, ":", filename, "\n") | ||
for i = 1, max do | ||
local hits = filedata[i] | ||
if not hits then | ||
hits = 0 | ||
end | ||
stats:write(hits, " ") | ||
end | ||
stats:write("\n") | ||
end | ||
stats:flush() | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
--- Load luacov using this if you want it to periodically | ||
-- save the stats file. This is useful if your script is | ||
-- a daemon (ie, does not properly terminate.) | ||
-- @class module | ||
-- @name luacov.tick | ||
require("luacov") | ||
return {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
## Overview | ||
|
||
LuaCov is a simple coverage analyzer for [Lua](http://www.lua.org) scripts. | ||
When a Lua script is run with the `luacov` module loaded, it generates a stats | ||
file with the number of executions of each line of the script and its loaded | ||
modules. The `luacov` command-line script then processes this file generating | ||
a report file which allows one to visualize which code paths were not | ||
traversed, which is useful for verifying the effectiveness of a test suite. | ||
|
||
LuaCov is free software and, like Lua, is released under the [MIT | ||
License](http://www.lua.org/license.html). | ||
|
||
## Download and Installation | ||
|
||
LuaCov can be downloaded from its [Github downloads | ||
page](https://github.com/keplerproject/luacov/releases). | ||
|
||
It can also be installed using Luarocks: | ||
|
||
luarocks install luacov | ||
|
||
LuaCov is written in pure Lua and has no external dependencies. | ||
|
||
## Instructions | ||
|
||
Using LuaCov consists of two steps: running your script to collect coverage | ||
data, and then running `luacov` on the collected data to generate a report | ||
(see _configuration_ below for other options). | ||
|
||
To collect coverage data, your script needs to load the `luacov` Lua module. | ||
This can be done from the command-line, without modifying your script, like | ||
this: | ||
|
||
lua -lluacov test.lua | ||
|
||
Alternatively, you can add `require("luacov")` to the first line of your | ||
script. | ||
|
||
Once the script is run, a file called `luacov.stats.out` is generated. If the | ||
file already exists, statistics are _added_ to it. This is useful, for | ||
example, for making a series of runs with different input parameters in a test | ||
suite. To start the accounting from scratch, just delete the stats file. | ||
|
||
To generate a report, just run the `luacov` command-line script. It expects to | ||
find a file named `luacov.stats.out` in the current directory, and outputs a | ||
file named `luacov.report.out`. The script take the following parameters; | ||
|
||
luacov [-c=configfile] [filename [ filename[ ...]]] | ||
|
||
For the `-c` option see below at _configuration_. The filenames (actually | ||
patterns) indicate the files to include in the report, specifying them here | ||
equals to adding them to the `include` list in the configuration file. | ||
|
||
This is an example output of the report file: | ||
|
||
============================================================ | ||
../test.lua | ||
============================================================ | ||
|
||
-- Which branch will run? | ||
1 if 10 > 100 then | ||
0 print("I don't think this line will execute.") | ||
0 else | ||
1 print("Hello, LuaCov!") | ||
1 end | ||
|
||
Note that to generate this report, `luacov` reads the source files. Therefore, | ||
it expects to find them in the same location they were when the `luacov` | ||
module ran (the stats file stores the filenames, but not the sources | ||
themselves). | ||
|
||
LuaCov saves its stats upon normal program termination. If your program is a | ||
daemon -- in other words, if it does not terminate normally -- you can use the | ||
`luacov.tick` module, which periodically saves the stats file. For example, to | ||
run (on Unix systems) LuaCov on | ||
[Xavante](http://www.keplerproject.org/xavante), just modify the first line of | ||
`xavante_start.lua` so it reads: | ||
|
||
#!/usr/bin/env lua -lluacov.tick | ||
|
||
|
||
## Configuration | ||
|
||
LuaCov includes several configuration options, which have their defaults | ||
stored in `/luacov/defaults.lua`. These are the global defaults. To create | ||
project specific defaults, copy the file and store it as `.luacov` in the | ||
project directory from where `luacov` is being run. | ||
|
||
Options include changing filenames, automatic report generation upon | ||
completion and removal of the stats after generating the report. | ||
|
||
## Credits | ||
|
||
LuaCov was designed and implemented by Hisham Muhammad as a tool for testing | ||
[LuaRocks](http://www.luarocks.org). |
Oops, something went wrong.