Skip to content

Commit 6608eb2

Browse files
committed
fix: calculation of coverage percentage
1 parent 7dc5cb7 commit 6608eb2

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
- Fix error trace reporting for functions executed with `Server:exec()`
2424
(gh-396).
2525
- Remove pretty-printing of `luatest.log` arguments.
26+
- Fixed calculation of coverage percentage (gh-402)
2627

2728
## 1.0.1
2829

luatest/coverage_utils.lua

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@ local function with_cwd(dir, fn)
2929
assert(fio.chdir(old), 'Failed to chdir to ' .. old)
3030
end
3131

32+
local function find_luas(list_of_lua_modules, path)
33+
for _, filename in pairs(fio.listdir(path)) do
34+
local full_filename = fio.pathjoin(path, filename)
35+
if fio.path.is_dir(full_filename) then
36+
find_luas(list_of_lua_modules, full_filename)
37+
elseif full_filename:endswith(".lua") then
38+
list_of_lua_modules[full_filename] = {max = 0, max_hits = 0}
39+
end
40+
end
41+
end
42+
3243
function export.enable()
3344
local root = os.getenv('LUATEST_LUACOV_ROOT')
3445
if not root then
@@ -42,6 +53,10 @@ function export.enable()
4253
for _, item in pairs(export.DEFAULT_EXCLUDE) do
4354
table.insert(config.exclude, item)
4455
end
56+
57+
runner.data = {}
58+
find_luas(runner.data, root)
59+
4560
runner.init(config)
4661
end)
4762
end

0 commit comments

Comments
 (0)