Skip to content

Commit

Permalink
fix: calculation of coverage percentage
Browse files Browse the repository at this point in the history
  • Loading branch information
a1div0 committed Nov 13, 2024
1 parent 7dc5cb7 commit 6608eb2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
- Fix error trace reporting for functions executed with `Server:exec()`
(gh-396).
- Remove pretty-printing of `luatest.log` arguments.
- Fixed calculation of coverage percentage (gh-402)

## 1.0.1

Expand Down
15 changes: 15 additions & 0 deletions luatest/coverage_utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ local function with_cwd(dir, fn)
assert(fio.chdir(old), 'Failed to chdir to ' .. old)
end

local function find_luas(list_of_lua_modules, path)
for _, filename in pairs(fio.listdir(path)) do
local full_filename = fio.pathjoin(path, filename)
if fio.path.is_dir(full_filename) then
find_luas(list_of_lua_modules, full_filename)
elseif full_filename:endswith(".lua") then
list_of_lua_modules[full_filename] = {max = 0, max_hits = 0}
end
end
end

function export.enable()
local root = os.getenv('LUATEST_LUACOV_ROOT')
if not root then
Expand All @@ -42,6 +53,10 @@ function export.enable()
for _, item in pairs(export.DEFAULT_EXCLUDE) do
table.insert(config.exclude, item)
end

runner.data = {}
find_luas(runner.data, root)

runner.init(config)
end)
end
Expand Down

0 comments on commit 6608eb2

Please sign in to comment.