Skip to content

Commit d55268c

Browse files
committed
junit: fix invalid XML for param tests with strs
Fix a bug where the JUnit reporter generated invalid XML for parameterized tests with string arguments. Closes #407
1 parent 2dcbed7 commit d55268c

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
- Fix a bug when the JUnit reporter generating invalid XML for parameterized
6+
tests with string arguments (gh-407).
57
- Group and suite hooks must now be registered using the call-style
68
API. Use:
79

luatest/output/junit.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ function Output.mt:end_suite()
9999

100100
for _, node in ipairs(self.result.tests.all) do
101101
self.fd:write(string.format(' <testcase group="%s" name="%s" time="%0.3f">\n',
102-
node.group.name or '', node.name, node.duration))
102+
Output.xml_escape(node.group.name or ''), Output.xml_escape(node.name or ''), node.duration))
103103
if not node:is('success') then
104104
self.fd:write(self.class.node_status_xml(node))
105105
end

test/luaunit/utility_test.lua

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ local t = require('luatest')
22
local g = t.group()
33

44
local fun = require('fun')
5+
local fio = require('fio')
56
local Runner = require('luatest.runner')
67
local utils = require('luatest.utils')
78

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

790+
function g.test_junit_output_escape_for_attributes()
791+
local tmpdir = fio.tempdir()
792+
local output_path = fio.pathjoin(tmpdir, 'test_junit_escape')
793+
794+
t.assert_equals(helper.run_suite(function(lu2)
795+
local g_positive_start_stages = lu2.group('touching_positive.start.stages', {
796+
{ stage = 'COMPLETED' },
797+
{ stage = 'CANCELLED' },
798+
})
799+
800+
function g_positive_start_stages.test_start() end
801+
end, {'-o', 'junit', '-n', output_path}), 0)
802+
803+
local file = assert(io.open(output_path .. '.xml'))
804+
local xml = file:read('*a')
805+
file:close()
806+
807+
t.assert_str_contains(
808+
xml,
809+
'group="touching_positive.start.stages.stage:&quot;COMPLETED&quot;"'
810+
)
811+
t.assert_str_contains(
812+
xml,
813+
'name="touching_positive.start.stages.stage:&quot;COMPLETED&quot;.test_start"'
814+
)
815+
816+
t.assert_str_contains(
817+
xml,
818+
'group="touching_positive.start.stages.stage:&quot;CANCELLED&quot;"'
819+
)
820+
t.assert_str_contains(
821+
xml,
822+
'name="touching_positive.start.stages.stage:&quot;CANCELLED&quot;.test_start"'
823+
)
824+
825+
fio.rmtree(tmpdir)
826+
end
827+
828+
789829
function g.test_stripStackTrace()
790830
local subject = utils.strip_luatest_trace
791831

0 commit comments

Comments
 (0)