Skip to content
Open
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- Fixed a bug when the JUnit reporter generated invalid XML for parameterized
tests with string arguments (gh-407).
- Group and suite hooks must now be registered using the call-style
API. Use:

Expand Down
2 changes: 1 addition & 1 deletion luatest/output/junit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function Output.mt:end_suite()

for _, node in ipairs(self.result.tests.all) do
self.fd:write(string.format(' <testcase group="%s" name="%s" time="%0.3f">\n',
node.group.name or '', node.name, node.duration))
Output.xml_escape(node.group.name or ''), Output.xml_escape(node.name or ''), node.duration))
if not node:is('success') then
self.fd:write(self.class.node_status_xml(node))
end
Expand Down
6 changes: 5 additions & 1 deletion luatest/parametrizer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ local function get_group_name(params)
table.sort(params_names)

for ind, param_name in ipairs(params_names) do
params_names[ind] = param_name .. ':' .. pp.tostring(params[param_name])
local param = params[param_name]
if type(param) ~= 'string' then
param = pp.tostring(param)
end
params_names[ind] = param_name .. ':' .. param
end
return table.concat(params_names, ".")
end
Expand Down
40 changes: 40 additions & 0 deletions test/luaunit/utility_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local t = require('luatest')
local g = t.group()

local fun = require('fun')
local fio = require('fio')
local Runner = require('luatest.runner')
local utils = require('luatest.utils')

Expand Down Expand Up @@ -786,6 +787,45 @@ function g.test_xml_c_data_escape()
t.assert_equals(subject("a<b]]>--"), 'a<b]]&gt;--')
end

function g.test_junit_output_escape_for_attributes()
local tmpdir = fio.tempdir()
local output_path = fio.pathjoin(tmpdir, 'test_junit_escape')

t.assert_equals(helper.run_suite(function(lu2)
local g_positive_start_stages = lu2.group('touching_positive.start.stages', {
{ stage = 'COMPLETED' },
{ stage = 'CANCELLED' },
})

function g_positive_start_stages.test_start() end
end, {'-o', 'junit', '-n', output_path}), 0)

local file = assert(io.open(output_path .. '.xml'))
local xml = file:read('*a')
file:close()

t.assert_str_contains(
xml,
'group="touching_positive.start.stages.stage:COMPLETED"'
)
t.assert_str_contains(
xml,
'name="touching_positive.start.stages.stage:COMPLETED.test_start"'
)

t.assert_str_contains(
xml,
'group="touching_positive.start.stages.stage:CANCELLED"'
)
t.assert_str_contains(
xml,
'name="touching_positive.start.stages.stage:CANCELLED.test_start"'
)

fio.rmtree(tmpdir)
end


function g.test_stripStackTrace()
local subject = utils.strip_luatest_trace

Expand Down
Loading