Skip to content

Commit

Permalink
chore(junit): Improve report formatting to avoid truncation (#742)
Browse files Browse the repository at this point in the history
  • Loading branch information
myzhan authored Oct 22, 2024
1 parent d1ba841 commit a2c755b
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions busted/outputHandlers/junit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -127,36 +127,38 @@ 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
class_name = package .. "." .. class_name .. ":" .. element.trace.currentline
else
junit_classname = junit_class_name ..":" .. element.trace.currentline
class_name = 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 = class_name,
name = test_case_full_name
})
top.xml_doc:add_direct_child(testcase_node)
Expand Down

0 comments on commit a2c755b

Please sign in to comment.