summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormpeterv <mpeterval@gmail.com>2016-04-17 15:58:26 +0300
committermpeterv <mpeterval@gmail.com>2016-04-17 15:58:26 +0300
commita5ff5b514ec0a0878b24d51a9db3db385e789d71 (patch)
tree9c42f88d1df84be3a51cc74cb6ee45e82daba9fd
parent31b109afa3e20761662c5ccc8f777e4b04e088ab (diff)
downloadluacov-a5ff5b514ec0a0878b24d51a9db3db385e789d71.tar.gz
Change luacov.stats to take statsfile path as argument
-rw-r--r--src/luacov/reporter.lua4
-rw-r--r--src/luacov/runner.lua7
-rw-r--r--src/luacov/stats.lua12
3 files changed, 10 insertions, 13 deletions
diff --git a/src/luacov/reporter.lua b/src/luacov/reporter.lua
index e5c8a83..5236d4f 100644
--- a/src/luacov/reporter.lua
+++ b/src/luacov/reporter.lua
@@ -335,9 +335,7 @@ ReporterBase.__index = ReporterBase
function ReporterBase:new(conf)
local stats = require("luacov.stats")
-
- stats.statsfile = conf.statsfile
- local data = stats.load()
+ local data = stats.load(conf.statsfile)
if not data then
return nil, "Could not load stats file " .. conf.statsfile .. "."
diff --git a/src/luacov/runner.lua b/src/luacov/runner.lua
index 6013485..6bf8c89 100644
--- a/src/luacov/runner.lua
+++ b/src/luacov/runner.lua
@@ -109,7 +109,7 @@ function runner.debug_hook(_, line_nr, level)
ctr = 0
if not paused then
- stats.save(data)
+ stats.save(runner.configuration.statsfile, data)
end
end
end
@@ -385,7 +385,7 @@ function runner.pause()
end
paused = true
- stats.save(data)
+ stats.save(runner.configuration.statsfile, data)
-- Reset data, so that after resuming it could be added to data loaded
-- from the stats file, possibly updated from another process.
data = {}
@@ -400,7 +400,7 @@ function runner.resume()
return
end
- local loaded = stats.load() or {}
+ local loaded = stats.load(runner.configuration.statsfile) or {}
if data then
for name, file in pairs(loaded) do
@@ -475,7 +475,6 @@ end
-- If table then config table (see file `luacov.default.lua` for an example)
function runner.init(configuration)
runner.configuration = runner.load_config(configuration)
- stats.statsfile = runner.configuration.statsfile
tick = runner.tick
runner.resume()
diff --git a/src/luacov/stats.lua b/src/luacov/stats.lua
index 4c5c49b..ecd0c58 100644
--- a/src/luacov/stats.lua
+++ b/src/luacov/stats.lua
@@ -1,20 +1,19 @@
-----------------------------------------------------
-- Manages the file with statistics (being) collected.
--- In general the module requires that its property `stats.statsfile`
--- has been set to the filename of the statsfile to create, load, etc.
-- @class module
-- @name luacov.stats
local stats = {}
-----------------------------------------------------
-- Loads the stats file.
+-- @param statsfile path to the stats file.
-- @return table with data. The table maps filenames to stats tables.
-- Per-file tables map line numbers to hits or nils when there are no hits.
-- Additionally, .max field contains maximum line number
-- and .max_hits contains maximum number of hits in the file.
-function stats.load()
+function stats.load(statsfile)
local data = {}
- local fd = io.open(stats.statsfile, "r")
+ local fd = io.open(statsfile, "r")
if not fd then
return nil
end
@@ -54,9 +53,10 @@ end
--------------------------------
-- Saves data to the statfile
+-- @param statsfile path to the stats file.
-- @param data data to store
-function stats.save(data)
- local fd = io.open(stats.statsfile, "w")
+function stats.save(statsfile, data)
+ local fd = io.open(statsfile, "w")
for filename, filedata in pairs(data) do
local max = filedata.max