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

opt: truncated package name in junit report #742

Merged
merged 3 commits into from
Oct 22, 2024
Merged
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
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
Loading