Skip to content
This repository was archived by the owner on Jan 1, 2026. It is now read-only.

Commit e12b2d7

Browse files
committed
Improves validation against JUnit schema
The two functions that generated JUnit XML were missing some required attributes as defined by the JUnit schema: https://raw.githubusercontent.com/windyroad/JUnit-Schema/master/JUnit.xsd This missing attributes were messing with downstream tools that expected those attributes to be present.
1 parent 49e06c6 commit e12b2d7

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

cppcheck_junit.py

100644100755
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import collections
99
import os
1010
import sys
11+
from datetime import datetime
12+
from socket import gethostname
1113
from typing import Dict, List # noqa: F401
1214
from xml.etree import ElementTree
1315

@@ -110,10 +112,12 @@ def generate_test_suite(errors):
110112
XML test suite.
111113
"""
112114
test_suite = ElementTree.Element('testsuite')
113-
test_suite.attrib['errors'] = str(len(errors))
114-
test_suite.attrib['failures'] = str(0)
115115
test_suite.attrib['name'] = 'Cppcheck errors'
116+
test_suite.attrib['timestamp'] = datetime.isoformat(datetime.now())
117+
test_suite.attrib['hostname'] = gethostname()
116118
test_suite.attrib['tests'] = str(len(errors))
119+
test_suite.attrib['failures'] = str(0)
120+
test_suite.attrib['errors'] = str(len(errors))
117121
test_suite.attrib['time'] = str(1)
118122

119123
for file_name, errors in errors.items():
@@ -137,7 +141,12 @@ def generate_single_success_test_suite():
137141
"""Generates a single successful JUnit XML testcase."""
138142
test_suite = ElementTree.Element('testsuite')
139143
test_suite.attrib['name'] = 'Cppcheck errors'
144+
test_suite.attrib['timestamp'] = datetime.isoformat(datetime.now())
145+
test_suite.attrib['hostname'] = gethostname()
140146
test_suite.attrib['tests'] = str(1)
147+
test_suite.attrib['failures'] = str(0)
148+
test_suite.attrib['errors'] = str(0)
149+
test_suite.attrib['time'] = str(1)
141150
ElementTree.SubElement(test_suite,
142151
'testcase',
143152
name='Cppcheck success')

0 commit comments

Comments
 (0)