Skip to content

Commit

Permalink
chore: better junit report
Browse files Browse the repository at this point in the history
  • Loading branch information
myzhan committed Jul 5, 2024
1 parent 269a348 commit 15e02e7
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions busted/outputHandlers/junit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -127,36 +127,39 @@ return function(options)
end
end

local function get_junit_info(path)
local junit_report_package_name, test_file_name
local function get_package_and_file(path)
local package, file

if string.match(path, "/") or string.match(path, "\\") then
-- Compatible with Windows platform
junit_report_package_name, test_file_name = path:match("(.-)[\\/]+([^\\/]+)$")
package, file = path:match("(.-)[\\/]+([^\\/]+)$")
else
test_file_name = path
junit_report_package_name = ""
package, file = "", path
end

return junit_report_package_name, test_file_name
return package, file
end

handler.testStart = function(element, parent)
local junit_classname
local test_case_full_name = handler.getFullName(element)
local junit_report_package_name, test_file_name = get_junit_info(element.trace.short_src)
local package, file_name = get_package_and_file(element.trace.source)

-- Jenkins CI Junit Plugin use the last one . to distinguish between package name and class name.
local junit_class_name = string.gsub(test_file_name, "%.", "_")
local class_name = string.gsub(file_name, "%.", "_")

if junit_report_package_name ~= "" then
junit_classname = junit_report_package_name .. "." .. junit_class_name ..":" .. element.trace.currentline
if package and package ~= "" then
if package:find("^@") then
package = string.sub(package, 2)
end
package = string.gsub(package, "/", ".")
classname = package .. "." .. class_name .. ":" .. element.trace.currentline
else
junit_classname = junit_class_name ..":" .. element.trace.currentline
classname = class_name .. ":" .. element.trace.currentline
end

testcase_node = xml.new('testcase', {
-- junit report uses package names and class names to structurally display result.
classname = junit_classname,
classname = classname,
name = test_case_full_name
})
top.xml_doc:add_direct_child(testcase_node)
Expand Down

0 comments on commit 15e02e7

Please sign in to comment.