Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: calculation of coverage percentage #403

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bad changelog - unclear what exactly was wrong. Would be nice to say that it added uncovered files to the coverage report.

Also, please write a descriptive commit message. It should include Closes #XXX. We don't start subject lines with "fix: ...". Should probably be "Add uncovered files to coverage report".


## 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accessing undocumented fields of luacov.runner. looks dangerous. At least, this requires a comment.

The only alternative I see is writing a coverage report file with zero counters before initializing luacov.runner. This could be done with luacov.stats.save.

@Totktonada WDYT?


runner.init(config)
end)
end
Expand Down
Loading