diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2012-08-23 22:02:42 +0100 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2012-08-23 22:02:42 +0100 |
commit | 142d1bc7549f04c29d4ca78ee5f796562a533435 (patch) | |
tree | a3009ba6f689ac9d6693b5d096733a54a18774ca /extras/luacov/src/luacov/stats.lua | |
parent | c85355947228b02d1e353c29530b185967ea86fe (diff) | |
download | clod-142d1bc7549f04c29d4ca78ee5f796562a533435.tar.gz |
TEST: Initial test suite, plus coverage code
Diffstat (limited to 'extras/luacov/src/luacov/stats.lua')
-rw-r--r-- | extras/luacov/src/luacov/stats.lua | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/extras/luacov/src/luacov/stats.lua b/extras/luacov/src/luacov/stats.lua new file mode 100644 index 0000000..5390c75 --- /dev/null +++ b/extras/luacov/src/luacov/stats.lua @@ -0,0 +1,73 @@ + +local M = {} + +local statsfile = "luacov.stats.out" +local stats + +function M.load() + local data, most_hits = {}, 0 + stats = io.open(statsfile, "r") + if not stats then + return data + 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 + +function M.start() + return io.open(statsfile, "w") +end + +function M.stop(stats) + stats:close() +end + +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 |