Skip to content

Commit

Permalink
Merge pull request #10 from oocytanb/fix/directory_separator_for_windows
Browse files Browse the repository at this point in the history
Fix the directory separator for windows
  • Loading branch information
to-kr authored Dec 20, 2022
2 parents 0b12ea9 + f794727 commit acce8f6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/luacov/multiple/tools.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,10 @@ function tools.toxml(value, indentation)
return xml
end

local separator_is_backslash = string.match(package.config, "^[^\n]+") == "\\"

function tools.normalize_path(path)
return separator_is_backslash and (path:gsub("\\", "/")) or path
end

return tools
5 changes: 3 additions & 2 deletions src/luacov/reporter/multiple/cobertura.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ function CoberturaReporter:on_start()
end

function CoberturaReporter:on_new_file(filename)
local norm_filename = tools.normalize_path(filename)
-- "test/package/file.lua" -> "file.lua"
local class_name = filename:gsub("^.*/", "")
local class_name = norm_filename:gsub("^.*/", "")
-- "test/package/file.lua" -> "test/package"
local package_name = filename:gsub(filename:gsub("^.*/", ""), ""):gsub("/$", "")
local package_name = norm_filename:gsub(norm_filename:gsub("^.*/", ""), ""):gsub("/$", "")

local package
for _,p in pairs(self.cobertura.coverage.packages) do
Expand Down
8 changes: 5 additions & 3 deletions src/luacov/reporter/multiple/html.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,12 @@ function HtmlReporter:on_start()
end

function HtmlReporter:on_new_file(filename)
local norm_filename = tools.normalize_path(filename)
-- class_name: "test/package/file.lua" -> "file.lua"
-- package_name: "test/package/file.lua" -> "test/package"
local package_name, class_name = filename:match("^(.*)/([^/]+)")
local package_name, class_name = norm_filename:match("^(.*)/([^/]+)")
class_name = class_name or ""
package_name = package_name or filename
package_name = package_name or norm_filename

local package
for _, p in pairs(self.data.coverage.packages) do
Expand Down Expand Up @@ -121,6 +122,7 @@ end
-- @param hits
-- @param miss
function HtmlReporter:on_end_file(filename, hits, miss)
local norm_filename = tools.normalize_path(filename)
self.current_package["hits"] = self.current_package["hits"] + hits
self.current_package["miss"] = self.current_package["miss"] + miss
self.current_package["rate"] =
Expand Down Expand Up @@ -152,7 +154,7 @@ function HtmlReporter:on_end_file(filename, hits, miss)
out:write(lustache:render(templateFile, {
css = css,
filename = filename,
basename = filename:gsub("(.*/)(.*)", "%2"),
basename = norm_filename:gsub("(.*/)(.*)", "%2"),
packageParts = packageParts,
lines = self.current_class.lines,
path = self.current_package.name,
Expand Down

0 comments on commit acce8f6

Please sign in to comment.